xref: /linux/fs/smb/common/smb2pdu.h (revision 869737543b39a145809c41a7253c6ee777e22729)
1 /* SPDX-License-Identifier: LGPL-2.1 */
2 #ifndef _COMMON_SMB2PDU_H
3 #define _COMMON_SMB2PDU_H
4 
5 /*
6  * Note that, due to trying to use names similar to the protocol specifications,
7  * there are many mixed case field names in the structures below.  Although
8  * this does not match typical Linux kernel style, it is necessary to be
9  * able to match against the protocol specification.
10  *
11  * SMB2 commands
12  * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses
13  * (ie no useful data other than the SMB error code itself) and are marked such.
14  * Knowing this helps avoid response buffer allocations and copy in some cases.
15  */
16 
17 /* List of commands in host endian */
18 #define SMB2_NEGOTIATE_HE	0x0000
19 #define SMB2_SESSION_SETUP_HE	0x0001
20 #define SMB2_LOGOFF_HE		0x0002 /* trivial request/resp */
21 #define SMB2_TREE_CONNECT_HE	0x0003
22 #define SMB2_TREE_DISCONNECT_HE	0x0004 /* trivial req/resp */
23 #define SMB2_CREATE_HE		0x0005
24 #define SMB2_CLOSE_HE		0x0006
25 #define SMB2_FLUSH_HE		0x0007 /* trivial resp */
26 #define SMB2_READ_HE		0x0008
27 #define SMB2_WRITE_HE		0x0009
28 #define SMB2_LOCK_HE		0x000A
29 #define SMB2_IOCTL_HE		0x000B
30 #define SMB2_CANCEL_HE		0x000C
31 #define SMB2_ECHO_HE		0x000D
32 #define SMB2_QUERY_DIRECTORY_HE	0x000E
33 #define SMB2_CHANGE_NOTIFY_HE	0x000F
34 #define SMB2_QUERY_INFO_HE	0x0010
35 #define SMB2_SET_INFO_HE	0x0011
36 #define SMB2_OPLOCK_BREAK_HE	0x0012
37 #define SMB2_SERVER_TO_CLIENT_NOTIFICATION 0x0013
38 
39 /* The same list in little endian */
40 #define SMB2_NEGOTIATE		cpu_to_le16(SMB2_NEGOTIATE_HE)
41 #define SMB2_SESSION_SETUP	cpu_to_le16(SMB2_SESSION_SETUP_HE)
42 #define SMB2_LOGOFF		cpu_to_le16(SMB2_LOGOFF_HE)
43 #define SMB2_TREE_CONNECT	cpu_to_le16(SMB2_TREE_CONNECT_HE)
44 #define SMB2_TREE_DISCONNECT	cpu_to_le16(SMB2_TREE_DISCONNECT_HE)
45 #define SMB2_CREATE		cpu_to_le16(SMB2_CREATE_HE)
46 #define SMB2_CLOSE		cpu_to_le16(SMB2_CLOSE_HE)
47 #define SMB2_FLUSH		cpu_to_le16(SMB2_FLUSH_HE)
48 #define SMB2_READ		cpu_to_le16(SMB2_READ_HE)
49 #define SMB2_WRITE		cpu_to_le16(SMB2_WRITE_HE)
50 #define SMB2_LOCK		cpu_to_le16(SMB2_LOCK_HE)
51 #define SMB2_IOCTL		cpu_to_le16(SMB2_IOCTL_HE)
52 #define SMB2_CANCEL		cpu_to_le16(SMB2_CANCEL_HE)
53 #define SMB2_ECHO		cpu_to_le16(SMB2_ECHO_HE)
54 #define SMB2_QUERY_DIRECTORY	cpu_to_le16(SMB2_QUERY_DIRECTORY_HE)
55 #define SMB2_CHANGE_NOTIFY	cpu_to_le16(SMB2_CHANGE_NOTIFY_HE)
56 #define SMB2_QUERY_INFO		cpu_to_le16(SMB2_QUERY_INFO_HE)
57 #define SMB2_SET_INFO		cpu_to_le16(SMB2_SET_INFO_HE)
58 #define SMB2_OPLOCK_BREAK	cpu_to_le16(SMB2_OPLOCK_BREAK_HE)
59 
60 #define SMB2_INTERNAL_CMD	cpu_to_le16(0xFFFF)
61 
62 #define NUMBER_OF_SMB2_COMMANDS	0x0013
63 
64 /*
65  * Size of the session key (crypto key encrypted with the password
66  */
67 #define SMB2_NTLMV2_SESSKEY_SIZE	16
68 #define SMB2_SIGNATURE_SIZE		16
69 #define SMB2_HMACSHA256_SIZE		32
70 #define SMB2_CMACAES_SIZE		16
71 #define SMB3_GCM128_CRYPTKEY_SIZE	16
72 #define SMB3_GCM256_CRYPTKEY_SIZE	32
73 
74 /*
75  * Size of the smb3 encryption/decryption keys
76  * This size is big enough to store any cipher key types.
77  */
78 #define SMB3_ENC_DEC_KEY_SIZE		32
79 
80 /*
81  * Size of the smb3 signing key
82  */
83 #define SMB3_SIGN_KEY_SIZE		16
84 
85 #define CIFS_CLIENT_CHALLENGE_SIZE	8
86 
87 /* Maximum buffer size value we can send with 1 credit */
88 #define SMB2_MAX_BUFFER_SIZE 65536
89 
90 /*
91  * The default wsize is 1M for SMB2 (and for some CIFS cases).
92  * find_get_pages seems to return a maximum of 256
93  * pages in a single call. With PAGE_SIZE == 4k, this means we can
94  * fill a single wsize request with a single call.
95  */
96 #define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024)
97 
98 /* According to MS-SMB2 specification The minimum recommended value is 65536.*/
99 #define CIFS_MIN_DEFAULT_IOSIZE (65536)
100 
101 /*
102  * SMB2 Header Definition
103  *
104  * "MBZ" :  Must be Zero
105  * "BB"  :  BugBug, Something to check/review/analyze later
106  * "PDU" :  "Protocol Data Unit" (ie a network "frame")
107  *
108  */
109 
110 #define __SMB2_HEADER_STRUCTURE_SIZE	64
111 #define SMB2_HEADER_STRUCTURE_SIZE				\
112 	cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE)
113 
114 #define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)
115 #define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
116 #define SMB2_COMPRESSION_TRANSFORM_ID cpu_to_le32(0x424d53fc)
117 
118 /*
119  *	SMB2 flag definitions
120  */
121 #define SMB2_FLAGS_SERVER_TO_REDIR	cpu_to_le32(0x00000001)
122 #define SMB2_FLAGS_ASYNC_COMMAND	cpu_to_le32(0x00000002)
123 #define SMB2_FLAGS_RELATED_OPERATIONS	cpu_to_le32(0x00000004)
124 #define SMB2_FLAGS_SIGNED		cpu_to_le32(0x00000008)
125 #define SMB2_FLAGS_PRIORITY_MASK	cpu_to_le32(0x00000070) /* SMB3.1.1 */
126 #define SMB2_FLAGS_DFS_OPERATIONS	cpu_to_le32(0x10000000)
127 #define SMB2_FLAGS_REPLAY_OPERATION	cpu_to_le32(0x20000000) /* SMB3 & up */
128 
129 /*
130  *	Definitions for SMB2 Protocol Data Units (network frames)
131  *
132  *  See MS-SMB2.PDF specification for protocol details.
133  *  The Naming convention is the lower case version of the SMB2
134  *  command code name for the struct. Note that structures must be packed.
135  *
136  */
137 
138 /* See MS-SMB2 section 2.2.1 */
139 struct smb2_hdr {
140 	__le32 ProtocolId;	/* 0xFE 'S' 'M' 'B' */
141 	__le16 StructureSize;	/* 64 */
142 	__le16 CreditCharge;	/* MBZ */
143 	__le32 Status;		/* Error from server */
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 
160 struct smb3_hdr_req {
161 	__le32 ProtocolId;	/* 0xFE 'S' 'M' 'B' */
162 	__le16 StructureSize;	/* 64 */
163 	__le16 CreditCharge;	/* MBZ */
164 	__le16 ChannelSequence; /* See MS-SMB2 3.2.4.1 and 3.2.7.1 */
165 	__le16 Reserved;
166 	__le16 Command;
167 	__le16 CreditRequest;	/* CreditResponse */
168 	__le32 Flags;
169 	__le32 NextCommand;
170 	__le64 MessageId;
171 	union {
172 		struct {
173 			__le32 ProcessId;
174 			__le32  TreeId;
175 		} __packed SyncId;
176 		__le64  AsyncId;
177 	} __packed Id;
178 	__le64  SessionId;
179 	__u8   Signature[16];
180 } __packed;
181 
182 struct smb2_pdu {
183 	struct smb2_hdr hdr;
184 	__le16 StructureSize2; /* size of wct area (varies, request specific) */
185 } __packed;
186 
187 #define SMB2_ERROR_STRUCTURE_SIZE2	9
188 #define SMB2_ERROR_STRUCTURE_SIZE2_LE	cpu_to_le16(SMB2_ERROR_STRUCTURE_SIZE2)
189 
190 struct smb2_err_rsp {
191 	struct smb2_hdr hdr;
192 	__le16 StructureSize;
193 	__u8   ErrorContextCount;
194 	__u8   Reserved;
195 	__le32 ByteCount;  /* even if zero, at least one byte follows */
196 	__u8   ErrorData[];  /* variable length */
197 } __packed;
198 
199 #define SMB3_AES_CCM_NONCE 11
200 #define SMB3_AES_GCM_NONCE 12
201 
202 /* Transform flags (for 3.0 dialect this flag indicates CCM */
203 #define TRANSFORM_FLAG_ENCRYPTED	0x0001
204 struct smb2_transform_hdr {
205 	__le32 ProtocolId;	/* 0xFD 'S' 'M' 'B' */
206 	__u8   Signature[16];
207 	__u8   Nonce[16];
208 	__le32 OriginalMessageSize;
209 	__u16  Reserved1;
210 	__le16 Flags; /* EncryptionAlgorithm for 3.0, enc enabled for 3.1.1 */
211 	__le64  SessionId;
212 } __packed;
213 
214 /*
215  * These are simplified versions from the spec, as we don't need a fully fledged
216  * form of both unchained and chained structs.
217  *
218  * Moreover, even in chained compressed payloads, the initial compression header
219  * has the form of the unchained one -- i.e. it never has the
220  * OriginalPayloadSize field and ::Offset field always represent an offset
221  * (instead of a length, as it is in the chained header).
222  *
223  * See MS-SMB2 2.2.42 for more details.
224  */
225 #define SMB2_COMPRESSION_FLAG_NONE	0x0000
226 #define SMB2_COMPRESSION_FLAG_CHAINED	0x0001
227 
228 struct smb2_compression_hdr {
229 	__le32 ProtocolId; /* 0xFC 'S' 'M' 'B' */
230 	__le32 OriginalCompressedSegmentSize;
231 	__le16 CompressionAlgorithm;
232 	__le16 Flags;
233 	__le32 Offset; /* this is the size of the uncompressed SMB2 header below */
234 	/* uncompressed SMB2 header (READ or WRITE) goes here */
235 	/* compressed data goes here */
236 } __packed;
237 
238 /*
239  * ... OTOH, set compression payload header to always have OriginalPayloadSize
240  * as it's easier to pass the struct size minus sizeof(OriginalPayloadSize)
241  * than to juggle around the header/data memory.
242  */
243 struct smb2_compression_payload_hdr {
244 	__le16	CompressionAlgorithm;
245 	__le16	Flags;
246 	__le32	Length; /* length of compressed playload including field below if present */
247 	__le32 OriginalPayloadSize; /* accounted when LZNT1, LZ77, LZ77+Huffman */
248 } __packed;
249 
250 struct smb2_compression_pattern_v1 {
251 	__u8	Pattern;
252 	__u8	Reserved1;
253 	__le16	Reserved2;
254 	__le32	Repetitions;
255 } __packed;
256 
257 /* See MS-SMB2 section 2.2.9.2 */
258 /* Context Types */
259 #define SMB2_RESERVED_TREE_CONNECT_CONTEXT_ID 0x0000
260 #define SMB2_REMOTED_IDENTITY_TREE_CONNECT_CONTEXT_ID cpu_to_le16(0x0001)
261 
262 struct tree_connect_contexts {
263 	__le16 ContextType;
264 	__le16 DataLength;
265 	__le32 Reserved;
266 	__u8   Data[];
267 } __packed;
268 
269 /* Remoted identity tree connect context structures - see MS-SMB2 2.2.9.2.1 */
270 struct smb3_blob_data {
271 	__le16 BlobSize;
272 	__u8   BlobData[];
273 } __packed;
274 
275 /* Valid values for Attr */
276 #define SE_GROUP_MANDATORY		0x00000001
277 #define SE_GROUP_ENABLED_BY_DEFAULT	0x00000002
278 #define SE_GROUP_ENABLED		0x00000004
279 #define SE_GROUP_OWNER			0x00000008
280 #define SE_GROUP_USE_FOR_DENY_ONLY	0x00000010
281 #define SE_GROUP_INTEGRITY		0x00000020
282 #define SE_GROUP_INTEGRITY_ENABLED	0x00000040
283 #define SE_GROUP_RESOURCE		0x20000000
284 #define SE_GROUP_LOGON_ID		0xC0000000
285 
286 struct sid_array_data {
287 	__le16 SidAttrCount;
288 	/* SidAttrList - array of sid_attr_data structs */
289 } __packed;
290 
291 /* struct sid_attr_data is SidData array in BlobData format then le32 Attr */
292 struct sid_attr_data {
293 	__le16 BlobSize;
294 	__u8 BlobData[];
295 	/* __le32 Attr */
296 } __packed;
297 
298 /*
299  * struct privilege_data is the same as BLOB_DATA - see MS-SMB2 2.2.9.2.1.5
300  * but with size of LUID_ATTR_DATA struct and BlobData set to LUID_ATTR DATA
301  */
302 
303 struct privilege_array_data {
304 	__le16 PrivilegeCount;
305 	/* array of privilege_data structs */
306 } __packed;
307 
308 struct remoted_identity_tcon_context {
309 	__le16 TicketType; /* must be 0x0001 */
310 	__le16 TicketSize; /* total size of this struct */
311 	__le16 User; /* offset to SID_ATTR_DATA struct with user info */
312 	__le16 UserName; /* offset to null terminated Unicode username string */
313 	__le16 Domain; /* offset to null terminated Unicode domain name */
314 	__le16 Groups; /* offset to SID_ARRAY_DATA struct with group info */
315 	__le16 RestrictedGroups; /* similar to above */
316 	__le16 Privileges; /* offset to PRIVILEGE_ARRAY_DATA struct */
317 	__le16 PrimaryGroup; /* offset to SID_ARRAY_DATA struct */
318 	__le16 Owner; /* offset to BLOB_DATA struct */
319 	__le16 DefaultDacl; /* offset to BLOB_DATA struct */
320 	__le16 DeviceGroups; /* offset to SID_ARRAY_DATA struct */
321 	__le16 UserClaims; /* offset to BLOB_DATA struct */
322 	__le16 DeviceClaims; /* offset to BLOB_DATA struct */
323 	__u8   TicketInfo[]; /* variable length buf - remoted identity data */
324 } __packed;
325 
326 struct smb2_tree_connect_req_extension {
327 	__le32 TreeConnectContextOffset;
328 	__le16 TreeConnectContextCount;
329 	__u8  Reserved[10];
330 	__u8  PathName[]; /* variable sized array */
331 	/* followed by array of TreeConnectContexts */
332 } __packed;
333 
334 /* Flags/Reserved for SMB3.1.1 */
335 #define SMB2_TREE_CONNECT_FLAG_CLUSTER_RECONNECT cpu_to_le16(0x0001)
336 #define SMB2_TREE_CONNECT_FLAG_REDIRECT_TO_OWNER cpu_to_le16(0x0002)
337 #define SMB2_TREE_CONNECT_FLAG_EXTENSION_PRESENT cpu_to_le16(0x0004)
338 
339 struct smb2_tree_connect_req {
340 	struct smb2_hdr hdr;
341 	__le16 StructureSize;	/* Must be 9 */
342 	__le16 Flags;		/* Flags in SMB3.1.1 */
343 	__le16 PathOffset;
344 	__le16 PathLength;
345 	__u8   Buffer[];	/* variable length */
346 } __packed;
347 
348 /* Possible ShareType values */
349 #define SMB2_SHARE_TYPE_DISK	0x01
350 #define SMB2_SHARE_TYPE_PIPE	0x02
351 #define	SMB2_SHARE_TYPE_PRINT	0x03
352 
353 /*
354  * Possible ShareFlags - exactly one and only one of the first 4 caching flags
355  * must be set (any of the remaining, SHI1005, flags may be set individually
356  * or in combination.
357  */
358 #define SMB2_SHAREFLAG_MANUAL_CACHING			0x00000000
359 #define SMB2_SHAREFLAG_AUTO_CACHING			0x00000010
360 #define SMB2_SHAREFLAG_VDO_CACHING			0x00000020
361 #define SMB2_SHAREFLAG_NO_CACHING			0x00000030
362 #define SHI1005_FLAGS_DFS				0x00000001
363 #define SHI1005_FLAGS_DFS_ROOT				0x00000002
364 #define SMB2_SHAREFLAG_RESTRICT_EXCLUSIVE_OPENS		0x00000100
365 #define SMB2_SHAREFLAG_FORCE_SHARED_DELETE		0x00000200
366 #define SMB2_SHAREFLAG_ALLOW_NAMESPACE_CACHING		0x00000400
367 #define SMB2_SHAREFLAG_ACCESS_BASED_DIRECTORY_ENUM	0x00000800
368 #define SMB2_SHAREFLAG_FORCE_LEVELII_OPLOCK		0x00001000
369 #define SMB2_SHAREFLAG_ENABLE_HASH_V1			0x00002000
370 #define SMB2_SHAREFLAG_ENABLE_HASH_V2			0x00004000
371 #define SHI1005_FLAGS_ENCRYPT_DATA			0x00008000
372 #define SMB2_SHAREFLAG_IDENTITY_REMOTING		0x00040000 /* 3.1.1 */
373 #define SMB2_SHAREFLAG_COMPRESS_DATA			0x00100000 /* 3.1.1 */
374 #define SMB2_SHAREFLAG_ISOLATED_TRANSPORT		0x00200000
375 #define SHI1005_FLAGS_ALL				0x0034FF33
376 
377 /* Possible share capabilities */
378 #define SMB2_SHARE_CAP_DFS	cpu_to_le32(0x00000008) /* all dialects */
379 #define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY cpu_to_le32(0x00000010) /* 3.0 */
380 #define SMB2_SHARE_CAP_SCALEOUT	cpu_to_le32(0x00000020) /* 3.0 */
381 #define SMB2_SHARE_CAP_CLUSTER	cpu_to_le32(0x00000040) /* 3.0 */
382 #define SMB2_SHARE_CAP_ASYMMETRIC cpu_to_le32(0x00000080) /* 3.02 */
383 #define SMB2_SHARE_CAP_REDIRECT_TO_OWNER cpu_to_le32(0x00000100) /* 3.1.1 */
384 
385 struct smb2_tree_connect_rsp {
386 	struct smb2_hdr hdr;
387 	__le16 StructureSize;	/* Must be 16 */
388 	__u8   ShareType;	/* see below */
389 	__u8   Reserved;
390 	__le32 ShareFlags;	/* see below */
391 	__le32 Capabilities;	/* see below */
392 	__le32 MaximalAccess;
393 } __packed;
394 
395 struct smb2_tree_disconnect_req {
396 	struct smb2_hdr hdr;
397 	__le16 StructureSize;	/* Must be 4 */
398 	__le16 Reserved;
399 } __packed;
400 
401 struct smb2_tree_disconnect_rsp {
402 	struct smb2_hdr hdr;
403 	__le16 StructureSize;	/* Must be 4 */
404 	__le16 Reserved;
405 } __packed;
406 
407 
408 /*
409  * SMB2_NEGOTIATE_PROTOCOL  See MS-SMB2 section 2.2.3
410  */
411 /* SecurityMode flags */
412 #define	SMB2_NEGOTIATE_SIGNING_ENABLED     0x0001
413 #define	SMB2_NEGOTIATE_SIGNING_ENABLED_LE  cpu_to_le16(0x0001)
414 #define SMB2_NEGOTIATE_SIGNING_REQUIRED	   0x0002
415 #define SMB2_NEGOTIATE_SIGNING_REQUIRED_LE cpu_to_le16(0x0002)
416 #define SMB2_SEC_MODE_FLAGS_ALL            0x0003
417 
418 /* Capabilities flags */
419 #define SMB2_GLOBAL_CAP_DFS		0x00000001
420 #define SMB2_GLOBAL_CAP_LEASING		0x00000002 /* Resp only New to SMB2.1 */
421 #define SMB2_GLOBAL_CAP_LARGE_MTU	0x00000004 /* Resp only New to SMB2.1 */
422 #define SMB2_GLOBAL_CAP_MULTI_CHANNEL	0x00000008 /* New to SMB3 */
423 #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
424 #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING  0x00000020 /* New to SMB3 */
425 #define SMB2_GLOBAL_CAP_ENCRYPTION	0x00000040 /* New to SMB3 */
426 #define SMB2_GLOBAL_CAP_NOTIFICATIONS	0x00000080 /* New to SMB3.1.1 */
427 /* Internal types */
428 #define SMB2_NT_FIND			0x00100000
429 #define SMB2_LARGE_FILES		0x00200000
430 
431 #define SMB2_CLIENT_GUID_SIZE		16
432 #define SMB2_CREATE_GUID_SIZE		16
433 
434 /* Dialects */
435 #define SMB10_PROT_ID  0x0000 /* local only, not sent on wire w/CIFS negprot */
436 #define SMB20_PROT_ID  0x0202
437 #define SMB21_PROT_ID  0x0210
438 #define SMB2X_PROT_ID  0x02FF
439 #define SMB30_PROT_ID  0x0300
440 #define SMB302_PROT_ID 0x0302
441 #define SMB311_PROT_ID 0x0311
442 #define BAD_PROT_ID    0xFFFF
443 
444 #define SMB311_SALT_SIZE			32
445 /* Hash Algorithm Types */
446 #define SMB2_PREAUTH_INTEGRITY_SHA512	cpu_to_le16(0x0001)
447 #define SMB2_PREAUTH_HASH_SIZE 64
448 
449 /* Negotiate Contexts - ContextTypes. See MS-SMB2 section 2.2.3.1 for details */
450 #define SMB2_PREAUTH_INTEGRITY_CAPABILITIES	cpu_to_le16(1)
451 #define SMB2_ENCRYPTION_CAPABILITIES		cpu_to_le16(2)
452 #define SMB2_COMPRESSION_CAPABILITIES		cpu_to_le16(3)
453 #define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID	cpu_to_le16(5)
454 #define SMB2_TRANSPORT_CAPABILITIES		cpu_to_le16(6)
455 #define SMB2_RDMA_TRANSFORM_CAPABILITIES	cpu_to_le16(7)
456 #define SMB2_SIGNING_CAPABILITIES		cpu_to_le16(8)
457 #define SMB2_POSIX_EXTENSIONS_AVAILABLE		cpu_to_le16(0x100)
458 
459 struct smb2_neg_context {
460 	__le16	ContextType;
461 	__le16	DataLength;
462 	__le32	Reserved;
463 	/* Followed by array of data. NOTE: some servers require padding to 8 byte boundary */
464 } __packed;
465 
466 /*
467  * SaltLength that the server send can be zero, so the only three required
468  * fields (all __le16) end up six bytes total, so the minimum context data len
469  * in the response is six bytes which accounts for
470  *
471  *      HashAlgorithmCount, SaltLength, and 1 HashAlgorithm.
472  */
473 #define MIN_PREAUTH_CTXT_DATA_LEN 6
474 
475 struct smb2_preauth_neg_context {
476 	__le16	ContextType; /* 1 */
477 	__le16	DataLength;
478 	__le32	Reserved;
479 	__le16	HashAlgorithmCount; /* 1 */
480 	__le16	SaltLength;
481 	__le16	HashAlgorithms; /* HashAlgorithms[0] since only one defined */
482 	__u8	Salt[SMB311_SALT_SIZE];
483 } __packed;
484 
485 /* Encryption Algorithms Ciphers */
486 #define SMB2_ENCRYPTION_AES128_CCM	cpu_to_le16(0x0001)
487 #define SMB2_ENCRYPTION_AES128_GCM	cpu_to_le16(0x0002)
488 #define SMB2_ENCRYPTION_AES256_CCM      cpu_to_le16(0x0003)
489 #define SMB2_ENCRYPTION_AES256_GCM      cpu_to_le16(0x0004)
490 
491 /* Min encrypt context data is one cipher so 2 bytes + 2 byte count field */
492 #define MIN_ENCRYPT_CTXT_DATA_LEN	4
493 struct smb2_encryption_neg_context {
494 	__le16	ContextType; /* 2 */
495 	__le16	DataLength;
496 	__le32	Reserved;
497 	/* CipherCount usually 2, but can be 3 when AES256-GCM enabled */
498 	__le16	CipherCount; /* AES128-GCM and AES128-CCM by default */
499 	__le16	Ciphers[];
500 } __packed;
501 
502 /* See MS-SMB2 2.2.3.1.3 */
503 #define SMB3_COMPRESS_NONE	cpu_to_le16(0x0000)
504 #define SMB3_COMPRESS_LZNT1	cpu_to_le16(0x0001)
505 #define SMB3_COMPRESS_LZ77	cpu_to_le16(0x0002)
506 #define SMB3_COMPRESS_LZ77_HUFF	cpu_to_le16(0x0003)
507 /* Pattern scanning algorithm See MS-SMB2 3.1.4.4.1 */
508 #define SMB3_COMPRESS_PATTERN	cpu_to_le16(0x0004) /* Pattern_V1 */
509 #define SMB3_COMPRESS_LZ4	cpu_to_le16(0x0005)
510 
511 /* Compression Flags */
512 #define SMB2_COMPRESSION_CAPABILITIES_FLAG_NONE		cpu_to_le32(0x00000000)
513 #define SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED	cpu_to_le32(0x00000001)
514 
515 struct smb2_compression_capabilities_context {
516 	__le16	ContextType; /* 3 */
517 	__le16  DataLength;
518 	__le32	Reserved;
519 	__le16	CompressionAlgorithmCount;
520 	__le16	Padding;
521 	__le32	Flags;
522 	__le16	CompressionAlgorithms[3];
523 	__u16	Pad;  /* Some servers require pad to DataLen multiple of 8 */
524 	/* Check if pad needed */
525 } __packed;
526 
527 /*
528  * For smb2_netname_negotiate_context_id See MS-SMB2 2.2.3.1.4.
529  * Its struct simply contains NetName, an array of Unicode characters
530  */
531 struct smb2_netname_neg_context {
532 	__le16	ContextType; /* 5 */
533 	__le16	DataLength;
534 	__le32	Reserved;
535 	__le16	NetName[]; /* hostname of target converted to UCS-2 */
536 } __packed;
537 
538 /*
539  * For smb2_transport_capabilities context see MS-SMB2 2.2.3.1.5
540  * and 2.2.4.1.5
541  */
542 
543 /* Flags */
544 #define SMB2_ACCEPT_TRANSPORT_LEVEL_SECURITY	0x00000001
545 
546 struct smb2_transport_capabilities_context {
547 	__le16	ContextType; /* 6 */
548 	__le16  DataLength;
549 	__u32	Reserved;
550 	__le32	Flags;
551 	__u32	Pad;
552 } __packed;
553 
554 /*
555  * For rdma transform capabilities context see MS-SMB2 2.2.3.1.6
556  * and 2.2.4.1.6
557  */
558 
559 /* RDMA Transform IDs */
560 #define SMB2_RDMA_TRANSFORM_NONE	0x0000
561 #define SMB2_RDMA_TRANSFORM_ENCRYPTION	0x0001
562 #define SMB2_RDMA_TRANSFORM_SIGNING	0x0002
563 
564 struct smb2_rdma_transform_capabilities_context {
565 	__le16	ContextType; /* 7 */
566 	__le16  DataLength;
567 	__u32	Reserved;
568 	__le16	TransformCount;
569 	__u16	Reserved1;
570 	__u32	Reserved2;
571 	__le16	RDMATransformIds[];
572 } __packed;
573 
574 /*
575  * For signing capabilities context see MS-SMB2 2.2.3.1.7
576  * and 2.2.4.1.7
577  */
578 
579 /* Signing algorithms */
580 #define SIGNING_ALG_HMAC_SHA256    0
581 #define SIGNING_ALG_HMAC_SHA256_LE cpu_to_le16(0)
582 #define SIGNING_ALG_AES_CMAC       1
583 #define SIGNING_ALG_AES_CMAC_LE    cpu_to_le16(1)
584 #define SIGNING_ALG_AES_GMAC       2
585 #define SIGNING_ALG_AES_GMAC_LE    cpu_to_le16(2)
586 
587 struct smb2_signing_capabilities {
588 	__le16	ContextType; /* 8 */
589 	__le16	DataLength;
590 	__le32	Reserved;
591 	__le16	SigningAlgorithmCount;
592 	__le16	SigningAlgorithms[];
593 	/*  Followed by padding to 8 byte boundary (required by some servers) */
594 } __packed;
595 
596 #define POSIX_CTXT_DATA_LEN	16
597 struct smb2_posix_neg_context {
598 	__le16	ContextType; /* 0x100 */
599 	__le16	DataLength;
600 	__le32	Reserved;
601 	__u8	Name[16]; /* POSIX ctxt GUID 93AD25509CB411E7B42383DE968BCD7C */
602 } __packed;
603 
604 struct smb2_negotiate_req {
605 	struct smb2_hdr hdr;
606 	__le16 StructureSize; /* Must be 36 */
607 	__le16 DialectCount;
608 	__le16 SecurityMode;
609 	__le16 Reserved;	/* MBZ */
610 	__le32 Capabilities;
611 	__u8   ClientGUID[SMB2_CLIENT_GUID_SIZE];
612 	/* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */
613 	__le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */
614 	__le16 NegotiateContextCount;  /* SMB3.1.1 only. MBZ earlier */
615 	__le16 Reserved2;
616 	__le16 Dialects[];
617 } __packed;
618 
619 struct smb2_negotiate_rsp {
620 	struct smb2_hdr hdr;
621 	__le16 StructureSize;	/* Must be 65 */
622 	__le16 SecurityMode;
623 	__le16 DialectRevision;
624 	__le16 NegotiateContextCount;	/* Prior to SMB3.1.1 was Reserved & MBZ */
625 	__u8   ServerGUID[16];
626 	__le32 Capabilities;
627 	__le32 MaxTransactSize;
628 	__le32 MaxReadSize;
629 	__le32 MaxWriteSize;
630 	__le64 SystemTime;	/* MBZ */
631 	__le64 ServerStartTime;
632 	__le16 SecurityBufferOffset;
633 	__le16 SecurityBufferLength;
634 	__le32 NegotiateContextOffset;	/* Pre:SMB3.1.1 was reserved/ignored */
635 	__u8   Buffer[];	/* variable length GSS security buffer */
636 } __packed;
637 
638 
639 /*
640  * SMB2_SESSION_SETUP  See MS-SMB2 section 2.2.5
641  */
642 /* Flags */
643 #define SMB2_SESSION_REQ_FLAG_BINDING		0x01
644 #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA	0x04
645 
646 struct smb2_sess_setup_req {
647 	struct smb2_hdr hdr;
648 	__le16 StructureSize; /* Must be 25 */
649 	__u8   Flags;
650 	__u8   SecurityMode;
651 	__le32 Capabilities;
652 	__le32 Channel;
653 	__le16 SecurityBufferOffset;
654 	__le16 SecurityBufferLength;
655 	__le64 PreviousSessionId;
656 	__u8   Buffer[];	/* variable length GSS security buffer */
657 } __packed;
658 
659 /* Currently defined SessionFlags */
660 #define SMB2_SESSION_FLAG_IS_GUEST        0x0001
661 #define SMB2_SESSION_FLAG_IS_GUEST_LE     cpu_to_le16(0x0001)
662 #define SMB2_SESSION_FLAG_IS_NULL         0x0002
663 #define SMB2_SESSION_FLAG_IS_NULL_LE      cpu_to_le16(0x0002)
664 #define SMB2_SESSION_FLAG_ENCRYPT_DATA    0x0004
665 #define SMB2_SESSION_FLAG_ENCRYPT_DATA_LE cpu_to_le16(0x0004)
666 
667 struct smb2_sess_setup_rsp {
668 	struct smb2_hdr hdr;
669 	__le16 StructureSize; /* Must be 9 */
670 	__le16 SessionFlags;
671 	__le16 SecurityBufferOffset;
672 	__le16 SecurityBufferLength;
673 	__u8   Buffer[];	/* variable length GSS security buffer */
674 } __packed;
675 
676 
677 /*
678  * SMB2_LOGOFF  See MS-SMB2 section 2.2.7
679  */
680 struct smb2_logoff_req {
681 	struct smb2_hdr hdr;
682 	__le16 StructureSize;	/* Must be 4 */
683 	__le16 Reserved;
684 } __packed;
685 
686 struct smb2_logoff_rsp {
687 	struct smb2_hdr hdr;
688 	__le16 StructureSize;	/* Must be 4 */
689 	__le16 Reserved;
690 } __packed;
691 
692 
693 /*
694  * SMB2_CLOSE  See MS-SMB2 section 2.2.15
695  */
696 /* Currently defined values for close flags */
697 #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB	cpu_to_le16(0x0001)
698 struct smb2_close_req {
699 	struct smb2_hdr hdr;
700 	__le16 StructureSize;	/* Must be 24 */
701 	__le16 Flags;
702 	__le32 Reserved;
703 	__u64  PersistentFileId; /* opaque endianness */
704 	__u64  VolatileFileId; /* opaque endianness */
705 } __packed;
706 
707 /*
708  * Maximum size of a SMB2_CLOSE response is 64 (smb2 header) + 60 (data)
709  */
710 #define MAX_SMB2_CLOSE_RESPONSE_SIZE 124
711 
712 struct smb2_close_rsp {
713 	struct smb2_hdr hdr;
714 	__le16 StructureSize; /* 60 */
715 	__le16 Flags;
716 	__le32 Reserved;
717 	struct_group_attr(network_open_info, __packed,
718 		__le64 CreationTime;
719 		__le64 LastAccessTime;
720 		__le64 LastWriteTime;
721 		__le64 ChangeTime;
722 		/* Beginning of FILE_STANDARD_INFO equivalent */
723 		__le64 AllocationSize;
724 		__le64 EndOfFile;
725 		__le32 Attributes;
726 	);
727 } __packed;
728 
729 
730 /*
731  * SMB2_READ  See MS-SMB2 section 2.2.19
732  */
733 /* For read request Flags field below, following flag is defined for SMB3.02 */
734 #define SMB2_READFLAG_READ_UNBUFFERED	0x01
735 #define SMB2_READFLAG_REQUEST_COMPRESSED 0x02 /* See MS-SMB2 2.2.19 */
736 
737 /* Channel field for read and write: exactly one of following flags can be set*/
738 #define SMB2_CHANNEL_NONE               cpu_to_le32(0x00000000)
739 #define SMB2_CHANNEL_RDMA_V1            cpu_to_le32(0x00000001)
740 #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002)
741 #define SMB2_CHANNEL_RDMA_TRANSFORM     cpu_to_le32(0x00000003)
742 
743 /* SMB2 read request without RFC1001 length at the beginning */
744 struct smb2_read_req {
745 	struct smb2_hdr hdr;
746 	__le16 StructureSize; /* Must be 49 */
747 	__u8   Padding; /* offset from start of SMB2 header to place read */
748 	__u8   Flags; /* MBZ unless SMB3.02 or later */
749 	__le32 Length;
750 	__le64 Offset;
751 	__u64  PersistentFileId;
752 	__u64  VolatileFileId;
753 	__le32 MinimumCount;
754 	__le32 Channel; /* MBZ except for SMB3 or later */
755 	__le32 RemainingBytes;
756 	__le16 ReadChannelInfoOffset;
757 	__le16 ReadChannelInfoLength;
758 	__u8   Buffer[];
759 } __packed;
760 
761 /* Read flags */
762 #define SMB2_READFLAG_RESPONSE_NONE            cpu_to_le32(0x00000000)
763 #define SMB2_READFLAG_RESPONSE_RDMA_TRANSFORM  cpu_to_le32(0x00000001)
764 
765 struct smb2_read_rsp {
766 	struct smb2_hdr hdr;
767 	__le16 StructureSize; /* Must be 17 */
768 	__u8   DataOffset;
769 	__u8   Reserved;
770 	__le32 DataLength;
771 	__le32 DataRemaining;
772 	__le32 Flags;
773 	__u8   Buffer[];
774 } __packed;
775 
776 
777 /*
778  * SMB2_WRITE  See MS-SMB2 section 2.2.21
779  */
780 /* For write request Flags field below the following flags are defined: */
781 #define SMB2_WRITEFLAG_WRITE_THROUGH	0x00000001	/* SMB2.1 or later */
782 #define SMB2_WRITEFLAG_WRITE_UNBUFFERED	0x00000002	/* SMB3.02 or later */
783 
784 struct smb2_write_req {
785 	struct smb2_hdr hdr;
786 	__le16 StructureSize; /* Must be 49 */
787 	__le16 DataOffset; /* offset from start of SMB2 header to write data */
788 	__le32 Length;
789 	__le64 Offset;
790 	__u64  PersistentFileId; /* opaque endianness */
791 	__u64  VolatileFileId; /* opaque endianness */
792 	__le32 Channel; /* MBZ unless SMB3.02 or later */
793 	__le32 RemainingBytes;
794 	__le16 WriteChannelInfoOffset;
795 	__le16 WriteChannelInfoLength;
796 	__le32 Flags;
797 	__u8   Buffer[];
798 } __packed;
799 
800 struct smb2_write_rsp {
801 	struct smb2_hdr hdr;
802 	__le16 StructureSize; /* Must be 17 */
803 	__u8   DataOffset;
804 	__u8   Reserved;
805 	__le32 DataLength;
806 	__le32 DataRemaining;
807 	__u32  Reserved2;
808 	__u8   Buffer[];
809 } __packed;
810 
811 
812 /*
813  * SMB2_FLUSH  See MS-SMB2 section 2.2.17
814  */
815 struct smb2_flush_req {
816 	struct smb2_hdr hdr;
817 	__le16 StructureSize;	/* Must be 24 */
818 	__le16 Reserved1;
819 	__le32 Reserved2;
820 	__u64  PersistentFileId;
821 	__u64  VolatileFileId;
822 } __packed;
823 
824 struct smb2_flush_rsp {
825 	struct smb2_hdr hdr;
826 	__le16 StructureSize;
827 	__le16 Reserved;
828 } __packed;
829 
830 #define SMB2_LOCKFLAG_SHARED		0x0001
831 #define SMB2_LOCKFLAG_EXCLUSIVE		0x0002
832 #define SMB2_LOCKFLAG_UNLOCK		0x0004
833 #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY	0x0010
834 #define SMB2_LOCKFLAG_MASK		0x0007
835 
836 struct smb2_lock_element {
837 	__le64 Offset;
838 	__le64 Length;
839 	__le32 Flags;
840 	__le32 Reserved;
841 } __packed;
842 
843 struct smb2_lock_req {
844 	struct smb2_hdr hdr;
845 	__le16 StructureSize; /* Must be 48 */
846 	__le16 LockCount;
847 	/*
848 	 * The least significant four bits are the index, the other 28 bits are
849 	 * the lock sequence number (0 to 64). See MS-SMB2 2.2.26
850 	 */
851 	__le32 LockSequenceNumber;
852 	__u64  PersistentFileId;
853 	__u64  VolatileFileId;
854 	/* Followed by at least one */
855 	union {
856 		struct smb2_lock_element lock;
857 		DECLARE_FLEX_ARRAY(struct smb2_lock_element, locks);
858 	};
859 } __packed;
860 
861 struct smb2_lock_rsp {
862 	struct smb2_hdr hdr;
863 	__le16 StructureSize; /* Must be 4 */
864 	__le16 Reserved;
865 } __packed;
866 
867 struct smb2_echo_req {
868 	struct smb2_hdr hdr;
869 	__le16 StructureSize;	/* Must be 4 */
870 	__u16  Reserved;
871 } __packed;
872 
873 struct smb2_echo_rsp {
874 	struct smb2_hdr hdr;
875 	__le16 StructureSize;	/* Must be 4 */
876 	__u16  Reserved;
877 } __packed;
878 
879 /*
880  * Valid FileInformation classes for query directory
881  *
882  * Note that these are a subset of the (file) QUERY_INFO levels defined
883  * later in this file (but since QUERY_DIRECTORY uses equivalent numbers
884  * we do not redefine them here)
885  *
886  * FileDirectoryInfomation		0x01
887  * FileFullDirectoryInformation		0x02
888  * FileIdFullDirectoryInformation	0x26
889  * FileBothDirectoryInformation		0x03
890  * FileIdBothDirectoryInformation	0x25
891  * FileNamesInformation			0x0C
892  * FileIdExtdDirectoryInformation	0x3C
893  */
894 
895 /* search (query_directory) Flags field */
896 #define SMB2_RESTART_SCANS		0x01
897 #define SMB2_RETURN_SINGLE_ENTRY	0x02
898 #define SMB2_INDEX_SPECIFIED		0x04
899 #define SMB2_REOPEN			0x10
900 
901 struct smb2_query_directory_req {
902 	struct smb2_hdr hdr;
903 	__le16 StructureSize; /* Must be 33 */
904 	__u8   FileInformationClass;
905 	__u8   Flags;
906 	__le32 FileIndex;
907 	__u64  PersistentFileId;
908 	__u64  VolatileFileId;
909 	__le16 FileNameOffset;
910 	__le16 FileNameLength;
911 	__le32 OutputBufferLength;
912 	__u8   Buffer[];
913 } __packed;
914 
915 struct smb2_query_directory_rsp {
916 	struct smb2_hdr hdr;
917 	__le16 StructureSize; /* Must be 9 */
918 	__le16 OutputBufferOffset;
919 	__le32 OutputBufferLength;
920 	__u8   Buffer[];
921 } __packed;
922 
923 /* DeviceType Flags */
924 #define FILE_DEVICE_CD_ROM              0x00000002
925 #define FILE_DEVICE_CD_ROM_FILE_SYSTEM  0x00000003
926 #define FILE_DEVICE_DFS                 0x00000006
927 #define FILE_DEVICE_DISK                0x00000007
928 #define FILE_DEVICE_DISK_FILE_SYSTEM    0x00000008
929 #define FILE_DEVICE_FILE_SYSTEM         0x00000009
930 #define FILE_DEVICE_NAMED_PIPE          0x00000011
931 #define FILE_DEVICE_NETWORK             0x00000012
932 #define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
933 #define FILE_DEVICE_NULL                0x00000015
934 #define FILE_DEVICE_PARALLEL_PORT       0x00000016
935 #define FILE_DEVICE_PRINTER             0x00000018
936 #define FILE_DEVICE_SERIAL_PORT         0x0000001b
937 #define FILE_DEVICE_STREAMS             0x0000001e
938 #define FILE_DEVICE_TAPE                0x0000001f
939 #define FILE_DEVICE_TAPE_FILE_SYSTEM    0x00000020
940 #define FILE_DEVICE_VIRTUAL_DISK        0x00000024
941 #define FILE_DEVICE_NETWORK_REDIRECTOR  0x00000028
942 
943 /* Device Characteristics */
944 #define FILE_REMOVABLE_MEDIA			0x00000001
945 #define FILE_READ_ONLY_DEVICE			0x00000002
946 #define FILE_FLOPPY_DISKETTE			0x00000004
947 #define FILE_WRITE_ONCE_MEDIA			0x00000008
948 #define FILE_REMOTE_DEVICE			0x00000010
949 #define FILE_DEVICE_IS_MOUNTED			0x00000020
950 #define FILE_VIRTUAL_VOLUME			0x00000040
951 #define FILE_DEVICE_SECURE_OPEN			0x00000100
952 #define FILE_CHARACTERISTIC_TS_DEVICE		0x00001000
953 #define FILE_CHARACTERISTIC_WEBDAV_DEVICE	0x00002000
954 #define FILE_PORTABLE_DEVICE			0x00004000
955 #define FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL 0x00020000
956 
957 /*
958  * Maximum number of iovs we need for a set-info request.
959  * The largest one is rename/hardlink
960  * [0] : struct smb2_set_info_req + smb2_file_[rename|link]_info
961  * [1] : path
962  * [2] : compound padding
963  */
964 #define SMB2_SET_INFO_IOV_SIZE 3
965 
966 struct smb2_set_info_req {
967 	struct smb2_hdr hdr;
968 	__le16 StructureSize; /* Must be 33 */
969 	__u8   InfoType;
970 	__u8   FileInfoClass;
971 	__le32 BufferLength;
972 	__le16 BufferOffset;
973 	__u16  Reserved;
974 	__le32 AdditionalInformation;
975 	__u64  PersistentFileId;
976 	__u64  VolatileFileId;
977 	__u8   Buffer[];
978 } __packed;
979 
980 struct smb2_set_info_rsp {
981 	struct smb2_hdr hdr;
982 	__le16 StructureSize; /* Must be 2 */
983 } __packed;
984 
985 /*
986  * SMB2_NOTIFY  See MS-SMB2 section 2.2.35
987  */
988 /* notify flags */
989 #define SMB2_WATCH_TREE			0x0001
990 
991 /* notify completion filter flags. See MS-FSCC 2.6 and MS-SMB2 2.2.35 */
992 #define FILE_NOTIFY_CHANGE_FILE_NAME		0x00000001
993 #define FILE_NOTIFY_CHANGE_DIR_NAME		0x00000002
994 #define FILE_NOTIFY_CHANGE_ATTRIBUTES		0x00000004
995 #define FILE_NOTIFY_CHANGE_SIZE			0x00000008
996 #define FILE_NOTIFY_CHANGE_LAST_WRITE		0x00000010
997 #define FILE_NOTIFY_CHANGE_LAST_ACCESS		0x00000020
998 #define FILE_NOTIFY_CHANGE_CREATION		0x00000040
999 #define FILE_NOTIFY_CHANGE_EA			0x00000080
1000 #define FILE_NOTIFY_CHANGE_SECURITY		0x00000100
1001 #define FILE_NOTIFY_CHANGE_STREAM_NAME		0x00000200
1002 #define FILE_NOTIFY_CHANGE_STREAM_SIZE		0x00000400
1003 #define FILE_NOTIFY_CHANGE_STREAM_WRITE		0x00000800
1004 
1005 /* SMB2 Notify Action Flags */
1006 #define FILE_ACTION_ADDED                       0x00000001
1007 #define FILE_ACTION_REMOVED                     0x00000002
1008 #define FILE_ACTION_MODIFIED                    0x00000003
1009 #define FILE_ACTION_RENAMED_OLD_NAME            0x00000004
1010 #define FILE_ACTION_RENAMED_NEW_NAME            0x00000005
1011 #define FILE_ACTION_ADDED_STREAM                0x00000006
1012 #define FILE_ACTION_REMOVED_STREAM              0x00000007
1013 #define FILE_ACTION_MODIFIED_STREAM             0x00000008
1014 #define FILE_ACTION_REMOVED_BY_DELETE           0x00000009
1015 
1016 struct smb2_change_notify_req {
1017 	struct smb2_hdr hdr;
1018 	__le16	StructureSize;
1019 	__le16	Flags;
1020 	__le32	OutputBufferLength;
1021 	__u64	PersistentFileId; /* opaque endianness */
1022 	__u64	VolatileFileId; /* opaque endianness */
1023 	__le32	CompletionFilter;
1024 	__u32	Reserved;
1025 } __packed;
1026 
1027 struct smb2_change_notify_rsp {
1028 	struct smb2_hdr hdr;
1029 	__le16	StructureSize;  /* Must be 9 */
1030 	__le16	OutputBufferOffset;
1031 	__le32	OutputBufferLength;
1032 	__u8	Buffer[]; /* array of file notify structs */
1033 } __packed;
1034 
1035 /*
1036  * SMB2_SERVER_TO_CLIENT_NOTIFICATION: See MS-SMB2 section 2.2.44
1037  */
1038 
1039 #define SMB2_NOTIFY_SESSION_CLOSED	0x0000
1040 
1041 struct smb2_server_client_notification {
1042 	struct smb2_hdr hdr;
1043 	__le16	StructureSize;
1044 	__u16	Reserved; /* MBZ */
1045 	__le32	NotificationType;
1046 	__u8	NotificationBuffer[4]; /* MBZ */
1047 } __packed;
1048 
1049 /*
1050  * SMB2_CREATE  See MS-SMB2 section 2.2.13
1051  */
1052 /* Oplock levels */
1053 #define SMB2_OPLOCK_LEVEL_NONE		0x00
1054 #define SMB2_OPLOCK_LEVEL_II		0x01
1055 #define SMB2_OPLOCK_LEVEL_EXCLUSIVE	0x08
1056 #define SMB2_OPLOCK_LEVEL_BATCH		0x09
1057 #define SMB2_OPLOCK_LEVEL_LEASE		0xFF
1058 /* Non-spec internal type */
1059 #define SMB2_OPLOCK_LEVEL_NOCHANGE	0x99
1060 
1061 /* Impersonation Levels. See MS-WPO section 9.7 and MSDN-IMPERS */
1062 #define IL_ANONYMOUS		cpu_to_le32(0x00000000)
1063 #define IL_IDENTIFICATION	cpu_to_le32(0x00000001)
1064 #define IL_IMPERSONATION	cpu_to_le32(0x00000002)
1065 #define IL_DELEGATE		cpu_to_le32(0x00000003)
1066 
1067 /* File Attributes */
1068 #define FILE_ATTRIBUTE_READONLY			0x00000001
1069 #define FILE_ATTRIBUTE_HIDDEN			0x00000002
1070 #define FILE_ATTRIBUTE_SYSTEM			0x00000004
1071 #define FILE_ATTRIBUTE_DIRECTORY		0x00000010
1072 #define FILE_ATTRIBUTE_ARCHIVE			0x00000020
1073 #define FILE_ATTRIBUTE_NORMAL			0x00000080
1074 #define FILE_ATTRIBUTE_TEMPORARY		0x00000100
1075 #define FILE_ATTRIBUTE_SPARSE_FILE		0x00000200
1076 #define FILE_ATTRIBUTE_REPARSE_POINT		0x00000400
1077 #define FILE_ATTRIBUTE_COMPRESSED		0x00000800
1078 #define FILE_ATTRIBUTE_OFFLINE			0x00001000
1079 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED	0x00002000
1080 #define FILE_ATTRIBUTE_ENCRYPTED		0x00004000
1081 #define FILE_ATTRIBUTE_INTEGRITY_STREAM		0x00008000
1082 #define FILE_ATTRIBUTE_NO_SCRUB_DATA		0x00020000
1083 #define FILE_ATTRIBUTE__MASK			0x00007FB7
1084 
1085 #define FILE_ATTRIBUTE_READONLY_LE              cpu_to_le32(0x00000001)
1086 #define FILE_ATTRIBUTE_HIDDEN_LE		cpu_to_le32(0x00000002)
1087 #define FILE_ATTRIBUTE_SYSTEM_LE		cpu_to_le32(0x00000004)
1088 #define FILE_ATTRIBUTE_DIRECTORY_LE		cpu_to_le32(0x00000010)
1089 #define FILE_ATTRIBUTE_ARCHIVE_LE		cpu_to_le32(0x00000020)
1090 #define FILE_ATTRIBUTE_NORMAL_LE		cpu_to_le32(0x00000080)
1091 #define FILE_ATTRIBUTE_TEMPORARY_LE		cpu_to_le32(0x00000100)
1092 #define FILE_ATTRIBUTE_SPARSE_FILE_LE		cpu_to_le32(0x00000200)
1093 #define FILE_ATTRIBUTE_REPARSE_POINT_LE		cpu_to_le32(0x00000400)
1094 #define FILE_ATTRIBUTE_COMPRESSED_LE		cpu_to_le32(0x00000800)
1095 #define FILE_ATTRIBUTE_OFFLINE_LE		cpu_to_le32(0x00001000)
1096 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED_LE	cpu_to_le32(0x00002000)
1097 #define FILE_ATTRIBUTE_ENCRYPTED_LE		cpu_to_le32(0x00004000)
1098 #define FILE_ATTRIBUTE_INTEGRITY_STREAM_LE	cpu_to_le32(0x00008000)
1099 #define FILE_ATTRIBUTE_NO_SCRUB_DATA_LE		cpu_to_le32(0x00020000)
1100 #define FILE_ATTRIBUTE_MASK_LE			cpu_to_le32(0x00007FB7)
1101 
1102 /* Desired Access Flags */
1103 #define FILE_READ_DATA_LE		cpu_to_le32(0x00000001)
1104 #define FILE_LIST_DIRECTORY_LE		cpu_to_le32(0x00000001)
1105 #define FILE_WRITE_DATA_LE		cpu_to_le32(0x00000002)
1106 #define FILE_APPEND_DATA_LE		cpu_to_le32(0x00000004)
1107 #define FILE_ADD_SUBDIRECTORY_LE	cpu_to_le32(0x00000004)
1108 #define FILE_READ_EA_LE			cpu_to_le32(0x00000008)
1109 #define FILE_WRITE_EA_LE		cpu_to_le32(0x00000010)
1110 #define FILE_EXECUTE_LE			cpu_to_le32(0x00000020)
1111 #define FILE_DELETE_CHILD_LE		cpu_to_le32(0x00000040)
1112 #define FILE_READ_ATTRIBUTES_LE		cpu_to_le32(0x00000080)
1113 #define FILE_WRITE_ATTRIBUTES_LE	cpu_to_le32(0x00000100)
1114 #define FILE_DELETE_LE			cpu_to_le32(0x00010000)
1115 #define FILE_READ_CONTROL_LE		cpu_to_le32(0x00020000)
1116 #define FILE_WRITE_DAC_LE		cpu_to_le32(0x00040000)
1117 #define FILE_WRITE_OWNER_LE		cpu_to_le32(0x00080000)
1118 #define FILE_SYNCHRONIZE_LE		cpu_to_le32(0x00100000)
1119 #define FILE_ACCESS_SYSTEM_SECURITY_LE	cpu_to_le32(0x01000000)
1120 #define FILE_MAXIMAL_ACCESS_LE		cpu_to_le32(0x02000000)
1121 #define FILE_GENERIC_ALL_LE		cpu_to_le32(0x10000000)
1122 #define FILE_GENERIC_EXECUTE_LE		cpu_to_le32(0x20000000)
1123 #define FILE_GENERIC_WRITE_LE		cpu_to_le32(0x40000000)
1124 #define FILE_GENERIC_READ_LE		cpu_to_le32(0x80000000)
1125 #define DESIRED_ACCESS_MASK             cpu_to_le32(0xF21F01FF)
1126 
1127 
1128 #define FILE_READ_DESIRED_ACCESS_LE     (FILE_READ_DATA_LE        |	\
1129 					 FILE_READ_EA_LE          |     \
1130 					 FILE_GENERIC_READ_LE)
1131 #define FILE_WRITE_DESIRE_ACCESS_LE     (FILE_WRITE_DATA_LE       |	\
1132 					 FILE_APPEND_DATA_LE      |	\
1133 					 FILE_WRITE_EA_LE         |	\
1134 					 FILE_WRITE_ATTRIBUTES_LE |	\
1135 					 FILE_GENERIC_WRITE_LE)
1136 
1137 /* ShareAccess Flags */
1138 #define FILE_SHARE_READ_LE		cpu_to_le32(0x00000001)
1139 #define FILE_SHARE_WRITE_LE		cpu_to_le32(0x00000002)
1140 #define FILE_SHARE_DELETE_LE		cpu_to_le32(0x00000004)
1141 #define FILE_SHARE_ALL_LE		cpu_to_le32(0x00000007)
1142 
1143 /* CreateDisposition Flags */
1144 #define FILE_SUPERSEDE_LE		cpu_to_le32(0x00000000)
1145 #define FILE_OPEN_LE			cpu_to_le32(0x00000001)
1146 #define FILE_CREATE_LE			cpu_to_le32(0x00000002)
1147 #define	FILE_OPEN_IF_LE			cpu_to_le32(0x00000003)
1148 #define FILE_OVERWRITE_LE		cpu_to_le32(0x00000004)
1149 #define FILE_OVERWRITE_IF_LE		cpu_to_le32(0x00000005)
1150 #define FILE_CREATE_MASK_LE             cpu_to_le32(0x00000007)
1151 
1152 /* CreateOptions Flags */
1153 #define FILE_DIRECTORY_FILE_LE		cpu_to_le32(0x00000001)
1154 /* same as #define CREATE_NOT_FILE_LE	cpu_to_le32(0x00000001) */
1155 #define FILE_WRITE_THROUGH_LE		cpu_to_le32(0x00000002)
1156 #define FILE_SEQUENTIAL_ONLY_LE		cpu_to_le32(0x00000004)
1157 #define FILE_NO_INTERMEDIATE_BUFFERING_LE cpu_to_le32(0x00000008)
1158 /* FILE_SYNCHRONOUS_IO_ALERT_LE		cpu_to_le32(0x00000010) should be zero, ignored */
1159 /* FILE_SYNCHRONOUS_IO_NONALERT		cpu_to_le32(0x00000020) should be zero, ignored */
1160 #define FILE_NON_DIRECTORY_FILE_LE	cpu_to_le32(0x00000040)
1161 #define FILE_COMPLETE_IF_OPLOCKED_LE	cpu_to_le32(0x00000100)
1162 #define FILE_NO_EA_KNOWLEDGE_LE		cpu_to_le32(0x00000200)
1163 /* FILE_OPEN_REMOTE_INSTANCE		cpu_to_le32(0x00000400) should be zero, ignored */
1164 #define FILE_RANDOM_ACCESS_LE		cpu_to_le32(0x00000800)
1165 #define FILE_DELETE_ON_CLOSE_LE		cpu_to_le32(0x00001000) /* MBZ */
1166 #define FILE_OPEN_BY_FILE_ID_LE		cpu_to_le32(0x00002000)
1167 #define FILE_OPEN_FOR_BACKUP_INTENT_LE	cpu_to_le32(0x00004000)
1168 #define FILE_NO_COMPRESSION_LE		cpu_to_le32(0x00008000)
1169 /* FILE_OPEN_REQUIRING_OPLOCK		cpu_to_le32(0x00010000) should be zero, ignored */
1170 /* FILE_DISALLOW_EXCLUSIVE		cpu_to_le32(0x00020000) should be zero, ignored */
1171 /* FILE_RESERVE_OPFILTER		cpu_to_le32(0x00100000) MBZ */
1172 #define FILE_OPEN_REPARSE_POINT_LE	cpu_to_le32(0x00200000)
1173 #define FILE_OPEN_NO_RECALL_LE		cpu_to_le32(0x00400000)
1174 /* #define FILE_OPEN_FOR_FREE_SPACE_QUERY cpu_to_le32(0x00800000) should be zero, ignored */
1175 #define CREATE_OPTIONS_MASK_LE          cpu_to_le32(0x00FFFFFF)
1176 
1177 #define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \
1178 			| FILE_READ_ATTRIBUTES_LE)
1179 #define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \
1180 			| FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
1181 #define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
1182 
1183 /* Create Context Values */
1184 #define SMB2_CREATE_EA_BUFFER			"ExtA" /* extended attributes */
1185 #define SMB2_CREATE_SD_BUFFER			"SecD" /* security descriptor */
1186 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST	"DHnQ"
1187 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT	"DHnC"
1188 #define SMB2_CREATE_ALLOCATION_SIZE		"AlSi"
1189 #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
1190 #define SMB2_CREATE_TIMEWARP_REQUEST		"TWrp"
1191 #define SMB2_CREATE_QUERY_ON_DISK_ID		"QFid"
1192 #define SMB2_CREATE_REQUEST_LEASE		"RqLs"
1193 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2	"DH2Q"
1194 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2	"DH2C"
1195 #define SMB2_CREATE_TAG_POSIX		"\x93\xAD\x25\x50\x9C\xB4\x11\xE7\xB4\x23\x83\xDE\x96\x8B\xCD\x7C"
1196 #define SMB2_CREATE_APP_INSTANCE_ID	"\x45\xBC\xA6\x6A\xEF\xA7\xF7\x4A\x90\x08\xFA\x46\x2E\x14\x4D\x74"
1197 #define SMB2_CREATE_APP_INSTANCE_VERSION "\xB9\x82\xD0\xB7\x3B\x56\x07\x4F\xA0\x7B\x52\x4A\x81\x16\xA0\x10"
1198 #define SVHDX_OPEN_DEVICE_CONTEXT	"\x9C\xCB\xCF\x9E\x04\xC1\xE6\x43\x98\x0E\x15\x8D\xA1\xF6\xEC\x83"
1199 #define SMB2_CREATE_TAG_AAPL			"AAPL"
1200 
1201 /* Flag (SMB3 open response) values */
1202 #define SMB2_CREATE_FLAG_REPARSEPOINT 0x01
1203 
1204 struct create_context {
1205 	/* New members must be added within the struct_group() macro below. */
1206 	__struct_group(create_context_hdr, hdr, __packed,
1207 		__le32 Next;
1208 		__le16 NameOffset;
1209 		__le16 NameLength;
1210 		__le16 Reserved;
1211 		__le16 DataOffset;
1212 		__le32 DataLength;
1213 	);
1214 	__u8 Buffer[];
1215 } __packed;
1216 static_assert(offsetof(struct create_context, Buffer) == sizeof(struct create_context_hdr),
1217 	      "struct member likely outside of __struct_group()");
1218 
1219 struct smb2_create_req {
1220 	struct smb2_hdr hdr;
1221 	__le16 StructureSize;	/* Must be 57 */
1222 	__u8   SecurityFlags;
1223 	__u8   RequestedOplockLevel;
1224 	__le32 ImpersonationLevel;
1225 	__le64 SmbCreateFlags;
1226 	__le64 Reserved;
1227 	__le32 DesiredAccess;
1228 	__le32 FileAttributes;
1229 	__le32 ShareAccess;
1230 	__le32 CreateDisposition;
1231 	__le32 CreateOptions;
1232 	__le16 NameOffset;
1233 	__le16 NameLength;
1234 	__le32 CreateContextsOffset;
1235 	__le32 CreateContextsLength;
1236 	__u8   Buffer[];
1237 } __packed;
1238 
1239 struct smb2_create_rsp {
1240 	struct smb2_hdr hdr;
1241 	__le16 StructureSize;	/* Must be 89 */
1242 	__u8   OplockLevel;
1243 	__u8   Flags;  /* 0x01 if reparse point */
1244 	__le32 CreateAction;
1245 	__le64 CreationTime;
1246 	__le64 LastAccessTime;
1247 	__le64 LastWriteTime;
1248 	__le64 ChangeTime;
1249 	__le64 AllocationSize;
1250 	__le64 EndofFile;
1251 	__le32 FileAttributes;
1252 	__le32 Reserved2;
1253 	__u64  PersistentFileId;
1254 	__u64  VolatileFileId;
1255 	__le32 CreateContextsOffset;
1256 	__le32 CreateContextsLength;
1257 	__u8   Buffer[];
1258 } __packed;
1259 
1260 struct create_posix {
1261 	struct create_context_hdr ccontext;
1262 	__u8    Name[16];
1263 	__le32  Mode;
1264 	__u32   Reserved;
1265 } __packed;
1266 
1267 /* See MS-SMB2 2.2.13.2.3 and MS-SMB2 2.2.13.2.4 */
1268 typedef struct {
1269 	struct create_context_hdr ccontext;
1270 	__u8   Name[8];
1271 	union {
1272 		__u8  Reserved[16];
1273 		struct {
1274 			__u64 PersistentFileId;
1275 			__u64 VolatileFileId;
1276 		} Fid;
1277 	} Data;
1278 } __packed create_durable_req_t, create_durable_reconn_t;
1279 
1280 /* See MS-SMB2 2.2.13.2.5 */
1281 struct create_mxac_req {
1282 	struct create_context_hdr ccontext;
1283 	__u8   Name[8];
1284 	__le64 Timestamp;
1285 } __packed;
1286 
1287 /*
1288  * Flags
1289  * See MS-SMB2 2.2.13.2.11
1290  *     MS-SMB2 2.2.13.2.12
1291  *     MS-SMB2 2.2.14.2.12
1292  */
1293 #define SMB2_DHANDLE_FLAG_PERSISTENT	0x00000002
1294 
1295 /* See MS-SMB2 2.2.13.2.11 */
1296 struct durable_context_v2_req {
1297 	__le32 Timeout;
1298 	__le32 Flags; /* see SMB2_DHANDLE_FLAG_PERSISTENT */
1299 	__u64 Reserved;
1300 	__u8 CreateGuid[16];
1301 } __packed;
1302 
1303 struct create_durable_req_v2 {
1304 	struct create_context_hdr ccontext;
1305 	__u8   Name[8];
1306 	struct durable_context_v2_req dcontext;
1307 } __packed;
1308 
1309 /* See MS-SMB2 2.2.13.2.12 */
1310 struct durable_reconnect_context_v2 {
1311 	struct {
1312 		__u64 PersistentFileId;
1313 		__u64 VolatileFileId;
1314 	} Fid;
1315 	__u8 CreateGuid[16];
1316 	__le32 Flags; /* see SMB2_DHANDLE_FLAG_PERSISTENT */
1317 } __packed;
1318 
1319 struct create_durable_handle_reconnect_v2 {
1320 	struct create_context_hdr ccontext;
1321 	__u8   Name[8];
1322 	struct durable_reconnect_context_v2 dcontext;
1323 } __packed;
1324 
1325 /* See MS-SMB2 2.2.14.2.12 */
1326 struct durable_context_v2_rsp {
1327 	__le32 Timeout;
1328 	__le32 Flags; /* see SMB2_DHANDLE_FLAG_PERSISTENT */
1329 } __packed;
1330 
1331 struct create_durable_rsp_v2 {
1332 	struct create_context_hdr ccontext;
1333 	__u8   Name[8];
1334 	struct durable_context_v2_rsp dcontext;
1335 } __packed;
1336 
1337 /* See MS-SMB2 2.2.14.2.5 */
1338 struct create_mxac_rsp {
1339 	struct create_context_hdr ccontext;
1340 	__u8   Name[8];
1341 	__le32 QueryStatus;
1342 	__le32 MaximalAccess;
1343 } __packed;
1344 
1345 #define SMB2_LEASE_NONE_LE			cpu_to_le32(0x00)
1346 #define SMB2_LEASE_READ_CACHING_LE		cpu_to_le32(0x01)
1347 #define SMB2_LEASE_HANDLE_CACHING_LE		cpu_to_le32(0x02)
1348 #define SMB2_LEASE_WRITE_CACHING_LE		cpu_to_le32(0x04)
1349 
1350 #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE	cpu_to_le32(0x02)
1351 #define SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET_LE	cpu_to_le32(0x04)
1352 
1353 #define SMB2_LEASE_KEY_SIZE			16
1354 
1355 /* See MS-SMB2 2.2.13.2.8 */
1356 struct lease_context {
1357 	__u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
1358 	__le32 LeaseState;
1359 	__le32 LeaseFlags;
1360 	__le64 LeaseDuration;
1361 } __packed;
1362 
1363 /* See MS-SMB2 2.2.13.2.10 */
1364 struct lease_context_v2 {
1365 	__u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
1366 	__le32 LeaseState;
1367 	__le32 LeaseFlags;
1368 	__le64 LeaseDuration;
1369 	__u8 ParentLeaseKey[SMB2_LEASE_KEY_SIZE];
1370 	__le16 Epoch;
1371 	__le16 Reserved;
1372 } __packed;
1373 
1374 struct create_lease {
1375 	struct create_context_hdr ccontext;
1376 	__u8   Name[8];
1377 	struct lease_context lcontext;
1378 } __packed;
1379 
1380 struct create_lease_v2 {
1381 	struct create_context_hdr ccontext;
1382 	__u8   Name[8];
1383 	struct lease_context_v2 lcontext;
1384 	__u8   Pad[4];
1385 } __packed;
1386 
1387 /* See MS-SMB2 2.2.14.2.9 */
1388 struct create_disk_id_rsp {
1389 	struct create_context_hdr ccontext;
1390 	__u8   Name[8];
1391 	__le64 DiskFileId;
1392 	__le64 VolumeId;
1393 	__u8  Reserved[16];
1394 } __packed;
1395 
1396 /* See MS-SMB2 2.2.13.2.13 */
1397 struct create_app_inst_id {
1398 	struct create_context_hdr ccontext;
1399 	__u8 Name[16];
1400 	__le32 StructureSize; /* Must be 20 */
1401 	__u16 Reserved;
1402 	__u8 AppInstanceId[16];
1403 } __packed;
1404 
1405 /* See MS-SMB2 2.2.13.2.15 */
1406 struct create_app_inst_id_vers {
1407 	struct create_context_hdr ccontext;
1408 	__u8 Name[16];
1409 	__le32 StructureSize; /* Must be 24 */
1410 	__u16 Reserved;
1411 	__u32 Padding;
1412 	__le64 AppInstanceVersionHigh;
1413 	__le64 AppInstanceVersionLow;
1414 } __packed;
1415 
1416 /* See MS-SMB2 2.2.31 and 2.2.32 */
1417 struct smb2_ioctl_req {
1418 	struct smb2_hdr hdr;
1419 	__le16 StructureSize; /* Must be 57 */
1420 	__le16 Reserved; /* offset from start of SMB2 header to write data */
1421 	__le32 CtlCode;
1422 	__u64  PersistentFileId;
1423 	__u64  VolatileFileId;
1424 	__le32 InputOffset; /* Reserved MBZ */
1425 	__le32 InputCount;
1426 	__le32 MaxInputResponse;
1427 	__le32 OutputOffset;
1428 	__le32 OutputCount;
1429 	__le32 MaxOutputResponse;
1430 	__le32 Flags;
1431 	__le32 Reserved2;
1432 	__u8   Buffer[];
1433 } __packed;
1434 
1435 /* See MS-SMB2 2.2.31.1.1 */
1436 struct srv_copychunk {
1437 	__le64 SourceOffset;
1438 	__le64 TargetOffset;
1439 	__le32 Length;
1440 	__le32 Reserved;
1441 } __packed;
1442 
1443 #define COPY_CHUNK_RES_KEY_SIZE	24
1444 
1445 /* See MS-SMB2 2.2.31.1 */
1446 /* this goes in the ioctl buffer when doing a copychunk request */
1447 struct copychunk_ioctl_req {
1448 	union {
1449 		char SourceKey[COPY_CHUNK_RES_KEY_SIZE];
1450 		__le64 SourceKeyU64[3];
1451 	};
1452 	__le32 ChunkCount;
1453 	__le32 Reserved;
1454 	struct srv_copychunk Chunks[] __counted_by_le(ChunkCount);
1455 } __packed;
1456 
1457 /* See MS-SMB2 2.2.32.1 */
1458 struct copychunk_ioctl_rsp {
1459 	__le32 ChunksWritten;
1460 	__le32 ChunkBytesWritten;
1461 	__le32 TotalBytesWritten;
1462 } __packed;
1463 
1464 /* See MS-SMB2 2.2.32.3 */
1465 struct resume_key_ioctl_rsp {
1466 	union {
1467 		char ResumeKey[COPY_CHUNK_RES_KEY_SIZE];
1468 		__u64 ResumeKeyU64[3];
1469 	};
1470 	__le32	ContextLength;	/* MBZ */
1471 	char	Context[];	/* ignored, Windows sets to 4 bytes of zero */
1472 } __packed;
1473 
1474 struct smb2_ioctl_rsp {
1475 	struct smb2_hdr hdr;
1476 	__le16 StructureSize; /* Must be 49 */
1477 	__le16 Reserved;
1478 	__le32 CtlCode;
1479 	__u64  PersistentFileId;
1480 	__u64  VolatileFileId;
1481 	__le32 InputOffset; /* Reserved MBZ */
1482 	__le32 InputCount;
1483 	__le32 OutputOffset;
1484 	__le32 OutputCount;
1485 	__le32 Flags;
1486 	__le32 Reserved2;
1487 	__u8   Buffer[];
1488 } __packed;
1489 
1490 /* See MS-SMB2 2.2.32.5.1.1 */
1491 struct smb_sockaddr_in {
1492 	__be16 Port;
1493 	__be32 IPv4Address;
1494 	__u8   Reserved[8];
1495 } __packed;
1496 
1497 /* See MS-SMB2 2.2.32.5.1.2 */
1498 struct smb_sockaddr_in6 {
1499 	__be16 Port;
1500 	__be32 FlowInfo;
1501 	__u8   IPv6Address[16];
1502 	__be32 ScopeId;
1503 } __packed;
1504 
1505 /* See MS-SMB2 2.2.32.5 and MS-SMB2 2.2.32.5.1 */
1506 #define RSS_CAPABLE	cpu_to_le32(0x00000001)
1507 #define RDMA_CAPABLE	cpu_to_le32(0x00000002)
1508 #define INTERNETWORK	cpu_to_le16(0x0002)
1509 #define INTERNETWORKV6	cpu_to_le16(0x0017)
1510 struct network_interface_info_ioctl_rsp {
1511 	__le32 Next; /* next interface. zero if this is last one */
1512 	__le32 IfIndex;
1513 	__le32 Capability; /* RSS or RDMA Capable */
1514 	__le32 Reserved;
1515 	__le64 LinkSpeed;
1516 	union {
1517 		char	SockAddr_Storage[128];
1518 		struct {
1519 			__le16 Family;
1520 			__u8 Buffer[126];
1521 		};
1522 	};
1523 } __packed;
1524 
1525 /* this goes in the ioctl buffer when doing FSCTL_SET_ZERO_DATA */
1526 struct file_zero_data_information {
1527 	__le64	FileOffset;
1528 	__le64	BeyondFinalZero;
1529 } __packed;
1530 
1531 /* See MS-FSCC 2.3.7 */
1532 struct duplicate_extents_to_file {
1533 	__u64 PersistentFileHandle; /* source file handle, opaque endianness */
1534 	__u64 VolatileFileHandle;
1535 	__le64 SourceFileOffset;
1536 	__le64 TargetFileOffset;
1537 	__le64 ByteCount;  /* Bytes to be copied */
1538 } __packed;
1539 
1540 /* See MS-FSCC 2.3.8 */
1541 #define DUPLICATE_EXTENTS_DATA_EX_SOURCE_ATOMIC	0x00000001
1542 struct duplicate_extents_to_file_ex {
1543 	__u64 PersistentFileHandle; /* source file handle, opaque endianness */
1544 	__u64 VolatileFileHandle;
1545 	__le64 SourceFileOffset;
1546 	__le64 TargetFileOffset;
1547 	__le64 ByteCount;  /* Bytes to be copied */
1548 	__le32 Flags;
1549 	__le32 Reserved;
1550 } __packed;
1551 
1552 
1553 /* See MS-FSCC 2.3.20 */
1554 struct fsctl_get_integrity_information_rsp {
1555 	__le16	ChecksumAlgorithm;
1556 	__le16	Reserved;
1557 	__le32	Flags;
1558 	__le32	ChecksumChunkSizeInBytes;
1559 	__le32	ClusterSizeInBytes;
1560 } __packed;
1561 
1562 /* See MS-FSCC 2.3.55 */
1563 struct fsctl_query_file_regions_req {
1564 	__le64	FileOffset;
1565 	__le64	Length;
1566 	__le32	DesiredUsage;
1567 	__le32	Reserved;
1568 } __packed;
1569 
1570 /* DesiredUsage flags see MS-FSCC 2.3.56.1 */
1571 #define FILE_USAGE_INVALID_RANGE	0x00000000
1572 #define FILE_USAGE_VALID_CACHED_DATA	0x00000001
1573 #define FILE_USAGE_NONCACHED_DATA	0x00000002
1574 
1575 struct file_region_info {
1576 	__le64	FileOffset;
1577 	__le64	Length;
1578 	__le32	DesiredUsage;
1579 	__le32	Reserved;
1580 } __packed;
1581 
1582 /* See MS-FSCC 2.3.56 */
1583 struct fsctl_query_file_region_rsp {
1584 	__le32 Flags;
1585 	__le32 TotalRegionEntryCount;
1586 	__le32 RegionEntryCount;
1587 	__u32  Reserved;
1588 	struct  file_region_info Regions[];
1589 } __packed;
1590 
1591 /* See MS-FSCC 2.3.58 */
1592 struct fsctl_query_on_disk_vol_info_rsp {
1593 	__le64	DirectoryCount;
1594 	__le64	FileCount;
1595 	__le16	FsFormatMajVersion;
1596 	__le16	FsFormatMinVersion;
1597 	__u8	FsFormatName[24];
1598 	__le64	FormatTime;
1599 	__le64	LastUpdateTime;
1600 	__u8	CopyrightInfo[68];
1601 	__u8	AbstractInfo[68];
1602 	__u8	FormatImplInfo[68];
1603 	__u8	LastModifyImplInfo[68];
1604 } __packed;
1605 
1606 /* See MS-FSCC 2.3.73 */
1607 struct fsctl_set_integrity_information_req {
1608 	__le16	ChecksumAlgorithm;
1609 	__le16	Reserved;
1610 	__le32	Flags;
1611 } __packed;
1612 
1613 /* See MS-FSCC 2.3.75 */
1614 struct fsctl_set_integrity_info_ex_req {
1615 	__u8	EnableIntegrity;
1616 	__u8	KeepState;
1617 	__u16	Reserved;
1618 	__le32	Flags;
1619 	__u8	Version;
1620 	__u8	Reserved2[7];
1621 } __packed;
1622 
1623 /* Integrity ChecksumAlgorithm choices for above */
1624 #define	CHECKSUM_TYPE_NONE	0x0000
1625 #define	CHECKSUM_TYPE_CRC64	0x0002
1626 #define	CHECKSUM_TYPE_UNCHANGED	0xFFFF	/* set only */
1627 
1628 /* Integrity flags for above */
1629 #define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF	0x00000001
1630 
1631 /* Reparse structures - see MS-FSCC 2.1.2 */
1632 
1633 /* struct fsctl_reparse_info_req is empty, only response structs (see below) */
1634 struct reparse_data_buffer {
1635 	__le32	ReparseTag;
1636 	__le16	ReparseDataLength;
1637 	__u16	Reserved;
1638 	__u8	DataBuffer[]; /* Variable Length */
1639 } __packed;
1640 
1641 struct reparse_guid_data_buffer {
1642 	__le32	ReparseTag;
1643 	__le16	ReparseDataLength;
1644 	__u16	Reserved;
1645 	__u8	ReparseGuid[16];
1646 	__u8	DataBuffer[]; /* Variable Length */
1647 } __packed;
1648 
1649 struct reparse_mount_point_data_buffer {
1650 	__le32	ReparseTag;
1651 	__le16	ReparseDataLength;
1652 	__u16	Reserved;
1653 	__le16	SubstituteNameOffset;
1654 	__le16	SubstituteNameLength;
1655 	__le16	PrintNameOffset;
1656 	__le16	PrintNameLength;
1657 	__u8	PathBuffer[]; /* Variable Length */
1658 } __packed;
1659 
1660 #define SYMLINK_FLAG_RELATIVE 0x00000001
1661 
1662 struct reparse_symlink_data_buffer {
1663 	__le32	ReparseTag;
1664 	__le16	ReparseDataLength;
1665 	__u16	Reserved;
1666 	__le16	SubstituteNameOffset;
1667 	__le16	SubstituteNameLength;
1668 	__le16	PrintNameOffset;
1669 	__le16	PrintNameLength;
1670 	__le32	Flags;
1671 	__u8	PathBuffer[]; /* Variable Length */
1672 } __packed;
1673 
1674 /* For IO_REPARSE_TAG_NFS - see MS-FSCC 2.1.2.6 */
1675 #define NFS_SPECFILE_LNK	0x00000000014B4E4C
1676 #define NFS_SPECFILE_CHR	0x0000000000524843
1677 #define NFS_SPECFILE_BLK	0x00000000004B4C42
1678 #define NFS_SPECFILE_FIFO	0x000000004F464946
1679 #define NFS_SPECFILE_SOCK	0x000000004B434F53
1680 struct reparse_nfs_data_buffer {
1681 	__le32	ReparseTag;
1682 	__le16	ReparseDataLength;
1683 	__u16	Reserved;
1684 	__le64	InodeType; /* NFS_SPECFILE_* */
1685 	__u8	DataBuffer[];
1686 } __packed;
1687 
1688 /* For IO_REPARSE_TAG_LX_SYMLINK - see MS-FSCC 2.1.2.7 */
1689 struct reparse_wsl_symlink_data_buffer {
1690 	__le32	ReparseTag;
1691 	__le16	ReparseDataLength;
1692 	__u16	Reserved;
1693 	__le32	Version; /* Always 2 */
1694 	__u8	Target[]; /* Variable Length UTF-8 string without nul-term */
1695 } __packed;
1696 
1697 struct validate_negotiate_info_req {
1698 	__le32 Capabilities;
1699 	__u8   Guid[SMB2_CLIENT_GUID_SIZE];
1700 	__le16 SecurityMode;
1701 	__le16 DialectCount;
1702 	__le16 Dialects[4]; /* BB expand this if autonegotiate > 4 dialects */
1703 } __packed;
1704 
1705 struct validate_negotiate_info_rsp {
1706 	__le32 Capabilities;
1707 	__u8   Guid[SMB2_CLIENT_GUID_SIZE];
1708 	__le16 SecurityMode;
1709 	__le16 Dialect; /* Dialect in use for the connection */
1710 } __packed;
1711 
1712 
1713 /* Possible InfoType values */
1714 #define SMB2_O_INFO_FILE	0x01
1715 #define SMB2_O_INFO_FILESYSTEM	0x02
1716 #define SMB2_O_INFO_SECURITY	0x03
1717 #define SMB2_O_INFO_QUOTA	0x04
1718 
1719 /* SMB2 Query Info see MS-SMB2 (2.2.37) or MS-DTYP */
1720 
1721 /* List of QUERY INFO levels (those also valid for QUERY_DIR are noted below */
1722 #define FILE_DIRECTORY_INFORMATION	1	/* also for QUERY_DIR */
1723 #define FILE_FULL_DIRECTORY_INFORMATION 2	/* also for QUERY_DIR */
1724 #define FILE_BOTH_DIRECTORY_INFORMATION 3	/* also for QUERY_DIR */
1725 #define FILE_BASIC_INFORMATION		4
1726 #define FILE_STANDARD_INFORMATION	5
1727 #define FILE_INTERNAL_INFORMATION	6
1728 #define FILE_EA_INFORMATION	        7
1729 #define FILE_ACCESS_INFORMATION		8
1730 #define FILE_NAME_INFORMATION		9
1731 #define FILE_RENAME_INFORMATION		10
1732 #define FILE_LINK_INFORMATION		11
1733 #define FILE_NAMES_INFORMATION		12	/* also for QUERY_DIR */
1734 #define FILE_DISPOSITION_INFORMATION	13
1735 #define FILE_POSITION_INFORMATION	14
1736 #define FILE_FULL_EA_INFORMATION	15
1737 #define FILE_MODE_INFORMATION		16
1738 #define FILE_ALIGNMENT_INFORMATION	17
1739 #define FILE_ALL_INFORMATION		18
1740 #define FILE_ALLOCATION_INFORMATION	19
1741 #define FILE_END_OF_FILE_INFORMATION	20
1742 #define FILE_ALTERNATE_NAME_INFORMATION 21
1743 #define FILE_STREAM_INFORMATION		22
1744 #define FILE_PIPE_INFORMATION		23
1745 #define FILE_PIPE_LOCAL_INFORMATION	24
1746 #define FILE_PIPE_REMOTE_INFORMATION	25
1747 #define FILE_MAILSLOT_QUERY_INFORMATION 26
1748 #define FILE_MAILSLOT_SET_INFORMATION	27
1749 #define FILE_COMPRESSION_INFORMATION	28
1750 #define FILE_OBJECT_ID_INFORMATION	29
1751 /* Number 30 not defined in documents */
1752 #define FILE_MOVE_CLUSTER_INFORMATION	31
1753 #define FILE_QUOTA_INFORMATION		32
1754 #define FILE_REPARSE_POINT_INFORMATION	33
1755 #define FILE_NETWORK_OPEN_INFORMATION	34
1756 #define FILE_ATTRIBUTE_TAG_INFORMATION	35
1757 #define FILE_TRACKING_INFORMATION	36
1758 #define FILEID_BOTH_DIRECTORY_INFORMATION 37	/* also for QUERY_DIR */
1759 #define FILEID_FULL_DIRECTORY_INFORMATION 38	/* also for QUERY_DIR */
1760 #define FILE_VALID_DATA_LENGTH_INFORMATION 39
1761 #define FILE_SHORT_NAME_INFORMATION	40
1762 #define FILE_SFIO_RESERVE_INFORMATION	44
1763 #define FILE_SFIO_VOLUME_INFORMATION	45
1764 #define FILE_HARD_LINK_INFORMATION	46
1765 #define FILE_NORMALIZED_NAME_INFORMATION 48
1766 #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
1767 #define FILE_STANDARD_LINK_INFORMATION	54
1768 #define FILE_ID_INFORMATION		59
1769 #define FILE_ID_EXTD_DIRECTORY_INFORMATION 60	/* also for QUERY_DIR */
1770 /* Used for Query Info and Find File POSIX Info for SMB3.1.1 and SMB1 */
1771 #define SMB_FIND_FILE_POSIX_INFO	0x064
1772 
1773 /* Security info type additionalinfo flags. */
1774 #define OWNER_SECINFO   0x00000001
1775 #define GROUP_SECINFO   0x00000002
1776 #define DACL_SECINFO   0x00000004
1777 #define SACL_SECINFO   0x00000008
1778 #define LABEL_SECINFO   0x00000010
1779 #define ATTRIBUTE_SECINFO   0x00000020
1780 #define SCOPE_SECINFO   0x00000040
1781 #define BACKUP_SECINFO   0x00010000
1782 #define UNPROTECTED_SACL_SECINFO   0x10000000
1783 #define UNPROTECTED_DACL_SECINFO   0x20000000
1784 #define PROTECTED_SACL_SECINFO   0x40000000
1785 #define PROTECTED_DACL_SECINFO   0x80000000
1786 
1787 /* Flags used for FileFullEAinfo */
1788 #define SL_RESTART_SCAN		0x00000001
1789 #define SL_RETURN_SINGLE_ENTRY	0x00000002
1790 #define SL_INDEX_SPECIFIED	0x00000004
1791 
1792 struct smb2_query_info_req {
1793 	struct smb2_hdr hdr;
1794 	__le16 StructureSize; /* Must be 41 */
1795 	__u8   InfoType;
1796 	__u8   FileInfoClass;
1797 	__le32 OutputBufferLength;
1798 	__le16 InputBufferOffset;
1799 	__u16  Reserved;
1800 	__le32 InputBufferLength;
1801 	__le32 AdditionalInformation;
1802 	__le32 Flags;
1803 	__u64  PersistentFileId;
1804 	__u64  VolatileFileId;
1805 	__u8   Buffer[];
1806 } __packed;
1807 
1808 struct smb2_query_info_rsp {
1809 	struct smb2_hdr hdr;
1810 	__le16 StructureSize; /* Must be 9 */
1811 	__le16 OutputBufferOffset;
1812 	__le32 OutputBufferLength;
1813 	__u8   Buffer[];
1814 } __packed;
1815 
1816 /*
1817  *	PDU query infolevel structure definitions
1818  */
1819 
1820 /* See MS-FSCC 2.3.52 */
1821 struct file_allocated_range_buffer {
1822 	__le64	file_offset;
1823 	__le64	length;
1824 } __packed;
1825 
1826 struct smb2_file_internal_info {
1827 	__le64 IndexNumber;
1828 } __packed; /* level 6 Query */
1829 
1830 struct smb2_file_rename_info { /* encoding of request for level 10 */
1831 	/* New members MUST be added within the struct_group() macro below. */
1832 	__struct_group(smb2_file_rename_info_hdr, __hdr, __packed,
1833 		__u8   ReplaceIfExists; /* 1 = replace existing target with new */
1834 					/* 0 = fail if target already exists */
1835 		__u8   Reserved[7];
1836 		__u64  RootDirectory;  /* MBZ for network operations (why says spec?) */
1837 		__le32 FileNameLength;
1838 	);
1839 	char   FileName[];     /* New name to be assigned */
1840 	/* padding - overall struct size must be >= 24 so filename + pad >= 6 */
1841 } __packed; /* level 10 Set */
1842 static_assert(offsetof(struct smb2_file_rename_info, FileName) == sizeof(struct smb2_file_rename_info_hdr),
1843 	      "struct member likely outside of __struct_group()");
1844 
1845 struct smb2_file_link_info { /* encoding of request for level 11 */
1846 	/* New members MUST be added within the struct_group() macro below. */
1847 	__struct_group(smb2_file_link_info_hdr, __hdr, __packed,
1848 		__u8   ReplaceIfExists; /* 1 = replace existing link with new */
1849 					/* 0 = fail if link already exists */
1850 		__u8   Reserved[7];
1851 		__u64  RootDirectory;  /* MBZ for network operations (why says spec?) */
1852 		__le32 FileNameLength;
1853 	);
1854 	char   FileName[];     /* Name to be assigned to new link */
1855 } __packed; /* level 11 Set */
1856 static_assert(offsetof(struct smb2_file_link_info, FileName) == sizeof(struct smb2_file_link_info_hdr),
1857 	      "struct member likely outside of __struct_group()");
1858 
1859 /*
1860  * This level 18, although with struct with same name is different from cifs
1861  * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
1862  * CurrentByteOffset.
1863  */
1864 struct smb2_file_all_info { /* data block encoding of response to level 18 */
1865 	__le64 CreationTime;	/* Beginning of FILE_BASIC_INFO equivalent */
1866 	__le64 LastAccessTime;
1867 	__le64 LastWriteTime;
1868 	__le64 ChangeTime;
1869 	__le32 Attributes;
1870 	__u32  Pad1;		/* End of FILE_BASIC_INFO_INFO equivalent */
1871 	__le64 AllocationSize;	/* Beginning of FILE_STANDARD_INFO equivalent */
1872 	__le64 EndOfFile;	/* size ie offset to first free byte in file */
1873 	__le32 NumberOfLinks;	/* hard links */
1874 	__u8   DeletePending;
1875 	__u8   Directory;
1876 	__u16  Pad2;		/* End of FILE_STANDARD_INFO equivalent */
1877 	__le64 IndexNumber;
1878 	__le32 EASize;
1879 	__le32 AccessFlags;
1880 	__le64 CurrentByteOffset;
1881 	__le32 Mode;
1882 	__le32 AlignmentRequirement;
1883 	__le32 FileNameLength;
1884 	union {
1885 		char __pad;	/* Legacy structure padding */
1886 		DECLARE_FLEX_ARRAY(char, FileName);
1887 	};
1888 } __packed; /* level 18 Query */
1889 
1890 struct smb2_file_eof_info { /* encoding of request for level 10 */
1891 	__le64 EndOfFile; /* new end of file value */
1892 } __packed; /* level 20 Set */
1893 
1894 /* Level 100 query info */
1895 struct smb311_posix_qinfo {
1896 	__le64 CreationTime;
1897 	__le64 LastAccessTime;
1898 	__le64 LastWriteTime;
1899 	__le64 ChangeTime;
1900 	__le64 EndOfFile;
1901 	__le64 AllocationSize;
1902 	__le32 DosAttributes;
1903 	__le64 Inode;
1904 	__le32 DeviceId;
1905 	__le32 Zero;
1906 	/* beginning of POSIX Create Context Response */
1907 	__le32 HardLinks;
1908 	__le32 ReparseTag;
1909 	__le32 Mode;
1910 	u8     Sids[];
1911 	/*
1912 	 * var sized owner SID
1913 	 * var sized group SID
1914 	 * le32 filenamelength
1915 	 * u8  filename[]
1916 	 */
1917 } __packed;
1918 
1919 /* File System Information Classes */
1920 #define FS_VOLUME_INFORMATION		1 /* Query */
1921 #define FS_LABEL_INFORMATION		2 /* Set */
1922 #define FS_SIZE_INFORMATION		3 /* Query */
1923 #define FS_DEVICE_INFORMATION		4 /* Query */
1924 #define FS_ATTRIBUTE_INFORMATION	5 /* Query */
1925 #define FS_CONTROL_INFORMATION		6 /* Query, Set */
1926 #define FS_FULL_SIZE_INFORMATION	7 /* Query */
1927 #define FS_OBJECT_ID_INFORMATION	8 /* Query, Set */
1928 #define FS_DRIVER_PATH_INFORMATION	9 /* Query */
1929 #define FS_SECTOR_SIZE_INFORMATION	11 /* SMB3 or later. Query */
1930 #define FS_POSIX_INFORMATION		100 /* SMB3.1.1 POSIX. Query */
1931 
1932 struct smb2_fs_full_size_info {
1933 	__le64 TotalAllocationUnits;
1934 	__le64 CallerAvailableAllocationUnits;
1935 	__le64 ActualAvailableAllocationUnits;
1936 	__le32 SectorsPerAllocationUnit;
1937 	__le32 BytesPerSector;
1938 } __packed;
1939 
1940 #define SSINFO_FLAGS_ALIGNED_DEVICE		0x00000001
1941 #define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
1942 #define SSINFO_FLAGS_NO_SEEK_PENALTY		0x00000004
1943 #define SSINFO_FLAGS_TRIM_ENABLED		0x00000008
1944 
1945 /* sector size info struct */
1946 struct smb3_fs_ss_info {
1947 	__le32 LogicalBytesPerSector;
1948 	__le32 PhysicalBytesPerSectorForAtomicity;
1949 	__le32 PhysicalBytesPerSectorForPerf;
1950 	__le32 FSEffPhysicalBytesPerSectorForAtomicity;
1951 	__le32 Flags;
1952 	__le32 ByteOffsetForSectorAlignment;
1953 	__le32 ByteOffsetForPartitionAlignment;
1954 } __packed;
1955 
1956 /* File System Control Information */
1957 struct smb2_fs_control_info {
1958 	__le64 FreeSpaceStartFiltering;
1959 	__le64 FreeSpaceThreshold;
1960 	__le64 FreeSpaceStopFiltering;
1961 	__le64 DefaultQuotaThreshold;
1962 	__le64 DefaultQuotaLimit;
1963 	__le32 FileSystemControlFlags;
1964 	__le32 Padding;
1965 } __packed;
1966 
1967 /* volume info struct - see MS-FSCC 2.5.9 */
1968 #define MAX_VOL_LABEL_LEN	32
1969 struct smb3_fs_vol_info {
1970 	__le64	VolumeCreationTime;
1971 	__u32	VolumeSerialNumber;
1972 	__le32	VolumeLabelLength; /* includes trailing null */
1973 	__u8	SupportsObjects; /* True if eg like NTFS, supports objects */
1974 	__u8	Reserved;
1975 	__u8	VolumeLabel[]; /* variable len */
1976 } __packed;
1977 
1978 /* See MS-SMB2 2.2.23 through 2.2.25 */
1979 struct smb2_oplock_break {
1980 	struct smb2_hdr hdr;
1981 	__le16 StructureSize; /* Must be 24 */
1982 	__u8   OplockLevel;
1983 	__u8   Reserved;
1984 	__le32 Reserved2;
1985 	__u64  PersistentFid;
1986 	__u64  VolatileFid;
1987 } __packed;
1988 
1989 #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
1990 
1991 struct smb2_lease_break {
1992 	struct smb2_hdr hdr;
1993 	__le16 StructureSize; /* Must be 44 */
1994 	__le16 Epoch;
1995 	__le32 Flags;
1996 	__u8   LeaseKey[16];
1997 	__le32 CurrentLeaseState;
1998 	__le32 NewLeaseState;
1999 	__le32 BreakReason;
2000 	__le32 AccessMaskHint;
2001 	__le32 ShareMaskHint;
2002 } __packed;
2003 
2004 struct smb2_lease_ack {
2005 	struct smb2_hdr hdr;
2006 	__le16 StructureSize; /* Must be 36 */
2007 	__le16 Reserved;
2008 	__le32 Flags;
2009 	__u8   LeaseKey[16];
2010 	__le32 LeaseState;
2011 	__le64 LeaseDuration;
2012 } __packed;
2013 
2014 /*
2015  * See MS-CIFS 2.2.3.1
2016  *     MS-SMB 2.2.3.1
2017  */
2018 struct smb_hdr {
2019 	__be32 smb_buf_length;	/* BB length is only two (rarely three) bytes,
2020 		with one or two byte "type" preceding it that will be
2021 		zero - we could mask the type byte off */
2022 	__u8 Protocol[4];
2023 	__u8 Command;
2024 	union {
2025 		struct {
2026 			__u8 ErrorClass;
2027 			__u8 Reserved;
2028 			__le16 Error;
2029 		} __packed DosError;
2030 		__le32 CifsError;
2031 	} __packed Status;
2032 	__u8 Flags;
2033 	__le16 Flags2;		/* note: le */
2034 	__le16 PidHigh;
2035 	union {
2036 		struct {
2037 			__le32 SequenceNumber;  /* le */
2038 			__u32 Reserved; /* zero */
2039 		} __packed Sequence;
2040 		__u8 SecuritySignature[8];	/* le */
2041 	} __packed Signature;
2042 	__u8 pad[2];
2043 	__u16 Tid;
2044 	__le16 Pid;
2045 	__u16 Uid;
2046 	__le16 Mid;
2047 	__u8 WordCount;
2048 } __packed;
2049 
2050 #define OP_BREAK_STRUCT_SIZE_20		24
2051 #define OP_BREAK_STRUCT_SIZE_21		36
2052 
2053 /*
2054  * See MS-SMB2 2.2.13.1.1
2055  *     MS-SMB 2.2.1.4.1
2056  * These are the file access permission bits defined in CIFS for the
2057  * NTCreateAndX as well as the level 0x107
2058  * TRANS2_QUERY_PATH_INFORMATION API.  The level 0x107, SMB_QUERY_FILE_ALL_INFO
2059  * responds with the AccessFlags.
2060  * The AccessFlags specifies the access permissions a caller has to the
2061  * file and can have any suitable combination of the following values:
2062  */
2063 #define FILE_READ_DATA        0x00000001  /* Data can be read from the file   */
2064 					  /* or directory child entries can   */
2065 					  /* be listed together with the      */
2066 					  /* associated child attributes      */
2067 					  /* (so the FILE_READ_ATTRIBUTES on  */
2068 					  /* the child entry is not needed)   */
2069 #define FILE_WRITE_DATA       0x00000002  /* Data can be written to the file  */
2070 					  /* or new file can be created in    */
2071 					  /* the directory                    */
2072 #define FILE_APPEND_DATA      0x00000004  /* Data can be appended to the file */
2073 					  /* (for non-local files over SMB it */
2074 					  /* is same as FILE_WRITE_DATA)      */
2075 					  /* or new subdirectory can be       */
2076 					  /* created in the directory         */
2077 #define FILE_READ_EA          0x00000008  /* Extended attributes associated   */
2078 					  /* with the file can be read        */
2079 #define FILE_WRITE_EA         0x00000010  /* Extended attributes associated   */
2080 					  /* with the file can be written     */
2081 #define FILE_EXECUTE          0x00000020  /*Data can be read into memory from */
2082 					  /* the file using system paging I/O */
2083 					  /* for executing the file / script  */
2084 					  /* or right to traverse directory   */
2085 					  /* (but by default all users have   */
2086 					  /* directory bypass traverse        */
2087 					  /* privilege and do not need this   */
2088 					  /* permission on directories at all)*/
2089 #define FILE_DELETE_CHILD     0x00000040  /* Child entry can be deleted from  */
2090 					  /* the directory (so the DELETE on  */
2091 					  /* the child entry is not needed)   */
2092 #define FILE_READ_ATTRIBUTES  0x00000080  /* Attributes associated with the   */
2093 					  /* file or directory can be read    */
2094 #define FILE_WRITE_ATTRIBUTES 0x00000100  /* Attributes associated with the   */
2095 					  /* file or directory can be written */
2096 #define DELETE                0x00010000  /* The file or dir can be deleted   */
2097 #define READ_CONTROL          0x00020000  /* The discretionary access control */
2098 					  /* list and ownership associated    */
2099 					  /* with the file or dir can be read */
2100 #define WRITE_DAC             0x00040000  /* The discretionary access control */
2101 					  /* list associated with the file or */
2102 					  /* directory can be written         */
2103 #define WRITE_OWNER           0x00080000  /* Ownership information associated */
2104 					  /* with the file/dir can be written */
2105 #define SYNCHRONIZE           0x00100000  /* The file handle can waited on to */
2106 					  /* synchronize with the completion  */
2107 					  /* of an input/output request       */
2108 #define SYSTEM_SECURITY       0x01000000  /* The system access control list   */
2109 					  /* associated with the file or      */
2110 					  /* directory can be read or written */
2111 					  /* (cannot be in DACL, can in SACL) */
2112 #define MAXIMUM_ALLOWED       0x02000000  /* Maximal subset of GENERIC_ALL    */
2113 					  /* permissions which can be granted */
2114 					  /* (cannot be in DACL nor SACL)     */
2115 #define GENERIC_ALL           0x10000000  /* Same as: GENERIC_EXECUTE |       */
2116 					  /*          GENERIC_WRITE |         */
2117 					  /*          GENERIC_READ |          */
2118 					  /*          FILE_DELETE_CHILD |     */
2119 					  /*          DELETE |                */
2120 					  /*          WRITE_DAC |             */
2121 					  /*          WRITE_OWNER             */
2122 					  /* So GENERIC_ALL contains all bits */
2123 					  /* mentioned above except these two */
2124 					  /* SYSTEM_SECURITY  MAXIMUM_ALLOWED */
2125 #define GENERIC_EXECUTE       0x20000000  /* Same as: FILE_EXECUTE |          */
2126 					  /*          FILE_READ_ATTRIBUTES |  */
2127 					  /*          READ_CONTROL |          */
2128 					  /*          SYNCHRONIZE             */
2129 #define GENERIC_WRITE         0x40000000  /* Same as: FILE_WRITE_DATA |       */
2130 					  /*          FILE_APPEND_DATA |      */
2131 					  /*          FILE_WRITE_EA |         */
2132 					  /*          FILE_WRITE_ATTRIBUTES | */
2133 					  /*          READ_CONTROL |          */
2134 					  /*          SYNCHRONIZE             */
2135 #define GENERIC_READ          0x80000000  /* Same as: FILE_READ_DATA |        */
2136 					  /*          FILE_READ_EA |          */
2137 					  /*          FILE_READ_ATTRIBUTES |  */
2138 					  /*          READ_CONTROL |          */
2139 					  /*          SYNCHRONIZE             */
2140 
2141 /* Combinations of file access permission bits */
2142 #define FILE_READ_RIGHTS (FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES)
2143 #define FILE_WRITE_RIGHTS (FILE_WRITE_DATA | FILE_APPEND_DATA \
2144 			| FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES)
2145 #define FILE_EXEC_RIGHTS (FILE_EXECUTE)
2146 #define SET_FILE_EXEC_RIGHTS (FILE_READ_EA | FILE_WRITE_EA | FILE_EXECUTE \
2147 				| FILE_READ_ATTRIBUTES \
2148 				| FILE_WRITE_ATTRIBUTES \
2149 				| DELETE | READ_CONTROL | WRITE_DAC \
2150 				| WRITE_OWNER | SYNCHRONIZE)
2151 #define SET_MINIMUM_RIGHTS (FILE_READ_EA | FILE_READ_ATTRIBUTES \
2152 				| READ_CONTROL | SYNCHRONIZE)
2153 
2154 /* See MS-CIFS 2.2.4.52.1 */
2155 typedef struct smb_negotiate_req {
2156 	struct smb_hdr hdr;	/* wct = 0 */
2157 	__le16 ByteCount;
2158 	unsigned char DialectsArray[];
2159 } __packed SMB_NEGOTIATE_REQ;
2160 
2161 #endif				/* _COMMON_SMB2PDU_H */
2162