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