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