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