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