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