Merge tag 'kvmarm-fixes-5.11-1' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / fs / cifs / smb2pdu.h
1 /*
2  *   fs/cifs/smb2pdu.h
3  *
4  *   Copyright (c) International Business Machines  Corp., 2009, 2013
5  *                 Etersoft, 2012
6  *   Author(s): Steve French (sfrench@us.ibm.com)
7  *              Pavel Shilovsky (pshilovsky@samba.org) 2012
8  *
9  *   This library is free software; you can redistribute it and/or modify
10  *   it under the terms of the GNU Lesser General Public License as published
11  *   by the Free Software Foundation; either version 2.1 of the License, or
12  *   (at your option) any later version.
13  *
14  *   This library is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
17  *   the GNU Lesser General Public License for more details.
18  *
19  *   You should have received a copy of the GNU Lesser General Public License
20  *   along with this library; if not, write to the Free Software
21  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */
23
24 #ifndef _SMB2PDU_H
25 #define _SMB2PDU_H
26
27 #include <net/sock.h>
28 #include <cifsacl.h>
29
30 /*
31  * Note that, due to trying to use names similar to the protocol specifications,
32  * there are many mixed case field names in the structures below.  Although
33  * this does not match typical Linux kernel style, it is necessary to be
34  * able to match against the protocol specfication.
35  *
36  * SMB2 commands
37  * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses
38  * (ie no useful data other than the SMB error code itself) and are marked such.
39  * Knowing this helps avoid response buffer allocations and copy in some cases.
40  */
41
42 /* List of commands in host endian */
43 #define SMB2_NEGOTIATE_HE       0x0000
44 #define SMB2_SESSION_SETUP_HE   0x0001
45 #define SMB2_LOGOFF_HE          0x0002 /* trivial request/resp */
46 #define SMB2_TREE_CONNECT_HE    0x0003
47 #define SMB2_TREE_DISCONNECT_HE 0x0004 /* trivial req/resp */
48 #define SMB2_CREATE_HE          0x0005
49 #define SMB2_CLOSE_HE           0x0006
50 #define SMB2_FLUSH_HE           0x0007 /* trivial resp */
51 #define SMB2_READ_HE            0x0008
52 #define SMB2_WRITE_HE           0x0009
53 #define SMB2_LOCK_HE            0x000A
54 #define SMB2_IOCTL_HE           0x000B
55 #define SMB2_CANCEL_HE          0x000C
56 #define SMB2_ECHO_HE            0x000D
57 #define SMB2_QUERY_DIRECTORY_HE 0x000E
58 #define SMB2_CHANGE_NOTIFY_HE   0x000F
59 #define SMB2_QUERY_INFO_HE      0x0010
60 #define SMB2_SET_INFO_HE        0x0011
61 #define SMB2_OPLOCK_BREAK_HE    0x0012
62
63 /* The same list in little endian */
64 #define SMB2_NEGOTIATE          cpu_to_le16(SMB2_NEGOTIATE_HE)
65 #define SMB2_SESSION_SETUP      cpu_to_le16(SMB2_SESSION_SETUP_HE)
66 #define SMB2_LOGOFF             cpu_to_le16(SMB2_LOGOFF_HE)
67 #define SMB2_TREE_CONNECT       cpu_to_le16(SMB2_TREE_CONNECT_HE)
68 #define SMB2_TREE_DISCONNECT    cpu_to_le16(SMB2_TREE_DISCONNECT_HE)
69 #define SMB2_CREATE             cpu_to_le16(SMB2_CREATE_HE)
70 #define SMB2_CLOSE              cpu_to_le16(SMB2_CLOSE_HE)
71 #define SMB2_FLUSH              cpu_to_le16(SMB2_FLUSH_HE)
72 #define SMB2_READ               cpu_to_le16(SMB2_READ_HE)
73 #define SMB2_WRITE              cpu_to_le16(SMB2_WRITE_HE)
74 #define SMB2_LOCK               cpu_to_le16(SMB2_LOCK_HE)
75 #define SMB2_IOCTL              cpu_to_le16(SMB2_IOCTL_HE)
76 #define SMB2_CANCEL             cpu_to_le16(SMB2_CANCEL_HE)
77 #define SMB2_ECHO               cpu_to_le16(SMB2_ECHO_HE)
78 #define SMB2_QUERY_DIRECTORY    cpu_to_le16(SMB2_QUERY_DIRECTORY_HE)
79 #define SMB2_CHANGE_NOTIFY      cpu_to_le16(SMB2_CHANGE_NOTIFY_HE)
80 #define SMB2_QUERY_INFO         cpu_to_le16(SMB2_QUERY_INFO_HE)
81 #define SMB2_SET_INFO           cpu_to_le16(SMB2_SET_INFO_HE)
82 #define SMB2_OPLOCK_BREAK       cpu_to_le16(SMB2_OPLOCK_BREAK_HE)
83
84 #define SMB2_INTERNAL_CMD       cpu_to_le16(0xFFFF)
85
86 #define NUMBER_OF_SMB2_COMMANDS 0x0013
87
88 /* 52 transform hdr + 64 hdr + 88 create rsp */
89 #define SMB2_TRANSFORM_HEADER_SIZE 52
90 #define MAX_SMB2_HDR_SIZE 204
91
92 #define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)
93 #define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
94 #define SMB2_COMPRESSION_TRANSFORM_ID cpu_to_le32(0x424d53fc)
95
96 /*
97  * SMB2 Header Definition
98  *
99  * "MBZ" :  Must be Zero
100  * "BB"  :  BugBug, Something to check/review/analyze later
101  * "PDU" :  "Protocol Data Unit" (ie a network "frame")
102  *
103  */
104
105 #define SMB2_HEADER_STRUCTURE_SIZE cpu_to_le16(64)
106
107 struct smb2_sync_hdr {
108         __le32 ProtocolId;      /* 0xFE 'S' 'M' 'B' */
109         __le16 StructureSize;   /* 64 */
110         __le16 CreditCharge;    /* MBZ */
111         __le32 Status;          /* Error from server */
112         __le16 Command;
113         __le16 CreditRequest;  /* CreditResponse */
114         __le32 Flags;
115         __le32 NextCommand;
116         __le64 MessageId;
117         __le32 ProcessId;
118         __u32  TreeId;          /* opaque - so do not make little endian */
119         __u64  SessionId;       /* opaque - so do not make little endian */
120         __u8   Signature[16];
121 } __packed;
122
123 /* The total header size for SMB2 read and write */
124 #define SMB2_READWRITE_PDU_HEADER_SIZE (48 + sizeof(struct smb2_sync_hdr))
125
126 struct smb2_sync_pdu {
127         struct smb2_sync_hdr sync_hdr;
128         __le16 StructureSize2; /* size of wct area (varies, request specific) */
129 } __packed;
130
131 #define SMB3_AES_CCM_NONCE 11
132 #define SMB3_AES_GCM_NONCE 12
133
134 /* Transform flags (for 3.0 dialect this flag indicates CCM */
135 #define TRANSFORM_FLAG_ENCRYPTED        0x0001
136 struct smb2_transform_hdr {
137         __le32 ProtocolId;      /* 0xFD 'S' 'M' 'B' */
138         __u8   Signature[16];
139         __u8   Nonce[16];
140         __le32 OriginalMessageSize;
141         __u16  Reserved1;
142         __le16 Flags; /* EncryptionAlgorithm for 3.0, enc enabled for 3.1.1 */
143         __u64  SessionId;
144 } __packed;
145
146 /* See MS-SMB2 2.2.42 */
147 struct smb2_compression_transform_hdr {
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 } __packed;
967
968
969 #define COPY_CHUNK_RES_KEY_SIZE 24
970 struct resume_key_req {
971         char ResumeKey[COPY_CHUNK_RES_KEY_SIZE];
972         __le32  ContextLength;  /* MBZ */
973         char    Context[];      /* ignored, Windows sets to 4 bytes of zero */
974 } __packed;
975
976 /* this goes in the ioctl buffer when doing a copychunk request */
977 struct copychunk_ioctl {
978         char SourceKey[COPY_CHUNK_RES_KEY_SIZE];
979         __le32 ChunkCount; /* we are only sending 1 */
980         __le32 Reserved;
981         /* array will only be one chunk long for us */
982         __le64 SourceOffset;
983         __le64 TargetOffset;
984         __le32 Length; /* how many bytes to copy */
985         __u32 Reserved2;
986 } __packed;
987
988 /* this goes in the ioctl buffer when doing FSCTL_SET_ZERO_DATA */
989 struct file_zero_data_information {
990         __le64  FileOffset;
991         __le64  BeyondFinalZero;
992 } __packed;
993
994 struct copychunk_ioctl_rsp {
995         __le32 ChunksWritten;
996         __le32 ChunkBytesWritten;
997         __le32 TotalBytesWritten;
998 } __packed;
999
1000 /* See MS-FSCC 2.3.29 and 2.3.30 */
1001 struct get_retrieval_pointer_count_req {
1002         __le64 StartingVcn; /* virtual cluster number (signed) */
1003 } __packed;
1004
1005 struct get_retrieval_pointer_count_rsp {
1006         __le32 ExtentCount;
1007 } __packed;
1008
1009 /*
1010  * See MS-FSCC 2.3.33 and 2.3.34
1011  * request is the same as get_retrieval_point_count_req struct above
1012  */
1013 struct smb3_extents {
1014         __le64 NextVcn;
1015         __le64 Lcn; /* logical cluster number */
1016 } __packed;
1017
1018 struct get_retrieval_pointers_refcount_rsp {
1019         __le32 ExtentCount;
1020         __u32  Reserved;
1021         __le64 StartingVcn;
1022         struct smb3_extents extents[];
1023 } __packed;
1024
1025 struct fsctl_set_integrity_information_req {
1026         __le16  ChecksumAlgorithm;
1027         __le16  Reserved;
1028         __le32  Flags;
1029 } __packed;
1030
1031 struct fsctl_get_integrity_information_rsp {
1032         __le16  ChecksumAlgorithm;
1033         __le16  Reserved;
1034         __le32  Flags;
1035         __le32  ChecksumChunkSizeInBytes;
1036         __le32  ClusterSizeInBytes;
1037 } __packed;
1038
1039 struct file_allocated_range_buffer {
1040         __le64  file_offset;
1041         __le64  length;
1042 } __packed;
1043
1044 /* Integrity ChecksumAlgorithm choices for above */
1045 #define CHECKSUM_TYPE_NONE      0x0000
1046 #define CHECKSUM_TYPE_CRC64     0x0002
1047 #define CHECKSUM_TYPE_UNCHANGED 0xFFFF  /* set only */
1048
1049 /* Integrity flags for above */
1050 #define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF   0x00000001
1051
1052 /* Reparse structures - see MS-FSCC 2.1.2 */
1053
1054 /* struct fsctl_reparse_info_req is empty, only response structs (see below) */
1055
1056 struct reparse_data_buffer {
1057         __le32  ReparseTag;
1058         __le16  ReparseDataLength;
1059         __u16   Reserved;
1060         __u8    DataBuffer[]; /* Variable Length */
1061 } __packed;
1062
1063 struct reparse_guid_data_buffer {
1064         __le32  ReparseTag;
1065         __le16  ReparseDataLength;
1066         __u16   Reserved;
1067         __u8    ReparseGuid[16];
1068         __u8    DataBuffer[]; /* Variable Length */
1069 } __packed;
1070
1071 struct reparse_mount_point_data_buffer {
1072         __le32  ReparseTag;
1073         __le16  ReparseDataLength;
1074         __u16   Reserved;
1075         __le16  SubstituteNameOffset;
1076         __le16  SubstituteNameLength;
1077         __le16  PrintNameOffset;
1078         __le16  PrintNameLength;
1079         __u8    PathBuffer[]; /* Variable Length */
1080 } __packed;
1081
1082 #define SYMLINK_FLAG_RELATIVE 0x00000001
1083
1084 struct reparse_symlink_data_buffer {
1085         __le32  ReparseTag;
1086         __le16  ReparseDataLength;
1087         __u16   Reserved;
1088         __le16  SubstituteNameOffset;
1089         __le16  SubstituteNameLength;
1090         __le16  PrintNameOffset;
1091         __le16  PrintNameLength;
1092         __le32  Flags;
1093         __u8    PathBuffer[]; /* Variable Length */
1094 } __packed;
1095
1096 /* See MS-FSCC 2.1.2.6 and cifspdu.h for struct reparse_posix_data */
1097
1098
1099 /* See MS-DFSC 2.2.2 */
1100 struct fsctl_get_dfs_referral_req {
1101         __le16 MaxReferralLevel;
1102         __u8 RequestFileName[];
1103 } __packed;
1104
1105 /* DFS response is struct get_dfs_refer_rsp */
1106
1107 /* See MS-SMB2 2.2.31.3 */
1108 struct network_resiliency_req {
1109         __le32 Timeout;
1110         __le32 Reserved;
1111 } __packed;
1112 /* There is no buffer for the response ie no struct network_resiliency_rsp */
1113
1114
1115 struct validate_negotiate_info_req {
1116         __le32 Capabilities;
1117         __u8   Guid[SMB2_CLIENT_GUID_SIZE];
1118         __le16 SecurityMode;
1119         __le16 DialectCount;
1120         __le16 Dialects[4]; /* BB expand this if autonegotiate > 4 dialects */
1121 } __packed;
1122
1123 struct validate_negotiate_info_rsp {
1124         __le32 Capabilities;
1125         __u8   Guid[SMB2_CLIENT_GUID_SIZE];
1126         __le16 SecurityMode;
1127         __le16 Dialect; /* Dialect in use for the connection */
1128 } __packed;
1129
1130 #define RSS_CAPABLE     cpu_to_le32(0x00000001)
1131 #define RDMA_CAPABLE    cpu_to_le32(0x00000002)
1132
1133 #define INTERNETWORK    cpu_to_le16(0x0002)
1134 #define INTERNETWORKV6  cpu_to_le16(0x0017)
1135
1136 struct network_interface_info_ioctl_rsp {
1137         __le32 Next; /* next interface. zero if this is last one */
1138         __le32 IfIndex;
1139         __le32 Capability; /* RSS or RDMA Capable */
1140         __le32 Reserved;
1141         __le64 LinkSpeed;
1142         __le16 Family;
1143         __u8 Buffer[126];
1144 } __packed;
1145
1146 struct iface_info_ipv4 {
1147         __be16 Port;
1148         __be32 IPv4Address;
1149         __be64 Reserved;
1150 } __packed;
1151
1152 struct iface_info_ipv6 {
1153         __be16 Port;
1154         __be32 FlowInfo;
1155         __u8   IPv6Address[16];
1156         __be32 ScopeId;
1157 } __packed;
1158
1159 #define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */
1160
1161 struct compress_ioctl {
1162         __le16 CompressionState; /* See cifspdu.h for possible flag values */
1163 } __packed;
1164
1165 struct duplicate_extents_to_file {
1166         __u64 PersistentFileHandle; /* source file handle, opaque endianness */
1167         __u64 VolatileFileHandle;
1168         __le64 SourceFileOffset;
1169         __le64 TargetFileOffset;
1170         __le64 ByteCount;  /* Bytes to be copied */
1171 } __packed;
1172
1173 /*
1174  * Maximum number of iovs we need for an ioctl request.
1175  * [0] : struct smb2_ioctl_req
1176  * [1] : in_data
1177  */
1178 #define SMB2_IOCTL_IOV_SIZE 2
1179
1180 struct smb2_ioctl_req {
1181         struct smb2_sync_hdr sync_hdr;
1182         __le16 StructureSize;   /* Must be 57 */
1183         __u16 Reserved;
1184         __le32 CtlCode;
1185         __u64  PersistentFileId; /* opaque endianness */
1186         __u64  VolatileFileId; /* opaque endianness */
1187         __le32 InputOffset;
1188         __le32 InputCount;
1189         __le32 MaxInputResponse;
1190         __le32 OutputOffset;
1191         __le32 OutputCount;
1192         __le32 MaxOutputResponse;
1193         __le32 Flags;
1194         __u32  Reserved2;
1195         __u8   Buffer[];
1196 } __packed;
1197
1198 struct smb2_ioctl_rsp {
1199         struct smb2_sync_hdr sync_hdr;
1200         __le16 StructureSize;   /* Must be 57 */
1201         __u16 Reserved;
1202         __le32 CtlCode;
1203         __u64  PersistentFileId; /* opaque endianness */
1204         __u64  VolatileFileId; /* opaque endianness */
1205         __le32 InputOffset;
1206         __le32 InputCount;
1207         __le32 OutputOffset;
1208         __le32 OutputCount;
1209         __le32 Flags;
1210         __u32  Reserved2;
1211         /* char * buffer[] */
1212 } __packed;
1213
1214 /* Currently defined values for close flags */
1215 #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB        cpu_to_le16(0x0001)
1216 struct smb2_close_req {
1217         struct smb2_sync_hdr sync_hdr;
1218         __le16 StructureSize;   /* Must be 24 */
1219         __le16 Flags;
1220         __le32 Reserved;
1221         __u64  PersistentFileId; /* opaque endianness */
1222         __u64  VolatileFileId; /* opaque endianness */
1223 } __packed;
1224
1225 /*
1226  * Maximum size of a SMB2_CLOSE response is 64 (smb2 header) + 60 (data)
1227  */
1228 #define MAX_SMB2_CLOSE_RESPONSE_SIZE 124
1229
1230 struct smb2_close_rsp {
1231         struct smb2_sync_hdr sync_hdr;
1232         __le16 StructureSize; /* 60 */
1233         __le16 Flags;
1234         __le32 Reserved;
1235         __le64 CreationTime;
1236         __le64 LastAccessTime;
1237         __le64 LastWriteTime;
1238         __le64 ChangeTime;
1239         __le64 AllocationSize;  /* Beginning of FILE_STANDARD_INFO equivalent */
1240         __le64 EndOfFile;
1241         __le32 Attributes;
1242 } __packed;
1243
1244 struct smb2_flush_req {
1245         struct smb2_sync_hdr sync_hdr;
1246         __le16 StructureSize;   /* Must be 24 */
1247         __le16 Reserved1;
1248         __le32 Reserved2;
1249         __u64  PersistentFileId; /* opaque endianness */
1250         __u64  VolatileFileId; /* opaque endianness */
1251 } __packed;
1252
1253 struct smb2_flush_rsp {
1254         struct smb2_sync_hdr sync_hdr;
1255         __le16 StructureSize;
1256         __le16 Reserved;
1257 } __packed;
1258
1259 /* For read request Flags field below, following flag is defined for SMB3.02 */
1260 #define SMB2_READFLAG_READ_UNBUFFERED   0x01
1261 #define SMB2_READFLAG_REQUEST_COMPRESSED 0x02 /* See MS-SMB2 2.2.19 */
1262
1263 /* Channel field for read and write: exactly one of following flags can be set*/
1264 #define SMB2_CHANNEL_NONE       cpu_to_le32(0x00000000)
1265 #define SMB2_CHANNEL_RDMA_V1    cpu_to_le32(0x00000001) /* SMB3 or later */
1266 #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002) /* >= SMB3.02 */
1267 #define SMB2_CHANNEL_RDMA_TRANSFORM cpu_to_le32(0x00000003) /* >= SMB3.02, only used on write */
1268
1269 /* SMB2 read request without RFC1001 length at the beginning */
1270 struct smb2_read_plain_req {
1271         struct smb2_sync_hdr sync_hdr;
1272         __le16 StructureSize; /* Must be 49 */
1273         __u8   Padding; /* offset from start of SMB2 header to place read */
1274         __u8   Flags; /* MBZ unless SMB3.02 or later */
1275         __le32 Length;
1276         __le64 Offset;
1277         __u64  PersistentFileId; /* opaque endianness */
1278         __u64  VolatileFileId; /* opaque endianness */
1279         __le32 MinimumCount;
1280         __le32 Channel; /* MBZ except for SMB3 or later */
1281         __le32 RemainingBytes;
1282         __le16 ReadChannelInfoOffset;
1283         __le16 ReadChannelInfoLength;
1284         __u8   Buffer[1];
1285 } __packed;
1286
1287 /* Read flags */
1288 #define SMB2_READFLAG_RESPONSE_NONE     0x00000000
1289 #define SMB2_READFLAG_RESPONSE_RDMA_TRANSFORM   0x00000001
1290
1291 struct smb2_read_rsp {
1292         struct smb2_sync_hdr sync_hdr;
1293         __le16 StructureSize; /* Must be 17 */
1294         __u8   DataOffset;
1295         __u8   Reserved;
1296         __le32 DataLength;
1297         __le32 DataRemaining;
1298         __u32  Flags;
1299         __u8   Buffer[1];
1300 } __packed;
1301
1302 /* For write request Flags field below the following flags are defined: */
1303 #define SMB2_WRITEFLAG_WRITE_THROUGH    0x00000001      /* SMB2.1 or later */
1304 #define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002      /* SMB3.02 or later */
1305
1306 struct smb2_write_req {
1307         struct smb2_sync_hdr sync_hdr;
1308         __le16 StructureSize; /* Must be 49 */
1309         __le16 DataOffset; /* offset from start of SMB2 header to write data */
1310         __le32 Length;
1311         __le64 Offset;
1312         __u64  PersistentFileId; /* opaque endianness */
1313         __u64  VolatileFileId; /* opaque endianness */
1314         __le32 Channel; /* MBZ unless SMB3.02 or later */
1315         __le32 RemainingBytes;
1316         __le16 WriteChannelInfoOffset;
1317         __le16 WriteChannelInfoLength;
1318         __le32 Flags;
1319         __u8   Buffer[1];
1320 } __packed;
1321
1322 struct smb2_write_rsp {
1323         struct smb2_sync_hdr sync_hdr;
1324         __le16 StructureSize; /* Must be 17 */
1325         __u8   DataOffset;
1326         __u8   Reserved;
1327         __le32 DataLength;
1328         __le32 DataRemaining;
1329         __u32  Reserved2;
1330         __u8   Buffer[1];
1331 } __packed;
1332
1333 /* notify flags */
1334 #define SMB2_WATCH_TREE                 0x0001
1335
1336 /* notify completion filter flags. See MS-FSCC 2.6 and MS-SMB2 2.2.35 */
1337 #define FILE_NOTIFY_CHANGE_FILE_NAME            0x00000001
1338 #define FILE_NOTIFY_CHANGE_DIR_NAME             0x00000002
1339 #define FILE_NOTIFY_CHANGE_ATTRIBUTES           0x00000004
1340 #define FILE_NOTIFY_CHANGE_SIZE                 0x00000008
1341 #define FILE_NOTIFY_CHANGE_LAST_WRITE           0x00000010
1342 #define FILE_NOTIFY_CHANGE_LAST_ACCESS          0x00000020
1343 #define FILE_NOTIFY_CHANGE_CREATION             0x00000040
1344 #define FILE_NOTIFY_CHANGE_EA                   0x00000080
1345 #define FILE_NOTIFY_CHANGE_SECURITY             0x00000100
1346 #define FILE_NOTIFY_CHANGE_STREAM_NAME          0x00000200
1347 #define FILE_NOTIFY_CHANGE_STREAM_SIZE          0x00000400
1348 #define FILE_NOTIFY_CHANGE_STREAM_WRITE         0x00000800
1349
1350 struct smb2_change_notify_req {
1351         struct smb2_sync_hdr sync_hdr;
1352         __le16  StructureSize;
1353         __le16  Flags;
1354         __le32  OutputBufferLength;
1355         __u64   PersistentFileId; /* opaque endianness */
1356         __u64   VolatileFileId; /* opaque endianness */
1357         __le32  CompletionFilter;
1358         __u32   Reserved;
1359 } __packed;
1360
1361 struct smb2_change_notify_rsp {
1362         struct smb2_sync_hdr sync_hdr;
1363         __le16  StructureSize;  /* Must be 9 */
1364         __le16  OutputBufferOffset;
1365         __le32  OutputBufferLength;
1366         __u8    Buffer[1]; /* array of file notify structs */
1367 } __packed;
1368
1369 #define SMB2_LOCKFLAG_SHARED_LOCK       0x0001
1370 #define SMB2_LOCKFLAG_EXCLUSIVE_LOCK    0x0002
1371 #define SMB2_LOCKFLAG_UNLOCK            0x0004
1372 #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY  0x0010
1373
1374 struct smb2_lock_element {
1375         __le64 Offset;
1376         __le64 Length;
1377         __le32 Flags;
1378         __le32 Reserved;
1379 } __packed;
1380
1381 struct smb2_lock_req {
1382         struct smb2_sync_hdr sync_hdr;
1383         __le16 StructureSize; /* Must be 48 */
1384         __le16 LockCount;
1385         __le32 Reserved;
1386         __u64  PersistentFileId; /* opaque endianness */
1387         __u64  VolatileFileId; /* opaque endianness */
1388         /* Followed by at least one */
1389         struct smb2_lock_element locks[1];
1390 } __packed;
1391
1392 struct smb2_lock_rsp {
1393         struct smb2_sync_hdr sync_hdr;
1394         __le16 StructureSize; /* Must be 4 */
1395         __le16 Reserved;
1396 } __packed;
1397
1398 struct smb2_echo_req {
1399         struct smb2_sync_hdr sync_hdr;
1400         __le16 StructureSize;   /* Must be 4 */
1401         __u16  Reserved;
1402 } __packed;
1403
1404 struct smb2_echo_rsp {
1405         struct smb2_sync_hdr sync_hdr;
1406         __le16 StructureSize;   /* Must be 4 */
1407         __u16  Reserved;
1408 } __packed;
1409
1410 /* search (query_directory) Flags field */
1411 #define SMB2_RESTART_SCANS              0x01
1412 #define SMB2_RETURN_SINGLE_ENTRY        0x02
1413 #define SMB2_INDEX_SPECIFIED            0x04
1414 #define SMB2_REOPEN                     0x10
1415
1416 #define SMB2_QUERY_DIRECTORY_IOV_SIZE 2
1417
1418 struct smb2_query_directory_req {
1419         struct smb2_sync_hdr sync_hdr;
1420         __le16 StructureSize; /* Must be 33 */
1421         __u8   FileInformationClass;
1422         __u8   Flags;
1423         __le32 FileIndex;
1424         __u64  PersistentFileId; /* opaque endianness */
1425         __u64  VolatileFileId; /* opaque endianness */
1426         __le16 FileNameOffset;
1427         __le16 FileNameLength;
1428         __le32 OutputBufferLength;
1429         __u8   Buffer[1];
1430 } __packed;
1431
1432 struct smb2_query_directory_rsp {
1433         struct smb2_sync_hdr sync_hdr;
1434         __le16 StructureSize; /* Must be 9 */
1435         __le16 OutputBufferOffset;
1436         __le32 OutputBufferLength;
1437         __u8   Buffer[1];
1438 } __packed;
1439
1440 /* Possible InfoType values */
1441 #define SMB2_O_INFO_FILE        0x01
1442 #define SMB2_O_INFO_FILESYSTEM  0x02
1443 #define SMB2_O_INFO_SECURITY    0x03
1444 #define SMB2_O_INFO_QUOTA       0x04
1445
1446 /* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */
1447 #define OWNER_SECINFO   0x00000001
1448 #define GROUP_SECINFO   0x00000002
1449 #define DACL_SECINFO   0x00000004
1450 #define SACL_SECINFO   0x00000008
1451 #define LABEL_SECINFO   0x00000010
1452 #define ATTRIBUTE_SECINFO   0x00000020
1453 #define SCOPE_SECINFO   0x00000040
1454 #define BACKUP_SECINFO   0x00010000
1455 #define UNPROTECTED_SACL_SECINFO   0x10000000
1456 #define UNPROTECTED_DACL_SECINFO   0x20000000
1457 #define PROTECTED_SACL_SECINFO   0x40000000
1458 #define PROTECTED_DACL_SECINFO   0x80000000
1459
1460 /* Flags used for FileFullEAinfo */
1461 #define SL_RESTART_SCAN         0x00000001
1462 #define SL_RETURN_SINGLE_ENTRY  0x00000002
1463 #define SL_INDEX_SPECIFIED      0x00000004
1464
1465 struct smb2_query_info_req {
1466         struct smb2_sync_hdr sync_hdr;
1467         __le16 StructureSize; /* Must be 41 */
1468         __u8   InfoType;
1469         __u8   FileInfoClass;
1470         __le32 OutputBufferLength;
1471         __le16 InputBufferOffset;
1472         __u16  Reserved;
1473         __le32 InputBufferLength;
1474         __le32 AdditionalInformation;
1475         __le32 Flags;
1476         __u64  PersistentFileId; /* opaque endianness */
1477         __u64  VolatileFileId; /* opaque endianness */
1478         __u8   Buffer[1];
1479 } __packed;
1480
1481 struct smb2_query_info_rsp {
1482         struct smb2_sync_hdr sync_hdr;
1483         __le16 StructureSize; /* Must be 9 */
1484         __le16 OutputBufferOffset;
1485         __le32 OutputBufferLength;
1486         __u8   Buffer[1];
1487 } __packed;
1488
1489 /*
1490  * Maximum number of iovs we need for a set-info request.
1491  * The largest one is rename/hardlink
1492  * [0] : struct smb2_set_info_req + smb2_file_[rename|link]_info
1493  * [1] : path
1494  * [2] : compound padding
1495  */
1496 #define SMB2_SET_INFO_IOV_SIZE 3
1497
1498 struct smb2_set_info_req {
1499         struct smb2_sync_hdr sync_hdr;
1500         __le16 StructureSize; /* Must be 33 */
1501         __u8   InfoType;
1502         __u8   FileInfoClass;
1503         __le32 BufferLength;
1504         __le16 BufferOffset;
1505         __u16  Reserved;
1506         __le32 AdditionalInformation;
1507         __u64  PersistentFileId; /* opaque endianness */
1508         __u64  VolatileFileId; /* opaque endianness */
1509         __u8   Buffer[1];
1510 } __packed;
1511
1512 struct smb2_set_info_rsp {
1513         struct smb2_sync_hdr sync_hdr;
1514         __le16 StructureSize; /* Must be 2 */
1515 } __packed;
1516
1517 struct smb2_oplock_break {
1518         struct smb2_sync_hdr sync_hdr;
1519         __le16 StructureSize; /* Must be 24 */
1520         __u8   OplockLevel;
1521         __u8   Reserved;
1522         __le32 Reserved2;
1523         __u64  PersistentFid;
1524         __u64  VolatileFid;
1525 } __packed;
1526
1527 #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
1528
1529 struct smb2_lease_break {
1530         struct smb2_sync_hdr sync_hdr;
1531         __le16 StructureSize; /* Must be 44 */
1532         __le16 Epoch;
1533         __le32 Flags;
1534         __u8   LeaseKey[16];
1535         __le32 CurrentLeaseState;
1536         __le32 NewLeaseState;
1537         __le32 BreakReason;
1538         __le32 AccessMaskHint;
1539         __le32 ShareMaskHint;
1540 } __packed;
1541
1542 struct smb2_lease_ack {
1543         struct smb2_sync_hdr sync_hdr;
1544         __le16 StructureSize; /* Must be 36 */
1545         __le16 Reserved;
1546         __le32 Flags;
1547         __u8   LeaseKey[16];
1548         __le32 LeaseState;
1549         __le64 LeaseDuration;
1550 } __packed;
1551
1552 /*
1553  *      PDU infolevel structure definitions
1554  *      BB consider moving to a different header
1555  */
1556
1557 /* File System Information Classes */
1558 #define FS_VOLUME_INFORMATION           1 /* Query */
1559 #define FS_LABEL_INFORMATION            2 /* Local only */
1560 #define FS_SIZE_INFORMATION             3 /* Query */
1561 #define FS_DEVICE_INFORMATION           4 /* Query */
1562 #define FS_ATTRIBUTE_INFORMATION        5 /* Query */
1563 #define FS_CONTROL_INFORMATION          6 /* Query, Set */
1564 #define FS_FULL_SIZE_INFORMATION        7 /* Query */
1565 #define FS_OBJECT_ID_INFORMATION        8 /* Query, Set */
1566 #define FS_DRIVER_PATH_INFORMATION      9 /* Local only */
1567 #define FS_VOLUME_FLAGS_INFORMATION     10 /* Local only */
1568 #define FS_SECTOR_SIZE_INFORMATION      11 /* SMB3 or later. Query */
1569 #define FS_POSIX_INFORMATION            100 /* SMB3.1.1 POSIX. Query */
1570
1571 struct smb2_fs_full_size_info {
1572         __le64 TotalAllocationUnits;
1573         __le64 CallerAvailableAllocationUnits;
1574         __le64 ActualAvailableAllocationUnits;
1575         __le32 SectorsPerAllocationUnit;
1576         __le32 BytesPerSector;
1577 } __packed;
1578
1579 #define SSINFO_FLAGS_ALIGNED_DEVICE             0x00000001
1580 #define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
1581 #define SSINFO_FLAGS_NO_SEEK_PENALTY            0x00000004
1582 #define SSINFO_FLAGS_TRIM_ENABLED               0x00000008
1583
1584 /* sector size info struct */
1585 struct smb3_fs_ss_info {
1586         __le32 LogicalBytesPerSector;
1587         __le32 PhysicalBytesPerSectorForAtomicity;
1588         __le32 PhysicalBytesPerSectorForPerf;
1589         __le32 FileSystemEffectivePhysicalBytesPerSectorForAtomicity;
1590         __le32 Flags;
1591         __le32 ByteOffsetForSectorAlignment;
1592         __le32 ByteOffsetForPartitionAlignment;
1593 } __packed;
1594
1595 /* volume info struct - see MS-FSCC 2.5.9 */
1596 #define MAX_VOL_LABEL_LEN       32
1597 struct smb3_fs_vol_info {
1598         __le64  VolumeCreationTime;
1599         __u32   VolumeSerialNumber;
1600         __le32  VolumeLabelLength; /* includes trailing null */
1601         __u8    SupportsObjects; /* True if eg like NTFS, supports objects */
1602         __u8    Reserved;
1603         __u8    VolumeLabel[]; /* variable len */
1604 } __packed;
1605
1606 /* partial list of QUERY INFO levels */
1607 #define FILE_DIRECTORY_INFORMATION      1
1608 #define FILE_FULL_DIRECTORY_INFORMATION 2
1609 #define FILE_BOTH_DIRECTORY_INFORMATION 3
1610 #define FILE_BASIC_INFORMATION          4
1611 #define FILE_STANDARD_INFORMATION       5
1612 #define FILE_INTERNAL_INFORMATION       6
1613 #define FILE_EA_INFORMATION             7
1614 #define FILE_ACCESS_INFORMATION         8
1615 #define FILE_NAME_INFORMATION           9
1616 #define FILE_RENAME_INFORMATION         10
1617 #define FILE_LINK_INFORMATION           11
1618 #define FILE_NAMES_INFORMATION          12
1619 #define FILE_DISPOSITION_INFORMATION    13
1620 #define FILE_POSITION_INFORMATION       14
1621 #define FILE_FULL_EA_INFORMATION        15
1622 #define FILE_MODE_INFORMATION           16
1623 #define FILE_ALIGNMENT_INFORMATION      17
1624 #define FILE_ALL_INFORMATION            18
1625 #define FILE_ALLOCATION_INFORMATION     19
1626 #define FILE_END_OF_FILE_INFORMATION    20
1627 #define FILE_ALTERNATE_NAME_INFORMATION 21
1628 #define FILE_STREAM_INFORMATION         22
1629 #define FILE_PIPE_INFORMATION           23
1630 #define FILE_PIPE_LOCAL_INFORMATION     24
1631 #define FILE_PIPE_REMOTE_INFORMATION    25
1632 #define FILE_MAILSLOT_QUERY_INFORMATION 26
1633 #define FILE_MAILSLOT_SET_INFORMATION   27
1634 #define FILE_COMPRESSION_INFORMATION    28
1635 #define FILE_OBJECT_ID_INFORMATION      29
1636 /* Number 30 not defined in documents */
1637 #define FILE_MOVE_CLUSTER_INFORMATION   31
1638 #define FILE_QUOTA_INFORMATION          32
1639 #define FILE_REPARSE_POINT_INFORMATION  33
1640 #define FILE_NETWORK_OPEN_INFORMATION   34
1641 #define FILE_ATTRIBUTE_TAG_INFORMATION  35
1642 #define FILE_TRACKING_INFORMATION       36
1643 #define FILEID_BOTH_DIRECTORY_INFORMATION 37
1644 #define FILEID_FULL_DIRECTORY_INFORMATION 38
1645 #define FILE_VALID_DATA_LENGTH_INFORMATION 39
1646 #define FILE_SHORT_NAME_INFORMATION     40
1647 #define FILE_SFIO_RESERVE_INFORMATION   44
1648 #define FILE_SFIO_VOLUME_INFORMATION    45
1649 #define FILE_HARD_LINK_INFORMATION      46
1650 #define FILE_NORMALIZED_NAME_INFORMATION 48
1651 #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
1652 #define FILE_STANDARD_LINK_INFORMATION  54
1653 #define FILE_ID_INFORMATION             59
1654
1655 struct smb2_file_internal_info {
1656         __le64 IndexNumber;
1657 } __packed; /* level 6 Query */
1658
1659 struct smb2_file_rename_info { /* encoding of request for level 10 */
1660         __u8   ReplaceIfExists; /* 1 = replace existing target with new */
1661                                 /* 0 = fail if target already exists */
1662         __u8   Reserved[7];
1663         __u64  RootDirectory;  /* MBZ for network operations (why says spec?) */
1664         __le32 FileNameLength;
1665         char   FileName[];     /* New name to be assigned */
1666         /* padding - overall struct size must be >= 24 so filename + pad >= 6 */
1667 } __packed; /* level 10 Set */
1668
1669 struct smb2_file_link_info { /* encoding of request for level 11 */
1670         __u8   ReplaceIfExists; /* 1 = replace existing link with new */
1671                                 /* 0 = fail if link already exists */
1672         __u8   Reserved[7];
1673         __u64  RootDirectory;  /* MBZ for network operations (why says spec?) */
1674         __le32 FileNameLength;
1675         char   FileName[];     /* Name to be assigned to new link */
1676 } __packed; /* level 11 Set */
1677
1678 struct smb2_file_full_ea_info { /* encoding of response for level 15 */
1679         __le32 next_entry_offset;
1680         __u8   flags;
1681         __u8   ea_name_length;
1682         __le16 ea_value_length;
1683         char   ea_data[]; /* \0 terminated name plus value */
1684 } __packed; /* level 15 Set */
1685
1686 /*
1687  * This level 18, although with struct with same name is different from cifs
1688  * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
1689  * CurrentByteOffset.
1690  */
1691 struct smb2_file_all_info { /* data block encoding of response to level 18 */
1692         __le64 CreationTime;    /* Beginning of FILE_BASIC_INFO equivalent */
1693         __le64 LastAccessTime;
1694         __le64 LastWriteTime;
1695         __le64 ChangeTime;
1696         __le32 Attributes;
1697         __u32  Pad1;            /* End of FILE_BASIC_INFO_INFO equivalent */
1698         __le64 AllocationSize;  /* Beginning of FILE_STANDARD_INFO equivalent */
1699         __le64 EndOfFile;       /* size ie offset to first free byte in file */
1700         __le32 NumberOfLinks;   /* hard links */
1701         __u8   DeletePending;
1702         __u8   Directory;
1703         __u16  Pad2;            /* End of FILE_STANDARD_INFO equivalent */
1704         __le64 IndexNumber;
1705         __le32 EASize;
1706         __le32 AccessFlags;
1707         __le64 CurrentByteOffset;
1708         __le32 Mode;
1709         __le32 AlignmentRequirement;
1710         __le32 FileNameLength;
1711         char   FileName[1];
1712 } __packed; /* level 18 Query */
1713
1714 struct smb2_file_eof_info { /* encoding of request for level 10 */
1715         __le64 EndOfFile; /* new end of file value */
1716 } __packed; /* level 20 Set */
1717
1718 struct smb2_file_reparse_point_info {
1719         __le64 IndexNumber;
1720         __le32 Tag;
1721 } __packed;
1722
1723 struct smb2_file_network_open_info {
1724         __le64 CreationTime;
1725         __le64 LastAccessTime;
1726         __le64 LastWriteTime;
1727         __le64 ChangeTime;
1728         __le64 AllocationSize;
1729         __le64 EndOfFile;
1730         __le32 Attributes;
1731         __le32 Reserved;
1732 } __packed; /* level 34 Query also similar returned in close rsp and open rsp */
1733
1734 /* See MS-FSCC 2.4.43 */
1735 struct smb2_file_id_information {
1736         __le64  VolumeSerialNumber;
1737         __u64  PersistentFileId; /* opaque endianness */
1738         __u64  VolatileFileId; /* opaque endianness */
1739 } __packed; /* level 59 */
1740
1741 extern char smb2_padding[7];
1742
1743 /* equivalent of the contents of SMB3.1.1 POSIX open context response */
1744 struct create_posix_rsp {
1745         u32 nlink;
1746         u32 reparse_tag;
1747         u32 mode;
1748         struct cifs_sid owner; /* var-sized on the wire */
1749         struct cifs_sid group; /* var-sized on the wire */
1750 } __packed;
1751
1752 /*
1753  * SMB2-only POSIX info level for query dir
1754  *
1755  * See posix_info_sid_size(), posix_info_extra_size() and
1756  * posix_info_parse() to help with the handling of this struct.
1757  */
1758 struct smb2_posix_info {
1759         __le32 NextEntryOffset;
1760         __u32 Ignored;
1761         __le64 CreationTime;
1762         __le64 LastAccessTime;
1763         __le64 LastWriteTime;
1764         __le64 ChangeTime;
1765         __le64 EndOfFile;
1766         __le64 AllocationSize;
1767         __le32 DosAttributes;
1768         __le64 Inode;
1769         __le32 DeviceId;
1770         __le32 Zero;
1771         /* beginning of POSIX Create Context Response */
1772         __le32 HardLinks;
1773         __le32 ReparseTag;
1774         __le32 Mode;
1775         /*
1776          * var sized owner SID
1777          * var sized group SID
1778          * le32 filenamelength
1779          * u8  filename[]
1780          */
1781 } __packed;
1782
1783 /* Level 100 query info */
1784 struct smb311_posix_qinfo {
1785         __le64 CreationTime;
1786         __le64 LastAccessTime;
1787         __le64 LastWriteTime;
1788         __le64 ChangeTime;
1789         __le64 EndOfFile;
1790         __le64 AllocationSize;
1791         __le32 DosAttributes;
1792         __le64 Inode;
1793         __le32 DeviceId;
1794         __le32 Zero;
1795         /* beginning of POSIX Create Context Response */
1796         __le32 HardLinks;
1797         __le32 ReparseTag;
1798         __le32 Mode;
1799         u8     Sids[];
1800         /*
1801          * var sized owner SID
1802          * var sized group SID
1803          * le32 filenamelength
1804          * u8  filename[]
1805          */
1806 } __packed;
1807
1808 /*
1809  * Parsed version of the above struct. Allows direct access to the
1810  * variable length fields
1811  */
1812 struct smb2_posix_info_parsed {
1813         const struct smb2_posix_info *base;
1814         size_t size;
1815         struct cifs_sid owner;
1816         struct cifs_sid group;
1817         int name_len;
1818         const u8 *name;
1819 };
1820
1821 #endif                          /* _SMB2PDU_H */