smb2pdu.h 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724
  1. /* SPDX-License-Identifier: LGPL-2.1 */
  2. #ifndef _COMMON_SMB2PDU_H
  3. #define _COMMON_SMB2PDU_H
  4. /*
  5. * Note that, due to trying to use names similar to the protocol specifications,
  6. * there are many mixed case field names in the structures below. Although
  7. * this does not match typical Linux kernel style, it is necessary to be
  8. * able to match against the protocol specfication.
  9. *
  10. * SMB2 commands
  11. * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses
  12. * (ie no useful data other than the SMB error code itself) and are marked such.
  13. * Knowing this helps avoid response buffer allocations and copy in some cases.
  14. */
  15. /* List of commands in host endian */
  16. #define SMB2_NEGOTIATE_HE 0x0000
  17. #define SMB2_SESSION_SETUP_HE 0x0001
  18. #define SMB2_LOGOFF_HE 0x0002 /* trivial request/resp */
  19. #define SMB2_TREE_CONNECT_HE 0x0003
  20. #define SMB2_TREE_DISCONNECT_HE 0x0004 /* trivial req/resp */
  21. #define SMB2_CREATE_HE 0x0005
  22. #define SMB2_CLOSE_HE 0x0006
  23. #define SMB2_FLUSH_HE 0x0007 /* trivial resp */
  24. #define SMB2_READ_HE 0x0008
  25. #define SMB2_WRITE_HE 0x0009
  26. #define SMB2_LOCK_HE 0x000A
  27. #define SMB2_IOCTL_HE 0x000B
  28. #define SMB2_CANCEL_HE 0x000C
  29. #define SMB2_ECHO_HE 0x000D
  30. #define SMB2_QUERY_DIRECTORY_HE 0x000E
  31. #define SMB2_CHANGE_NOTIFY_HE 0x000F
  32. #define SMB2_QUERY_INFO_HE 0x0010
  33. #define SMB2_SET_INFO_HE 0x0011
  34. #define SMB2_OPLOCK_BREAK_HE 0x0012
  35. /* The same list in little endian */
  36. #define SMB2_NEGOTIATE cpu_to_le16(SMB2_NEGOTIATE_HE)
  37. #define SMB2_SESSION_SETUP cpu_to_le16(SMB2_SESSION_SETUP_HE)
  38. #define SMB2_LOGOFF cpu_to_le16(SMB2_LOGOFF_HE)
  39. #define SMB2_TREE_CONNECT cpu_to_le16(SMB2_TREE_CONNECT_HE)
  40. #define SMB2_TREE_DISCONNECT cpu_to_le16(SMB2_TREE_DISCONNECT_HE)
  41. #define SMB2_CREATE cpu_to_le16(SMB2_CREATE_HE)
  42. #define SMB2_CLOSE cpu_to_le16(SMB2_CLOSE_HE)
  43. #define SMB2_FLUSH cpu_to_le16(SMB2_FLUSH_HE)
  44. #define SMB2_READ cpu_to_le16(SMB2_READ_HE)
  45. #define SMB2_WRITE cpu_to_le16(SMB2_WRITE_HE)
  46. #define SMB2_LOCK cpu_to_le16(SMB2_LOCK_HE)
  47. #define SMB2_IOCTL cpu_to_le16(SMB2_IOCTL_HE)
  48. #define SMB2_CANCEL cpu_to_le16(SMB2_CANCEL_HE)
  49. #define SMB2_ECHO cpu_to_le16(SMB2_ECHO_HE)
  50. #define SMB2_QUERY_DIRECTORY cpu_to_le16(SMB2_QUERY_DIRECTORY_HE)
  51. #define SMB2_CHANGE_NOTIFY cpu_to_le16(SMB2_CHANGE_NOTIFY_HE)
  52. #define SMB2_QUERY_INFO cpu_to_le16(SMB2_QUERY_INFO_HE)
  53. #define SMB2_SET_INFO cpu_to_le16(SMB2_SET_INFO_HE)
  54. #define SMB2_OPLOCK_BREAK cpu_to_le16(SMB2_OPLOCK_BREAK_HE)
  55. #define SMB2_INTERNAL_CMD cpu_to_le16(0xFFFF)
  56. #define NUMBER_OF_SMB2_COMMANDS 0x0013
  57. /*
  58. * Size of the session key (crypto key encrypted with the password
  59. */
  60. #define SMB2_NTLMV2_SESSKEY_SIZE 16
  61. #define SMB2_SIGNATURE_SIZE 16
  62. #define SMB2_HMACSHA256_SIZE 32
  63. #define SMB2_CMACAES_SIZE 16
  64. #define SMB3_GCM128_CRYPTKEY_SIZE 16
  65. #define SMB3_GCM256_CRYPTKEY_SIZE 32
  66. /*
  67. * Size of the smb3 encryption/decryption keys
  68. * This size is big enough to store any cipher key types.
  69. */
  70. #define SMB3_ENC_DEC_KEY_SIZE 32
  71. /*
  72. * Size of the smb3 signing key
  73. */
  74. #define SMB3_SIGN_KEY_SIZE 16
  75. #define CIFS_CLIENT_CHALLENGE_SIZE 8
  76. /* Maximum buffer size value we can send with 1 credit */
  77. #define SMB2_MAX_BUFFER_SIZE 65536
  78. /*
  79. * The default wsize is 1M for SMB2 (and for some CIFS cases).
  80. * find_get_pages seems to return a maximum of 256
  81. * pages in a single call. With PAGE_SIZE == 4k, this means we can
  82. * fill a single wsize request with a single call.
  83. */
  84. #define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024)
  85. /*
  86. * SMB2 Header Definition
  87. *
  88. * "MBZ" : Must be Zero
  89. * "BB" : BugBug, Something to check/review/analyze later
  90. * "PDU" : "Protocol Data Unit" (ie a network "frame")
  91. *
  92. */
  93. #define __SMB2_HEADER_STRUCTURE_SIZE 64
  94. #define SMB2_HEADER_STRUCTURE_SIZE \
  95. cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE)
  96. #define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)
  97. #define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
  98. #define SMB2_COMPRESSION_TRANSFORM_ID cpu_to_le32(0x424d53fc)
  99. /*
  100. * SMB2 flag definitions
  101. */
  102. #define SMB2_FLAGS_SERVER_TO_REDIR cpu_to_le32(0x00000001)
  103. #define SMB2_FLAGS_ASYNC_COMMAND cpu_to_le32(0x00000002)
  104. #define SMB2_FLAGS_RELATED_OPERATIONS cpu_to_le32(0x00000004)
  105. #define SMB2_FLAGS_SIGNED cpu_to_le32(0x00000008)
  106. #define SMB2_FLAGS_PRIORITY_MASK cpu_to_le32(0x00000070) /* SMB3.1.1 */
  107. #define SMB2_FLAGS_DFS_OPERATIONS cpu_to_le32(0x10000000)
  108. #define SMB2_FLAGS_REPLAY_OPERATION cpu_to_le32(0x20000000) /* SMB3 & up */
  109. /*
  110. * Definitions for SMB2 Protocol Data Units (network frames)
  111. *
  112. * See MS-SMB2.PDF specification for protocol details.
  113. * The Naming convention is the lower case version of the SMB2
  114. * command code name for the struct. Note that structures must be packed.
  115. *
  116. */
  117. /* See MS-SMB2 section 2.2.1 */
  118. struct smb2_hdr {
  119. __le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */
  120. __le16 StructureSize; /* 64 */
  121. __le16 CreditCharge; /* MBZ */
  122. __le32 Status; /* Error from server */
  123. __le16 Command;
  124. __le16 CreditRequest; /* CreditResponse */
  125. __le32 Flags;
  126. __le32 NextCommand;
  127. __le64 MessageId;
  128. union {
  129. struct {
  130. __le32 ProcessId;
  131. __le32 TreeId;
  132. } __packed SyncId;
  133. __le64 AsyncId;
  134. } __packed Id;
  135. __le64 SessionId;
  136. __u8 Signature[16];
  137. } __packed;
  138. struct smb3_hdr_req {
  139. __le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */
  140. __le16 StructureSize; /* 64 */
  141. __le16 CreditCharge; /* MBZ */
  142. __le16 ChannelSequence; /* See MS-SMB2 3.2.4.1 and 3.2.7.1 */
  143. __le16 Reserved;
  144. __le16 Command;
  145. __le16 CreditRequest; /* CreditResponse */
  146. __le32 Flags;
  147. __le32 NextCommand;
  148. __le64 MessageId;
  149. union {
  150. struct {
  151. __le32 ProcessId;
  152. __le32 TreeId;
  153. } __packed SyncId;
  154. __le64 AsyncId;
  155. } __packed Id;
  156. __le64 SessionId;
  157. __u8 Signature[16];
  158. } __packed;
  159. struct smb2_pdu {
  160. struct smb2_hdr hdr;
  161. __le16 StructureSize2; /* size of wct area (varies, request specific) */
  162. } __packed;
  163. #define SMB2_ERROR_STRUCTURE_SIZE2 9
  164. #define SMB2_ERROR_STRUCTURE_SIZE2_LE cpu_to_le16(SMB2_ERROR_STRUCTURE_SIZE2)
  165. struct smb2_err_rsp {
  166. struct smb2_hdr hdr;
  167. __le16 StructureSize;
  168. __u8 ErrorContextCount;
  169. __u8 Reserved;
  170. __le32 ByteCount; /* even if zero, at least one byte follows */
  171. __u8 ErrorData[1]; /* variable length */
  172. } __packed;
  173. #define SMB3_AES_CCM_NONCE 11
  174. #define SMB3_AES_GCM_NONCE 12
  175. /* Transform flags (for 3.0 dialect this flag indicates CCM */
  176. #define TRANSFORM_FLAG_ENCRYPTED 0x0001
  177. struct smb2_transform_hdr {
  178. __le32 ProtocolId; /* 0xFD 'S' 'M' 'B' */
  179. __u8 Signature[16];
  180. __u8 Nonce[16];
  181. __le32 OriginalMessageSize;
  182. __u16 Reserved1;
  183. __le16 Flags; /* EncryptionAlgorithm for 3.0, enc enabled for 3.1.1 */
  184. __le64 SessionId;
  185. } __packed;
  186. /* See MS-SMB2 2.2.42 */
  187. struct smb2_compression_transform_hdr_unchained {
  188. __le32 ProtocolId; /* 0xFC 'S' 'M' 'B' */
  189. __le32 OriginalCompressedSegmentSize;
  190. __le16 CompressionAlgorithm;
  191. __le16 Flags;
  192. __le16 Length; /* if chained it is length, else offset */
  193. } __packed;
  194. /* See MS-SMB2 2.2.42.1 */
  195. #define SMB2_COMPRESSION_FLAG_NONE 0x0000
  196. #define SMB2_COMPRESSION_FLAG_CHAINED 0x0001
  197. struct compression_payload_header {
  198. __le16 CompressionAlgorithm;
  199. __le16 Flags;
  200. __le32 Length; /* length of compressed playload including field below if present */
  201. /* __le32 OriginalPayloadSize; */ /* optional, present when LZNT1, LZ77, LZ77+Huffman */
  202. } __packed;
  203. /* See MS-SMB2 2.2.42.2 */
  204. struct smb2_compression_transform_hdr_chained {
  205. __le32 ProtocolId; /* 0xFC 'S' 'M' 'B' */
  206. __le32 OriginalCompressedSegmentSize;
  207. /* struct compression_payload_header[] */
  208. } __packed;
  209. /* See MS-SMB2 2.2.42.2.2 */
  210. struct compression_pattern_payload_v1 {
  211. __le16 Pattern;
  212. __le16 Reserved1;
  213. __le16 Reserved2;
  214. __le32 Repetitions;
  215. } __packed;
  216. /* See MS-SMB2 section 2.2.9.2 */
  217. /* Context Types */
  218. #define SMB2_RESERVED_TREE_CONNECT_CONTEXT_ID 0x0000
  219. #define SMB2_REMOTED_IDENTITY_TREE_CONNECT_CONTEXT_ID cpu_to_le16(0x0001)
  220. struct tree_connect_contexts {
  221. __le16 ContextType;
  222. __le16 DataLength;
  223. __le32 Reserved;
  224. __u8 Data[];
  225. } __packed;
  226. /* Remoted identity tree connect context structures - see MS-SMB2 2.2.9.2.1 */
  227. struct smb3_blob_data {
  228. __le16 BlobSize;
  229. __u8 BlobData[];
  230. } __packed;
  231. /* Valid values for Attr */
  232. #define SE_GROUP_MANDATORY 0x00000001
  233. #define SE_GROUP_ENABLED_BY_DEFAULT 0x00000002
  234. #define SE_GROUP_ENABLED 0x00000004
  235. #define SE_GROUP_OWNER 0x00000008
  236. #define SE_GROUP_USE_FOR_DENY_ONLY 0x00000010
  237. #define SE_GROUP_INTEGRITY 0x00000020
  238. #define SE_GROUP_INTEGRITY_ENABLED 0x00000040
  239. #define SE_GROUP_RESOURCE 0x20000000
  240. #define SE_GROUP_LOGON_ID 0xC0000000
  241. /* struct sid_attr_data is SidData array in BlobData format then le32 Attr */
  242. struct sid_array_data {
  243. __le16 SidAttrCount;
  244. /* SidAttrList - array of sid_attr_data structs */
  245. } __packed;
  246. struct luid_attr_data {
  247. } __packed;
  248. /*
  249. * struct privilege_data is the same as BLOB_DATA - see MS-SMB2 2.2.9.2.1.5
  250. * but with size of LUID_ATTR_DATA struct and BlobData set to LUID_ATTR DATA
  251. */
  252. struct privilege_array_data {
  253. __le16 PrivilegeCount;
  254. /* array of privilege_data structs */
  255. } __packed;
  256. struct remoted_identity_tcon_context {
  257. __le16 TicketType; /* must be 0x0001 */
  258. __le16 TicketSize; /* total size of this struct */
  259. __le16 User; /* offset to SID_ATTR_DATA struct with user info */
  260. __le16 UserName; /* offset to null terminated Unicode username string */
  261. __le16 Domain; /* offset to null terminated Unicode domain name */
  262. __le16 Groups; /* offset to SID_ARRAY_DATA struct with group info */
  263. __le16 RestrictedGroups; /* similar to above */
  264. __le16 Privileges; /* offset to PRIVILEGE_ARRAY_DATA struct */
  265. __le16 PrimaryGroup; /* offset to SID_ARRAY_DATA struct */
  266. __le16 Owner; /* offset to BLOB_DATA struct */
  267. __le16 DefaultDacl; /* offset to BLOB_DATA struct */
  268. __le16 DeviceGroups; /* offset to SID_ARRAY_DATA struct */
  269. __le16 UserClaims; /* offset to BLOB_DATA struct */
  270. __le16 DeviceClaims; /* offset to BLOB_DATA struct */
  271. __u8 TicketInfo[]; /* variable length buf - remoted identity data */
  272. } __packed;
  273. struct smb2_tree_connect_req_extension {
  274. __le32 TreeConnectContextOffset;
  275. __le16 TreeConnectContextCount;
  276. __u8 Reserved[10];
  277. __u8 PathName[]; /* variable sized array */
  278. /* followed by array of TreeConnectContexts */
  279. } __packed;
  280. /* Flags/Reserved for SMB3.1.1 */
  281. #define SMB2_TREE_CONNECT_FLAG_CLUSTER_RECONNECT cpu_to_le16(0x0001)
  282. #define SMB2_TREE_CONNECT_FLAG_REDIRECT_TO_OWNER cpu_to_le16(0x0002)
  283. #define SMB2_TREE_CONNECT_FLAG_EXTENSION_PRESENT cpu_to_le16(0x0004)
  284. struct smb2_tree_connect_req {
  285. struct smb2_hdr hdr;
  286. __le16 StructureSize; /* Must be 9 */
  287. __le16 Flags; /* Flags in SMB3.1.1 */
  288. __le16 PathOffset;
  289. __le16 PathLength;
  290. __u8 Buffer[1]; /* variable length */
  291. } __packed;
  292. /* Possible ShareType values */
  293. #define SMB2_SHARE_TYPE_DISK 0x01
  294. #define SMB2_SHARE_TYPE_PIPE 0x02
  295. #define SMB2_SHARE_TYPE_PRINT 0x03
  296. /*
  297. * Possible ShareFlags - exactly one and only one of the first 4 caching flags
  298. * must be set (any of the remaining, SHI1005, flags may be set individually
  299. * or in combination.
  300. */
  301. #define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000
  302. #define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010
  303. #define SMB2_SHAREFLAG_VDO_CACHING 0x00000020
  304. #define SMB2_SHAREFLAG_NO_CACHING 0x00000030
  305. #define SHI1005_FLAGS_DFS 0x00000001
  306. #define SHI1005_FLAGS_DFS_ROOT 0x00000002
  307. #define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS 0x00000100
  308. #define SHI1005_FLAGS_FORCE_SHARED_DELETE 0x00000200
  309. #define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING 0x00000400
  310. #define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM 0x00000800
  311. #define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK 0x00001000
  312. #define SHI1005_FLAGS_ENABLE_HASH_V1 0x00002000
  313. #define SHI1005_FLAGS_ENABLE_HASH_V2 0x00004000
  314. #define SHI1005_FLAGS_ENCRYPT_DATA 0x00008000
  315. #define SMB2_SHAREFLAG_IDENTITY_REMOTING 0x00040000 /* 3.1.1 */
  316. #define SMB2_SHAREFLAG_COMPRESS_DATA 0x00100000 /* 3.1.1 */
  317. #define SHI1005_FLAGS_ALL 0x0014FF33
  318. /* Possible share capabilities */
  319. #define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008) /* all dialects */
  320. #define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY cpu_to_le32(0x00000010) /* 3.0 */
  321. #define SMB2_SHARE_CAP_SCALEOUT cpu_to_le32(0x00000020) /* 3.0 */
  322. #define SMB2_SHARE_CAP_CLUSTER cpu_to_le32(0x00000040) /* 3.0 */
  323. #define SMB2_SHARE_CAP_ASYMMETRIC cpu_to_le32(0x00000080) /* 3.02 */
  324. #define SMB2_SHARE_CAP_REDIRECT_TO_OWNER cpu_to_le32(0x00000100) /* 3.1.1 */
  325. struct smb2_tree_connect_rsp {
  326. struct smb2_hdr hdr;
  327. __le16 StructureSize; /* Must be 16 */
  328. __u8 ShareType; /* see below */
  329. __u8 Reserved;
  330. __le32 ShareFlags; /* see below */
  331. __le32 Capabilities; /* see below */
  332. __le32 MaximalAccess;
  333. } __packed;
  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. /*
  345. * SMB2_NEGOTIATE_PROTOCOL See MS-SMB2 section 2.2.3
  346. */
  347. /* SecurityMode flags */
  348. #define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001
  349. #define SMB2_NEGOTIATE_SIGNING_ENABLED_LE cpu_to_le16(0x0001)
  350. #define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
  351. #define SMB2_NEGOTIATE_SIGNING_REQUIRED_LE cpu_to_le16(0x0002)
  352. #define SMB2_SEC_MODE_FLAGS_ALL 0x0003
  353. /* Capabilities flags */
  354. #define SMB2_GLOBAL_CAP_DFS 0x00000001
  355. #define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */
  356. #define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */
  357. #define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */
  358. #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
  359. #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */
  360. #define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */
  361. /* Internal types */
  362. #define SMB2_NT_FIND 0x00100000
  363. #define SMB2_LARGE_FILES 0x00200000
  364. #define SMB2_CLIENT_GUID_SIZE 16
  365. #define SMB2_CREATE_GUID_SIZE 16
  366. /* Dialects */
  367. #define SMB10_PROT_ID 0x0000 /* local only, not sent on wire w/CIFS negprot */
  368. #define SMB20_PROT_ID 0x0202
  369. #define SMB21_PROT_ID 0x0210
  370. #define SMB2X_PROT_ID 0x02FF
  371. #define SMB30_PROT_ID 0x0300
  372. #define SMB302_PROT_ID 0x0302
  373. #define SMB311_PROT_ID 0x0311
  374. #define BAD_PROT_ID 0xFFFF
  375. #define SMB311_SALT_SIZE 32
  376. /* Hash Algorithm Types */
  377. #define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001)
  378. #define SMB2_PREAUTH_HASH_SIZE 64
  379. /* Negotiate Contexts - ContextTypes. See MS-SMB2 section 2.2.3.1 for details */
  380. #define SMB2_PREAUTH_INTEGRITY_CAPABILITIES cpu_to_le16(1)
  381. #define SMB2_ENCRYPTION_CAPABILITIES cpu_to_le16(2)
  382. #define SMB2_COMPRESSION_CAPABILITIES cpu_to_le16(3)
  383. #define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID cpu_to_le16(5)
  384. #define SMB2_TRANSPORT_CAPABILITIES cpu_to_le16(6)
  385. #define SMB2_RDMA_TRANSFORM_CAPABILITIES cpu_to_le16(7)
  386. #define SMB2_SIGNING_CAPABILITIES cpu_to_le16(8)
  387. #define SMB2_POSIX_EXTENSIONS_AVAILABLE cpu_to_le16(0x100)
  388. struct smb2_neg_context {
  389. __le16 ContextType;
  390. __le16 DataLength;
  391. __le32 Reserved;
  392. /* Followed by array of data. NOTE: some servers require padding to 8 byte boundary */
  393. } __packed;
  394. /*
  395. * SaltLength that the server send can be zero, so the only three required
  396. * fields (all __le16) end up six bytes total, so the minimum context data len
  397. * in the response is six bytes which accounts for
  398. *
  399. * HashAlgorithmCount, SaltLength, and 1 HashAlgorithm.
  400. */
  401. #define MIN_PREAUTH_CTXT_DATA_LEN 6
  402. struct smb2_preauth_neg_context {
  403. __le16 ContextType; /* 1 */
  404. __le16 DataLength;
  405. __le32 Reserved;
  406. __le16 HashAlgorithmCount; /* 1 */
  407. __le16 SaltLength;
  408. __le16 HashAlgorithms; /* HashAlgorithms[0] since only one defined */
  409. __u8 Salt[SMB311_SALT_SIZE];
  410. } __packed;
  411. /* Encryption Algorithms Ciphers */
  412. #define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001)
  413. #define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002)
  414. #define SMB2_ENCRYPTION_AES256_CCM cpu_to_le16(0x0003)
  415. #define SMB2_ENCRYPTION_AES256_GCM cpu_to_le16(0x0004)
  416. /* Min encrypt context data is one cipher so 2 bytes + 2 byte count field */
  417. #define MIN_ENCRYPT_CTXT_DATA_LEN 4
  418. struct smb2_encryption_neg_context {
  419. __le16 ContextType; /* 2 */
  420. __le16 DataLength;
  421. __le32 Reserved;
  422. /* CipherCount usally 2, but can be 3 when AES256-GCM enabled */
  423. __le16 CipherCount; /* AES128-GCM and AES128-CCM by default */
  424. __le16 Ciphers[];
  425. } __packed;
  426. /* See MS-SMB2 2.2.3.1.3 */
  427. #define SMB3_COMPRESS_NONE cpu_to_le16(0x0000)
  428. #define SMB3_COMPRESS_LZNT1 cpu_to_le16(0x0001)
  429. #define SMB3_COMPRESS_LZ77 cpu_to_le16(0x0002)
  430. #define SMB3_COMPRESS_LZ77_HUFF cpu_to_le16(0x0003)
  431. /* Pattern scanning algorithm See MS-SMB2 3.1.4.4.1 */
  432. #define SMB3_COMPRESS_PATTERN cpu_to_le16(0x0004) /* Pattern_V1 */
  433. /* Compression Flags */
  434. #define SMB2_COMPRESSION_CAPABILITIES_FLAG_NONE cpu_to_le32(0x00000000)
  435. #define SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED cpu_to_le32(0x00000001)
  436. struct smb2_compression_capabilities_context {
  437. __le16 ContextType; /* 3 */
  438. __le16 DataLength;
  439. __le32 Reserved;
  440. __le16 CompressionAlgorithmCount;
  441. __le16 Padding;
  442. __le32 Flags;
  443. __le16 CompressionAlgorithms[3];
  444. __u16 Pad; /* Some servers require pad to DataLen multiple of 8 */
  445. /* Check if pad needed */
  446. } __packed;
  447. /*
  448. * For smb2_netname_negotiate_context_id See MS-SMB2 2.2.3.1.4.
  449. * Its struct simply contains NetName, an array of Unicode characters
  450. */
  451. struct smb2_netname_neg_context {
  452. __le16 ContextType; /* 5 */
  453. __le16 DataLength;
  454. __le32 Reserved;
  455. __le16 NetName[]; /* hostname of target converted to UCS-2 */
  456. } __packed;
  457. /*
  458. * For smb2_transport_capabilities context see MS-SMB2 2.2.3.1.5
  459. * and 2.2.4.1.5
  460. */
  461. /* Flags */
  462. #define SMB2_ACCEPT_TRANSPORT_LEVEL_SECURITY 0x00000001
  463. struct smb2_transport_capabilities_context {
  464. __le16 ContextType; /* 6 */
  465. __le16 DataLength;
  466. __u32 Reserved;
  467. __le32 Flags;
  468. __u32 Pad;
  469. } __packed;
  470. /*
  471. * For rdma transform capabilities context see MS-SMB2 2.2.3.1.6
  472. * and 2.2.4.1.6
  473. */
  474. /* RDMA Transform IDs */
  475. #define SMB2_RDMA_TRANSFORM_NONE 0x0000
  476. #define SMB2_RDMA_TRANSFORM_ENCRYPTION 0x0001
  477. #define SMB2_RDMA_TRANSFORM_SIGNING 0x0002
  478. struct smb2_rdma_transform_capabilities_context {
  479. __le16 ContextType; /* 7 */
  480. __le16 DataLength;
  481. __u32 Reserved;
  482. __le16 TransformCount;
  483. __u16 Reserved1;
  484. __u32 Reserved2;
  485. __le16 RDMATransformIds[];
  486. } __packed;
  487. /*
  488. * For signing capabilities context see MS-SMB2 2.2.3.1.7
  489. * and 2.2.4.1.7
  490. */
  491. /* Signing algorithms */
  492. #define SIGNING_ALG_HMAC_SHA256 0
  493. #define SIGNING_ALG_HMAC_SHA256_LE cpu_to_le16(0)
  494. #define SIGNING_ALG_AES_CMAC 1
  495. #define SIGNING_ALG_AES_CMAC_LE cpu_to_le16(1)
  496. #define SIGNING_ALG_AES_GMAC 2
  497. #define SIGNING_ALG_AES_GMAC_LE cpu_to_le16(2)
  498. struct smb2_signing_capabilities {
  499. __le16 ContextType; /* 8 */
  500. __le16 DataLength;
  501. __le32 Reserved;
  502. __le16 SigningAlgorithmCount;
  503. __le16 SigningAlgorithms[];
  504. /* Followed by padding to 8 byte boundary (required by some servers) */
  505. } __packed;
  506. #define POSIX_CTXT_DATA_LEN 16
  507. struct smb2_posix_neg_context {
  508. __le16 ContextType; /* 0x100 */
  509. __le16 DataLength;
  510. __le32 Reserved;
  511. __u8 Name[16]; /* POSIX ctxt GUID 93AD25509CB411E7B42383DE968BCD7C */
  512. } __packed;
  513. struct smb2_negotiate_req {
  514. struct smb2_hdr hdr;
  515. __le16 StructureSize; /* Must be 36 */
  516. __le16 DialectCount;
  517. __le16 SecurityMode;
  518. __le16 Reserved; /* MBZ */
  519. __le32 Capabilities;
  520. __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE];
  521. /* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */
  522. __le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */
  523. __le16 NegotiateContextCount; /* SMB3.1.1 only. MBZ earlier */
  524. __le16 Reserved2;
  525. __le16 Dialects[];
  526. } __packed;
  527. struct smb2_negotiate_rsp {
  528. struct smb2_hdr hdr;
  529. __le16 StructureSize; /* Must be 65 */
  530. __le16 SecurityMode;
  531. __le16 DialectRevision;
  532. __le16 NegotiateContextCount; /* Prior to SMB3.1.1 was Reserved & MBZ */
  533. __u8 ServerGUID[16];
  534. __le32 Capabilities;
  535. __le32 MaxTransactSize;
  536. __le32 MaxReadSize;
  537. __le32 MaxWriteSize;
  538. __le64 SystemTime; /* MBZ */
  539. __le64 ServerStartTime;
  540. __le16 SecurityBufferOffset;
  541. __le16 SecurityBufferLength;
  542. __le32 NegotiateContextOffset; /* Pre:SMB3.1.1 was reserved/ignored */
  543. __u8 Buffer[1]; /* variable length GSS security buffer */
  544. } __packed;
  545. /*
  546. * SMB2_SESSION_SETUP See MS-SMB2 section 2.2.5
  547. */
  548. /* Flags */
  549. #define SMB2_SESSION_REQ_FLAG_BINDING 0x01
  550. #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04
  551. struct smb2_sess_setup_req {
  552. struct smb2_hdr hdr;
  553. __le16 StructureSize; /* Must be 25 */
  554. __u8 Flags;
  555. __u8 SecurityMode;
  556. __le32 Capabilities;
  557. __le32 Channel;
  558. __le16 SecurityBufferOffset;
  559. __le16 SecurityBufferLength;
  560. __le64 PreviousSessionId;
  561. __u8 Buffer[1]; /* variable length GSS security buffer */
  562. } __packed;
  563. /* Currently defined SessionFlags */
  564. #define SMB2_SESSION_FLAG_IS_GUEST 0x0001
  565. #define SMB2_SESSION_FLAG_IS_GUEST_LE cpu_to_le16(0x0001)
  566. #define SMB2_SESSION_FLAG_IS_NULL 0x0002
  567. #define SMB2_SESSION_FLAG_IS_NULL_LE cpu_to_le16(0x0002)
  568. #define SMB2_SESSION_FLAG_ENCRYPT_DATA 0x0004
  569. #define SMB2_SESSION_FLAG_ENCRYPT_DATA_LE cpu_to_le16(0x0004)
  570. struct smb2_sess_setup_rsp {
  571. struct smb2_hdr hdr;
  572. __le16 StructureSize; /* Must be 9 */
  573. __le16 SessionFlags;
  574. __le16 SecurityBufferOffset;
  575. __le16 SecurityBufferLength;
  576. __u8 Buffer[1]; /* variable length GSS security buffer */
  577. } __packed;
  578. /*
  579. * SMB2_LOGOFF See MS-SMB2 section 2.2.7
  580. */
  581. struct smb2_logoff_req {
  582. struct smb2_hdr hdr;
  583. __le16 StructureSize; /* Must be 4 */
  584. __le16 Reserved;
  585. } __packed;
  586. struct smb2_logoff_rsp {
  587. struct smb2_hdr hdr;
  588. __le16 StructureSize; /* Must be 4 */
  589. __le16 Reserved;
  590. } __packed;
  591. /*
  592. * SMB2_CLOSE See MS-SMB2 section 2.2.15
  593. */
  594. /* Currently defined values for close flags */
  595. #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
  596. struct smb2_close_req {
  597. struct smb2_hdr hdr;
  598. __le16 StructureSize; /* Must be 24 */
  599. __le16 Flags;
  600. __le32 Reserved;
  601. __u64 PersistentFileId; /* opaque endianness */
  602. __u64 VolatileFileId; /* opaque endianness */
  603. } __packed;
  604. /*
  605. * Maximum size of a SMB2_CLOSE response is 64 (smb2 header) + 60 (data)
  606. */
  607. #define MAX_SMB2_CLOSE_RESPONSE_SIZE 124
  608. struct smb2_close_rsp {
  609. struct smb2_hdr hdr;
  610. __le16 StructureSize; /* 60 */
  611. __le16 Flags;
  612. __le32 Reserved;
  613. __le64 CreationTime;
  614. __le64 LastAccessTime;
  615. __le64 LastWriteTime;
  616. __le64 ChangeTime;
  617. __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
  618. __le64 EndOfFile;
  619. __le32 Attributes;
  620. } __packed;
  621. /*
  622. * SMB2_READ See MS-SMB2 section 2.2.19
  623. */
  624. /* For read request Flags field below, following flag is defined for SMB3.02 */
  625. #define SMB2_READFLAG_READ_UNBUFFERED 0x01
  626. #define SMB2_READFLAG_REQUEST_COMPRESSED 0x02 /* See MS-SMB2 2.2.19 */
  627. /* Channel field for read and write: exactly one of following flags can be set*/
  628. #define SMB2_CHANNEL_NONE cpu_to_le32(0x00000000)
  629. #define SMB2_CHANNEL_RDMA_V1 cpu_to_le32(0x00000001)
  630. #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002)
  631. #define SMB2_CHANNEL_RDMA_TRANSFORM cpu_to_le32(0x00000003)
  632. /* SMB2 read request without RFC1001 length at the beginning */
  633. struct smb2_read_req {
  634. struct smb2_hdr hdr;
  635. __le16 StructureSize; /* Must be 49 */
  636. __u8 Padding; /* offset from start of SMB2 header to place read */
  637. __u8 Flags; /* MBZ unless SMB3.02 or later */
  638. __le32 Length;
  639. __le64 Offset;
  640. __u64 PersistentFileId;
  641. __u64 VolatileFileId;
  642. __le32 MinimumCount;
  643. __le32 Channel; /* MBZ except for SMB3 or later */
  644. __le32 RemainingBytes;
  645. __le16 ReadChannelInfoOffset;
  646. __le16 ReadChannelInfoLength;
  647. __u8 Buffer[1];
  648. } __packed;
  649. /* Read flags */
  650. #define SMB2_READFLAG_RESPONSE_NONE cpu_to_le32(0x00000000)
  651. #define SMB2_READFLAG_RESPONSE_RDMA_TRANSFORM cpu_to_le32(0x00000001)
  652. struct smb2_read_rsp {
  653. struct smb2_hdr hdr;
  654. __le16 StructureSize; /* Must be 17 */
  655. __u8 DataOffset;
  656. __u8 Reserved;
  657. __le32 DataLength;
  658. __le32 DataRemaining;
  659. __le32 Flags;
  660. __u8 Buffer[1];
  661. } __packed;
  662. /*
  663. * SMB2_WRITE See MS-SMB2 section 2.2.21
  664. */
  665. /* For write request Flags field below the following flags are defined: */
  666. #define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 /* SMB2.1 or later */
  667. #define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002 /* SMB3.02 or later */
  668. struct smb2_write_req {
  669. struct smb2_hdr hdr;
  670. __le16 StructureSize; /* Must be 49 */
  671. __le16 DataOffset; /* offset from start of SMB2 header to write data */
  672. __le32 Length;
  673. __le64 Offset;
  674. __u64 PersistentFileId; /* opaque endianness */
  675. __u64 VolatileFileId; /* opaque endianness */
  676. __le32 Channel; /* MBZ unless SMB3.02 or later */
  677. __le32 RemainingBytes;
  678. __le16 WriteChannelInfoOffset;
  679. __le16 WriteChannelInfoLength;
  680. __le32 Flags;
  681. __u8 Buffer[1];
  682. } __packed;
  683. struct smb2_write_rsp {
  684. struct smb2_hdr hdr;
  685. __le16 StructureSize; /* Must be 17 */
  686. __u8 DataOffset;
  687. __u8 Reserved;
  688. __le32 DataLength;
  689. __le32 DataRemaining;
  690. __u32 Reserved2;
  691. __u8 Buffer[1];
  692. } __packed;
  693. /*
  694. * SMB2_FLUSH See MS-SMB2 section 2.2.17
  695. */
  696. struct smb2_flush_req {
  697. struct smb2_hdr hdr;
  698. __le16 StructureSize; /* Must be 24 */
  699. __le16 Reserved1;
  700. __le32 Reserved2;
  701. __u64 PersistentFileId;
  702. __u64 VolatileFileId;
  703. } __packed;
  704. struct smb2_flush_rsp {
  705. struct smb2_hdr hdr;
  706. __le16 StructureSize;
  707. __le16 Reserved;
  708. } __packed;
  709. #define SMB2_LOCKFLAG_SHARED 0x0001
  710. #define SMB2_LOCKFLAG_EXCLUSIVE 0x0002
  711. #define SMB2_LOCKFLAG_UNLOCK 0x0004
  712. #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010
  713. #define SMB2_LOCKFLAG_MASK 0x0007
  714. struct smb2_lock_element {
  715. __le64 Offset;
  716. __le64 Length;
  717. __le32 Flags;
  718. __le32 Reserved;
  719. } __packed;
  720. struct smb2_lock_req {
  721. struct smb2_hdr hdr;
  722. __le16 StructureSize; /* Must be 48 */
  723. __le16 LockCount;
  724. /*
  725. * The least significant four bits are the index, the other 28 bits are
  726. * the lock sequence number (0 to 64). See MS-SMB2 2.2.26
  727. */
  728. __le32 LockSequenceNumber;
  729. __u64 PersistentFileId;
  730. __u64 VolatileFileId;
  731. /* Followed by at least one */
  732. struct smb2_lock_element locks[1];
  733. } __packed;
  734. struct smb2_lock_rsp {
  735. struct smb2_hdr hdr;
  736. __le16 StructureSize; /* Must be 4 */
  737. __le16 Reserved;
  738. } __packed;
  739. struct smb2_echo_req {
  740. struct smb2_hdr hdr;
  741. __le16 StructureSize; /* Must be 4 */
  742. __u16 Reserved;
  743. } __packed;
  744. struct smb2_echo_rsp {
  745. struct smb2_hdr hdr;
  746. __le16 StructureSize; /* Must be 4 */
  747. __u16 Reserved;
  748. } __packed;
  749. /*
  750. * Valid FileInformation classes for query directory
  751. *
  752. * Note that these are a subset of the (file) QUERY_INFO levels defined
  753. * later in this file (but since QUERY_DIRECTORY uses equivalent numbers
  754. * we do not redefine them here)
  755. *
  756. * FileDirectoryInfomation 0x01
  757. * FileFullDirectoryInformation 0x02
  758. * FileIdFullDirectoryInformation 0x26
  759. * FileBothDirectoryInformation 0x03
  760. * FileIdBothDirectoryInformation 0x25
  761. * FileNamesInformation 0x0C
  762. * FileIdExtdDirectoryInformation 0x3C
  763. */
  764. /* search (query_directory) Flags field */
  765. #define SMB2_RESTART_SCANS 0x01
  766. #define SMB2_RETURN_SINGLE_ENTRY 0x02
  767. #define SMB2_INDEX_SPECIFIED 0x04
  768. #define SMB2_REOPEN 0x10
  769. struct smb2_query_directory_req {
  770. struct smb2_hdr hdr;
  771. __le16 StructureSize; /* Must be 33 */
  772. __u8 FileInformationClass;
  773. __u8 Flags;
  774. __le32 FileIndex;
  775. __u64 PersistentFileId;
  776. __u64 VolatileFileId;
  777. __le16 FileNameOffset;
  778. __le16 FileNameLength;
  779. __le32 OutputBufferLength;
  780. __u8 Buffer[1];
  781. } __packed;
  782. struct smb2_query_directory_rsp {
  783. struct smb2_hdr hdr;
  784. __le16 StructureSize; /* Must be 9 */
  785. __le16 OutputBufferOffset;
  786. __le32 OutputBufferLength;
  787. __u8 Buffer[1];
  788. } __packed;
  789. /*
  790. * Maximum number of iovs we need for a set-info request.
  791. * The largest one is rename/hardlink
  792. * [0] : struct smb2_set_info_req + smb2_file_[rename|link]_info
  793. * [1] : path
  794. * [2] : compound padding
  795. */
  796. #define SMB2_SET_INFO_IOV_SIZE 3
  797. struct smb2_set_info_req {
  798. struct smb2_hdr hdr;
  799. __le16 StructureSize; /* Must be 33 */
  800. __u8 InfoType;
  801. __u8 FileInfoClass;
  802. __le32 BufferLength;
  803. __le16 BufferOffset;
  804. __u16 Reserved;
  805. __le32 AdditionalInformation;
  806. __u64 PersistentFileId;
  807. __u64 VolatileFileId;
  808. __u8 Buffer[1];
  809. } __packed;
  810. struct smb2_set_info_rsp {
  811. struct smb2_hdr hdr;
  812. __le16 StructureSize; /* Must be 2 */
  813. } __packed;
  814. /*
  815. * SMB2_NOTIFY See MS-SMB2 section 2.2.35
  816. */
  817. /* notify flags */
  818. #define SMB2_WATCH_TREE 0x0001
  819. /* notify completion filter flags. See MS-FSCC 2.6 and MS-SMB2 2.2.35 */
  820. #define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001
  821. #define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002
  822. #define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004
  823. #define FILE_NOTIFY_CHANGE_SIZE 0x00000008
  824. #define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010
  825. #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020
  826. #define FILE_NOTIFY_CHANGE_CREATION 0x00000040
  827. #define FILE_NOTIFY_CHANGE_EA 0x00000080
  828. #define FILE_NOTIFY_CHANGE_SECURITY 0x00000100
  829. #define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200
  830. #define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400
  831. #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
  832. /* SMB2 Notify Action Flags */
  833. #define FILE_ACTION_ADDED 0x00000001
  834. #define FILE_ACTION_REMOVED 0x00000002
  835. #define FILE_ACTION_MODIFIED 0x00000003
  836. #define FILE_ACTION_RENAMED_OLD_NAME 0x00000004
  837. #define FILE_ACTION_RENAMED_NEW_NAME 0x00000005
  838. #define FILE_ACTION_ADDED_STREAM 0x00000006
  839. #define FILE_ACTION_REMOVED_STREAM 0x00000007
  840. #define FILE_ACTION_MODIFIED_STREAM 0x00000008
  841. #define FILE_ACTION_REMOVED_BY_DELETE 0x00000009
  842. struct smb2_change_notify_req {
  843. struct smb2_hdr hdr;
  844. __le16 StructureSize;
  845. __le16 Flags;
  846. __le32 OutputBufferLength;
  847. __u64 PersistentFileId; /* opaque endianness */
  848. __u64 VolatileFileId; /* opaque endianness */
  849. __le32 CompletionFilter;
  850. __u32 Reserved;
  851. } __packed;
  852. struct smb2_change_notify_rsp {
  853. struct smb2_hdr hdr;
  854. __le16 StructureSize; /* Must be 9 */
  855. __le16 OutputBufferOffset;
  856. __le32 OutputBufferLength;
  857. __u8 Buffer[1]; /* array of file notify structs */
  858. } __packed;
  859. /*
  860. * SMB2_CREATE See MS-SMB2 section 2.2.13
  861. */
  862. /* Oplock levels */
  863. #define SMB2_OPLOCK_LEVEL_NONE 0x00
  864. #define SMB2_OPLOCK_LEVEL_II 0x01
  865. #define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
  866. #define SMB2_OPLOCK_LEVEL_BATCH 0x09
  867. #define SMB2_OPLOCK_LEVEL_LEASE 0xFF
  868. /* Non-spec internal type */
  869. #define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99
  870. /* Impersonation Levels. See MS-WPO section 9.7 and MSDN-IMPERS */
  871. #define IL_ANONYMOUS cpu_to_le32(0x00000000)
  872. #define IL_IDENTIFICATION cpu_to_le32(0x00000001)
  873. #define IL_IMPERSONATION cpu_to_le32(0x00000002)
  874. #define IL_DELEGATE cpu_to_le32(0x00000003)
  875. /* File Attrubutes */
  876. #define FILE_ATTRIBUTE_READONLY 0x00000001
  877. #define FILE_ATTRIBUTE_HIDDEN 0x00000002
  878. #define FILE_ATTRIBUTE_SYSTEM 0x00000004
  879. #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
  880. #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
  881. #define FILE_ATTRIBUTE_NORMAL 0x00000080
  882. #define FILE_ATTRIBUTE_TEMPORARY 0x00000100
  883. #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
  884. #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
  885. #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
  886. #define FILE_ATTRIBUTE_OFFLINE 0x00001000
  887. #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
  888. #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
  889. #define FILE_ATTRIBUTE_INTEGRITY_STREAM 0x00008000
  890. #define FILE_ATTRIBUTE_NO_SCRUB_DATA 0x00020000
  891. #define FILE_ATTRIBUTE__MASK 0x00007FB7
  892. #define FILE_ATTRIBUTE_READONLY_LE cpu_to_le32(0x00000001)
  893. #define FILE_ATTRIBUTE_HIDDEN_LE cpu_to_le32(0x00000002)
  894. #define FILE_ATTRIBUTE_SYSTEM_LE cpu_to_le32(0x00000004)
  895. #define FILE_ATTRIBUTE_DIRECTORY_LE cpu_to_le32(0x00000010)
  896. #define FILE_ATTRIBUTE_ARCHIVE_LE cpu_to_le32(0x00000020)
  897. #define FILE_ATTRIBUTE_NORMAL_LE cpu_to_le32(0x00000080)
  898. #define FILE_ATTRIBUTE_TEMPORARY_LE cpu_to_le32(0x00000100)
  899. #define FILE_ATTRIBUTE_SPARSE_FILE_LE cpu_to_le32(0x00000200)
  900. #define FILE_ATTRIBUTE_REPARSE_POINT_LE cpu_to_le32(0x00000400)
  901. #define FILE_ATTRIBUTE_COMPRESSED_LE cpu_to_le32(0x00000800)
  902. #define FILE_ATTRIBUTE_OFFLINE_LE cpu_to_le32(0x00001000)
  903. #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED_LE cpu_to_le32(0x00002000)
  904. #define FILE_ATTRIBUTE_ENCRYPTED_LE cpu_to_le32(0x00004000)
  905. #define FILE_ATTRIBUTE_INTEGRITY_STREAM_LE cpu_to_le32(0x00008000)
  906. #define FILE_ATTRIBUTE_NO_SCRUB_DATA_LE cpu_to_le32(0x00020000)
  907. #define FILE_ATTRIBUTE_MASK_LE cpu_to_le32(0x00007FB7)
  908. /* Desired Access Flags */
  909. #define FILE_READ_DATA_LE cpu_to_le32(0x00000001)
  910. #define FILE_LIST_DIRECTORY_LE cpu_to_le32(0x00000001)
  911. #define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002)
  912. #define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004)
  913. #define FILE_ADD_SUBDIRECTORY_LE cpu_to_le32(0x00000004)
  914. #define FILE_READ_EA_LE cpu_to_le32(0x00000008)
  915. #define FILE_WRITE_EA_LE cpu_to_le32(0x00000010)
  916. #define FILE_EXECUTE_LE cpu_to_le32(0x00000020)
  917. #define FILE_DELETE_CHILD_LE cpu_to_le32(0x00000040)
  918. #define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080)
  919. #define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100)
  920. #define FILE_DELETE_LE cpu_to_le32(0x00010000)
  921. #define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000)
  922. #define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000)
  923. #define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000)
  924. #define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000)
  925. #define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000)
  926. #define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000)
  927. #define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000)
  928. #define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000)
  929. #define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000)
  930. #define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000)
  931. #define DESIRED_ACCESS_MASK cpu_to_le32(0xF21F01FF)
  932. #define FILE_READ_DESIRED_ACCESS_LE (FILE_READ_DATA_LE | \
  933. FILE_READ_EA_LE | \
  934. FILE_GENERIC_READ_LE)
  935. #define FILE_WRITE_DESIRE_ACCESS_LE (FILE_WRITE_DATA_LE | \
  936. FILE_APPEND_DATA_LE | \
  937. FILE_WRITE_EA_LE | \
  938. FILE_WRITE_ATTRIBUTES_LE | \
  939. FILE_GENERIC_WRITE_LE)
  940. /* ShareAccess Flags */
  941. #define FILE_SHARE_READ_LE cpu_to_le32(0x00000001)
  942. #define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002)
  943. #define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004)
  944. #define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007)
  945. /* CreateDisposition Flags */
  946. #define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000)
  947. #define FILE_OPEN_LE cpu_to_le32(0x00000001)
  948. #define FILE_CREATE_LE cpu_to_le32(0x00000002)
  949. #define FILE_OPEN_IF_LE cpu_to_le32(0x00000003)
  950. #define FILE_OVERWRITE_LE cpu_to_le32(0x00000004)
  951. #define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005)
  952. #define FILE_CREATE_MASK_LE cpu_to_le32(0x00000007)
  953. #define FILE_READ_RIGHTS (FILE_READ_DATA | FILE_READ_EA \
  954. | FILE_READ_ATTRIBUTES)
  955. #define FILE_WRITE_RIGHTS (FILE_WRITE_DATA | FILE_APPEND_DATA \
  956. | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES)
  957. #define FILE_EXEC_RIGHTS (FILE_EXECUTE)
  958. /* CreateOptions Flags */
  959. #define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001)
  960. /* same as #define CREATE_NOT_FILE_LE cpu_to_le32(0x00000001) */
  961. #define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002)
  962. #define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004)
  963. #define FILE_NO_INTERMEDIATE_BUFFERING_LE cpu_to_le32(0x00000008)
  964. #define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040)
  965. #define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100)
  966. #define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200)
  967. #define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800)
  968. #define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000)
  969. #define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000)
  970. #define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000)
  971. #define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000)
  972. #define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000)
  973. #define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000)
  974. #define CREATE_OPTIONS_MASK_LE cpu_to_le32(0x00FFFFFF)
  975. #define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \
  976. | FILE_READ_ATTRIBUTES_LE)
  977. #define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \
  978. | FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
  979. #define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
  980. /* Create Context Values */
  981. #define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */
  982. #define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */
  983. #define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ"
  984. #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC"
  985. #define SMB2_CREATE_ALLOCATION_SIZE "AISi"
  986. #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
  987. #define SMB2_CREATE_TIMEWARP_REQUEST "TWrp"
  988. #define SMB2_CREATE_QUERY_ON_DISK_ID "QFid"
  989. #define SMB2_CREATE_REQUEST_LEASE "RqLs"
  990. #define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 "DH2Q"
  991. #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 "DH2C"
  992. #define SMB2_CREATE_TAG_POSIX "\x93\xAD\x25\x50\x9C\xB4\x11\xE7\xB4\x23\x83\xDE\x96\x8B\xCD\x7C"
  993. #define SMB2_CREATE_APP_INSTANCE_ID "\x45\xBC\xA6\x6A\xEF\xA7\xF7\x4A\x90\x08\xFA\x46\x2E\x14\x4D\x74"
  994. #define SMB2_CREATE_APP_INSTANCE_VERSION "\xB9\x82\xD0\xB7\x3B\x56\x07\x4F\xA0\x7B\x52\x4A\x81\x16\xA0\x10"
  995. #define SVHDX_OPEN_DEVICE_CONTEXT "\x9C\xCB\xCF\x9E\x04\xC1\xE6\x43\x98\x0E\x15\x8D\xA1\xF6\xEC\x83"
  996. #define SMB2_CREATE_TAG_AAPL "AAPL"
  997. /* Flag (SMB3 open response) values */
  998. #define SMB2_CREATE_FLAG_REPARSEPOINT 0x01
  999. struct create_context {
  1000. __le32 Next;
  1001. __le16 NameOffset;
  1002. __le16 NameLength;
  1003. __le16 Reserved;
  1004. __le16 DataOffset;
  1005. __le32 DataLength;
  1006. __u8 Buffer[];
  1007. } __packed;
  1008. struct smb2_create_req {
  1009. struct smb2_hdr hdr;
  1010. __le16 StructureSize; /* Must be 57 */
  1011. __u8 SecurityFlags;
  1012. __u8 RequestedOplockLevel;
  1013. __le32 ImpersonationLevel;
  1014. __le64 SmbCreateFlags;
  1015. __le64 Reserved;
  1016. __le32 DesiredAccess;
  1017. __le32 FileAttributes;
  1018. __le32 ShareAccess;
  1019. __le32 CreateDisposition;
  1020. __le32 CreateOptions;
  1021. __le16 NameOffset;
  1022. __le16 NameLength;
  1023. __le32 CreateContextsOffset;
  1024. __le32 CreateContextsLength;
  1025. __u8 Buffer[];
  1026. } __packed;
  1027. struct smb2_create_rsp {
  1028. struct smb2_hdr hdr;
  1029. __le16 StructureSize; /* Must be 89 */
  1030. __u8 OplockLevel;
  1031. __u8 Flags; /* 0x01 if reparse point */
  1032. __le32 CreateAction;
  1033. __le64 CreationTime;
  1034. __le64 LastAccessTime;
  1035. __le64 LastWriteTime;
  1036. __le64 ChangeTime;
  1037. __le64 AllocationSize;
  1038. __le64 EndofFile;
  1039. __le32 FileAttributes;
  1040. __le32 Reserved2;
  1041. __u64 PersistentFileId;
  1042. __u64 VolatileFileId;
  1043. __le32 CreateContextsOffset;
  1044. __le32 CreateContextsLength;
  1045. __u8 Buffer[1];
  1046. } __packed;
  1047. struct create_posix {
  1048. struct create_context ccontext;
  1049. __u8 Name[16];
  1050. __le32 Mode;
  1051. __u32 Reserved;
  1052. } __packed;
  1053. #define SMB2_LEASE_NONE_LE cpu_to_le32(0x00)
  1054. #define SMB2_LEASE_READ_CACHING_LE cpu_to_le32(0x01)
  1055. #define SMB2_LEASE_HANDLE_CACHING_LE cpu_to_le32(0x02)
  1056. #define SMB2_LEASE_WRITE_CACHING_LE cpu_to_le32(0x04)
  1057. #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE cpu_to_le32(0x02)
  1058. #define SMB2_LEASE_KEY_SIZE 16
  1059. struct lease_context {
  1060. __u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
  1061. __le32 LeaseState;
  1062. __le32 LeaseFlags;
  1063. __le64 LeaseDuration;
  1064. } __packed;
  1065. struct lease_context_v2 {
  1066. __u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
  1067. __le32 LeaseState;
  1068. __le32 LeaseFlags;
  1069. __le64 LeaseDuration;
  1070. __u8 ParentLeaseKey[SMB2_LEASE_KEY_SIZE];
  1071. __le16 Epoch;
  1072. __le16 Reserved;
  1073. } __packed;
  1074. struct create_lease {
  1075. struct create_context ccontext;
  1076. __u8 Name[8];
  1077. struct lease_context lcontext;
  1078. } __packed;
  1079. struct create_lease_v2 {
  1080. struct create_context ccontext;
  1081. __u8 Name[8];
  1082. struct lease_context_v2 lcontext;
  1083. __u8 Pad[4];
  1084. } __packed;
  1085. /* See MS-SMB2 2.2.31 and 2.2.32 */
  1086. struct smb2_ioctl_req {
  1087. struct smb2_hdr hdr;
  1088. __le16 StructureSize; /* Must be 57 */
  1089. __le16 Reserved; /* offset from start of SMB2 header to write data */
  1090. __le32 CtlCode;
  1091. __u64 PersistentFileId;
  1092. __u64 VolatileFileId;
  1093. __le32 InputOffset; /* Reserved MBZ */
  1094. __le32 InputCount;
  1095. __le32 MaxInputResponse;
  1096. __le32 OutputOffset;
  1097. __le32 OutputCount;
  1098. __le32 MaxOutputResponse;
  1099. __le32 Flags;
  1100. __le32 Reserved2;
  1101. __u8 Buffer[];
  1102. } __packed;
  1103. struct smb2_ioctl_rsp {
  1104. struct smb2_hdr hdr;
  1105. __le16 StructureSize; /* Must be 49 */
  1106. __le16 Reserved;
  1107. __le32 CtlCode;
  1108. __u64 PersistentFileId;
  1109. __u64 VolatileFileId;
  1110. __le32 InputOffset; /* Reserved MBZ */
  1111. __le32 InputCount;
  1112. __le32 OutputOffset;
  1113. __le32 OutputCount;
  1114. __le32 Flags;
  1115. __le32 Reserved2;
  1116. __u8 Buffer[];
  1117. } __packed;
  1118. /* this goes in the ioctl buffer when doing FSCTL_SET_ZERO_DATA */
  1119. struct file_zero_data_information {
  1120. __le64 FileOffset;
  1121. __le64 BeyondFinalZero;
  1122. } __packed;
  1123. /* See MS-FSCC 2.3.7 */
  1124. struct duplicate_extents_to_file {
  1125. __u64 PersistentFileHandle; /* source file handle, opaque endianness */
  1126. __u64 VolatileFileHandle;
  1127. __le64 SourceFileOffset;
  1128. __le64 TargetFileOffset;
  1129. __le64 ByteCount; /* Bytes to be copied */
  1130. } __packed;
  1131. /* See MS-FSCC 2.3.8 */
  1132. #define DUPLICATE_EXTENTS_DATA_EX_SOURCE_ATOMIC 0x00000001
  1133. struct duplicate_extents_to_file_ex {
  1134. __u64 PersistentFileHandle; /* source file handle, opaque endianness */
  1135. __u64 VolatileFileHandle;
  1136. __le64 SourceFileOffset;
  1137. __le64 TargetFileOffset;
  1138. __le64 ByteCount; /* Bytes to be copied */
  1139. __le32 Flags;
  1140. __le32 Reserved;
  1141. } __packed;
  1142. /* See MS-FSCC 2.3.20 */
  1143. struct fsctl_get_integrity_information_rsp {
  1144. __le16 ChecksumAlgorithm;
  1145. __le16 Reserved;
  1146. __le32 Flags;
  1147. __le32 ChecksumChunkSizeInBytes;
  1148. __le32 ClusterSizeInBytes;
  1149. } __packed;
  1150. /* See MS-FSCC 2.3.55 */
  1151. struct fsctl_query_file_regions_req {
  1152. __le64 FileOffset;
  1153. __le64 Length;
  1154. __le32 DesiredUsage;
  1155. __le32 Reserved;
  1156. } __packed;
  1157. /* DesiredUsage flags see MS-FSCC 2.3.56.1 */
  1158. #define FILE_USAGE_INVALID_RANGE 0x00000000
  1159. #define FILE_USAGE_VALID_CACHED_DATA 0x00000001
  1160. #define FILE_USAGE_NONCACHED_DATA 0x00000002
  1161. struct file_region_info {
  1162. __le64 FileOffset;
  1163. __le64 Length;
  1164. __le32 DesiredUsage;
  1165. __le32 Reserved;
  1166. } __packed;
  1167. /* See MS-FSCC 2.3.56 */
  1168. struct fsctl_query_file_region_rsp {
  1169. __le32 Flags;
  1170. __le32 TotalRegionEntryCount;
  1171. __le32 RegionEntryCount;
  1172. __u32 Reserved;
  1173. struct file_region_info Regions[];
  1174. } __packed;
  1175. /* See MS-FSCC 2.3.58 */
  1176. struct fsctl_query_on_disk_vol_info_rsp {
  1177. __le64 DirectoryCount;
  1178. __le64 FileCount;
  1179. __le16 FsFormatMajVersion;
  1180. __le16 FsFormatMinVersion;
  1181. __u8 FsFormatName[24];
  1182. __le64 FormatTime;
  1183. __le64 LastUpdateTime;
  1184. __u8 CopyrightInfo[68];
  1185. __u8 AbstractInfo[68];
  1186. __u8 FormatImplInfo[68];
  1187. __u8 LastModifyImplInfo[68];
  1188. } __packed;
  1189. /* See MS-FSCC 2.3.73 */
  1190. struct fsctl_set_integrity_information_req {
  1191. __le16 ChecksumAlgorithm;
  1192. __le16 Reserved;
  1193. __le32 Flags;
  1194. } __packed;
  1195. /* See MS-FSCC 2.3.75 */
  1196. struct fsctl_set_integrity_info_ex_req {
  1197. __u8 EnableIntegrity;
  1198. __u8 KeepState;
  1199. __u16 Reserved;
  1200. __le32 Flags;
  1201. __u8 Version;
  1202. __u8 Reserved2[7];
  1203. } __packed;
  1204. /* Integrity ChecksumAlgorithm choices for above */
  1205. #define CHECKSUM_TYPE_NONE 0x0000
  1206. #define CHECKSUM_TYPE_CRC64 0x0002
  1207. #define CHECKSUM_TYPE_UNCHANGED 0xFFFF /* set only */
  1208. /* Integrity flags for above */
  1209. #define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF 0x00000001
  1210. /* Reparse structures - see MS-FSCC 2.1.2 */
  1211. /* struct fsctl_reparse_info_req is empty, only response structs (see below) */
  1212. struct reparse_data_buffer {
  1213. __le32 ReparseTag;
  1214. __le16 ReparseDataLength;
  1215. __u16 Reserved;
  1216. __u8 DataBuffer[]; /* Variable Length */
  1217. } __packed;
  1218. struct reparse_guid_data_buffer {
  1219. __le32 ReparseTag;
  1220. __le16 ReparseDataLength;
  1221. __u16 Reserved;
  1222. __u8 ReparseGuid[16];
  1223. __u8 DataBuffer[]; /* Variable Length */
  1224. } __packed;
  1225. struct reparse_mount_point_data_buffer {
  1226. __le32 ReparseTag;
  1227. __le16 ReparseDataLength;
  1228. __u16 Reserved;
  1229. __le16 SubstituteNameOffset;
  1230. __le16 SubstituteNameLength;
  1231. __le16 PrintNameOffset;
  1232. __le16 PrintNameLength;
  1233. __u8 PathBuffer[]; /* Variable Length */
  1234. } __packed;
  1235. #define SYMLINK_FLAG_RELATIVE 0x00000001
  1236. struct reparse_symlink_data_buffer {
  1237. __le32 ReparseTag;
  1238. __le16 ReparseDataLength;
  1239. __u16 Reserved;
  1240. __le16 SubstituteNameOffset;
  1241. __le16 SubstituteNameLength;
  1242. __le16 PrintNameOffset;
  1243. __le16 PrintNameLength;
  1244. __le32 Flags;
  1245. __u8 PathBuffer[]; /* Variable Length */
  1246. } __packed;
  1247. /* See MS-FSCC 2.1.2.6 and cifspdu.h for struct reparse_posix_data */
  1248. struct validate_negotiate_info_req {
  1249. __le32 Capabilities;
  1250. __u8 Guid[SMB2_CLIENT_GUID_SIZE];
  1251. __le16 SecurityMode;
  1252. __le16 DialectCount;
  1253. __le16 Dialects[4]; /* BB expand this if autonegotiate > 4 dialects */
  1254. } __packed;
  1255. struct validate_negotiate_info_rsp {
  1256. __le32 Capabilities;
  1257. __u8 Guid[SMB2_CLIENT_GUID_SIZE];
  1258. __le16 SecurityMode;
  1259. __le16 Dialect; /* Dialect in use for the connection */
  1260. } __packed;
  1261. /* Possible InfoType values */
  1262. #define SMB2_O_INFO_FILE 0x01
  1263. #define SMB2_O_INFO_FILESYSTEM 0x02
  1264. #define SMB2_O_INFO_SECURITY 0x03
  1265. #define SMB2_O_INFO_QUOTA 0x04
  1266. /* SMB2 Query Info see MS-SMB2 (2.2.37) or MS-DTYP */
  1267. /* List of QUERY INFO levels (those also valid for QUERY_DIR are noted below */
  1268. #define FILE_DIRECTORY_INFORMATION 1 /* also for QUERY_DIR */
  1269. #define FILE_FULL_DIRECTORY_INFORMATION 2 /* also for QUERY_DIR */
  1270. #define FILE_BOTH_DIRECTORY_INFORMATION 3 /* also for QUERY_DIR */
  1271. #define FILE_BASIC_INFORMATION 4
  1272. #define FILE_STANDARD_INFORMATION 5
  1273. #define FILE_INTERNAL_INFORMATION 6
  1274. #define FILE_EA_INFORMATION 7
  1275. #define FILE_ACCESS_INFORMATION 8
  1276. #define FILE_NAME_INFORMATION 9
  1277. #define FILE_RENAME_INFORMATION 10
  1278. #define FILE_LINK_INFORMATION 11
  1279. #define FILE_NAMES_INFORMATION 12 /* also for QUERY_DIR */
  1280. #define FILE_DISPOSITION_INFORMATION 13
  1281. #define FILE_POSITION_INFORMATION 14
  1282. #define FILE_FULL_EA_INFORMATION 15
  1283. #define FILE_MODE_INFORMATION 16
  1284. #define FILE_ALIGNMENT_INFORMATION 17
  1285. #define FILE_ALL_INFORMATION 18
  1286. #define FILE_ALLOCATION_INFORMATION 19
  1287. #define FILE_END_OF_FILE_INFORMATION 20
  1288. #define FILE_ALTERNATE_NAME_INFORMATION 21
  1289. #define FILE_STREAM_INFORMATION 22
  1290. #define FILE_PIPE_INFORMATION 23
  1291. #define FILE_PIPE_LOCAL_INFORMATION 24
  1292. #define FILE_PIPE_REMOTE_INFORMATION 25
  1293. #define FILE_MAILSLOT_QUERY_INFORMATION 26
  1294. #define FILE_MAILSLOT_SET_INFORMATION 27
  1295. #define FILE_COMPRESSION_INFORMATION 28
  1296. #define FILE_OBJECT_ID_INFORMATION 29
  1297. /* Number 30 not defined in documents */
  1298. #define FILE_MOVE_CLUSTER_INFORMATION 31
  1299. #define FILE_QUOTA_INFORMATION 32
  1300. #define FILE_REPARSE_POINT_INFORMATION 33
  1301. #define FILE_NETWORK_OPEN_INFORMATION 34
  1302. #define FILE_ATTRIBUTE_TAG_INFORMATION 35
  1303. #define FILE_TRACKING_INFORMATION 36
  1304. #define FILEID_BOTH_DIRECTORY_INFORMATION 37 /* also for QUERY_DIR */
  1305. #define FILEID_FULL_DIRECTORY_INFORMATION 38 /* also for QUERY_DIR */
  1306. #define FILE_VALID_DATA_LENGTH_INFORMATION 39
  1307. #define FILE_SHORT_NAME_INFORMATION 40
  1308. #define FILE_SFIO_RESERVE_INFORMATION 44
  1309. #define FILE_SFIO_VOLUME_INFORMATION 45
  1310. #define FILE_HARD_LINK_INFORMATION 46
  1311. #define FILE_NORMALIZED_NAME_INFORMATION 48
  1312. #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
  1313. #define FILE_STANDARD_LINK_INFORMATION 54
  1314. #define FILE_ID_INFORMATION 59
  1315. #define FILE_ID_EXTD_DIRECTORY_INFORMATION 60 /* also for QUERY_DIR */
  1316. /* Used for Query Info and Find File POSIX Info for SMB3.1.1 and SMB1 */
  1317. #define SMB_FIND_FILE_POSIX_INFO 0x064
  1318. /* Security info type additionalinfo flags. */
  1319. #define OWNER_SECINFO 0x00000001
  1320. #define GROUP_SECINFO 0x00000002
  1321. #define DACL_SECINFO 0x00000004
  1322. #define SACL_SECINFO 0x00000008
  1323. #define LABEL_SECINFO 0x00000010
  1324. #define ATTRIBUTE_SECINFO 0x00000020
  1325. #define SCOPE_SECINFO 0x00000040
  1326. #define BACKUP_SECINFO 0x00010000
  1327. #define UNPROTECTED_SACL_SECINFO 0x10000000
  1328. #define UNPROTECTED_DACL_SECINFO 0x20000000
  1329. #define PROTECTED_SACL_SECINFO 0x40000000
  1330. #define PROTECTED_DACL_SECINFO 0x80000000
  1331. /* Flags used for FileFullEAinfo */
  1332. #define SL_RESTART_SCAN 0x00000001
  1333. #define SL_RETURN_SINGLE_ENTRY 0x00000002
  1334. #define SL_INDEX_SPECIFIED 0x00000004
  1335. struct smb2_query_info_req {
  1336. struct smb2_hdr hdr;
  1337. __le16 StructureSize; /* Must be 41 */
  1338. __u8 InfoType;
  1339. __u8 FileInfoClass;
  1340. __le32 OutputBufferLength;
  1341. __le16 InputBufferOffset;
  1342. __u16 Reserved;
  1343. __le32 InputBufferLength;
  1344. __le32 AdditionalInformation;
  1345. __le32 Flags;
  1346. __u64 PersistentFileId;
  1347. __u64 VolatileFileId;
  1348. __u8 Buffer[1];
  1349. } __packed;
  1350. struct smb2_query_info_rsp {
  1351. struct smb2_hdr hdr;
  1352. __le16 StructureSize; /* Must be 9 */
  1353. __le16 OutputBufferOffset;
  1354. __le32 OutputBufferLength;
  1355. __u8 Buffer[1];
  1356. } __packed;
  1357. /*
  1358. * PDU query infolevel structure definitions
  1359. */
  1360. /* See MS-FSCC 2.3.52 */
  1361. struct file_allocated_range_buffer {
  1362. __le64 file_offset;
  1363. __le64 length;
  1364. } __packed;
  1365. struct smb2_file_internal_info {
  1366. __le64 IndexNumber;
  1367. } __packed; /* level 6 Query */
  1368. struct smb2_file_rename_info { /* encoding of request for level 10 */
  1369. __u8 ReplaceIfExists; /* 1 = replace existing target with new */
  1370. /* 0 = fail if target already exists */
  1371. __u8 Reserved[7];
  1372. __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
  1373. __le32 FileNameLength;
  1374. char FileName[]; /* New name to be assigned */
  1375. /* padding - overall struct size must be >= 24 so filename + pad >= 6 */
  1376. } __packed; /* level 10 Set */
  1377. struct smb2_file_link_info { /* encoding of request for level 11 */
  1378. __u8 ReplaceIfExists; /* 1 = replace existing link with new */
  1379. /* 0 = fail if link already exists */
  1380. __u8 Reserved[7];
  1381. __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
  1382. __le32 FileNameLength;
  1383. char FileName[]; /* Name to be assigned to new link */
  1384. } __packed; /* level 11 Set */
  1385. /*
  1386. * This level 18, although with struct with same name is different from cifs
  1387. * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
  1388. * CurrentByteOffset.
  1389. */
  1390. struct smb2_file_all_info { /* data block encoding of response to level 18 */
  1391. __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
  1392. __le64 LastAccessTime;
  1393. __le64 LastWriteTime;
  1394. __le64 ChangeTime;
  1395. __le32 Attributes;
  1396. __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
  1397. __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
  1398. __le64 EndOfFile; /* size ie offset to first free byte in file */
  1399. __le32 NumberOfLinks; /* hard links */
  1400. __u8 DeletePending;
  1401. __u8 Directory;
  1402. __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */
  1403. __le64 IndexNumber;
  1404. __le32 EASize;
  1405. __le32 AccessFlags;
  1406. __le64 CurrentByteOffset;
  1407. __le32 Mode;
  1408. __le32 AlignmentRequirement;
  1409. __le32 FileNameLength;
  1410. char FileName[1];
  1411. } __packed; /* level 18 Query */
  1412. struct smb2_file_eof_info { /* encoding of request for level 10 */
  1413. __le64 EndOfFile; /* new end of file value */
  1414. } __packed; /* level 20 Set */
  1415. /* Level 100 query info */
  1416. struct smb311_posix_qinfo {
  1417. __le64 CreationTime;
  1418. __le64 LastAccessTime;
  1419. __le64 LastWriteTime;
  1420. __le64 ChangeTime;
  1421. __le64 EndOfFile;
  1422. __le64 AllocationSize;
  1423. __le32 DosAttributes;
  1424. __le64 Inode;
  1425. __le32 DeviceId;
  1426. __le32 Zero;
  1427. /* beginning of POSIX Create Context Response */
  1428. __le32 HardLinks;
  1429. __le32 ReparseTag;
  1430. __le32 Mode;
  1431. u8 Sids[];
  1432. /*
  1433. * var sized owner SID
  1434. * var sized group SID
  1435. * le32 filenamelength
  1436. * u8 filename[]
  1437. */
  1438. } __packed;
  1439. /* File System Information Classes */
  1440. #define FS_VOLUME_INFORMATION 1 /* Query */
  1441. #define FS_LABEL_INFORMATION 2 /* Set */
  1442. #define FS_SIZE_INFORMATION 3 /* Query */
  1443. #define FS_DEVICE_INFORMATION 4 /* Query */
  1444. #define FS_ATTRIBUTE_INFORMATION 5 /* Query */
  1445. #define FS_CONTROL_INFORMATION 6 /* Query, Set */
  1446. #define FS_FULL_SIZE_INFORMATION 7 /* Query */
  1447. #define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */
  1448. #define FS_DRIVER_PATH_INFORMATION 9 /* Query */
  1449. #define FS_SECTOR_SIZE_INFORMATION 11 /* SMB3 or later. Query */
  1450. #define FS_POSIX_INFORMATION 100 /* SMB3.1.1 POSIX. Query */
  1451. struct smb2_fs_full_size_info {
  1452. __le64 TotalAllocationUnits;
  1453. __le64 CallerAvailableAllocationUnits;
  1454. __le64 ActualAvailableAllocationUnits;
  1455. __le32 SectorsPerAllocationUnit;
  1456. __le32 BytesPerSector;
  1457. } __packed;
  1458. #define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001
  1459. #define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
  1460. #define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004
  1461. #define SSINFO_FLAGS_TRIM_ENABLED 0x00000008
  1462. /* sector size info struct */
  1463. struct smb3_fs_ss_info {
  1464. __le32 LogicalBytesPerSector;
  1465. __le32 PhysicalBytesPerSectorForAtomicity;
  1466. __le32 PhysicalBytesPerSectorForPerf;
  1467. __le32 FSEffPhysicalBytesPerSectorForAtomicity;
  1468. __le32 Flags;
  1469. __le32 ByteOffsetForSectorAlignment;
  1470. __le32 ByteOffsetForPartitionAlignment;
  1471. } __packed;
  1472. /* File System Control Information */
  1473. struct smb2_fs_control_info {
  1474. __le64 FreeSpaceStartFiltering;
  1475. __le64 FreeSpaceThreshold;
  1476. __le64 FreeSpaceStopFiltering;
  1477. __le64 DefaultQuotaThreshold;
  1478. __le64 DefaultQuotaLimit;
  1479. __le32 FileSystemControlFlags;
  1480. __le32 Padding;
  1481. } __packed;
  1482. /* volume info struct - see MS-FSCC 2.5.9 */
  1483. #define MAX_VOL_LABEL_LEN 32
  1484. struct smb3_fs_vol_info {
  1485. __le64 VolumeCreationTime;
  1486. __u32 VolumeSerialNumber;
  1487. __le32 VolumeLabelLength; /* includes trailing null */
  1488. __u8 SupportsObjects; /* True if eg like NTFS, supports objects */
  1489. __u8 Reserved;
  1490. __u8 VolumeLabel[]; /* variable len */
  1491. } __packed;
  1492. /* See MS-SMB2 2.2.23 through 2.2.25 */
  1493. struct smb2_oplock_break {
  1494. struct smb2_hdr hdr;
  1495. __le16 StructureSize; /* Must be 24 */
  1496. __u8 OplockLevel;
  1497. __u8 Reserved;
  1498. __le32 Reserved2;
  1499. __u64 PersistentFid;
  1500. __u64 VolatileFid;
  1501. } __packed;
  1502. #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
  1503. struct smb2_lease_break {
  1504. struct smb2_hdr hdr;
  1505. __le16 StructureSize; /* Must be 44 */
  1506. __le16 Epoch;
  1507. __le32 Flags;
  1508. __u8 LeaseKey[16];
  1509. __le32 CurrentLeaseState;
  1510. __le32 NewLeaseState;
  1511. __le32 BreakReason;
  1512. __le32 AccessMaskHint;
  1513. __le32 ShareMaskHint;
  1514. } __packed;
  1515. struct smb2_lease_ack {
  1516. struct smb2_hdr hdr;
  1517. __le16 StructureSize; /* Must be 36 */
  1518. __le16 Reserved;
  1519. __le32 Flags;
  1520. __u8 LeaseKey[16];
  1521. __le32 LeaseState;
  1522. __le64 LeaseDuration;
  1523. } __packed;
  1524. #define OP_BREAK_STRUCT_SIZE_20 24
  1525. #define OP_BREAK_STRUCT_SIZE_21 36
  1526. #endif /* _COMMON_SMB2PDU_H */