smb2pdu.h 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  1. /*
  2. * fs/cifs/smb2pdu.h
  3. *
  4. * Copyright (c) International Business Machines Corp., 2009, 2013
  5. * Etersoft, 2012
  6. * Author(s): Steve French (sfrench@us.ibm.com)
  7. * Pavel Shilovsky (pshilovsky@samba.org) 2012
  8. *
  9. * This library is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU Lesser General Public License as published
  11. * by the Free Software Foundation; either version 2.1 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  17. * the GNU Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public License
  20. * along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #ifndef _SMB2PDU_H
  24. #define _SMB2PDU_H
  25. #include <net/sock.h>
  26. /*
  27. * Note that, due to trying to use names similar to the protocol specifications,
  28. * there are many mixed case field names in the structures below. Although
  29. * this does not match typical Linux kernel style, it is necessary to be
  30. * be able to match against the protocol specfication.
  31. *
  32. * SMB2 commands
  33. * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses
  34. * (ie no useful data other than the SMB error code itself) and are marked such.
  35. * Knowing this helps avoid response buffer allocations and copy in some cases.
  36. */
  37. /* List of commands in host endian */
  38. #define SMB2_NEGOTIATE_HE 0x0000
  39. #define SMB2_SESSION_SETUP_HE 0x0001
  40. #define SMB2_LOGOFF_HE 0x0002 /* trivial request/resp */
  41. #define SMB2_TREE_CONNECT_HE 0x0003
  42. #define SMB2_TREE_DISCONNECT_HE 0x0004 /* trivial req/resp */
  43. #define SMB2_CREATE_HE 0x0005
  44. #define SMB2_CLOSE_HE 0x0006
  45. #define SMB2_FLUSH_HE 0x0007 /* trivial resp */
  46. #define SMB2_READ_HE 0x0008
  47. #define SMB2_WRITE_HE 0x0009
  48. #define SMB2_LOCK_HE 0x000A
  49. #define SMB2_IOCTL_HE 0x000B
  50. #define SMB2_CANCEL_HE 0x000C
  51. #define SMB2_ECHO_HE 0x000D
  52. #define SMB2_QUERY_DIRECTORY_HE 0x000E
  53. #define SMB2_CHANGE_NOTIFY_HE 0x000F
  54. #define SMB2_QUERY_INFO_HE 0x0010
  55. #define SMB2_SET_INFO_HE 0x0011
  56. #define SMB2_OPLOCK_BREAK_HE 0x0012
  57. /* The same list in little endian */
  58. #define SMB2_NEGOTIATE cpu_to_le16(SMB2_NEGOTIATE_HE)
  59. #define SMB2_SESSION_SETUP cpu_to_le16(SMB2_SESSION_SETUP_HE)
  60. #define SMB2_LOGOFF cpu_to_le16(SMB2_LOGOFF_HE)
  61. #define SMB2_TREE_CONNECT cpu_to_le16(SMB2_TREE_CONNECT_HE)
  62. #define SMB2_TREE_DISCONNECT cpu_to_le16(SMB2_TREE_DISCONNECT_HE)
  63. #define SMB2_CREATE cpu_to_le16(SMB2_CREATE_HE)
  64. #define SMB2_CLOSE cpu_to_le16(SMB2_CLOSE_HE)
  65. #define SMB2_FLUSH cpu_to_le16(SMB2_FLUSH_HE)
  66. #define SMB2_READ cpu_to_le16(SMB2_READ_HE)
  67. #define SMB2_WRITE cpu_to_le16(SMB2_WRITE_HE)
  68. #define SMB2_LOCK cpu_to_le16(SMB2_LOCK_HE)
  69. #define SMB2_IOCTL cpu_to_le16(SMB2_IOCTL_HE)
  70. #define SMB2_CANCEL cpu_to_le16(SMB2_CANCEL_HE)
  71. #define SMB2_ECHO cpu_to_le16(SMB2_ECHO_HE)
  72. #define SMB2_QUERY_DIRECTORY cpu_to_le16(SMB2_QUERY_DIRECTORY_HE)
  73. #define SMB2_CHANGE_NOTIFY cpu_to_le16(SMB2_CHANGE_NOTIFY_HE)
  74. #define SMB2_QUERY_INFO cpu_to_le16(SMB2_QUERY_INFO_HE)
  75. #define SMB2_SET_INFO cpu_to_le16(SMB2_SET_INFO_HE)
  76. #define SMB2_OPLOCK_BREAK cpu_to_le16(SMB2_OPLOCK_BREAK_HE)
  77. #define SMB2_INTERNAL_CMD cpu_to_le16(0xFFFF)
  78. #define NUMBER_OF_SMB2_COMMANDS 0x0013
  79. /* 4 len + 52 transform hdr + 64 hdr + 56 create rsp */
  80. #define MAX_SMB2_HDR_SIZE 0x00b0
  81. #define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)
  82. #define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
  83. /*
  84. * SMB2 Header Definition
  85. *
  86. * "MBZ" : Must be Zero
  87. * "BB" : BugBug, Something to check/review/analyze later
  88. * "PDU" : "Protocol Data Unit" (ie a network "frame")
  89. *
  90. */
  91. #define SMB2_HEADER_STRUCTURE_SIZE cpu_to_le16(64)
  92. struct smb2_sync_hdr {
  93. __le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */
  94. __le16 StructureSize; /* 64 */
  95. __le16 CreditCharge; /* MBZ */
  96. __le32 Status; /* Error from server */
  97. __le16 Command;
  98. __le16 CreditRequest; /* CreditResponse */
  99. __le32 Flags;
  100. __le32 NextCommand;
  101. __le64 MessageId;
  102. __le32 ProcessId;
  103. __u32 TreeId; /* opaque - so do not make little endian */
  104. __u64 SessionId; /* opaque - so do not make little endian */
  105. __u8 Signature[16];
  106. } __packed;
  107. struct smb2_sync_pdu {
  108. struct smb2_sync_hdr sync_hdr;
  109. __le16 StructureSize2; /* size of wct area (varies, request specific) */
  110. } __packed;
  111. struct smb2_hdr {
  112. __be32 smb2_buf_length; /* big endian on wire */
  113. /* length is only two or three bytes - with */
  114. /* one or two byte type preceding it that MBZ */
  115. struct smb2_sync_hdr sync_hdr;
  116. } __packed;
  117. struct smb2_pdu {
  118. struct smb2_hdr hdr;
  119. __le16 StructureSize2; /* size of wct area (varies, request specific) */
  120. } __packed;
  121. #define SMB3_AES128CMM_NONCE 11
  122. #define SMB3_AES128GCM_NONCE 12
  123. struct smb2_transform_hdr {
  124. __be32 smb2_buf_length; /* big endian on wire */
  125. /* length is only two or three bytes - with
  126. one or two byte type preceding it that MBZ */
  127. __le32 ProtocolId; /* 0xFD 'S' 'M' 'B' */
  128. __u8 Signature[16];
  129. __u8 Nonce[16];
  130. __le32 OriginalMessageSize;
  131. __u16 Reserved1;
  132. __le16 Flags; /* EncryptionAlgorithm */
  133. __u64 SessionId;
  134. } __packed;
  135. /*
  136. * SMB2 flag definitions
  137. */
  138. #define SMB2_FLAGS_SERVER_TO_REDIR cpu_to_le32(0x00000001)
  139. #define SMB2_FLAGS_ASYNC_COMMAND cpu_to_le32(0x00000002)
  140. #define SMB2_FLAGS_RELATED_OPERATIONS cpu_to_le32(0x00000004)
  141. #define SMB2_FLAGS_SIGNED cpu_to_le32(0x00000008)
  142. #define SMB2_FLAGS_DFS_OPERATIONS cpu_to_le32(0x10000000)
  143. /*
  144. * Definitions for SMB2 Protocol Data Units (network frames)
  145. *
  146. * See MS-SMB2.PDF specification for protocol details.
  147. * The Naming convention is the lower case version of the SMB2
  148. * command code name for the struct. Note that structures must be packed.
  149. *
  150. */
  151. #define SMB2_ERROR_STRUCTURE_SIZE2 cpu_to_le16(9)
  152. struct smb2_err_rsp {
  153. struct smb2_hdr hdr;
  154. __le16 StructureSize;
  155. __le16 Reserved; /* MBZ */
  156. __le32 ByteCount; /* even if zero, at least one byte follows */
  157. __u8 ErrorData[1]; /* variable length */
  158. } __packed;
  159. struct smb2_symlink_err_rsp {
  160. __le32 SymLinkLength;
  161. __le32 SymLinkErrorTag;
  162. __le32 ReparseTag;
  163. __le16 ReparseDataLength;
  164. __le16 UnparsedPathLength;
  165. __le16 SubstituteNameOffset;
  166. __le16 SubstituteNameLength;
  167. __le16 PrintNameOffset;
  168. __le16 PrintNameLength;
  169. __le32 Flags;
  170. __u8 PathBuffer[0];
  171. } __packed;
  172. #define SMB2_CLIENT_GUID_SIZE 16
  173. struct smb2_negotiate_req {
  174. struct smb2_hdr hdr;
  175. __le16 StructureSize; /* Must be 36 */
  176. __le16 DialectCount;
  177. __le16 SecurityMode;
  178. __le16 Reserved; /* MBZ */
  179. __le32 Capabilities;
  180. __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE];
  181. /* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */
  182. __le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */
  183. __le16 NegotiateContextCount; /* SMB3.1.1 only. MBZ earlier */
  184. __le16 Reserved2;
  185. __le16 Dialects[1]; /* One dialect (vers=) at a time for now */
  186. } __packed;
  187. /* Dialects */
  188. #define SMB20_PROT_ID 0x0202
  189. #define SMB21_PROT_ID 0x0210
  190. #define SMB30_PROT_ID 0x0300
  191. #define SMB302_PROT_ID 0x0302
  192. #define SMB311_PROT_ID 0x0311
  193. #define BAD_PROT_ID 0xFFFF
  194. /* SecurityMode flags */
  195. #define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001
  196. #define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
  197. /* Capabilities flags */
  198. #define SMB2_GLOBAL_CAP_DFS 0x00000001
  199. #define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */
  200. #define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */
  201. #define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */
  202. #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
  203. #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */
  204. #define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */
  205. /* Internal types */
  206. #define SMB2_NT_FIND 0x00100000
  207. #define SMB2_LARGE_FILES 0x00200000
  208. #define SMB311_SALT_SIZE 32
  209. /* Hash Algorithm Types */
  210. #define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001)
  211. struct smb2_preauth_neg_context {
  212. __le16 ContextType; /* 1 */
  213. __le16 DataLength;
  214. __le32 Reserved;
  215. __le16 HashAlgorithmCount; /* 1 */
  216. __le16 SaltLength;
  217. __le16 HashAlgorithms; /* HashAlgorithms[0] since only one defined */
  218. __u8 Salt[SMB311_SALT_SIZE];
  219. } __packed;
  220. /* Encryption Algorithms Ciphers */
  221. #define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001)
  222. #define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002)
  223. struct smb2_encryption_neg_context {
  224. __le16 ContextType; /* 2 */
  225. __le16 DataLength;
  226. __le32 Reserved;
  227. __le16 CipherCount; /* AES-128-GCM and AES-128-CCM */
  228. __le16 Ciphers[2]; /* Ciphers[0] since only one used now */
  229. } __packed;
  230. struct smb2_negotiate_rsp {
  231. struct smb2_hdr hdr;
  232. __le16 StructureSize; /* Must be 65 */
  233. __le16 SecurityMode;
  234. __le16 DialectRevision;
  235. __le16 NegotiateContextCount; /* Prior to SMB3.1.1 was Reserved & MBZ */
  236. __u8 ServerGUID[16];
  237. __le32 Capabilities;
  238. __le32 MaxTransactSize;
  239. __le32 MaxReadSize;
  240. __le32 MaxWriteSize;
  241. __le64 SystemTime; /* MBZ */
  242. __le64 ServerStartTime;
  243. __le16 SecurityBufferOffset;
  244. __le16 SecurityBufferLength;
  245. __le32 NegotiateContextOffset; /* Pre:SMB3.1.1 was reserved/ignored */
  246. __u8 Buffer[1]; /* variable length GSS security buffer */
  247. } __packed;
  248. /* Flags */
  249. #define SMB2_SESSION_REQ_FLAG_BINDING 0x01
  250. #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04
  251. struct smb2_sess_setup_req {
  252. struct smb2_hdr hdr;
  253. __le16 StructureSize; /* Must be 25 */
  254. __u8 Flags;
  255. __u8 SecurityMode;
  256. __le32 Capabilities;
  257. __le32 Channel;
  258. __le16 SecurityBufferOffset;
  259. __le16 SecurityBufferLength;
  260. __u64 PreviousSessionId;
  261. __u8 Buffer[1]; /* variable length GSS security buffer */
  262. } __packed;
  263. /* Currently defined SessionFlags */
  264. #define SMB2_SESSION_FLAG_IS_GUEST 0x0001
  265. #define SMB2_SESSION_FLAG_IS_NULL 0x0002
  266. #define SMB2_SESSION_FLAG_ENCRYPT_DATA 0x0004
  267. struct smb2_sess_setup_rsp {
  268. struct smb2_hdr hdr;
  269. __le16 StructureSize; /* Must be 9 */
  270. __le16 SessionFlags;
  271. __le16 SecurityBufferOffset;
  272. __le16 SecurityBufferLength;
  273. __u8 Buffer[1]; /* variable length GSS security buffer */
  274. } __packed;
  275. struct smb2_logoff_req {
  276. struct smb2_hdr hdr;
  277. __le16 StructureSize; /* Must be 4 */
  278. __le16 Reserved;
  279. } __packed;
  280. struct smb2_logoff_rsp {
  281. struct smb2_hdr hdr;
  282. __le16 StructureSize; /* Must be 4 */
  283. __le16 Reserved;
  284. } __packed;
  285. /* Flags/Reserved for SMB3.1.1 */
  286. #define SMB2_SHAREFLAG_CLUSTER_RECONNECT 0x0001
  287. struct smb2_tree_connect_req {
  288. struct smb2_hdr hdr;
  289. __le16 StructureSize; /* Must be 9 */
  290. __le16 Reserved; /* Flags in SMB3.1.1 */
  291. __le16 PathOffset;
  292. __le16 PathLength;
  293. __u8 Buffer[1]; /* variable length */
  294. } __packed;
  295. struct smb2_tree_connect_rsp {
  296. struct smb2_hdr hdr;
  297. __le16 StructureSize; /* Must be 16 */
  298. __u8 ShareType; /* see below */
  299. __u8 Reserved;
  300. __le32 ShareFlags; /* see below */
  301. __le32 Capabilities; /* see below */
  302. __le32 MaximalAccess;
  303. } __packed;
  304. /* Possible ShareType values */
  305. #define SMB2_SHARE_TYPE_DISK 0x01
  306. #define SMB2_SHARE_TYPE_PIPE 0x02
  307. #define SMB2_SHARE_TYPE_PRINT 0x03
  308. /*
  309. * Possible ShareFlags - exactly one and only one of the first 4 caching flags
  310. * must be set (any of the remaining, SHI1005, flags may be set individually
  311. * or in combination.
  312. */
  313. #define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000
  314. #define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010
  315. #define SMB2_SHAREFLAG_VDO_CACHING 0x00000020
  316. #define SMB2_SHAREFLAG_NO_CACHING 0x00000030
  317. #define SHI1005_FLAGS_DFS 0x00000001
  318. #define SHI1005_FLAGS_DFS_ROOT 0x00000002
  319. #define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS 0x00000100
  320. #define SHI1005_FLAGS_FORCE_SHARED_DELETE 0x00000200
  321. #define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING 0x00000400
  322. #define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM 0x00000800
  323. #define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK 0x00001000
  324. #define SHI1005_FLAGS_ENABLE_HASH_V1 0x00002000
  325. #define SHI1005_FLAGS_ENABLE_HASH_V2 0x00004000
  326. #define SHI1005_FLAGS_ENCRYPT_DATA 0x00008000
  327. #define SHI1005_FLAGS_ALL 0x0000FF33
  328. /* Possible share capabilities */
  329. #define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008) /* all dialects */
  330. #define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY cpu_to_le32(0x00000010) /* 3.0 */
  331. #define SMB2_SHARE_CAP_SCALEOUT cpu_to_le32(0x00000020) /* 3.0 */
  332. #define SMB2_SHARE_CAP_CLUSTER cpu_to_le32(0x00000040) /* 3.0 */
  333. #define SMB2_SHARE_CAP_ASYMMETRIC cpu_to_le32(0x00000080) /* 3.02 */
  334. struct smb2_tree_disconnect_req {
  335. struct smb2_hdr hdr;
  336. __le16 StructureSize; /* Must be 4 */
  337. __le16 Reserved;
  338. } __packed;
  339. struct smb2_tree_disconnect_rsp {
  340. struct smb2_hdr hdr;
  341. __le16 StructureSize; /* Must be 4 */
  342. __le16 Reserved;
  343. } __packed;
  344. /* File Attrubutes */
  345. #define FILE_ATTRIBUTE_READONLY 0x00000001
  346. #define FILE_ATTRIBUTE_HIDDEN 0x00000002
  347. #define FILE_ATTRIBUTE_SYSTEM 0x00000004
  348. #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
  349. #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
  350. #define FILE_ATTRIBUTE_NORMAL 0x00000080
  351. #define FILE_ATTRIBUTE_TEMPORARY 0x00000100
  352. #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
  353. #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
  354. #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
  355. #define FILE_ATTRIBUTE_OFFLINE 0x00001000
  356. #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
  357. #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
  358. #define FILE_ATTRIBUTE_INTEGRITY_STREAM 0x00008000
  359. #define FILE_ATTRIBUTE_NO_SCRUB_DATA 0x00020000
  360. /* Oplock levels */
  361. #define SMB2_OPLOCK_LEVEL_NONE 0x00
  362. #define SMB2_OPLOCK_LEVEL_II 0x01
  363. #define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
  364. #define SMB2_OPLOCK_LEVEL_BATCH 0x09
  365. #define SMB2_OPLOCK_LEVEL_LEASE 0xFF
  366. /* Non-spec internal type */
  367. #define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99
  368. /* Desired Access Flags */
  369. #define FILE_READ_DATA_LE cpu_to_le32(0x00000001)
  370. #define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002)
  371. #define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004)
  372. #define FILE_READ_EA_LE cpu_to_le32(0x00000008)
  373. #define FILE_WRITE_EA_LE cpu_to_le32(0x00000010)
  374. #define FILE_EXECUTE_LE cpu_to_le32(0x00000020)
  375. #define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080)
  376. #define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100)
  377. #define FILE_DELETE_LE cpu_to_le32(0x00010000)
  378. #define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000)
  379. #define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000)
  380. #define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000)
  381. #define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000)
  382. #define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000)
  383. #define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000)
  384. #define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000)
  385. #define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000)
  386. #define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000)
  387. #define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000)
  388. /* ShareAccess Flags */
  389. #define FILE_SHARE_READ_LE cpu_to_le32(0x00000001)
  390. #define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002)
  391. #define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004)
  392. #define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007)
  393. /* CreateDisposition Flags */
  394. #define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000)
  395. #define FILE_OPEN_LE cpu_to_le32(0x00000001)
  396. #define FILE_CREATE_LE cpu_to_le32(0x00000002)
  397. #define FILE_OPEN_IF_LE cpu_to_le32(0x00000003)
  398. #define FILE_OVERWRITE_LE cpu_to_le32(0x00000004)
  399. #define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005)
  400. /* CreateOptions Flags */
  401. #define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001)
  402. /* same as #define CREATE_NOT_FILE_LE cpu_to_le32(0x00000001) */
  403. #define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002)
  404. #define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004)
  405. #define FILE_NO_INTERMEDIATE_BUFFERRING_LE cpu_to_le32(0x00000008)
  406. #define FILE_SYNCHRONOUS_IO_ALERT_LE cpu_to_le32(0x00000010)
  407. #define FILE_SYNCHRONOUS_IO_NON_ALERT_LE cpu_to_le32(0x00000020)
  408. #define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040)
  409. #define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100)
  410. #define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200)
  411. #define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800)
  412. #define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000)
  413. #define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000)
  414. #define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000)
  415. #define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000)
  416. #define FILE_RESERVE_OPFILTER_LE cpu_to_le32(0x00100000)
  417. #define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000)
  418. #define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000)
  419. #define FILE_OPEN_FOR_FREE_SPACE_QUERY_LE cpu_to_le32(0x00800000)
  420. #define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \
  421. | FILE_READ_ATTRIBUTES_LE)
  422. #define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \
  423. | FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
  424. #define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
  425. /* Impersonation Levels */
  426. #define IL_ANONYMOUS cpu_to_le32(0x00000000)
  427. #define IL_IDENTIFICATION cpu_to_le32(0x00000001)
  428. #define IL_IMPERSONATION cpu_to_le32(0x00000002)
  429. #define IL_DELEGATE cpu_to_le32(0x00000003)
  430. /* Create Context Values */
  431. #define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */
  432. #define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */
  433. #define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ"
  434. #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC"
  435. #define SMB2_CREATE_ALLOCATION_SIZE "AISi"
  436. #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
  437. #define SMB2_CREATE_TIMEWARP_REQUEST "TWrp"
  438. #define SMB2_CREATE_QUERY_ON_DISK_ID "QFid"
  439. #define SMB2_CREATE_REQUEST_LEASE "RqLs"
  440. #define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 "DH2Q"
  441. #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 "DH2C"
  442. #define SMB2_CREATE_APP_INSTANCE_ID 0x45BCA66AEFA7F74A9008FA462E144D74
  443. #define SVHDX_OPEN_DEVICE_CONTEXT 0x83CE6F1AD851E0986E34401CC9BCFCE9
  444. struct smb2_create_req {
  445. struct smb2_hdr hdr;
  446. __le16 StructureSize; /* Must be 57 */
  447. __u8 SecurityFlags;
  448. __u8 RequestedOplockLevel;
  449. __le32 ImpersonationLevel;
  450. __le64 SmbCreateFlags;
  451. __le64 Reserved;
  452. __le32 DesiredAccess;
  453. __le32 FileAttributes;
  454. __le32 ShareAccess;
  455. __le32 CreateDisposition;
  456. __le32 CreateOptions;
  457. __le16 NameOffset;
  458. __le16 NameLength;
  459. __le32 CreateContextsOffset;
  460. __le32 CreateContextsLength;
  461. __u8 Buffer[0];
  462. } __packed;
  463. struct smb2_create_rsp {
  464. struct smb2_hdr hdr;
  465. __le16 StructureSize; /* Must be 89 */
  466. __u8 OplockLevel;
  467. __u8 Reserved;
  468. __le32 CreateAction;
  469. __le64 CreationTime;
  470. __le64 LastAccessTime;
  471. __le64 LastWriteTime;
  472. __le64 ChangeTime;
  473. __le64 AllocationSize;
  474. __le64 EndofFile;
  475. __le32 FileAttributes;
  476. __le32 Reserved2;
  477. __u64 PersistentFileId; /* opaque endianness */
  478. __u64 VolatileFileId; /* opaque endianness */
  479. __le32 CreateContextsOffset;
  480. __le32 CreateContextsLength;
  481. __u8 Buffer[1];
  482. } __packed;
  483. struct create_context {
  484. __le32 Next;
  485. __le16 NameOffset;
  486. __le16 NameLength;
  487. __le16 Reserved;
  488. __le16 DataOffset;
  489. __le32 DataLength;
  490. __u8 Buffer[0];
  491. } __packed;
  492. #define SMB2_LEASE_READ_CACHING_HE 0x01
  493. #define SMB2_LEASE_HANDLE_CACHING_HE 0x02
  494. #define SMB2_LEASE_WRITE_CACHING_HE 0x04
  495. #define SMB2_LEASE_NONE cpu_to_le32(0x00)
  496. #define SMB2_LEASE_READ_CACHING cpu_to_le32(0x01)
  497. #define SMB2_LEASE_HANDLE_CACHING cpu_to_le32(0x02)
  498. #define SMB2_LEASE_WRITE_CACHING cpu_to_le32(0x04)
  499. #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS cpu_to_le32(0x02)
  500. #define SMB2_LEASE_KEY_SIZE 16
  501. struct lease_context {
  502. __le64 LeaseKeyLow;
  503. __le64 LeaseKeyHigh;
  504. __le32 LeaseState;
  505. __le32 LeaseFlags;
  506. __le64 LeaseDuration;
  507. } __packed;
  508. struct lease_context_v2 {
  509. __le64 LeaseKeyLow;
  510. __le64 LeaseKeyHigh;
  511. __le32 LeaseState;
  512. __le32 LeaseFlags;
  513. __le64 LeaseDuration;
  514. __le64 ParentLeaseKeyLow;
  515. __le64 ParentLeaseKeyHigh;
  516. __le16 Epoch;
  517. __le16 Reserved;
  518. } __packed;
  519. struct create_lease {
  520. struct create_context ccontext;
  521. __u8 Name[8];
  522. struct lease_context lcontext;
  523. } __packed;
  524. struct create_lease_v2 {
  525. struct create_context ccontext;
  526. __u8 Name[8];
  527. struct lease_context_v2 lcontext;
  528. __u8 Pad[4];
  529. } __packed;
  530. struct create_durable {
  531. struct create_context ccontext;
  532. __u8 Name[8];
  533. union {
  534. __u8 Reserved[16];
  535. struct {
  536. __u64 PersistentFileId;
  537. __u64 VolatileFileId;
  538. } Fid;
  539. } Data;
  540. } __packed;
  541. /* See MS-SMB2 2.2.13.2.11 */
  542. /* Flags */
  543. #define SMB2_DHANDLE_FLAG_PERSISTENT 0x00000002
  544. struct durable_context_v2 {
  545. __le32 Timeout;
  546. __le32 Flags;
  547. __u64 Reserved;
  548. __u8 CreateGuid[16];
  549. } __packed;
  550. struct create_durable_v2 {
  551. struct create_context ccontext;
  552. __u8 Name[8];
  553. struct durable_context_v2 dcontext;
  554. } __packed;
  555. /* See MS-SMB2 2.2.13.2.12 */
  556. struct durable_reconnect_context_v2 {
  557. struct {
  558. __u64 PersistentFileId;
  559. __u64 VolatileFileId;
  560. } Fid;
  561. __u8 CreateGuid[16];
  562. __le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
  563. } __packed;
  564. /* See MS-SMB2 2.2.14.2.12 */
  565. struct durable_reconnect_context_v2_rsp {
  566. __le32 Timeout;
  567. __le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
  568. } __packed;
  569. struct create_durable_handle_reconnect_v2 {
  570. struct create_context ccontext;
  571. __u8 Name[8];
  572. struct durable_reconnect_context_v2 dcontext;
  573. } __packed;
  574. #define COPY_CHUNK_RES_KEY_SIZE 24
  575. struct resume_key_req {
  576. char ResumeKey[COPY_CHUNK_RES_KEY_SIZE];
  577. __le32 ContextLength; /* MBZ */
  578. char Context[0]; /* ignored, Windows sets to 4 bytes of zero */
  579. } __packed;
  580. /* this goes in the ioctl buffer when doing a copychunk request */
  581. struct copychunk_ioctl {
  582. char SourceKey[COPY_CHUNK_RES_KEY_SIZE];
  583. __le32 ChunkCount; /* we are only sending 1 */
  584. __le32 Reserved;
  585. /* array will only be one chunk long for us */
  586. __le64 SourceOffset;
  587. __le64 TargetOffset;
  588. __le32 Length; /* how many bytes to copy */
  589. __u32 Reserved2;
  590. } __packed;
  591. /* this goes in the ioctl buffer when doing FSCTL_SET_ZERO_DATA */
  592. struct file_zero_data_information {
  593. __le64 FileOffset;
  594. __le64 BeyondFinalZero;
  595. } __packed;
  596. struct copychunk_ioctl_rsp {
  597. __le32 ChunksWritten;
  598. __le32 ChunkBytesWritten;
  599. __le32 TotalBytesWritten;
  600. } __packed;
  601. struct fsctl_set_integrity_information_req {
  602. __le16 ChecksumAlgorithm;
  603. __le16 Reserved;
  604. __le32 Flags;
  605. } __packed;
  606. struct fsctl_get_integrity_information_rsp {
  607. __le16 ChecksumAlgorithm;
  608. __le16 Reserved;
  609. __le32 Flags;
  610. __le32 ChecksumChunkSizeInBytes;
  611. __le32 ClusterSizeInBytes;
  612. } __packed;
  613. /* Integrity ChecksumAlgorithm choices for above */
  614. #define CHECKSUM_TYPE_NONE 0x0000
  615. #define CHECKSUM_TYPE_CRC64 0x0002
  616. #define CHECKSUM_TYPE_UNCHANGED 0xFFFF /* set only */
  617. /* Integrity flags for above */
  618. #define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF 0x00000001
  619. /* See MS-DFSC 2.2.2 */
  620. struct fsctl_get_dfs_referral_req {
  621. __le16 MaxReferralLevel;
  622. __u8 RequestFileName[];
  623. } __packed;
  624. /* DFS response is struct get_dfs_refer_rsp */
  625. /* See MS-SMB2 2.2.31.3 */
  626. struct network_resiliency_req {
  627. __le32 Timeout;
  628. __le32 Reserved;
  629. } __packed;
  630. /* There is no buffer for the response ie no struct network_resiliency_rsp */
  631. struct validate_negotiate_info_req {
  632. __le32 Capabilities;
  633. __u8 Guid[SMB2_CLIENT_GUID_SIZE];
  634. __le16 SecurityMode;
  635. __le16 DialectCount;
  636. __le16 Dialects[3]; /* BB expand this if autonegotiate > 3 dialects */
  637. } __packed;
  638. struct validate_negotiate_info_rsp {
  639. __le32 Capabilities;
  640. __u8 Guid[SMB2_CLIENT_GUID_SIZE];
  641. __le16 SecurityMode;
  642. __le16 Dialect; /* Dialect in use for the connection */
  643. } __packed;
  644. #define RSS_CAPABLE 0x00000001
  645. #define RDMA_CAPABLE 0x00000002
  646. struct network_interface_info_ioctl_rsp {
  647. __le32 Next; /* next interface. zero if this is last one */
  648. __le32 IfIndex;
  649. __le32 Capability; /* RSS or RDMA Capable */
  650. __le32 Reserved;
  651. __le64 LinkSpeed;
  652. char SockAddr_Storage[128];
  653. } __packed;
  654. #define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */
  655. struct compress_ioctl {
  656. __le16 CompressionState; /* See cifspdu.h for possible flag values */
  657. } __packed;
  658. struct duplicate_extents_to_file {
  659. __u64 PersistentFileHandle; /* source file handle, opaque endianness */
  660. __u64 VolatileFileHandle;
  661. __le64 SourceFileOffset;
  662. __le64 TargetFileOffset;
  663. __le64 ByteCount; /* Bytes to be copied */
  664. } __packed;
  665. struct smb2_ioctl_req {
  666. struct smb2_hdr hdr;
  667. __le16 StructureSize; /* Must be 57 */
  668. __u16 Reserved;
  669. __le32 CtlCode;
  670. __u64 PersistentFileId; /* opaque endianness */
  671. __u64 VolatileFileId; /* opaque endianness */
  672. __le32 InputOffset;
  673. __le32 InputCount;
  674. __le32 MaxInputResponse;
  675. __le32 OutputOffset;
  676. __le32 OutputCount;
  677. __le32 MaxOutputResponse;
  678. __le32 Flags;
  679. __u32 Reserved2;
  680. __u8 Buffer[0];
  681. } __packed;
  682. struct smb2_ioctl_rsp {
  683. struct smb2_hdr hdr;
  684. __le16 StructureSize; /* Must be 57 */
  685. __u16 Reserved;
  686. __le32 CtlCode;
  687. __u64 PersistentFileId; /* opaque endianness */
  688. __u64 VolatileFileId; /* opaque endianness */
  689. __le32 InputOffset;
  690. __le32 InputCount;
  691. __le32 OutputOffset;
  692. __le32 OutputCount;
  693. __le32 Flags;
  694. __u32 Reserved2;
  695. /* char * buffer[] */
  696. } __packed;
  697. /* Currently defined values for close flags */
  698. #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
  699. struct smb2_close_req {
  700. struct smb2_hdr hdr;
  701. __le16 StructureSize; /* Must be 24 */
  702. __le16 Flags;
  703. __le32 Reserved;
  704. __u64 PersistentFileId; /* opaque endianness */
  705. __u64 VolatileFileId; /* opaque endianness */
  706. } __packed;
  707. struct smb2_close_rsp {
  708. struct smb2_hdr hdr;
  709. __le16 StructureSize; /* 60 */
  710. __le16 Flags;
  711. __le32 Reserved;
  712. __le64 CreationTime;
  713. __le64 LastAccessTime;
  714. __le64 LastWriteTime;
  715. __le64 ChangeTime;
  716. __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
  717. __le64 EndOfFile;
  718. __le32 Attributes;
  719. } __packed;
  720. struct smb2_flush_req {
  721. struct smb2_hdr hdr;
  722. __le16 StructureSize; /* Must be 24 */
  723. __le16 Reserved1;
  724. __le32 Reserved2;
  725. __u64 PersistentFileId; /* opaque endianness */
  726. __u64 VolatileFileId; /* opaque endianness */
  727. } __packed;
  728. struct smb2_flush_rsp {
  729. struct smb2_hdr hdr;
  730. __le16 StructureSize;
  731. __le16 Reserved;
  732. } __packed;
  733. /* For read request Flags field below, following flag is defined for SMB3.02 */
  734. #define SMB2_READFLAG_READ_UNBUFFERED 0x01
  735. /* Channel field for read and write: exactly one of following flags can be set*/
  736. #define SMB2_CHANNEL_NONE 0x00000000
  737. #define SMB2_CHANNEL_RDMA_V1 0x00000001 /* SMB3 or later */
  738. #define SMB2_CHANNEL_RDMA_V1_INVALIDATE 0x00000001 /* SMB3.02 or later */
  739. /* SMB2 read request without RFC1001 length at the beginning */
  740. struct smb2_read_plain_req {
  741. struct smb2_sync_hdr sync_hdr;
  742. __le16 StructureSize; /* Must be 49 */
  743. __u8 Padding; /* offset from start of SMB2 header to place read */
  744. __u8 Flags; /* MBZ unless SMB3.02 or later */
  745. __le32 Length;
  746. __le64 Offset;
  747. __u64 PersistentFileId; /* opaque endianness */
  748. __u64 VolatileFileId; /* opaque endianness */
  749. __le32 MinimumCount;
  750. __le32 Channel; /* MBZ except for SMB3 or later */
  751. __le32 RemainingBytes;
  752. __le16 ReadChannelInfoOffset; /* Reserved MBZ */
  753. __le16 ReadChannelInfoLength; /* Reserved MBZ */
  754. __u8 Buffer[1];
  755. } __packed;
  756. struct smb2_read_rsp {
  757. struct smb2_hdr hdr;
  758. __le16 StructureSize; /* Must be 17 */
  759. __u8 DataOffset;
  760. __u8 Reserved;
  761. __le32 DataLength;
  762. __le32 DataRemaining;
  763. __u32 Reserved2;
  764. __u8 Buffer[1];
  765. } __packed;
  766. /* For write request Flags field below the following flags are defined: */
  767. #define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 /* SMB2.1 or later */
  768. #define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002 /* SMB3.02 or later */
  769. struct smb2_write_req {
  770. struct smb2_hdr hdr;
  771. __le16 StructureSize; /* Must be 49 */
  772. __le16 DataOffset; /* offset from start of SMB2 header to write data */
  773. __le32 Length;
  774. __le64 Offset;
  775. __u64 PersistentFileId; /* opaque endianness */
  776. __u64 VolatileFileId; /* opaque endianness */
  777. __le32 Channel; /* Reserved MBZ */
  778. __le32 RemainingBytes;
  779. __le16 WriteChannelInfoOffset; /* Reserved MBZ */
  780. __le16 WriteChannelInfoLength; /* Reserved MBZ */
  781. __le32 Flags;
  782. __u8 Buffer[1];
  783. } __packed;
  784. struct smb2_write_rsp {
  785. struct smb2_hdr hdr;
  786. __le16 StructureSize; /* Must be 17 */
  787. __u8 DataOffset;
  788. __u8 Reserved;
  789. __le32 DataLength;
  790. __le32 DataRemaining;
  791. __u32 Reserved2;
  792. __u8 Buffer[1];
  793. } __packed;
  794. #define SMB2_LOCKFLAG_SHARED_LOCK 0x0001
  795. #define SMB2_LOCKFLAG_EXCLUSIVE_LOCK 0x0002
  796. #define SMB2_LOCKFLAG_UNLOCK 0x0004
  797. #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010
  798. struct smb2_lock_element {
  799. __le64 Offset;
  800. __le64 Length;
  801. __le32 Flags;
  802. __le32 Reserved;
  803. } __packed;
  804. struct smb2_lock_req {
  805. struct smb2_hdr hdr;
  806. __le16 StructureSize; /* Must be 48 */
  807. __le16 LockCount;
  808. __le32 Reserved;
  809. __u64 PersistentFileId; /* opaque endianness */
  810. __u64 VolatileFileId; /* opaque endianness */
  811. /* Followed by at least one */
  812. struct smb2_lock_element locks[1];
  813. } __packed;
  814. struct smb2_lock_rsp {
  815. struct smb2_hdr hdr;
  816. __le16 StructureSize; /* Must be 4 */
  817. __le16 Reserved;
  818. } __packed;
  819. struct smb2_echo_req {
  820. struct smb2_hdr hdr;
  821. __le16 StructureSize; /* Must be 4 */
  822. __u16 Reserved;
  823. } __packed;
  824. struct smb2_echo_rsp {
  825. struct smb2_hdr hdr;
  826. __le16 StructureSize; /* Must be 4 */
  827. __u16 Reserved;
  828. } __packed;
  829. /* search (query_directory) Flags field */
  830. #define SMB2_RESTART_SCANS 0x01
  831. #define SMB2_RETURN_SINGLE_ENTRY 0x02
  832. #define SMB2_INDEX_SPECIFIED 0x04
  833. #define SMB2_REOPEN 0x10
  834. struct smb2_query_directory_req {
  835. struct smb2_hdr hdr;
  836. __le16 StructureSize; /* Must be 33 */
  837. __u8 FileInformationClass;
  838. __u8 Flags;
  839. __le32 FileIndex;
  840. __u64 PersistentFileId; /* opaque endianness */
  841. __u64 VolatileFileId; /* opaque endianness */
  842. __le16 FileNameOffset;
  843. __le16 FileNameLength;
  844. __le32 OutputBufferLength;
  845. __u8 Buffer[1];
  846. } __packed;
  847. struct smb2_query_directory_rsp {
  848. struct smb2_hdr hdr;
  849. __le16 StructureSize; /* Must be 9 */
  850. __le16 OutputBufferOffset;
  851. __le32 OutputBufferLength;
  852. __u8 Buffer[1];
  853. } __packed;
  854. /* Possible InfoType values */
  855. #define SMB2_O_INFO_FILE 0x01
  856. #define SMB2_O_INFO_FILESYSTEM 0x02
  857. #define SMB2_O_INFO_SECURITY 0x03
  858. #define SMB2_O_INFO_QUOTA 0x04
  859. /* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */
  860. #define OWNER_SECINFO 0x00000001
  861. #define GROUP_SECINFO 0x00000002
  862. #define DACL_SECINFO 0x00000004
  863. #define SACL_SECINFO 0x00000008
  864. #define LABEL_SECINFO 0x00000010
  865. #define ATTRIBUTE_SECINFO 0x00000020
  866. #define SCOPE_SECINFO 0x00000040
  867. #define BACKUP_SECINFO 0x00010000
  868. #define UNPROTECTED_SACL_SECINFO 0x10000000
  869. #define UNPROTECTED_DACL_SECINFO 0x20000000
  870. #define PROTECTED_SACL_SECINFO 0x40000000
  871. #define PROTECTED_DACL_SECINFO 0x80000000
  872. /* Flags used for FileFullEAinfo */
  873. #define SL_RESTART_SCAN 0x00000001
  874. #define SL_RETURN_SINGLE_ENTRY 0x00000002
  875. #define SL_INDEX_SPECIFIED 0x00000004
  876. struct smb2_query_info_req {
  877. struct smb2_hdr hdr;
  878. __le16 StructureSize; /* Must be 41 */
  879. __u8 InfoType;
  880. __u8 FileInfoClass;
  881. __le32 OutputBufferLength;
  882. __le16 InputBufferOffset;
  883. __u16 Reserved;
  884. __le32 InputBufferLength;
  885. __le32 AdditionalInformation;
  886. __le32 Flags;
  887. __u64 PersistentFileId; /* opaque endianness */
  888. __u64 VolatileFileId; /* opaque endianness */
  889. __u8 Buffer[1];
  890. } __packed;
  891. struct smb2_query_info_rsp {
  892. struct smb2_hdr hdr;
  893. __le16 StructureSize; /* Must be 9 */
  894. __le16 OutputBufferOffset;
  895. __le32 OutputBufferLength;
  896. __u8 Buffer[1];
  897. } __packed;
  898. struct smb2_set_info_req {
  899. struct smb2_hdr hdr;
  900. __le16 StructureSize; /* Must be 33 */
  901. __u8 InfoType;
  902. __u8 FileInfoClass;
  903. __le32 BufferLength;
  904. __le16 BufferOffset;
  905. __u16 Reserved;
  906. __le32 AdditionalInformation;
  907. __u64 PersistentFileId; /* opaque endianness */
  908. __u64 VolatileFileId; /* opaque endianness */
  909. __u8 Buffer[1];
  910. } __packed;
  911. struct smb2_set_info_rsp {
  912. struct smb2_hdr hdr;
  913. __le16 StructureSize; /* Must be 2 */
  914. } __packed;
  915. struct smb2_oplock_break {
  916. struct smb2_hdr hdr;
  917. __le16 StructureSize; /* Must be 24 */
  918. __u8 OplockLevel;
  919. __u8 Reserved;
  920. __le32 Reserved2;
  921. __u64 PersistentFid;
  922. __u64 VolatileFid;
  923. } __packed;
  924. #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
  925. struct smb2_lease_break {
  926. struct smb2_hdr hdr;
  927. __le16 StructureSize; /* Must be 44 */
  928. __le16 Reserved;
  929. __le32 Flags;
  930. __u8 LeaseKey[16];
  931. __le32 CurrentLeaseState;
  932. __le32 NewLeaseState;
  933. __le32 BreakReason;
  934. __le32 AccessMaskHint;
  935. __le32 ShareMaskHint;
  936. } __packed;
  937. struct smb2_lease_ack {
  938. struct smb2_hdr hdr;
  939. __le16 StructureSize; /* Must be 36 */
  940. __le16 Reserved;
  941. __le32 Flags;
  942. __u8 LeaseKey[16];
  943. __le32 LeaseState;
  944. __le64 LeaseDuration;
  945. } __packed;
  946. /*
  947. * PDU infolevel structure definitions
  948. * BB consider moving to a different header
  949. */
  950. /* File System Information Classes */
  951. #define FS_VOLUME_INFORMATION 1 /* Query */
  952. #define FS_LABEL_INFORMATION 2 /* Local only */
  953. #define FS_SIZE_INFORMATION 3 /* Query */
  954. #define FS_DEVICE_INFORMATION 4 /* Query */
  955. #define FS_ATTRIBUTE_INFORMATION 5 /* Query */
  956. #define FS_CONTROL_INFORMATION 6 /* Query, Set */
  957. #define FS_FULL_SIZE_INFORMATION 7 /* Query */
  958. #define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */
  959. #define FS_DRIVER_PATH_INFORMATION 9 /* Local only */
  960. #define FS_VOLUME_FLAGS_INFORMATION 10 /* Local only */
  961. #define FS_SECTOR_SIZE_INFORMATION 11 /* SMB3 or later. Query */
  962. struct smb2_fs_full_size_info {
  963. __le64 TotalAllocationUnits;
  964. __le64 CallerAvailableAllocationUnits;
  965. __le64 ActualAvailableAllocationUnits;
  966. __le32 SectorsPerAllocationUnit;
  967. __le32 BytesPerSector;
  968. } __packed;
  969. #define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001
  970. #define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
  971. #define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004
  972. #define SSINFO_FLAGS_TRIM_ENABLED 0x00000008
  973. /* sector size info struct */
  974. struct smb3_fs_ss_info {
  975. __le32 LogicalBytesPerSector;
  976. __le32 PhysicalBytesPerSectorForAtomicity;
  977. __le32 PhysicalBytesPerSectorForPerf;
  978. __le32 FileSystemEffectivePhysicalBytesPerSectorForAtomicity;
  979. __le32 Flags;
  980. __le32 ByteOffsetForSectorAlignment;
  981. __le32 ByteOffsetForPartitionAlignment;
  982. } __packed;
  983. /* partial list of QUERY INFO levels */
  984. #define FILE_DIRECTORY_INFORMATION 1
  985. #define FILE_FULL_DIRECTORY_INFORMATION 2
  986. #define FILE_BOTH_DIRECTORY_INFORMATION 3
  987. #define FILE_BASIC_INFORMATION 4
  988. #define FILE_STANDARD_INFORMATION 5
  989. #define FILE_INTERNAL_INFORMATION 6
  990. #define FILE_EA_INFORMATION 7
  991. #define FILE_ACCESS_INFORMATION 8
  992. #define FILE_NAME_INFORMATION 9
  993. #define FILE_RENAME_INFORMATION 10
  994. #define FILE_LINK_INFORMATION 11
  995. #define FILE_NAMES_INFORMATION 12
  996. #define FILE_DISPOSITION_INFORMATION 13
  997. #define FILE_POSITION_INFORMATION 14
  998. #define FILE_FULL_EA_INFORMATION 15
  999. #define FILE_MODE_INFORMATION 16
  1000. #define FILE_ALIGNMENT_INFORMATION 17
  1001. #define FILE_ALL_INFORMATION 18
  1002. #define FILE_ALLOCATION_INFORMATION 19
  1003. #define FILE_END_OF_FILE_INFORMATION 20
  1004. #define FILE_ALTERNATE_NAME_INFORMATION 21
  1005. #define FILE_STREAM_INFORMATION 22
  1006. #define FILE_PIPE_INFORMATION 23
  1007. #define FILE_PIPE_LOCAL_INFORMATION 24
  1008. #define FILE_PIPE_REMOTE_INFORMATION 25
  1009. #define FILE_MAILSLOT_QUERY_INFORMATION 26
  1010. #define FILE_MAILSLOT_SET_INFORMATION 27
  1011. #define FILE_COMPRESSION_INFORMATION 28
  1012. #define FILE_OBJECT_ID_INFORMATION 29
  1013. /* Number 30 not defined in documents */
  1014. #define FILE_MOVE_CLUSTER_INFORMATION 31
  1015. #define FILE_QUOTA_INFORMATION 32
  1016. #define FILE_REPARSE_POINT_INFORMATION 33
  1017. #define FILE_NETWORK_OPEN_INFORMATION 34
  1018. #define FILE_ATTRIBUTE_TAG_INFORMATION 35
  1019. #define FILE_TRACKING_INFORMATION 36
  1020. #define FILEID_BOTH_DIRECTORY_INFORMATION 37
  1021. #define FILEID_FULL_DIRECTORY_INFORMATION 38
  1022. #define FILE_VALID_DATA_LENGTH_INFORMATION 39
  1023. #define FILE_SHORT_NAME_INFORMATION 40
  1024. #define FILE_SFIO_RESERVE_INFORMATION 44
  1025. #define FILE_SFIO_VOLUME_INFORMATION 45
  1026. #define FILE_HARD_LINK_INFORMATION 46
  1027. #define FILE_NORMALIZED_NAME_INFORMATION 48
  1028. #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
  1029. #define FILE_STANDARD_LINK_INFORMATION 54
  1030. struct smb2_file_internal_info {
  1031. __le64 IndexNumber;
  1032. } __packed; /* level 6 Query */
  1033. struct smb2_file_rename_info { /* encoding of request for level 10 */
  1034. __u8 ReplaceIfExists; /* 1 = replace existing target with new */
  1035. /* 0 = fail if target already exists */
  1036. __u8 Reserved[7];
  1037. __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
  1038. __le32 FileNameLength;
  1039. char FileName[0]; /* New name to be assigned */
  1040. } __packed; /* level 10 Set */
  1041. struct smb2_file_link_info { /* encoding of request for level 11 */
  1042. __u8 ReplaceIfExists; /* 1 = replace existing link with new */
  1043. /* 0 = fail if link already exists */
  1044. __u8 Reserved[7];
  1045. __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
  1046. __le32 FileNameLength;
  1047. char FileName[0]; /* Name to be assigned to new link */
  1048. } __packed; /* level 11 Set */
  1049. #define SMB2_MAX_EA_BUF 2048
  1050. struct smb2_file_full_ea_info { /* encoding of response for level 15 */
  1051. __le32 next_entry_offset;
  1052. __u8 flags;
  1053. __u8 ea_name_length;
  1054. __le16 ea_value_length;
  1055. char ea_data[0]; /* \0 terminated name plus value */
  1056. } __packed; /* level 15 Set */
  1057. /*
  1058. * This level 18, although with struct with same name is different from cifs
  1059. * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
  1060. * CurrentByteOffset.
  1061. */
  1062. struct smb2_file_all_info { /* data block encoding of response to level 18 */
  1063. __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
  1064. __le64 LastAccessTime;
  1065. __le64 LastWriteTime;
  1066. __le64 ChangeTime;
  1067. __le32 Attributes;
  1068. __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
  1069. __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
  1070. __le64 EndOfFile; /* size ie offset to first free byte in file */
  1071. __le32 NumberOfLinks; /* hard links */
  1072. __u8 DeletePending;
  1073. __u8 Directory;
  1074. __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */
  1075. __le64 IndexNumber;
  1076. __le32 EASize;
  1077. __le32 AccessFlags;
  1078. __le64 CurrentByteOffset;
  1079. __le32 Mode;
  1080. __le32 AlignmentRequirement;
  1081. __le32 FileNameLength;
  1082. char FileName[1];
  1083. } __packed; /* level 18 Query */
  1084. struct smb2_file_eof_info { /* encoding of request for level 10 */
  1085. __le64 EndOfFile; /* new end of file value */
  1086. } __packed; /* level 20 Set */
  1087. #endif /* _SMB2PDU_H */