blob: 204a622b89ed3575d3e5cda23e115341615afb7a [file] [log] [blame]
Steve Frenchddfbefb2011-03-15 02:08:48 +00001/*
2 * fs/cifs/smb2pdu.h
3 *
Steve Frenchbe7457d2013-06-19 17:41:10 -05004 * Copyright (c) International Business Machines Corp., 2009, 2013
Steve Frenchddfbefb2011-03-15 02:08:48 +00005 * 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>
Steve Frenchfdef6652019-12-06 02:02:38 -060028#include <cifsacl.h>
Steve Frenchddfbefb2011-03-15 02:08:48 +000029
30/*
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040031 * 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
Randy Dunlapa03f5072020-07-19 17:13:16 -070034 * able to match against the protocol specfication.
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040035 *
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
Pavel Shilovsky96a988f2016-11-29 11:31:23 -080084#define SMB2_INTERNAL_CMD cpu_to_le16(0xFFFF)
85
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040086#define NUMBER_OF_SMB2_COMMANDS 0x0013
87
Ronnie Sahlberg58d15ed2019-01-29 12:46:16 +100088/* 52 transform hdr + 64 hdr + 88 create rsp */
Ronnie Sahlbergc4627e62019-01-29 12:46:17 +100089#define SMB2_TRANSFORM_HEADER_SIZE 52
Ronnie Sahlberg58d15ed2019-01-29 12:46:16 +100090#define MAX_SMB2_HDR_SIZE 204
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040091
Fabian Frederickbc09d142014-12-10 15:41:15 -080092#define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)
Steve French373512e2015-12-18 13:05:30 -060093#define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
Steve French8895c662020-03-17 01:53:39 -050094#define SMB2_COMPRESSION_TRANSFORM_ID cpu_to_le32(0x424d53fc)
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +040095
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040096/*
Steve Frenchddfbefb2011-03-15 02:08:48 +000097 * 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 */
Pavel Shilovsky74112862012-07-27 01:20:41 +0400104
Fabian Frederickbc09d142014-12-10 15:41:15 -0800105#define SMB2_HEADER_STRUCTURE_SIZE cpu_to_le16(64)
Pavel Shilovsky74112862012-07-27 01:20:41 +0400106
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700107struct smb2_sync_hdr {
Steve French373512e2015-12-18 13:05:30 -0600108 __le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */
Steve Frenchddfbefb2011-03-15 02:08:48 +0000109 __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;
Sachin Prabhu9235d092014-12-09 17:37:00 +0000116 __le64 MessageId;
Steve Frenchddfbefb2011-03-15 02:08:48 +0000117 __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
Long Lif7950cb2020-03-26 19:42:24 -0700123/* The total header size for SMB2 read and write */
124#define SMB2_READWRITE_PDU_HEADER_SIZE (48 + sizeof(struct smb2_sync_hdr))
125
Pavel Shilovskycb200bd2016-10-24 16:59:57 -0700126struct smb2_sync_pdu {
127 struct smb2_sync_hdr sync_hdr;
128 __le16 StructureSize2; /* size of wct area (varies, request specific) */
129} __packed;
130
Steve Frenchfd08f2d2020-10-15 00:25:02 -0500131#define SMB3_AES_CCM_NONCE 11
132#define SMB3_AES_GCM_NONCE 12
Pavel Shilovsky026e93d2016-11-03 16:47:37 -0700133
Steve French8895c662020-03-17 01:53:39 -0500134/* Transform flags (for 3.0 dialect this flag indicates CCM */
135#define TRANSFORM_FLAG_ENCRYPTED 0x0001
Steve French0cbaa532013-11-15 23:50:24 -0600136struct smb2_transform_hdr {
Pavel Shilovsky026e93d2016-11-03 16:47:37 -0700137 __le32 ProtocolId; /* 0xFD 'S' 'M' 'B' */
Steve French0cbaa532013-11-15 23:50:24 -0600138 __u8 Signature[16];
Steve French373512e2015-12-18 13:05:30 -0600139 __u8 Nonce[16];
Steve French0cbaa532013-11-15 23:50:24 -0600140 __le32 OriginalMessageSize;
141 __u16 Reserved1;
Steve French8895c662020-03-17 01:53:39 -0500142 __le16 Flags; /* EncryptionAlgorithm for 3.0, enc enabled for 3.1.1 */
Steve French0cbaa532013-11-15 23:50:24 -0600143 __u64 SessionId;
144} __packed;
145
Steve French3563a6f2020-05-30 17:10:16 -0500146/* 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
Steve French8f233432020-03-15 18:04:13 -0500155/* See MS-SMB2 2.2.42.1 */
Steve French3984bdc2020-10-04 17:42:27 -0500156#define SMB2_COMPRESSION_FLAG_NONE 0x0000
Steve French1af34fd2020-10-21 20:36:26 -0500157#define SMB2_COMPRESSION_FLAG_CHAINED 0x0001
Steve French3984bdc2020-10-04 17:42:27 -0500158
Steve French3563a6f2020-05-30 17:10:16 -0500159struct compression_payload_header {
Steve French3984bdc2020-10-04 17:42:27 -0500160 __le16 CompressionAlgorithm;
161 __le16 Flags;
162 __le32 Length; /* length of compressed playload including field below if present */
163 /* __le32 OriginalPayloadSize; */ /* optional */
Steve French8f233432020-03-15 18:04:13 -0500164} __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
Steve French3984bdc2020-10-04 17:42:27 -0500174/* 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
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400194/*
195 * SMB2 flag definitions
196 */
Fabian Frederickbc09d142014-12-10 15:41:15 -0800197#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)
Steve French59519802019-07-25 18:19:42 -0500201#define SMB2_FLAGS_PRIORITY_MASK cpu_to_le32(0x00000070) /* SMB3.1.1 */
Fabian Frederickbc09d142014-12-10 15:41:15 -0800202#define SMB2_FLAGS_DFS_OPERATIONS cpu_to_le32(0x10000000)
Steve French59519802019-07-25 18:19:42 -0500203#define SMB2_FLAGS_REPLAY_OPERATION cpu_to_le32(0x20000000) /* SMB3 & up */
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400204
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 */
Pavel Shilovsky74112862012-07-27 01:20:41 +0400213
Ronnie Sahlberg730928c2018-08-08 15:07:49 +1000214#define COMPOUND_FID 0xFFFFFFFFFFFFFFFFULL
215
Fabian Frederickbc09d142014-12-10 15:41:15 -0800216#define SMB2_ERROR_STRUCTURE_SIZE2 cpu_to_le16(9)
Pavel Shilovsky74112862012-07-27 01:20:41 +0400217
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400218struct smb2_err_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +1000219 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400220 __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
Ronnie Sahlbergdf070af2019-07-09 18:41:11 +1000226#define SYMLINK_ERROR_TAG 0x4c4d5953
227
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400228struct 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;
Gustavo A. R. Silvacff2def2020-03-09 10:44:51 -0500239 __u8 PathBuffer[];
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400240} __packed;
241
Steve French5f60a562018-02-05 14:46:18 -0600242/* 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
Steve French8895c662020-03-17 01:53:39 -0500249/* ErrorId values */
250#define SMB2_ERROR_ID_DEFAULT 0x00000000
251#define SMB2_ERROR_ID_SHARE_REDIRECT cpu_to_le32(0x72645253) /* "rdRS" */
252
Steve French5f60a562018-02-05 14:46:18 -0600253/* 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;
Gustavo A. R. Silvacff2def2020-03-09 10:44:51 -0500271 struct move_dst_ipaddr IpAddrMoveList[];
Steve French5f60a562018-02-05 14:46:18 -0600272 /* __u8 ResourceName[] */ /* Name of share as counted Unicode string */
273} __packed;
274
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700275#define SMB2_CLIENT_GUID_SIZE 16
276
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400277struct smb2_negotiate_req {
Ronnie Sahlberg13cacea2017-11-20 11:24:30 +1100278 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400279 __le16 StructureSize; /* Must be 36 */
280 __le16 DialectCount;
281 __le16 SecurityMode;
282 __le16 Reserved; /* MBZ */
283 __le32 Capabilities;
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700284 __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE];
Steve French5f7fbf72014-12-17 22:52:58 -0600285 /* 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;
Steve Frenche4aa25e2012-10-01 12:26:22 -0500289 __le16 Dialects[1]; /* One dialect (vers=) at a time for now */
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400290} __packed;
291
Steve Frenche4aa25e2012-10-01 12:26:22 -0500292/* Dialects */
Steve French43cdae82019-06-13 14:26:49 -0500293#define SMB10_PROT_ID 0x0000 /* local only, not sent on wire w/CIFS negprot */
Steve Frenche4aa25e2012-10-01 12:26:22 -0500294#define SMB20_PROT_ID 0x0202
295#define SMB21_PROT_ID 0x0210
296#define SMB30_PROT_ID 0x0300
Steve French20b6d8b2013-06-12 22:48:41 -0500297#define SMB302_PROT_ID 0x0302
Steve French5f7fbf72014-12-17 22:52:58 -0600298#define SMB311_PROT_ID 0x0311
Steve Frenche4aa25e2012-10-01 12:26:22 -0500299#define BAD_PROT_ID 0xFFFF
300
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400301/* SecurityMode flags */
302#define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001
303#define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
Steve French07108d02018-04-01 20:15:55 -0500304#define SMB2_SEC_MODE_FLAGS_ALL 0x0003
305
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400306/* 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 */
Steve Frenche4aa25e2012-10-01 12:26:22 -0500310#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 */
Pavel Shilovsky29e20f92012-07-13 13:58:14 +0400314/* Internal types */
315#define SMB2_NT_FIND 0x00100000
316#define SMB2_LARGE_FILES 0x00200000
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400317
Steve Frenchd7bef4c2019-04-18 11:03:58 -0500318
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)
Steve French3984bdc2020-10-04 17:42:27 -0500324#define SMB2_TRANSPORT_CAPABILITIES cpu_to_le16(6)
325#define SMB2_RDMA_TRANSFORM_CAPABILITIES cpu_to_le16(7)
Steve French68295542020-10-10 20:11:47 -0500326#define SMB2_SIGNING_CAPABILITIES cpu_to_le16(8)
Steve Frenchd7bef4c2019-04-18 11:03:58 -0500327#define SMB2_POSIX_EXTENSIONS_AVAILABLE cpu_to_le16(0x100)
328
Steve French136ff1b2018-04-08 16:14:31 -0500329struct smb2_neg_context {
330 __le16 ContextType;
331 __le16 DataLength;
332 __le32 Reserved;
333 /* Followed by array of data */
334} __packed;
335
Steve French7955f102020-12-09 22:19:00 -0600336#define SMB311_LINUX_CLIENT_SALT_SIZE 32
Steve Frencheed0e172015-02-06 00:03:52 -0600337/* Hash Algorithm Types */
Steve Frenchebb3a9d2015-06-18 04:49:47 -0500338#define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001)
Aurelien Aptel8bd68c62018-02-16 19:19:29 +0100339#define SMB2_PREAUTH_HASH_SIZE 64
Steve Frencheed0e172015-02-06 00:03:52 -0600340
Steve French7955f102020-12-09 22:19:00 -0600341/*
342 * SaltLength that the server send can be zero, so the only three required
343 * fields (all __le16) end up six bytes total, so the minimum context data len
344 * in the response is six bytes which accounts for
345 *
346 * HashAlgorithmCount, SaltLength, and 1 HashAlgorithm.
347 */
348#define MIN_PREAUTH_CTXT_DATA_LEN 6
349
Steve Frencheed0e172015-02-06 00:03:52 -0600350struct smb2_preauth_neg_context {
351 __le16 ContextType; /* 1 */
352 __le16 DataLength;
353 __le32 Reserved;
354 __le16 HashAlgorithmCount; /* 1 */
355 __le16 SaltLength;
356 __le16 HashAlgorithms; /* HashAlgorithms[0] since only one defined */
Steve French7955f102020-12-09 22:19:00 -0600357 __u8 Salt[SMB311_LINUX_CLIENT_SALT_SIZE];
Steve Frencheed0e172015-02-06 00:03:52 -0600358} __packed;
359
360/* Encryption Algorithms Ciphers */
361#define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001)
362#define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002)
Steve French63ca5652020-10-15 23:41:40 -0500363/* we currently do not request AES256_CCM since presumably GCM faster */
Steve French119e4892020-03-18 00:51:48 -0500364#define SMB2_ENCRYPTION_AES256_CCM cpu_to_le16(0x0003)
365#define SMB2_ENCRYPTION_AES256_GCM cpu_to_le16(0x0004)
Steve Frencheed0e172015-02-06 00:03:52 -0600366
Steve French5100d8a2018-04-09 10:47:14 -0500367/* Min encrypt context data is one cipher so 2 bytes + 2 byte count field */
368#define MIN_ENCRYPT_CTXT_DATA_LEN 4
Steve Frencheed0e172015-02-06 00:03:52 -0600369struct smb2_encryption_neg_context {
370 __le16 ContextType; /* 2 */
371 __le16 DataLength;
372 __le32 Reserved;
Steve French29e27922020-10-14 20:24:09 -0500373 /* CipherCount usally 2, but can be 3 when AES256-GCM enabled */
374 __le16 CipherCount; /* AES128-GCM and AES128-CCM by default */
375 __le16 Ciphers[3];
Steve Frencheed0e172015-02-06 00:03:52 -0600376} __packed;
377
Steve Frenchd7bef4c2019-04-18 11:03:58 -0500378/* See MS-SMB2 2.2.3.1.3 */
Steve French26ea8882019-04-26 20:36:08 -0700379#define SMB3_COMPRESS_NONE cpu_to_le16(0x0000)
380#define SMB3_COMPRESS_LZNT1 cpu_to_le16(0x0001)
381#define SMB3_COMPRESS_LZ77 cpu_to_le16(0x0002)
382#define SMB3_COMPRESS_LZ77_HUFF cpu_to_le16(0x0003)
Steve French2fe4f622020-03-15 17:42:41 -0500383/* Pattern scanning algorithm See MS-SMB2 3.1.4.4.1 */
Steve French3563a6f2020-05-30 17:10:16 -0500384#define SMB3_COMPRESS_PATTERN cpu_to_le16(0x0004) /* Pattern_V1 */
Steve French2fe4f622020-03-15 17:42:41 -0500385
386/* Compression Flags */
387#define SMB2_COMPRESSION_CAPABILITIES_FLAG_NONE cpu_to_le32(0x00000000)
388#define SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED cpu_to_le32(0x00000001)
Steve Frenchd7bef4c2019-04-18 11:03:58 -0500389
390struct smb2_compression_capabilities_context {
Steve French26ea8882019-04-26 20:36:08 -0700391 __le16 ContextType; /* 3 */
392 __le16 DataLength;
Steve French3984bdc2020-10-04 17:42:27 -0500393 __u32 Reserved;
Steve Frenchd7bef4c2019-04-18 11:03:58 -0500394 __le16 CompressionAlgorithmCount;
395 __u16 Padding;
Steve French3984bdc2020-10-04 17:42:27 -0500396 __u32 Flags;
Steve French26ea8882019-04-26 20:36:08 -0700397 __le16 CompressionAlgorithms[3];
Steve Frenchd7bef4c2019-04-18 11:03:58 -0500398} __packed;
399
400/*
401 * For smb2_netname_negotiate_context_id See MS-SMB2 2.2.3.1.4.
402 * Its struct simply contains NetName, an array of Unicode characters
403 */
Steve French96d3cca2019-06-25 04:39:51 -0500404struct smb2_netname_neg_context {
Steve French3984bdc2020-10-04 17:42:27 -0500405 __le16 ContextType; /* 5 */
Steve French96d3cca2019-06-25 04:39:51 -0500406 __le16 DataLength;
407 __le32 Reserved;
Gustavo A. R. Silvacff2def2020-03-09 10:44:51 -0500408 __le16 NetName[]; /* hostname of target converted to UCS-2 */
Steve French96d3cca2019-06-25 04:39:51 -0500409} __packed;
Steve Frenchd7bef4c2019-04-18 11:03:58 -0500410
Steve French3984bdc2020-10-04 17:42:27 -0500411/*
412 * For rdma transform capabilities context see MS-SMB2 2.2.3.1.6
413 * and 2.2.4.1.5
414 */
415
416/* RDMA Transform IDs */
417#define SMB2_RDMA_TRANSFORM_NONE 0x0000
418#define SMB2_RDMA_TRANSFORM_ENCRYPTION 0x0001
419
420struct smb2_rdma_transform_capabilities_context {
421 __le16 ContextType; /* 7 */
422 __le16 DataLength;
423 __u32 Reserved;
424 __le16 TransformCount;
425 __u16 Reserved1;
426 __u32 Reserved2;
427 __le16 RDMATransformIds[1];
428} __packed;
429
Steve French68295542020-10-10 20:11:47 -0500430/* Signing algorithms */
431#define SIGNING_ALG_HMAC_SHA256 0
432#define SIGNING_ALG_AES_CMAC 1
433#define SIGNING_ALG_AES_GMAC 2
434
435struct smb2_signing_capabilities {
436 __le16 ContextType; /* 8 */
437 __le16 DataLength;
438 __u32 Reserved;
439 __le16 SigningAlgorithmCount;
440 __le16 SigningAlgorithms[];
441} __packed;
442
Steve French0d481322019-02-24 17:56:33 -0600443#define POSIX_CTXT_DATA_LEN 16
Steve Frenchfcef0db2018-05-19 20:45:27 -0500444struct smb2_posix_neg_context {
445 __le16 ContextType; /* 0x100 */
446 __le16 DataLength;
447 __le32 Reserved;
Steve French0d481322019-02-24 17:56:33 -0600448 __u8 Name[16]; /* POSIX ctxt GUID 93AD25509CB411E7B42383DE968BCD7C */
Steve Frenchfcef0db2018-05-19 20:45:27 -0500449} __packed;
450
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400451struct smb2_negotiate_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +1000452 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400453 __le16 StructureSize; /* Must be 65 */
454 __le16 SecurityMode;
455 __le16 DialectRevision;
Steve French5f7fbf72014-12-17 22:52:58 -0600456 __le16 NegotiateContextCount; /* Prior to SMB3.1.1 was Reserved & MBZ */
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400457 __u8 ServerGUID[16];
458 __le32 Capabilities;
459 __le32 MaxTransactSize;
460 __le32 MaxReadSize;
461 __le32 MaxWriteSize;
462 __le64 SystemTime; /* MBZ */
463 __le64 ServerStartTime;
464 __le16 SecurityBufferOffset;
465 __le16 SecurityBufferLength;
Steve French5f7fbf72014-12-17 22:52:58 -0600466 __le32 NegotiateContextOffset; /* Pre:SMB3.1.1 was reserved/ignored */
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400467 __u8 Buffer[1]; /* variable length GSS security buffer */
468} __packed;
469
Steve Frencheed0e172015-02-06 00:03:52 -0600470/* Flags */
471#define SMB2_SESSION_REQ_FLAG_BINDING 0x01
472#define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04
473
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400474struct smb2_sess_setup_req {
Ronnie Sahlberg88ea5cb2017-11-20 11:24:36 +1100475 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400476 __le16 StructureSize; /* Must be 25 */
Steve Frencheed0e172015-02-06 00:03:52 -0600477 __u8 Flags;
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400478 __u8 SecurityMode;
479 __le32 Capabilities;
480 __le32 Channel;
481 __le16 SecurityBufferOffset;
482 __le16 SecurityBufferLength;
Steve Frenchc2afb812016-09-20 22:56:13 -0500483 __u64 PreviousSessionId;
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400484 __u8 Buffer[1]; /* variable length GSS security buffer */
485} __packed;
486
487/* Currently defined SessionFlags */
488#define SMB2_SESSION_FLAG_IS_GUEST 0x0001
489#define SMB2_SESSION_FLAG_IS_NULL 0x0002
Steve French0cbaa532013-11-15 23:50:24 -0600490#define SMB2_SESSION_FLAG_ENCRYPT_DATA 0x0004
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400491struct smb2_sess_setup_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +1000492 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400493 __le16 StructureSize; /* Must be 9 */
494 __le16 SessionFlags;
495 __le16 SecurityBufferOffset;
496 __le16 SecurityBufferLength;
497 __u8 Buffer[1]; /* variable length GSS security buffer */
498} __packed;
499
500struct smb2_logoff_req {
Ronnie Sahlberg45305ed2017-11-09 12:14:17 +1100501 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400502 __le16 StructureSize; /* Must be 4 */
503 __le16 Reserved;
504} __packed;
505
506struct smb2_logoff_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +1000507 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400508 __le16 StructureSize; /* Must be 4 */
509 __le16 Reserved;
510} __packed;
511
Steve Frencheed0e172015-02-06 00:03:52 -0600512/* Flags/Reserved for SMB3.1.1 */
Steve French5f60a562018-02-05 14:46:18 -0600513#define SMB2_TREE_CONNECT_FLAG_CLUSTER_RECONNECT cpu_to_le16(0x0001)
514#define SMB2_TREE_CONNECT_FLAG_REDIRECT_TO_OWNER cpu_to_le16(0x0002)
515#define SMB2_TREE_CONNECT_FLAG_EXTENSION_PRESENT cpu_to_le16(0x0004)
Steve Frencheed0e172015-02-06 00:03:52 -0600516
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400517struct smb2_tree_connect_req {
Ronnie Sahlberg661bb9432017-11-09 12:14:23 +1100518 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400519 __le16 StructureSize; /* Must be 9 */
Steve French8895c662020-03-17 01:53:39 -0500520 __le16 Flags; /* Reserved MBZ for dialects prior to SMB3.1.1 */
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400521 __le16 PathOffset;
522 __le16 PathLength;
523 __u8 Buffer[1]; /* variable length */
524} __packed;
525
Steve French5f60a562018-02-05 14:46:18 -0600526/* See MS-SMB2 section 2.2.9.2 */
527/* Context Types */
528#define SMB2_RESERVED_TREE_CONNECT_CONTEXT_ID 0x0000
529#define SMB2_REMOTED_IDENTITY_TREE_CONNECT_CONTEXT_ID cpu_to_le16(0x0001)
530
531struct tree_connect_contexts {
532 __le16 ContextType;
533 __le16 DataLength;
534 __le32 Reserved;
Gustavo A. R. Silvacff2def2020-03-09 10:44:51 -0500535 __u8 Data[];
Steve French5f60a562018-02-05 14:46:18 -0600536} __packed;
537
538/* Remoted identity tree connect context structures - see MS-SMB2 2.2.9.2.1 */
539struct smb3_blob_data {
540 __le16 BlobSize;
Gustavo A. R. Silvacff2def2020-03-09 10:44:51 -0500541 __u8 BlobData[];
Steve French5f60a562018-02-05 14:46:18 -0600542} __packed;
543
544/* Valid values for Attr */
545#define SE_GROUP_MANDATORY 0x00000001
546#define SE_GROUP_ENABLED_BY_DEFAULT 0x00000002
547#define SE_GROUP_ENABLED 0x00000004
548#define SE_GROUP_OWNER 0x00000008
549#define SE_GROUP_USE_FOR_DENY_ONLY 0x00000010
550#define SE_GROUP_INTEGRITY 0x00000020
551#define SE_GROUP_INTEGRITY_ENABLED 0x00000040
552#define SE_GROUP_RESOURCE 0x20000000
553#define SE_GROUP_LOGON_ID 0xC0000000
554
555/* struct sid_attr_data is SidData array in BlobData format then le32 Attr */
556
557struct sid_array_data {
558 __le16 SidAttrCount;
559 /* SidAttrList - array of sid_attr_data structs */
560} __packed;
561
562struct luid_attr_data {
563
564} __packed;
565
566/*
567 * struct privilege_data is the same as BLOB_DATA - see MS-SMB2 2.2.9.2.1.5
568 * but with size of LUID_ATTR_DATA struct and BlobData set to LUID_ATTR DATA
569 */
570
571struct privilege_array_data {
572 __le16 PrivilegeCount;
573 /* array of privilege_data structs */
574} __packed;
575
576struct remoted_identity_tcon_context {
577 __le16 TicketType; /* must be 0x0001 */
578 __le16 TicketSize; /* total size of this struct */
579 __le16 User; /* offset to SID_ATTR_DATA struct with user info */
580 __le16 UserName; /* offset to null terminated Unicode username string */
581 __le16 Domain; /* offset to null terminated Unicode domain name */
582 __le16 Groups; /* offset to SID_ARRAY_DATA struct with group info */
583 __le16 RestrictedGroups; /* similar to above */
584 __le16 Privileges; /* offset to PRIVILEGE_ARRAY_DATA struct */
585 __le16 PrimaryGroup; /* offset to SID_ARRAY_DATA struct */
586 __le16 Owner; /* offset to BLOB_DATA struct */
587 __le16 DefaultDacl; /* offset to BLOB_DATA struct */
588 __le16 DeviceGroups; /* offset to SID_ARRAY_DATA struct */
589 __le16 UserClaims; /* offset to BLOB_DATA struct */
590 __le16 DeviceClaims; /* offset to BLOB_DATA struct */
Gustavo A. R. Silvacff2def2020-03-09 10:44:51 -0500591 __u8 TicketInfo[]; /* variable length buf - remoted identity data */
Steve French5f60a562018-02-05 14:46:18 -0600592} __packed;
593
594struct smb2_tree_connect_req_extension {
595 __le32 TreeConnectContextOffset;
596 __le16 TreeConnectContextCount;
597 __u8 Reserved[10];
Gustavo A. R. Silvacff2def2020-03-09 10:44:51 -0500598 __u8 PathName[]; /* variable sized array */
Steve French5f60a562018-02-05 14:46:18 -0600599 /* followed by array of TreeConnectContexts */
600} __packed;
601
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400602struct smb2_tree_connect_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +1000603 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400604 __le16 StructureSize; /* Must be 16 */
605 __u8 ShareType; /* see below */
606 __u8 Reserved;
607 __le32 ShareFlags; /* see below */
608 __le32 Capabilities; /* see below */
609 __le32 MaximalAccess;
610} __packed;
611
612/* Possible ShareType values */
613#define SMB2_SHARE_TYPE_DISK 0x01
614#define SMB2_SHARE_TYPE_PIPE 0x02
615#define SMB2_SHARE_TYPE_PRINT 0x03
616
617/*
618 * Possible ShareFlags - exactly one and only one of the first 4 caching flags
619 * must be set (any of the remaining, SHI1005, flags may be set individually
620 * or in combination.
621 */
622#define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000
623#define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010
624#define SMB2_SHAREFLAG_VDO_CACHING 0x00000020
625#define SMB2_SHAREFLAG_NO_CACHING 0x00000030
626#define SHI1005_FLAGS_DFS 0x00000001
627#define SHI1005_FLAGS_DFS_ROOT 0x00000002
628#define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS 0x00000100
629#define SHI1005_FLAGS_FORCE_SHARED_DELETE 0x00000200
630#define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING 0x00000400
631#define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM 0x00000800
632#define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK 0x00001000
Steve Frenchc8664732013-06-21 15:35:45 -0500633#define SHI1005_FLAGS_ENABLE_HASH_V1 0x00002000
634#define SHI1005_FLAGS_ENABLE_HASH_V2 0x00004000
635#define SHI1005_FLAGS_ENCRYPT_DATA 0x00008000
Steve French5f60a562018-02-05 14:46:18 -0600636#define SMB2_SHAREFLAG_IDENTITY_REMOTING 0x00040000 /* 3.1.1 */
637#define SHI1005_FLAGS_ALL 0x0004FF33
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400638
639/* Possible share capabilities */
Steve French2b5dc282013-06-13 10:51:10 -0500640#define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008) /* all dialects */
641#define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY cpu_to_le32(0x00000010) /* 3.0 */
642#define SMB2_SHARE_CAP_SCALEOUT cpu_to_le32(0x00000020) /* 3.0 */
643#define SMB2_SHARE_CAP_CLUSTER cpu_to_le32(0x00000040) /* 3.0 */
644#define SMB2_SHARE_CAP_ASYMMETRIC cpu_to_le32(0x00000080) /* 3.02 */
Steve French5f60a562018-02-05 14:46:18 -0600645#define SMB2_SHARE_CAP_REDIRECT_TO_OWNER cpu_to_le32(0x00000100) /* 3.1.1 */
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400646
647struct smb2_tree_disconnect_req {
Ronnie Sahlberg4eecf4c2017-11-09 12:14:18 +1100648 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400649 __le16 StructureSize; /* Must be 4 */
650 __le16 Reserved;
651} __packed;
652
653struct smb2_tree_disconnect_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +1000654 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400655 __le16 StructureSize; /* Must be 4 */
656 __le16 Reserved;
657} __packed;
658
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400659/* File Attrubutes */
660#define FILE_ATTRIBUTE_READONLY 0x00000001
661#define FILE_ATTRIBUTE_HIDDEN 0x00000002
662#define FILE_ATTRIBUTE_SYSTEM 0x00000004
663#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
664#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
665#define FILE_ATTRIBUTE_NORMAL 0x00000080
666#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
667#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
668#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
669#define FILE_ATTRIBUTE_COMPRESSED 0x00000800
670#define FILE_ATTRIBUTE_OFFLINE 0x00001000
671#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
672#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
Steve French73322972014-09-23 19:25:42 -0500673#define FILE_ATTRIBUTE_INTEGRITY_STREAM 0x00008000
674#define FILE_ATTRIBUTE_NO_SCRUB_DATA 0x00020000
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400675
676/* Oplock levels */
677#define SMB2_OPLOCK_LEVEL_NONE 0x00
678#define SMB2_OPLOCK_LEVEL_II 0x01
679#define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
680#define SMB2_OPLOCK_LEVEL_BATCH 0x09
681#define SMB2_OPLOCK_LEVEL_LEASE 0xFF
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700682/* Non-spec internal type */
683#define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400684
685/* Desired Access Flags */
686#define FILE_READ_DATA_LE cpu_to_le32(0x00000001)
687#define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002)
688#define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004)
689#define FILE_READ_EA_LE cpu_to_le32(0x00000008)
690#define FILE_WRITE_EA_LE cpu_to_le32(0x00000010)
691#define FILE_EXECUTE_LE cpu_to_le32(0x00000020)
692#define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080)
693#define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100)
694#define FILE_DELETE_LE cpu_to_le32(0x00010000)
695#define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000)
696#define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000)
697#define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000)
698#define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000)
699#define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000)
700#define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000)
701#define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000)
702#define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000)
703#define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000)
704#define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000)
705
706/* ShareAccess Flags */
707#define FILE_SHARE_READ_LE cpu_to_le32(0x00000001)
708#define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002)
709#define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004)
710#define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007)
711
712/* CreateDisposition Flags */
713#define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000)
714#define FILE_OPEN_LE cpu_to_le32(0x00000001)
715#define FILE_CREATE_LE cpu_to_le32(0x00000002)
716#define FILE_OPEN_IF_LE cpu_to_le32(0x00000003)
717#define FILE_OVERWRITE_LE cpu_to_le32(0x00000004)
718#define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005)
719
720/* CreateOptions Flags */
721#define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001)
722/* same as #define CREATE_NOT_FILE_LE cpu_to_le32(0x00000001) */
723#define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002)
724#define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004)
725#define FILE_NO_INTERMEDIATE_BUFFERRING_LE cpu_to_le32(0x00000008)
726#define FILE_SYNCHRONOUS_IO_ALERT_LE cpu_to_le32(0x00000010)
727#define FILE_SYNCHRONOUS_IO_NON_ALERT_LE cpu_to_le32(0x00000020)
728#define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040)
729#define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100)
730#define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200)
731#define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800)
732#define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000)
733#define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000)
734#define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000)
735#define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000)
736#define FILE_RESERVE_OPFILTER_LE cpu_to_le32(0x00100000)
737#define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000)
738#define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000)
739#define FILE_OPEN_FOR_FREE_SPACE_QUERY_LE cpu_to_le32(0x00800000)
740
741#define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \
742 | FILE_READ_ATTRIBUTES_LE)
743#define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \
744 | FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
745#define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
746
Steve French8895c662020-03-17 01:53:39 -0500747/* Impersonation Levels. See MS-WPO section 9.7 and MSDN-IMPERS */
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400748#define IL_ANONYMOUS cpu_to_le32(0x00000000)
749#define IL_IDENTIFICATION cpu_to_le32(0x00000001)
750#define IL_IMPERSONATION cpu_to_le32(0x00000002)
751#define IL_DELEGATE cpu_to_le32(0x00000003)
752
753/* Create Context Values */
754#define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */
755#define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */
756#define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ"
757#define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC"
Steve French12197a72014-05-14 05:29:40 -0700758#define SMB2_CREATE_ALLOCATION_SIZE "AISi"
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400759#define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
760#define SMB2_CREATE_TIMEWARP_REQUEST "TWrp"
761#define SMB2_CREATE_QUERY_ON_DISK_ID "QFid"
762#define SMB2_CREATE_REQUEST_LEASE "RqLs"
Steve French12197a72014-05-14 05:29:40 -0700763#define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 "DH2Q"
764#define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 "DH2C"
765#define SMB2_CREATE_APP_INSTANCE_ID 0x45BCA66AEFA7F74A9008FA462E144D74
Steve Frenche7348e32019-06-28 02:35:10 -0500766#define SMB2_CREATE_APP_INSTANCE_VERSION 0xB982D0B73B56074FA07B524A8116A010
Steve Frenchfe048402018-05-30 17:10:25 -0500767#define SVHDX_OPEN_DEVICE_CONTEX 0x9CCBCF9E04C1E643980E158DA1F6EC83
768#define SMB2_CREATE_TAG_POSIX 0x93AD25509CB411E7B42383DE968BCD7C
769
Steve French37e6a702018-09-19 02:02:58 -0500770/* Flag (SMB3 open response) values */
771#define SMB2_CREATE_FLAG_REPARSEPOINT 0x01
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400772
Ronnie Sahlberg4d8dfaf2018-08-21 11:49:21 +1000773/*
774 * Maximum number of iovs we need for an open/create request.
775 * [0] : struct smb2_create_req
776 * [1] : path
777 * [2] : lease context
778 * [3] : durable context
779 * [4] : posix context
780 * [5] : time warp context
Steve Frenchff2a09e2019-07-06 14:41:38 -0500781 * [6] : query id context
782 * [7] : compound padding
Ronnie Sahlberg4d8dfaf2018-08-21 11:49:21 +1000783 */
Steve Frenchff2a09e2019-07-06 14:41:38 -0500784#define SMB2_CREATE_IOV_SIZE 8
Ronnie Sahlberg4d8dfaf2018-08-21 11:49:21 +1000785
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400786struct smb2_create_req {
Ronnie Sahlberg4f33bc32017-11-20 11:24:38 +1100787 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400788 __le16 StructureSize; /* Must be 57 */
789 __u8 SecurityFlags;
790 __u8 RequestedOplockLevel;
791 __le32 ImpersonationLevel;
792 __le64 SmbCreateFlags;
793 __le64 Reserved;
794 __le32 DesiredAccess;
795 __le32 FileAttributes;
796 __le32 ShareAccess;
797 __le32 CreateDisposition;
798 __le32 CreateOptions;
799 __le16 NameOffset;
800 __le16 NameLength;
801 __le32 CreateContextsOffset;
802 __le32 CreateContextsLength;
Gustavo A. R. Silvacff2def2020-03-09 10:44:51 -0500803 __u8 Buffer[];
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400804} __packed;
805
Ronnie Sahlbergc4627e62019-01-29 12:46:17 +1000806/*
807 * Maximum size of a SMB2_CREATE response is 64 (smb2 header) +
Steve Frenchff2a09e2019-07-06 14:41:38 -0500808 * 88 (fixed part of create response) + 520 (path) + 208 (contexts) +
Ronnie Sahlbergc4627e62019-01-29 12:46:17 +1000809 * 2 bytes of padding.
810 */
Steve Frenchff2a09e2019-07-06 14:41:38 -0500811#define MAX_SMB2_CREATE_RESPONSE_SIZE 880
Ronnie Sahlbergc4627e62019-01-29 12:46:17 +1000812
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400813struct smb2_create_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +1000814 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400815 __le16 StructureSize; /* Must be 89 */
816 __u8 OplockLevel;
Steve French37e6a702018-09-19 02:02:58 -0500817 __u8 Flag; /* 0x01 if reparse point */
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400818 __le32 CreateAction;
819 __le64 CreationTime;
820 __le64 LastAccessTime;
821 __le64 LastWriteTime;
822 __le64 ChangeTime;
823 __le64 AllocationSize;
824 __le64 EndofFile;
825 __le32 FileAttributes;
826 __le32 Reserved2;
827 __u64 PersistentFileId; /* opaque endianness */
828 __u64 VolatileFileId; /* opaque endianness */
829 __le32 CreateContextsOffset;
830 __le32 CreateContextsLength;
831 __u8 Buffer[1];
832} __packed;
833
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700834struct create_context {
835 __le32 Next;
836 __le16 NameOffset;
837 __le16 NameLength;
838 __le16 Reserved;
839 __le16 DataOffset;
840 __le32 DataLength;
Gustavo A. R. Silvacff2def2020-03-09 10:44:51 -0500841 __u8 Buffer[];
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700842} __packed;
843
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400844#define SMB2_LEASE_READ_CACHING_HE 0x01
845#define SMB2_LEASE_HANDLE_CACHING_HE 0x02
846#define SMB2_LEASE_WRITE_CACHING_HE 0x04
847
Fabian Frederickbc09d142014-12-10 15:41:15 -0800848#define SMB2_LEASE_NONE cpu_to_le32(0x00)
849#define SMB2_LEASE_READ_CACHING cpu_to_le32(0x01)
850#define SMB2_LEASE_HANDLE_CACHING cpu_to_le32(0x02)
851#define SMB2_LEASE_WRITE_CACHING cpu_to_le32(0x04)
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700852
Steve French8895c662020-03-17 01:53:39 -0500853#define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS cpu_to_le32(0x00000002)
Steve French5f60a562018-02-05 14:46:18 -0600854#define SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET cpu_to_le32(0x00000004)
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700855
856#define SMB2_LEASE_KEY_SIZE 16
857
858struct lease_context {
Stefano Brivio729c0c92018-07-05 15:10:02 +0200859 u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700860 __le32 LeaseState;
861 __le32 LeaseFlags;
862 __le64 LeaseDuration;
863} __packed;
864
Pavel Shilovskyf0473902013-09-04 13:44:05 +0400865struct lease_context_v2 {
Stefano Brivio729c0c92018-07-05 15:10:02 +0200866 u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
Pavel Shilovskyf0473902013-09-04 13:44:05 +0400867 __le32 LeaseState;
868 __le32 LeaseFlags;
869 __le64 LeaseDuration;
870 __le64 ParentLeaseKeyLow;
871 __le64 ParentLeaseKeyHigh;
872 __le16 Epoch;
873 __le16 Reserved;
874} __packed;
875
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700876struct create_lease {
877 struct create_context ccontext;
878 __u8 Name[8];
879 struct lease_context lcontext;
880} __packed;
881
Pavel Shilovskyf0473902013-09-04 13:44:05 +0400882struct create_lease_v2 {
883 struct create_context ccontext;
884 __u8 Name[8];
885 struct lease_context_v2 lcontext;
886 __u8 Pad[4];
887} __packed;
888
Pavel Shilovsky63eb3de2013-07-04 18:41:09 +0400889struct create_durable {
890 struct create_context ccontext;
891 __u8 Name[8];
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400892 union {
893 __u8 Reserved[16];
894 struct {
895 __u64 PersistentFileId;
896 __u64 VolatileFileId;
897 } Fid;
898 } Data;
Pavel Shilovsky63eb3de2013-07-04 18:41:09 +0400899} __packed;
900
Steve Frenchfe048402018-05-30 17:10:25 -0500901struct create_posix {
902 struct create_context ccontext;
903 __u8 Name[16];
904 __le32 Mode;
905 __u32 Reserved;
906} __packed;
907
Steve Frenchb56eae42015-11-03 09:26:27 -0600908/* See MS-SMB2 2.2.13.2.11 */
909/* Flags */
910#define SMB2_DHANDLE_FLAG_PERSISTENT 0x00000002
911struct durable_context_v2 {
912 __le32 Timeout;
913 __le32 Flags;
914 __u64 Reserved;
915 __u8 CreateGuid[16];
916} __packed;
917
918struct create_durable_v2 {
919 struct create_context ccontext;
920 __u8 Name[8];
921 struct durable_context_v2 dcontext;
922} __packed;
923
924/* See MS-SMB2 2.2.13.2.12 */
925struct durable_reconnect_context_v2 {
926 struct {
927 __u64 PersistentFileId;
928 __u64 VolatileFileId;
929 } Fid;
930 __u8 CreateGuid[16];
931 __le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
932} __packed;
933
Steve Frenche7348e32019-06-28 02:35:10 -0500934/* See MS-SMB2 2.2.14.2.9 */
Steve French89a5bfa2019-07-18 17:22:18 -0500935struct create_on_disk_id {
936 struct create_context ccontext;
937 __u8 Name[8];
Steve Frenche7348e32019-06-28 02:35:10 -0500938 __le64 DiskFileId;
939 __le64 VolumeId;
Steve Frenchff2a09e2019-07-06 14:41:38 -0500940 __u32 Reserved[4];
Steve Frenche7348e32019-06-28 02:35:10 -0500941} __packed;
942
Steve Frenchb56eae42015-11-03 09:26:27 -0600943/* See MS-SMB2 2.2.14.2.12 */
944struct durable_reconnect_context_v2_rsp {
945 __le32 Timeout;
946 __le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
947} __packed;
948
949struct create_durable_handle_reconnect_v2 {
950 struct create_context ccontext;
951 __u8 Name[8];
952 struct durable_reconnect_context_v2 dcontext;
Pavel Shilovskyd243af72019-11-06 13:58:15 -0800953 __u8 Pad[4];
Steve Frenchb56eae42015-11-03 09:26:27 -0600954} __packed;
955
Steve Frenchcdeaf9d2018-08-10 02:25:06 -0500956/* See MS-SMB2 2.2.13.2.5 */
957struct crt_twarp_ctxt {
958 struct create_context ccontext;
959 __u8 Name[8];
960 __le64 Timestamp;
961
962} __packed;
963
Steve Frenchff2a09e2019-07-06 14:41:38 -0500964/* See MS-SMB2 2.2.13.2.9 */
965struct crt_query_id_ctxt {
966 struct create_context ccontext;
967 __u8 Name[8];
968} __packed;
969
Steve Frenchfdef6652019-12-06 02:02:38 -0600970struct crt_sd_ctxt {
971 struct create_context ccontext;
972 __u8 Name[8];
973 struct smb3_sd sd;
Steve Frenchfdef6652019-12-06 02:02:38 -0600974} __packed;
975
976
Steve French41c13582013-11-14 00:05:36 -0600977#define COPY_CHUNK_RES_KEY_SIZE 24
978struct resume_key_req {
979 char ResumeKey[COPY_CHUNK_RES_KEY_SIZE];
980 __le32 ContextLength; /* MBZ */
Gustavo A. R. Silvacff2def2020-03-09 10:44:51 -0500981 char Context[]; /* ignored, Windows sets to 4 bytes of zero */
Steve French41c13582013-11-14 00:05:36 -0600982} __packed;
983
Steve Frenchbe7457d2013-06-19 17:41:10 -0500984/* this goes in the ioctl buffer when doing a copychunk request */
985struct copychunk_ioctl {
Steve French41c13582013-11-14 00:05:36 -0600986 char SourceKey[COPY_CHUNK_RES_KEY_SIZE];
Steve Frenchbe7457d2013-06-19 17:41:10 -0500987 __le32 ChunkCount; /* we are only sending 1 */
988 __le32 Reserved;
989 /* array will only be one chunk long for us */
990 __le64 SourceOffset;
991 __le64 TargetOffset;
Steve Frenchc8664732013-06-21 15:35:45 -0500992 __le32 Length; /* how many bytes to copy */
Steve Frenchbe7457d2013-06-19 17:41:10 -0500993 __u32 Reserved2;
994} __packed;
995
Steve French31742c52014-08-17 08:38:47 -0500996/* this goes in the ioctl buffer when doing FSCTL_SET_ZERO_DATA */
997struct file_zero_data_information {
998 __le64 FileOffset;
999 __le64 BeyondFinalZero;
1000} __packed;
1001
Steve French41c13582013-11-14 00:05:36 -06001002struct copychunk_ioctl_rsp {
1003 __le32 ChunksWritten;
1004 __le32 ChunkBytesWritten;
1005 __le32 TotalBytesWritten;
1006} __packed;
1007
Steve French7d03ae42020-10-23 15:21:38 -05001008/* See MS-FSCC 2.3.29 and 2.3.30 */
1009struct get_retrieval_pointer_count_req {
1010 __le64 StartingVcn; /* virtual cluster number (signed) */
1011} __packed;
1012
1013struct get_retrieval_pointer_count_rsp {
1014 __le32 ExtentCount;
1015} __packed;
1016
1017/*
1018 * See MS-FSCC 2.3.33 and 2.3.34
1019 * request is the same as get_retrieval_point_count_req struct above
1020 */
1021struct smb3_extents {
1022 __le64 NextVcn;
1023 __le64 Lcn; /* logical cluster number */
1024} __packed;
1025
1026struct get_retrieval_pointers_refcount_rsp {
1027 __le32 ExtentCount;
1028 __u32 Reserved;
1029 __le64 StartingVcn;
1030 struct smb3_extents extents[];
1031} __packed;
1032
Steve French9d1b0662015-06-24 02:12:19 -05001033struct fsctl_set_integrity_information_req {
1034 __le16 ChecksumAlgorithm;
1035 __le16 Reserved;
1036 __le32 Flags;
1037} __packed;
1038
1039struct fsctl_get_integrity_information_rsp {
1040 __le16 ChecksumAlgorithm;
1041 __le16 Reserved;
1042 __le32 Flags;
1043 __le32 ChecksumChunkSizeInBytes;
1044 __le32 ClusterSizeInBytes;
1045} __packed;
1046
Ronnie Sahlberg2f3ebab2019-04-25 16:45:29 +10001047struct file_allocated_range_buffer {
1048 __le64 file_offset;
1049 __le64 length;
1050} __packed;
1051
Steve French9d1b0662015-06-24 02:12:19 -05001052/* Integrity ChecksumAlgorithm choices for above */
1053#define CHECKSUM_TYPE_NONE 0x0000
1054#define CHECKSUM_TYPE_CRC64 0x0002
Steve Frenchb3152e22015-06-24 03:17:02 -05001055#define CHECKSUM_TYPE_UNCHANGED 0xFFFF /* set only */
Steve French9d1b0662015-06-24 02:12:19 -05001056
1057/* Integrity flags for above */
1058#define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF 0x00000001
1059
Steve French0df444a2018-10-31 11:24:33 -05001060/* Reparse structures - see MS-FSCC 2.1.2 */
1061
1062/* struct fsctl_reparse_info_req is empty, only response structs (see below) */
1063
1064struct reparse_data_buffer {
1065 __le32 ReparseTag;
1066 __le16 ReparseDataLength;
1067 __u16 Reserved;
Gustavo A. R. Silvacff2def2020-03-09 10:44:51 -05001068 __u8 DataBuffer[]; /* Variable Length */
Steve French0df444a2018-10-31 11:24:33 -05001069} __packed;
1070
1071struct reparse_guid_data_buffer {
1072 __le32 ReparseTag;
1073 __le16 ReparseDataLength;
1074 __u16 Reserved;
1075 __u8 ReparseGuid[16];
Gustavo A. R. Silvacff2def2020-03-09 10:44:51 -05001076 __u8 DataBuffer[]; /* Variable Length */
Steve French0df444a2018-10-31 11:24:33 -05001077} __packed;
1078
1079struct reparse_mount_point_data_buffer {
1080 __le32 ReparseTag;
1081 __le16 ReparseDataLength;
1082 __u16 Reserved;
1083 __le16 SubstituteNameOffset;
1084 __le16 SubstituteNameLength;
1085 __le16 PrintNameOffset;
1086 __le16 PrintNameLength;
Gustavo A. R. Silvacff2def2020-03-09 10:44:51 -05001087 __u8 PathBuffer[]; /* Variable Length */
Steve French0df444a2018-10-31 11:24:33 -05001088} __packed;
1089
Ronnie Sahlberg5de254d2019-06-27 14:57:02 +10001090#define SYMLINK_FLAG_RELATIVE 0x00000001
1091
1092struct reparse_symlink_data_buffer {
1093 __le32 ReparseTag;
1094 __le16 ReparseDataLength;
1095 __u16 Reserved;
1096 __le16 SubstituteNameOffset;
1097 __le16 SubstituteNameLength;
1098 __le16 PrintNameOffset;
1099 __le16 PrintNameLength;
1100 __le32 Flags;
Gustavo A. R. Silvacff2def2020-03-09 10:44:51 -05001101 __u8 PathBuffer[]; /* Variable Length */
Ronnie Sahlberg5de254d2019-06-27 14:57:02 +10001102} __packed;
Steve French0df444a2018-10-31 11:24:33 -05001103
1104/* See MS-FSCC 2.1.2.6 and cifspdu.h for struct reparse_posix_data */
1105
1106
Aurelien Aptel9d496402017-02-13 16:16:49 +01001107/* See MS-DFSC 2.2.2 */
1108struct fsctl_get_dfs_referral_req {
1109 __le16 MaxReferralLevel;
1110 __u8 RequestFileName[];
1111} __packed;
1112
1113/* DFS response is struct get_dfs_refer_rsp */
1114
Steve Frenchb56eae42015-11-03 09:26:27 -06001115/* See MS-SMB2 2.2.31.3 */
1116struct network_resiliency_req {
1117 __le32 Timeout;
1118 __le32 Reserved;
1119} __packed;
1120/* There is no buffer for the response ie no struct network_resiliency_rsp */
1121
Steve French9d1b0662015-06-24 02:12:19 -05001122
Steve Frenchff1c0382013-11-19 23:44:46 -06001123struct validate_negotiate_info_req {
Steve French4a72daf2013-06-25 00:20:49 -05001124 __le32 Capabilities;
1125 __u8 Guid[SMB2_CLIENT_GUID_SIZE];
1126 __le16 SecurityMode;
1127 __le16 DialectCount;
Steve Frenchd5c70762019-01-03 02:37:21 -06001128 __le16 Dialects[4]; /* BB expand this if autonegotiate > 4 dialects */
Steve Frenchff1c0382013-11-19 23:44:46 -06001129} __packed;
1130
1131struct validate_negotiate_info_rsp {
1132 __le32 Capabilities;
1133 __u8 Guid[SMB2_CLIENT_GUID_SIZE];
1134 __le16 SecurityMode;
1135 __le16 Dialect; /* Dialect in use for the connection */
Steve French4a72daf2013-06-25 00:20:49 -05001136} __packed;
1137
Aurelien Aptelbead0422018-06-14 15:43:17 +02001138#define RSS_CAPABLE cpu_to_le32(0x00000001)
1139#define RDMA_CAPABLE cpu_to_le32(0x00000002)
1140
1141#define INTERNETWORK cpu_to_le16(0x0002)
1142#define INTERNETWORKV6 cpu_to_le16(0x0017)
Steve French4a72daf2013-06-25 00:20:49 -05001143
1144struct network_interface_info_ioctl_rsp {
1145 __le32 Next; /* next interface. zero if this is last one */
1146 __le32 IfIndex;
1147 __le32 Capability; /* RSS or RDMA Capable */
1148 __le32 Reserved;
1149 __le64 LinkSpeed;
Aurelien Aptelbead0422018-06-14 15:43:17 +02001150 __le16 Family;
1151 __u8 Buffer[126];
1152} __packed;
1153
1154struct iface_info_ipv4 {
1155 __be16 Port;
1156 __be32 IPv4Address;
1157 __be64 Reserved;
1158} __packed;
1159
1160struct iface_info_ipv6 {
1161 __be16 Port;
1162 __be32 FlowInfo;
1163 __u8 IPv6Address[16];
1164 __be32 ScopeId;
Steve French4a72daf2013-06-25 00:20:49 -05001165} __packed;
1166
1167#define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */
1168
Steve French64a5cfa2013-10-14 15:31:32 -05001169struct compress_ioctl {
Steve Frenchc7f508a2013-10-14 15:27:32 -05001170 __le16 CompressionState; /* See cifspdu.h for possible flag values */
Steve French64a5cfa2013-10-14 15:31:32 -05001171} __packed;
1172
Steve French02b16662015-06-27 21:18:36 -07001173struct duplicate_extents_to_file {
1174 __u64 PersistentFileHandle; /* source file handle, opaque endianness */
1175 __u64 VolatileFileHandle;
1176 __le64 SourceFileOffset;
1177 __le64 TargetFileOffset;
1178 __le64 ByteCount; /* Bytes to be copied */
1179} __packed;
1180
Ronnie Sahlberg72c419d2019-03-13 14:37:49 +10001181/*
1182 * Maximum number of iovs we need for an ioctl request.
1183 * [0] : struct smb2_ioctl_req
1184 * [1] : in_data
1185 */
1186#define SMB2_IOCTL_IOV_SIZE 2
1187
Steve Frenchbe7457d2013-06-19 17:41:10 -05001188struct smb2_ioctl_req {
Ronnie Sahlberg97754682017-11-09 12:14:20 +11001189 struct smb2_sync_hdr sync_hdr;
Steve Frenchbe7457d2013-06-19 17:41:10 -05001190 __le16 StructureSize; /* Must be 57 */
1191 __u16 Reserved;
1192 __le32 CtlCode;
1193 __u64 PersistentFileId; /* opaque endianness */
1194 __u64 VolatileFileId; /* opaque endianness */
1195 __le32 InputOffset;
1196 __le32 InputCount;
1197 __le32 MaxInputResponse;
1198 __le32 OutputOffset;
1199 __le32 OutputCount;
1200 __le32 MaxOutputResponse;
1201 __le32 Flags;
1202 __u32 Reserved2;
Gustavo A. R. Silvacff2def2020-03-09 10:44:51 -05001203 __u8 Buffer[];
Steve Frenchbe7457d2013-06-19 17:41:10 -05001204} __packed;
1205
1206struct smb2_ioctl_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001207 struct smb2_sync_hdr sync_hdr;
Steve Frenchbe7457d2013-06-19 17:41:10 -05001208 __le16 StructureSize; /* Must be 57 */
1209 __u16 Reserved;
1210 __le32 CtlCode;
1211 __u64 PersistentFileId; /* opaque endianness */
1212 __u64 VolatileFileId; /* opaque endianness */
1213 __le32 InputOffset;
1214 __le32 InputCount;
1215 __le32 OutputOffset;
1216 __le32 OutputCount;
1217 __le32 Flags;
1218 __u32 Reserved2;
1219 /* char * buffer[] */
1220} __packed;
1221
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +04001222/* Currently defined values for close flags */
1223#define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
1224struct smb2_close_req {
Ronnie Sahlbergafcccef2017-11-09 12:14:19 +11001225 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +04001226 __le16 StructureSize; /* Must be 24 */
1227 __le16 Flags;
1228 __le32 Reserved;
1229 __u64 PersistentFileId; /* opaque endianness */
1230 __u64 VolatileFileId; /* opaque endianness */
1231} __packed;
1232
Ronnie Sahlbergc4627e62019-01-29 12:46:17 +10001233/*
1234 * Maximum size of a SMB2_CLOSE response is 64 (smb2 header) + 60 (data)
1235 */
1236#define MAX_SMB2_CLOSE_RESPONSE_SIZE 124
1237
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +04001238struct smb2_close_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001239 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +04001240 __le16 StructureSize; /* 60 */
1241 __le16 Flags;
1242 __le32 Reserved;
1243 __le64 CreationTime;
1244 __le64 LastAccessTime;
1245 __le64 LastWriteTime;
1246 __le64 ChangeTime;
1247 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
1248 __le64 EndOfFile;
1249 __le32 Attributes;
1250} __packed;
1251
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -07001252struct smb2_flush_req {
Ronnie Sahlberg1f444e42017-11-20 11:24:39 +11001253 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -07001254 __le16 StructureSize; /* Must be 24 */
1255 __le16 Reserved1;
1256 __le32 Reserved2;
1257 __u64 PersistentFileId; /* opaque endianness */
1258 __u64 VolatileFileId; /* opaque endianness */
1259} __packed;
1260
1261struct smb2_flush_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001262 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -07001263 __le16 StructureSize;
1264 __le16 Reserved;
1265} __packed;
1266
Steve French2b5dc282013-06-13 10:51:10 -05001267/* For read request Flags field below, following flag is defined for SMB3.02 */
1268#define SMB2_READFLAG_READ_UNBUFFERED 0x01
Steve French0df7edd2019-04-27 02:06:20 -05001269#define SMB2_READFLAG_REQUEST_COMPRESSED 0x02 /* See MS-SMB2 2.2.19 */
Steve French2b5dc282013-06-13 10:51:10 -05001270
1271/* Channel field for read and write: exactly one of following flags can be set*/
Steve French2026b062018-01-24 23:07:41 -06001272#define SMB2_CHANNEL_NONE cpu_to_le32(0x00000000)
1273#define SMB2_CHANNEL_RDMA_V1 cpu_to_le32(0x00000001) /* SMB3 or later */
1274#define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002) /* >= SMB3.02 */
Steve French3984bdc2020-10-04 17:42:27 -05001275#define SMB2_CHANNEL_RDMA_TRANSFORM cpu_to_le32(0x00000003) /* >= SMB3.02, only used on write */
Steve French2b5dc282013-06-13 10:51:10 -05001276
Pavel Shilovskyb8f57ee2016-11-23 15:31:54 -08001277/* SMB2 read request without RFC1001 length at the beginning */
1278struct smb2_read_plain_req {
1279 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001280 __le16 StructureSize; /* Must be 49 */
1281 __u8 Padding; /* offset from start of SMB2 header to place read */
Steve French2b5dc282013-06-13 10:51:10 -05001282 __u8 Flags; /* MBZ unless SMB3.02 or later */
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001283 __le32 Length;
1284 __le64 Offset;
1285 __u64 PersistentFileId; /* opaque endianness */
1286 __u64 VolatileFileId; /* opaque endianness */
1287 __le32 MinimumCount;
Steve French2b5dc282013-06-13 10:51:10 -05001288 __le32 Channel; /* MBZ except for SMB3 or later */
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001289 __le32 RemainingBytes;
Steve French2026b062018-01-24 23:07:41 -06001290 __le16 ReadChannelInfoOffset;
1291 __le16 ReadChannelInfoLength;
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001292 __u8 Buffer[1];
1293} __packed;
1294
Steve French3984bdc2020-10-04 17:42:27 -05001295/* Read flags */
1296#define SMB2_READFLAG_RESPONSE_NONE 0x00000000
1297#define SMB2_READFLAG_RESPONSE_RDMA_TRANSFORM 0x00000001
1298
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001299struct smb2_read_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001300 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001301 __le16 StructureSize; /* Must be 17 */
1302 __u8 DataOffset;
1303 __u8 Reserved;
1304 __le32 DataLength;
1305 __le32 DataRemaining;
Steve French3984bdc2020-10-04 17:42:27 -05001306 __u32 Flags;
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001307 __u8 Buffer[1];
1308} __packed;
1309
Steve French2b5dc282013-06-13 10:51:10 -05001310/* For write request Flags field below the following flags are defined: */
1311#define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 /* SMB2.1 or later */
1312#define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002 /* SMB3.02 or later */
Pavel Shilovsky33319142012-09-18 16:20:29 -07001313
1314struct smb2_write_req {
Ronnie Sahlbergf5688a62017-11-20 11:24:41 +11001315 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky33319142012-09-18 16:20:29 -07001316 __le16 StructureSize; /* Must be 49 */
1317 __le16 DataOffset; /* offset from start of SMB2 header to write data */
1318 __le32 Length;
1319 __le64 Offset;
1320 __u64 PersistentFileId; /* opaque endianness */
1321 __u64 VolatileFileId; /* opaque endianness */
Steve French8f233432020-03-15 18:04:13 -05001322 __le32 Channel; /* MBZ unless SMB3.02 or later */
Pavel Shilovsky33319142012-09-18 16:20:29 -07001323 __le32 RemainingBytes;
Steve French2026b062018-01-24 23:07:41 -06001324 __le16 WriteChannelInfoOffset;
1325 __le16 WriteChannelInfoLength;
Pavel Shilovsky33319142012-09-18 16:20:29 -07001326 __le32 Flags;
1327 __u8 Buffer[1];
1328} __packed;
1329
1330struct smb2_write_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001331 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky33319142012-09-18 16:20:29 -07001332 __le16 StructureSize; /* Must be 17 */
1333 __u8 DataOffset;
1334 __u8 Reserved;
1335 __le32 DataLength;
1336 __le32 DataRemaining;
1337 __u32 Reserved2;
1338 __u8 Buffer[1];
1339} __packed;
1340
Steve Frenchedf3ef32019-05-05 17:25:12 -05001341/* notify flags */
1342#define SMB2_WATCH_TREE 0x0001
1343
1344/* notify completion filter flags. See MS-FSCC 2.6 and MS-SMB2 2.2.35 */
1345#define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001
1346#define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002
1347#define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004
1348#define FILE_NOTIFY_CHANGE_SIZE 0x00000008
1349#define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010
1350#define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020
1351#define FILE_NOTIFY_CHANGE_CREATION 0x00000040
1352#define FILE_NOTIFY_CHANGE_EA 0x00000080
1353#define FILE_NOTIFY_CHANGE_SECURITY 0x00000100
1354#define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200
1355#define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400
1356#define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
1357
1358struct smb2_change_notify_req {
1359 struct smb2_sync_hdr sync_hdr;
1360 __le16 StructureSize;
1361 __le16 Flags;
1362 __le32 OutputBufferLength;
1363 __u64 PersistentFileId; /* opaque endianness */
1364 __u64 VolatileFileId; /* opaque endianness */
1365 __le32 CompletionFilter;
1366 __u32 Reserved;
1367} __packed;
1368
1369struct smb2_change_notify_rsp {
1370 struct smb2_sync_hdr sync_hdr;
1371 __le16 StructureSize; /* Must be 9 */
1372 __le16 OutputBufferOffset;
1373 __le32 OutputBufferLength;
1374 __u8 Buffer[1]; /* array of file notify structs */
1375} __packed;
1376
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07001377#define SMB2_LOCKFLAG_SHARED_LOCK 0x0001
1378#define SMB2_LOCKFLAG_EXCLUSIVE_LOCK 0x0002
1379#define SMB2_LOCKFLAG_UNLOCK 0x0004
1380#define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010
1381
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07001382struct smb2_lock_element {
1383 __le64 Offset;
1384 __le64 Length;
1385 __le32 Flags;
1386 __le32 Reserved;
1387} __packed;
1388
1389struct smb2_lock_req {
Ronnie Sahlbergced93672017-11-21 10:07:27 +11001390 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07001391 __le16 StructureSize; /* Must be 48 */
1392 __le16 LockCount;
1393 __le32 Reserved;
1394 __u64 PersistentFileId; /* opaque endianness */
1395 __u64 VolatileFileId; /* opaque endianness */
1396 /* Followed by at least one */
1397 struct smb2_lock_element locks[1];
1398} __packed;
1399
1400struct smb2_lock_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001401 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07001402 __le16 StructureSize; /* Must be 4 */
1403 __le16 Reserved;
1404} __packed;
1405
Pavel Shilovsky9094fad2012-07-12 18:30:44 +04001406struct smb2_echo_req {
Ronnie Sahlberg7f7ae752017-11-09 12:14:21 +11001407 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky9094fad2012-07-12 18:30:44 +04001408 __le16 StructureSize; /* Must be 4 */
1409 __u16 Reserved;
1410} __packed;
1411
1412struct smb2_echo_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001413 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky9094fad2012-07-12 18:30:44 +04001414 __le16 StructureSize; /* Must be 4 */
1415 __u16 Reserved;
1416} __packed;
1417
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001418/* search (query_directory) Flags field */
1419#define SMB2_RESTART_SCANS 0x01
1420#define SMB2_RETURN_SINGLE_ENTRY 0x02
1421#define SMB2_INDEX_SPECIFIED 0x04
1422#define SMB2_REOPEN 0x10
1423
Ronnie Sahlberg0a177992020-01-08 13:08:04 +10001424#define SMB2_QUERY_DIRECTORY_IOV_SIZE 2
1425
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001426struct smb2_query_directory_req {
Ronnie Sahlberg7c00c3a2017-11-20 11:24:45 +11001427 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001428 __le16 StructureSize; /* Must be 33 */
1429 __u8 FileInformationClass;
1430 __u8 Flags;
1431 __le32 FileIndex;
1432 __u64 PersistentFileId; /* opaque endianness */
1433 __u64 VolatileFileId; /* opaque endianness */
1434 __le16 FileNameOffset;
1435 __le16 FileNameLength;
1436 __le32 OutputBufferLength;
1437 __u8 Buffer[1];
1438} __packed;
1439
1440struct smb2_query_directory_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001441 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001442 __le16 StructureSize; /* Must be 9 */
1443 __le16 OutputBufferOffset;
1444 __le32 OutputBufferLength;
1445 __u8 Buffer[1];
1446} __packed;
1447
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001448/* Possible InfoType values */
1449#define SMB2_O_INFO_FILE 0x01
1450#define SMB2_O_INFO_FILESYSTEM 0x02
1451#define SMB2_O_INFO_SECURITY 0x03
1452#define SMB2_O_INFO_QUOTA 0x04
1453
Steve French911a8df2014-10-19 19:18:05 -05001454/* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */
1455#define OWNER_SECINFO 0x00000001
1456#define GROUP_SECINFO 0x00000002
1457#define DACL_SECINFO 0x00000004
1458#define SACL_SECINFO 0x00000008
1459#define LABEL_SECINFO 0x00000010
1460#define ATTRIBUTE_SECINFO 0x00000020
1461#define SCOPE_SECINFO 0x00000040
1462#define BACKUP_SECINFO 0x00010000
1463#define UNPROTECTED_SACL_SECINFO 0x10000000
1464#define UNPROTECTED_DACL_SECINFO 0x20000000
1465#define PROTECTED_SACL_SECINFO 0x40000000
1466#define PROTECTED_DACL_SECINFO 0x80000000
1467
1468/* Flags used for FileFullEAinfo */
1469#define SL_RESTART_SCAN 0x00000001
1470#define SL_RETURN_SINGLE_ENTRY 0x00000002
1471#define SL_INDEX_SPECIFIED 0x00000004
1472
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001473struct smb2_query_info_req {
Ronnie Sahlbergb2fb7fe2017-11-20 11:24:46 +11001474 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001475 __le16 StructureSize; /* Must be 41 */
1476 __u8 InfoType;
1477 __u8 FileInfoClass;
1478 __le32 OutputBufferLength;
1479 __le16 InputBufferOffset;
1480 __u16 Reserved;
1481 __le32 InputBufferLength;
1482 __le32 AdditionalInformation;
1483 __le32 Flags;
1484 __u64 PersistentFileId; /* opaque endianness */
1485 __u64 VolatileFileId; /* opaque endianness */
1486 __u8 Buffer[1];
1487} __packed;
1488
1489struct smb2_query_info_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001490 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001491 __le16 StructureSize; /* Must be 9 */
1492 __le16 OutputBufferOffset;
1493 __le32 OutputBufferLength;
1494 __u8 Buffer[1];
1495} __packed;
1496
Ronnie Sahlberg14e562a2018-09-03 13:33:50 +10001497/*
1498 * Maximum number of iovs we need for a set-info request.
1499 * The largest one is rename/hardlink
1500 * [0] : struct smb2_set_info_req + smb2_file_[rename|link]_info
1501 * [1] : path
1502 * [2] : compound padding
1503 */
1504#define SMB2_SET_INFO_IOV_SIZE 3
1505
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07001506struct smb2_set_info_req {
Ronnie Sahlberg2fc803e2017-11-20 11:24:44 +11001507 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07001508 __le16 StructureSize; /* Must be 33 */
1509 __u8 InfoType;
1510 __u8 FileInfoClass;
1511 __le32 BufferLength;
1512 __le16 BufferOffset;
1513 __u16 Reserved;
1514 __le32 AdditionalInformation;
1515 __u64 PersistentFileId; /* opaque endianness */
1516 __u64 VolatileFileId; /* opaque endianness */
1517 __u8 Buffer[1];
1518} __packed;
1519
1520struct smb2_set_info_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001521 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07001522 __le16 StructureSize; /* Must be 2 */
1523} __packed;
1524
Ronnie Sahlberg0d5a2882018-06-01 10:53:03 +10001525struct smb2_oplock_break {
Ronnie Sahlberg21ad9482017-11-20 11:24:43 +11001526 struct smb2_sync_hdr sync_hdr;
1527 __le16 StructureSize; /* Must be 24 */
1528 __u8 OplockLevel;
1529 __u8 Reserved;
1530 __le32 Reserved2;
1531 __u64 PersistentFid;
1532 __u64 VolatileFid;
1533} __packed;
1534
Pavel Shilovsky0822f512012-09-19 06:22:45 -07001535#define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
1536
1537struct smb2_lease_break {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001538 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky0822f512012-09-19 06:22:45 -07001539 __le16 StructureSize; /* Must be 44 */
Pavel Shilovsky9bd45402019-10-29 16:51:19 -07001540 __le16 Epoch;
Pavel Shilovsky0822f512012-09-19 06:22:45 -07001541 __le32 Flags;
1542 __u8 LeaseKey[16];
1543 __le32 CurrentLeaseState;
1544 __le32 NewLeaseState;
1545 __le32 BreakReason;
1546 __le32 AccessMaskHint;
1547 __le32 ShareMaskHint;
1548} __packed;
1549
1550struct smb2_lease_ack {
Ronnie Sahlberg8eb79982017-11-21 11:04:37 +11001551 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky0822f512012-09-19 06:22:45 -07001552 __le16 StructureSize; /* Must be 36 */
1553 __le16 Reserved;
1554 __le32 Flags;
1555 __u8 LeaseKey[16];
1556 __le32 LeaseState;
1557 __le64 LeaseDuration;
1558} __packed;
1559
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001560/*
1561 * PDU infolevel structure definitions
1562 * BB consider moving to a different header
1563 */
1564
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001565/* File System Information Classes */
1566#define FS_VOLUME_INFORMATION 1 /* Query */
Steven Frenchaf6a12e2013-10-09 20:55:53 -05001567#define FS_LABEL_INFORMATION 2 /* Local only */
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001568#define FS_SIZE_INFORMATION 3 /* Query */
1569#define FS_DEVICE_INFORMATION 4 /* Query */
1570#define FS_ATTRIBUTE_INFORMATION 5 /* Query */
1571#define FS_CONTROL_INFORMATION 6 /* Query, Set */
1572#define FS_FULL_SIZE_INFORMATION 7 /* Query */
1573#define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */
Steven Frenchaf6a12e2013-10-09 20:55:53 -05001574#define FS_DRIVER_PATH_INFORMATION 9 /* Local only */
1575#define FS_VOLUME_FLAGS_INFORMATION 10 /* Local only */
1576#define FS_SECTOR_SIZE_INFORMATION 11 /* SMB3 or later. Query */
Steve French2d304212018-06-24 23:28:12 -05001577#define FS_POSIX_INFORMATION 100 /* SMB3.1.1 POSIX. Query */
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001578
1579struct smb2_fs_full_size_info {
1580 __le64 TotalAllocationUnits;
1581 __le64 CallerAvailableAllocationUnits;
1582 __le64 ActualAvailableAllocationUnits;
1583 __le32 SectorsPerAllocationUnit;
1584 __le32 BytesPerSector;
1585} __packed;
1586
Steven Frenchaf6a12e2013-10-09 20:55:53 -05001587#define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001
1588#define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
1589#define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004
1590#define SSINFO_FLAGS_TRIM_ENABLED 0x00000008
1591
1592/* sector size info struct */
1593struct smb3_fs_ss_info {
1594 __le32 LogicalBytesPerSector;
1595 __le32 PhysicalBytesPerSectorForAtomicity;
1596 __le32 PhysicalBytesPerSectorForPerf;
1597 __le32 FileSystemEffectivePhysicalBytesPerSectorForAtomicity;
1598 __le32 Flags;
1599 __le32 ByteOffsetForSectorAlignment;
1600 __le32 ByteOffsetForPartitionAlignment;
1601} __packed;
1602
Steve French21ba3842018-06-24 23:18:52 -05001603/* volume info struct - see MS-FSCC 2.5.9 */
1604#define MAX_VOL_LABEL_LEN 32
1605struct smb3_fs_vol_info {
1606 __le64 VolumeCreationTime;
1607 __u32 VolumeSerialNumber;
1608 __le32 VolumeLabelLength; /* includes trailing null */
1609 __u8 SupportsObjects; /* True if eg like NTFS, supports objects */
1610 __u8 Reserved;
Gustavo A. R. Silvacff2def2020-03-09 10:44:51 -05001611 __u8 VolumeLabel[]; /* variable len */
Steve French21ba3842018-06-24 23:18:52 -05001612} __packed;
1613
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001614/* partial list of QUERY INFO levels */
1615#define FILE_DIRECTORY_INFORMATION 1
1616#define FILE_FULL_DIRECTORY_INFORMATION 2
1617#define FILE_BOTH_DIRECTORY_INFORMATION 3
1618#define FILE_BASIC_INFORMATION 4
1619#define FILE_STANDARD_INFORMATION 5
1620#define FILE_INTERNAL_INFORMATION 6
1621#define FILE_EA_INFORMATION 7
1622#define FILE_ACCESS_INFORMATION 8
1623#define FILE_NAME_INFORMATION 9
1624#define FILE_RENAME_INFORMATION 10
1625#define FILE_LINK_INFORMATION 11
1626#define FILE_NAMES_INFORMATION 12
1627#define FILE_DISPOSITION_INFORMATION 13
1628#define FILE_POSITION_INFORMATION 14
1629#define FILE_FULL_EA_INFORMATION 15
1630#define FILE_MODE_INFORMATION 16
1631#define FILE_ALIGNMENT_INFORMATION 17
1632#define FILE_ALL_INFORMATION 18
1633#define FILE_ALLOCATION_INFORMATION 19
1634#define FILE_END_OF_FILE_INFORMATION 20
1635#define FILE_ALTERNATE_NAME_INFORMATION 21
1636#define FILE_STREAM_INFORMATION 22
1637#define FILE_PIPE_INFORMATION 23
1638#define FILE_PIPE_LOCAL_INFORMATION 24
1639#define FILE_PIPE_REMOTE_INFORMATION 25
1640#define FILE_MAILSLOT_QUERY_INFORMATION 26
1641#define FILE_MAILSLOT_SET_INFORMATION 27
1642#define FILE_COMPRESSION_INFORMATION 28
1643#define FILE_OBJECT_ID_INFORMATION 29
1644/* Number 30 not defined in documents */
1645#define FILE_MOVE_CLUSTER_INFORMATION 31
1646#define FILE_QUOTA_INFORMATION 32
1647#define FILE_REPARSE_POINT_INFORMATION 33
1648#define FILE_NETWORK_OPEN_INFORMATION 34
1649#define FILE_ATTRIBUTE_TAG_INFORMATION 35
1650#define FILE_TRACKING_INFORMATION 36
1651#define FILEID_BOTH_DIRECTORY_INFORMATION 37
1652#define FILEID_FULL_DIRECTORY_INFORMATION 38
1653#define FILE_VALID_DATA_LENGTH_INFORMATION 39
1654#define FILE_SHORT_NAME_INFORMATION 40
1655#define FILE_SFIO_RESERVE_INFORMATION 44
1656#define FILE_SFIO_VOLUME_INFORMATION 45
1657#define FILE_HARD_LINK_INFORMATION 46
1658#define FILE_NORMALIZED_NAME_INFORMATION 48
1659#define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
1660#define FILE_STANDARD_LINK_INFORMATION 54
Steve French51d92d62020-02-06 12:32:03 -06001661#define FILE_ID_INFORMATION 59
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001662
Pavel Shilovskyf0df7372012-09-18 16:20:26 -07001663struct smb2_file_internal_info {
1664 __le64 IndexNumber;
1665} __packed; /* level 6 Query */
1666
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07001667struct smb2_file_rename_info { /* encoding of request for level 10 */
1668 __u8 ReplaceIfExists; /* 1 = replace existing target with new */
1669 /* 0 = fail if target already exists */
1670 __u8 Reserved[7];
1671 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1672 __le32 FileNameLength;
Gustavo A. R. Silvacff2def2020-03-09 10:44:51 -05001673 char FileName[]; /* New name to be assigned */
Steve French7d03ae42020-10-23 15:21:38 -05001674 /* padding - overall struct size must be >= 24 so filename + pad >= 6 */
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07001675} __packed; /* level 10 Set */
1676
Pavel Shilovsky568798c2012-09-18 16:20:31 -07001677struct smb2_file_link_info { /* encoding of request for level 11 */
1678 __u8 ReplaceIfExists; /* 1 = replace existing link with new */
1679 /* 0 = fail if link already exists */
1680 __u8 Reserved[7];
1681 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1682 __le32 FileNameLength;
Gustavo A. R. Silvacff2def2020-03-09 10:44:51 -05001683 char FileName[]; /* Name to be assigned to new link */
Pavel Shilovsky568798c2012-09-18 16:20:31 -07001684} __packed; /* level 11 Set */
1685
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +10001686struct smb2_file_full_ea_info { /* encoding of response for level 15 */
1687 __le32 next_entry_offset;
1688 __u8 flags;
1689 __u8 ea_name_length;
1690 __le16 ea_value_length;
Gustavo A. R. Silvacff2def2020-03-09 10:44:51 -05001691 char ea_data[]; /* \0 terminated name plus value */
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +10001692} __packed; /* level 15 Set */
1693
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001694/*
1695 * This level 18, although with struct with same name is different from cifs
1696 * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
1697 * CurrentByteOffset.
1698 */
1699struct smb2_file_all_info { /* data block encoding of response to level 18 */
1700 __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
1701 __le64 LastAccessTime;
1702 __le64 LastWriteTime;
1703 __le64 ChangeTime;
1704 __le32 Attributes;
1705 __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
1706 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
1707 __le64 EndOfFile; /* size ie offset to first free byte in file */
1708 __le32 NumberOfLinks; /* hard links */
1709 __u8 DeletePending;
1710 __u8 Directory;
1711 __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */
1712 __le64 IndexNumber;
1713 __le32 EASize;
1714 __le32 AccessFlags;
1715 __le64 CurrentByteOffset;
1716 __le32 Mode;
1717 __le32 AlignmentRequirement;
1718 __le32 FileNameLength;
1719 char FileName[1];
1720} __packed; /* level 18 Query */
1721
Pavel Shilovskyc839ff22012-09-18 16:20:32 -07001722struct smb2_file_eof_info { /* encoding of request for level 10 */
1723 __le64 EndOfFile; /* new end of file value */
1724} __packed; /* level 20 Set */
1725
Steve French2e4564b2020-10-22 22:03:14 -05001726struct smb2_file_reparse_point_info {
1727 __le64 IndexNumber;
1728 __le32 Tag;
1729} __packed;
1730
Steve French43f8a6a2019-12-02 21:46:54 -06001731struct smb2_file_network_open_info {
1732 __le64 CreationTime;
1733 __le64 LastAccessTime;
1734 __le64 LastWriteTime;
1735 __le64 ChangeTime;
1736 __le64 AllocationSize;
1737 __le64 EndOfFile;
1738 __le32 Attributes;
1739 __le32 Reserved;
1740} __packed; /* level 34 Query also similar returned in close rsp and open rsp */
1741
Steve French51d92d62020-02-06 12:32:03 -06001742/* See MS-FSCC 2.4.43 */
1743struct smb2_file_id_information {
1744 __le64 VolumeSerialNumber;
1745 __u64 PersistentFileId; /* opaque endianness */
1746 __u64 VolatileFileId; /* opaque endianness */
1747} __packed; /* level 59 */
1748
Ronnie Sahlberg730928c2018-08-08 15:07:49 +10001749extern char smb2_padding[7];
1750
Steve Frenchab3459d2020-02-06 17:31:56 -06001751/* equivalent of the contents of SMB3.1.1 POSIX open context response */
Aurelien Aptel2e8af972020-02-08 15:50:56 +01001752struct create_posix_rsp {
Aurelien Aptel69dda302020-03-02 17:53:22 +01001753 u32 nlink;
1754 u32 reparse_tag;
1755 u32 mode;
1756 struct cifs_sid owner; /* var-sized on the wire */
1757 struct cifs_sid group; /* var-sized on the wire */
Aurelien Aptel2e8af972020-02-08 15:50:56 +01001758} __packed;
Aurelien Aptel349e13a2020-02-08 15:50:57 +01001759
1760/*
Steve French6a5f6592020-06-11 19:25:47 -05001761 * SMB2-only POSIX info level for query dir
Aurelien Aptel349e13a2020-02-08 15:50:57 +01001762 *
1763 * See posix_info_sid_size(), posix_info_extra_size() and
1764 * posix_info_parse() to help with the handling of this struct.
1765 */
1766struct smb2_posix_info {
1767 __le32 NextEntryOffset;
1768 __u32 Ignored;
1769 __le64 CreationTime;
1770 __le64 LastAccessTime;
1771 __le64 LastWriteTime;
1772 __le64 ChangeTime;
1773 __le64 EndOfFile;
1774 __le64 AllocationSize;
1775 __le32 DosAttributes;
1776 __le64 Inode;
1777 __le32 DeviceId;
1778 __le32 Zero;
1779 /* beginning of POSIX Create Context Response */
1780 __le32 HardLinks;
1781 __le32 ReparseTag;
1782 __le32 Mode;
1783 /*
1784 * var sized owner SID
1785 * var sized group SID
1786 * le32 filenamelength
1787 * u8 filename[]
1788 */
1789} __packed;
1790
Steve French6a5f6592020-06-11 19:25:47 -05001791/* Level 100 query info */
1792struct smb311_posix_qinfo {
1793 __le64 CreationTime;
1794 __le64 LastAccessTime;
1795 __le64 LastWriteTime;
1796 __le64 ChangeTime;
1797 __le64 EndOfFile;
1798 __le64 AllocationSize;
1799 __le32 DosAttributes;
1800 __le64 Inode;
1801 __le32 DeviceId;
1802 __le32 Zero;
1803 /* beginning of POSIX Create Context Response */
1804 __le32 HardLinks;
1805 __le32 ReparseTag;
1806 __le32 Mode;
1807 u8 Sids[];
1808 /*
1809 * var sized owner SID
1810 * var sized group SID
1811 * le32 filenamelength
1812 * u8 filename[]
1813 */
1814} __packed;
1815
Aurelien Aptel349e13a2020-02-08 15:50:57 +01001816/*
1817 * Parsed version of the above struct. Allows direct access to the
1818 * variable length fields
1819 */
1820struct smb2_posix_info_parsed {
1821 const struct smb2_posix_info *base;
1822 size_t size;
1823 struct cifs_sid owner;
1824 struct cifs_sid group;
1825 int name_len;
1826 const u8 *name;
Steve Frenchab3459d2020-02-06 17:31:56 -06001827};
Aurelien Aptel349e13a2020-02-08 15:50:57 +01001828
Steve Frenchddfbefb2011-03-15 02:08:48 +00001829#endif /* _SMB2PDU_H */