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