smb2pdu.h 54 KB

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