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