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