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