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