blob: 538e2299805fe52e4bbc569fe8b42035d289d2e3 [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>
28
29/*
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040030 * 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
Pavel Shilovsky96a988f2016-11-29 11:31:23 -080083#define SMB2_INTERNAL_CMD cpu_to_le16(0xFFFF)
84
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040085#define NUMBER_OF_SMB2_COMMANDS 0x0013
86
Ronnie Sahlberg58d15ed2019-01-29 12:46:16 +100087/* 52 transform hdr + 64 hdr + 88 create rsp */
Ronnie Sahlbergc4627e62019-01-29 12:46:17 +100088#define SMB2_TRANSFORM_HEADER_SIZE 52
Ronnie Sahlberg58d15ed2019-01-29 12:46:16 +100089#define MAX_SMB2_HDR_SIZE 204
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040090
Fabian Frederickbc09d142014-12-10 15:41:15 -080091#define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)
Steve French373512e2015-12-18 13:05:30 -060092#define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +040093
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040094/*
Steve Frenchddfbefb2011-03-15 02:08:48 +000095 * 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 */
Pavel Shilovsky74112862012-07-27 01:20:41 +0400102
Fabian Frederickbc09d142014-12-10 15:41:15 -0800103#define SMB2_HEADER_STRUCTURE_SIZE cpu_to_le16(64)
Pavel Shilovsky74112862012-07-27 01:20:41 +0400104
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700105struct smb2_sync_hdr {
Steve French373512e2015-12-18 13:05:30 -0600106 __le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */
Steve Frenchddfbefb2011-03-15 02:08:48 +0000107 __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;
Sachin Prabhu9235d092014-12-09 17:37:00 +0000114 __le64 MessageId;
Steve Frenchddfbefb2011-03-15 02:08:48 +0000115 __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
Pavel Shilovskycb200bd2016-10-24 16:59:57 -0700121struct smb2_sync_pdu {
122 struct smb2_sync_hdr sync_hdr;
123 __le16 StructureSize2; /* size of wct area (varies, request specific) */
124} __packed;
125
Pavel Shilovsky026e93d2016-11-03 16:47:37 -0700126#define SMB3_AES128CMM_NONCE 11
127#define SMB3_AES128GCM_NONCE 12
128
Steve French0cbaa532013-11-15 23:50:24 -0600129struct smb2_transform_hdr {
Pavel Shilovsky026e93d2016-11-03 16:47:37 -0700130 __le32 ProtocolId; /* 0xFD 'S' 'M' 'B' */
Steve French0cbaa532013-11-15 23:50:24 -0600131 __u8 Signature[16];
Steve French373512e2015-12-18 13:05:30 -0600132 __u8 Nonce[16];
Steve French0cbaa532013-11-15 23:50:24 -0600133 __le32 OriginalMessageSize;
134 __u16 Reserved1;
Steve French373512e2015-12-18 13:05:30 -0600135 __le16 Flags; /* EncryptionAlgorithm */
Steve French0cbaa532013-11-15 23:50:24 -0600136 __u64 SessionId;
137} __packed;
138
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400139/*
140 * SMB2 flag definitions
141 */
Fabian Frederickbc09d142014-12-10 15:41:15 -0800142#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)
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400147
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 */
Pavel Shilovsky74112862012-07-27 01:20:41 +0400156
Ronnie Sahlberg730928c2018-08-08 15:07:49 +1000157#define COMPOUND_FID 0xFFFFFFFFFFFFFFFFULL
158
Fabian Frederickbc09d142014-12-10 15:41:15 -0800159#define SMB2_ERROR_STRUCTURE_SIZE2 cpu_to_le16(9)
Pavel Shilovsky74112862012-07-27 01:20:41 +0400160
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400161struct smb2_err_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +1000162 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400163 __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
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400169struct 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
Steve French5f60a562018-02-05 14:46:18 -0600183/* 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
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700212#define SMB2_CLIENT_GUID_SIZE 16
213
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400214struct smb2_negotiate_req {
Ronnie Sahlberg13cacea2017-11-20 11:24:30 +1100215 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400216 __le16 StructureSize; /* Must be 36 */
217 __le16 DialectCount;
218 __le16 SecurityMode;
219 __le16 Reserved; /* MBZ */
220 __le32 Capabilities;
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700221 __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE];
Steve French5f7fbf72014-12-17 22:52:58 -0600222 /* 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;
Steve Frenche4aa25e2012-10-01 12:26:22 -0500226 __le16 Dialects[1]; /* One dialect (vers=) at a time for now */
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400227} __packed;
228
Steve Frenche4aa25e2012-10-01 12:26:22 -0500229/* Dialects */
230#define SMB20_PROT_ID 0x0202
231#define SMB21_PROT_ID 0x0210
232#define SMB30_PROT_ID 0x0300
Steve French20b6d8b2013-06-12 22:48:41 -0500233#define SMB302_PROT_ID 0x0302
Steve French5f7fbf72014-12-17 22:52:58 -0600234#define SMB311_PROT_ID 0x0311
Steve Frenche4aa25e2012-10-01 12:26:22 -0500235#define BAD_PROT_ID 0xFFFF
236
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400237/* SecurityMode flags */
238#define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001
239#define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
Steve French07108d02018-04-01 20:15:55 -0500240#define SMB2_SEC_MODE_FLAGS_ALL 0x0003
241
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400242/* 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 */
Steve Frenche4aa25e2012-10-01 12:26:22 -0500246#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 */
Pavel Shilovsky29e20f92012-07-13 13:58:14 +0400250/* Internal types */
251#define SMB2_NT_FIND 0x00100000
252#define SMB2_LARGE_FILES 0x00200000
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400253
Steve French136ff1b2018-04-08 16:14:31 -0500254struct smb2_neg_context {
255 __le16 ContextType;
256 __le16 DataLength;
257 __le32 Reserved;
258 /* Followed by array of data */
259} __packed;
260
Steve Frencheed0e172015-02-06 00:03:52 -0600261#define SMB311_SALT_SIZE 32
262/* Hash Algorithm Types */
Steve Frenchebb3a9d2015-06-18 04:49:47 -0500263#define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001)
Aurelien Aptel8bd68c62018-02-16 19:19:29 +0100264#define SMB2_PREAUTH_HASH_SIZE 64
Steve Frencheed0e172015-02-06 00:03:52 -0600265
Steve French5100d8a2018-04-09 10:47:14 -0500266#define MIN_PREAUTH_CTXT_DATA_LEN (SMB311_SALT_SIZE + 6)
Steve Frencheed0e172015-02-06 00:03:52 -0600267struct 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
Steve French5100d8a2018-04-09 10:47:14 -0500281/* Min encrypt context data is one cipher so 2 bytes + 2 byte count field */
282#define MIN_ENCRYPT_CTXT_DATA_LEN 4
Steve Frencheed0e172015-02-06 00:03:52 -0600283struct smb2_encryption_neg_context {
284 __le16 ContextType; /* 2 */
285 __le16 DataLength;
286 __le32 Reserved;
Steve Frenchebb3a9d2015-06-18 04:49:47 -0500287 __le16 CipherCount; /* AES-128-GCM and AES-128-CCM */
Steve French23657ad2018-04-22 15:14:58 -0500288 __le16 Ciphers[1]; /* Ciphers[0] since only one used now */
Steve Frencheed0e172015-02-06 00:03:52 -0600289} __packed;
290
Steve Frenchfcef0db2018-05-19 20:45:27 -0500291#define POSIX_CTXT_DATA_LEN 8
292struct smb2_posix_neg_context {
293 __le16 ContextType; /* 0x100 */
294 __le16 DataLength;
295 __le32 Reserved;
296 __le64 Reserved1; /* In case needed for future (eg version or caps) */
297} __packed;
298
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400299struct smb2_negotiate_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +1000300 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400301 __le16 StructureSize; /* Must be 65 */
302 __le16 SecurityMode;
303 __le16 DialectRevision;
Steve French5f7fbf72014-12-17 22:52:58 -0600304 __le16 NegotiateContextCount; /* Prior to SMB3.1.1 was Reserved & MBZ */
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400305 __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;
Steve French5f7fbf72014-12-17 22:52:58 -0600314 __le32 NegotiateContextOffset; /* Pre:SMB3.1.1 was reserved/ignored */
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400315 __u8 Buffer[1]; /* variable length GSS security buffer */
316} __packed;
317
Steve Frencheed0e172015-02-06 00:03:52 -0600318/* Flags */
319#define SMB2_SESSION_REQ_FLAG_BINDING 0x01
320#define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04
321
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400322struct smb2_sess_setup_req {
Ronnie Sahlberg88ea5cb2017-11-20 11:24:36 +1100323 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400324 __le16 StructureSize; /* Must be 25 */
Steve Frencheed0e172015-02-06 00:03:52 -0600325 __u8 Flags;
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400326 __u8 SecurityMode;
327 __le32 Capabilities;
328 __le32 Channel;
329 __le16 SecurityBufferOffset;
330 __le16 SecurityBufferLength;
Steve Frenchc2afb812016-09-20 22:56:13 -0500331 __u64 PreviousSessionId;
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400332 __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
Steve French0cbaa532013-11-15 23:50:24 -0600338#define SMB2_SESSION_FLAG_ENCRYPT_DATA 0x0004
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400339struct smb2_sess_setup_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +1000340 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400341 __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 {
Ronnie Sahlberg45305ed2017-11-09 12:14:17 +1100349 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400350 __le16 StructureSize; /* Must be 4 */
351 __le16 Reserved;
352} __packed;
353
354struct smb2_logoff_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +1000355 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400356 __le16 StructureSize; /* Must be 4 */
357 __le16 Reserved;
358} __packed;
359
Steve Frencheed0e172015-02-06 00:03:52 -0600360/* Flags/Reserved for SMB3.1.1 */
Steve French5f60a562018-02-05 14:46:18 -0600361#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)
Steve Frencheed0e172015-02-06 00:03:52 -0600364
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400365struct smb2_tree_connect_req {
Ronnie Sahlberg661bb9432017-11-09 12:14:23 +1100366 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400367 __le16 StructureSize; /* Must be 9 */
Steve Frencheed0e172015-02-06 00:03:52 -0600368 __le16 Reserved; /* Flags in SMB3.1.1 */
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400369 __le16 PathOffset;
370 __le16 PathLength;
371 __u8 Buffer[1]; /* variable length */
372} __packed;
373
Steve French5f60a562018-02-05 14:46:18 -0600374/* 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
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400450struct smb2_tree_connect_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +1000451 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400452 __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
Steve Frenchc8664732013-06-21 15:35:45 -0500481#define SHI1005_FLAGS_ENABLE_HASH_V1 0x00002000
482#define SHI1005_FLAGS_ENABLE_HASH_V2 0x00004000
483#define SHI1005_FLAGS_ENCRYPT_DATA 0x00008000
Steve French5f60a562018-02-05 14:46:18 -0600484#define SMB2_SHAREFLAG_IDENTITY_REMOTING 0x00040000 /* 3.1.1 */
485#define SHI1005_FLAGS_ALL 0x0004FF33
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400486
487/* Possible share capabilities */
Steve French2b5dc282013-06-13 10:51:10 -0500488#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 */
Steve French5f60a562018-02-05 14:46:18 -0600493#define SMB2_SHARE_CAP_REDIRECT_TO_OWNER cpu_to_le32(0x00000100) /* 3.1.1 */
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400494
495struct smb2_tree_disconnect_req {
Ronnie Sahlberg4eecf4c2017-11-09 12:14:18 +1100496 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400497 __le16 StructureSize; /* Must be 4 */
498 __le16 Reserved;
499} __packed;
500
501struct smb2_tree_disconnect_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +1000502 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400503 __le16 StructureSize; /* Must be 4 */
504 __le16 Reserved;
505} __packed;
506
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400507/* 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
Steve French73322972014-09-23 19:25:42 -0500521#define FILE_ATTRIBUTE_INTEGRITY_STREAM 0x00008000
522#define FILE_ATTRIBUTE_NO_SCRUB_DATA 0x00020000
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400523
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
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700530/* Non-spec internal type */
531#define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400532
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"
Steve French12197a72014-05-14 05:29:40 -0700606#define SMB2_CREATE_ALLOCATION_SIZE "AISi"
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400607#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"
Steve French12197a72014-05-14 05:29:40 -0700611#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
Steve Frenchfe048402018-05-30 17:10:25 -0500614#define SVHDX_OPEN_DEVICE_CONTEX 0x9CCBCF9E04C1E643980E158DA1F6EC83
615#define SMB2_CREATE_TAG_POSIX 0x93AD25509CB411E7B42383DE968BCD7C
616
Steve French37e6a702018-09-19 02:02:58 -0500617/* Flag (SMB3 open response) values */
618#define SMB2_CREATE_FLAG_REPARSEPOINT 0x01
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400619
Ronnie Sahlberg4d8dfaf2018-08-21 11:49:21 +1000620/*
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
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400632struct smb2_create_req {
Ronnie Sahlberg4f33bc32017-11-20 11:24:38 +1100633 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400634 __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;
Pavel Shilovsky59aa3712013-07-04 19:41:24 +0400649 __u8 Buffer[0];
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400650} __packed;
651
Ronnie Sahlbergc4627e62019-01-29 12:46:17 +1000652/*
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
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400659struct smb2_create_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +1000660 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400661 __le16 StructureSize; /* Must be 89 */
662 __u8 OplockLevel;
Steve French37e6a702018-09-19 02:02:58 -0500663 __u8 Flag; /* 0x01 if reparse point */
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400664 __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
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700680struct 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
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400690#define SMB2_LEASE_READ_CACHING_HE 0x01
691#define SMB2_LEASE_HANDLE_CACHING_HE 0x02
692#define SMB2_LEASE_WRITE_CACHING_HE 0x04
693
Fabian Frederickbc09d142014-12-10 15:41:15 -0800694#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)
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700698
Fabian Frederickbc09d142014-12-10 15:41:15 -0800699#define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS cpu_to_le32(0x02)
Steve French5f60a562018-02-05 14:46:18 -0600700#define SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET cpu_to_le32(0x00000004)
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700701
702#define SMB2_LEASE_KEY_SIZE 16
703
704struct lease_context {
Stefano Brivio729c0c92018-07-05 15:10:02 +0200705 u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700706 __le32 LeaseState;
707 __le32 LeaseFlags;
708 __le64 LeaseDuration;
709} __packed;
710
Pavel Shilovskyf0473902013-09-04 13:44:05 +0400711struct lease_context_v2 {
Stefano Brivio729c0c92018-07-05 15:10:02 +0200712 u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
Pavel Shilovskyf0473902013-09-04 13:44:05 +0400713 __le32 LeaseState;
714 __le32 LeaseFlags;
715 __le64 LeaseDuration;
716 __le64 ParentLeaseKeyLow;
717 __le64 ParentLeaseKeyHigh;
718 __le16 Epoch;
719 __le16 Reserved;
720} __packed;
721
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700722struct create_lease {
723 struct create_context ccontext;
724 __u8 Name[8];
725 struct lease_context lcontext;
726} __packed;
727
Pavel Shilovskyf0473902013-09-04 13:44:05 +0400728struct 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
Pavel Shilovsky63eb3de2013-07-04 18:41:09 +0400735struct create_durable {
736 struct create_context ccontext;
737 __u8 Name[8];
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400738 union {
739 __u8 Reserved[16];
740 struct {
741 __u64 PersistentFileId;
742 __u64 VolatileFileId;
743 } Fid;
744 } Data;
Pavel Shilovsky63eb3de2013-07-04 18:41:09 +0400745} __packed;
746
Steve Frenchfe048402018-05-30 17:10:25 -0500747struct create_posix {
748 struct create_context ccontext;
749 __u8 Name[16];
750 __le32 Mode;
751 __u32 Reserved;
752} __packed;
753
Steve Frenchb56eae42015-11-03 09:26:27 -0600754/* 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
Steve Frenchcdeaf9d2018-08-10 02:25:06 -0500792/* 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
Steve French41c13582013-11-14 00:05:36 -0600800#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
Steve Frenchbe7457d2013-06-19 17:41:10 -0500807/* this goes in the ioctl buffer when doing a copychunk request */
808struct copychunk_ioctl {
Steve French41c13582013-11-14 00:05:36 -0600809 char SourceKey[COPY_CHUNK_RES_KEY_SIZE];
Steve Frenchbe7457d2013-06-19 17:41:10 -0500810 __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;
Steve Frenchc8664732013-06-21 15:35:45 -0500815 __le32 Length; /* how many bytes to copy */
Steve Frenchbe7457d2013-06-19 17:41:10 -0500816 __u32 Reserved2;
817} __packed;
818
Steve French31742c52014-08-17 08:38:47 -0500819/* 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
Steve French41c13582013-11-14 00:05:36 -0600825struct copychunk_ioctl_rsp {
826 __le32 ChunksWritten;
827 __le32 ChunkBytesWritten;
828 __le32 TotalBytesWritten;
829} __packed;
830
Steve French9d1b0662015-06-24 02:12:19 -0500831struct 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
Steve Frenchb3152e22015-06-24 03:17:02 -0500848#define CHECKSUM_TYPE_UNCHANGED 0xFFFF /* set only */
Steve French9d1b0662015-06-24 02:12:19 -0500849
850/* Integrity flags for above */
851#define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF 0x00000001
852
Steve French0df444a2018-10-31 11:24:33 -0500853/* 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
Aurelien Aptel9d496402017-02-13 16:16:49 +0100888/* 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
Steve Frenchb56eae42015-11-03 09:26:27 -0600896/* 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
Steve French9d1b0662015-06-24 02:12:19 -0500903
Steve Frenchff1c0382013-11-19 23:44:46 -0600904struct validate_negotiate_info_req {
Steve French4a72daf2013-06-25 00:20:49 -0500905 __le32 Capabilities;
906 __u8 Guid[SMB2_CLIENT_GUID_SIZE];
907 __le16 SecurityMode;
908 __le16 DialectCount;
Steve Frenchd5c70762019-01-03 02:37:21 -0600909 __le16 Dialects[4]; /* BB expand this if autonegotiate > 4 dialects */
Steve Frenchff1c0382013-11-19 23:44:46 -0600910} __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 */
Steve French4a72daf2013-06-25 00:20:49 -0500917} __packed;
918
Aurelien Aptelbead0422018-06-14 15:43:17 +0200919#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)
Steve French4a72daf2013-06-25 00:20:49 -0500924
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;
Aurelien Aptelbead0422018-06-14 15:43:17 +0200931 __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;
Steve French4a72daf2013-06-25 00:20:49 -0500946} __packed;
947
948#define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */
949
Steve French64a5cfa2013-10-14 15:31:32 -0500950struct compress_ioctl {
Steve Frenchc7f508a2013-10-14 15:27:32 -0500951 __le16 CompressionState; /* See cifspdu.h for possible flag values */
Steve French64a5cfa2013-10-14 15:31:32 -0500952} __packed;
953
Steve French02b16662015-06-27 21:18:36 -0700954struct 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
Steve Frenchbe7457d2013-06-19 17:41:10 -0500962struct smb2_ioctl_req {
Ronnie Sahlberg97754682017-11-09 12:14:20 +1100963 struct smb2_sync_hdr sync_hdr;
Steve Frenchbe7457d2013-06-19 17:41:10 -0500964 __le16 StructureSize; /* Must be 57 */
965 __u16 Reserved;
966 __le32 CtlCode;
967 __u64 PersistentFileId; /* opaque endianness */
968 __u64 VolatileFileId; /* opaque endianness */
969 __le32 InputOffset;
970 __le32 InputCount;
971 __le32 MaxInputResponse;
972 __le32 OutputOffset;
973 __le32 OutputCount;
974 __le32 MaxOutputResponse;
975 __le32 Flags;
976 __u32 Reserved2;
Steve French64a5cfa2013-10-14 15:31:32 -0500977 __u8 Buffer[0];
Steve Frenchbe7457d2013-06-19 17:41:10 -0500978} __packed;
979
980struct smb2_ioctl_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +1000981 struct smb2_sync_hdr sync_hdr;
Steve Frenchbe7457d2013-06-19 17:41:10 -0500982 __le16 StructureSize; /* Must be 57 */
983 __u16 Reserved;
984 __le32 CtlCode;
985 __u64 PersistentFileId; /* opaque endianness */
986 __u64 VolatileFileId; /* opaque endianness */
987 __le32 InputOffset;
988 __le32 InputCount;
989 __le32 OutputOffset;
990 __le32 OutputCount;
991 __le32 Flags;
992 __u32 Reserved2;
993 /* char * buffer[] */
994} __packed;
995
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400996/* Currently defined values for close flags */
997#define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
998struct smb2_close_req {
Ronnie Sahlbergafcccef2017-11-09 12:14:19 +1100999 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +04001000 __le16 StructureSize; /* Must be 24 */
1001 __le16 Flags;
1002 __le32 Reserved;
1003 __u64 PersistentFileId; /* opaque endianness */
1004 __u64 VolatileFileId; /* opaque endianness */
1005} __packed;
1006
Ronnie Sahlbergc4627e62019-01-29 12:46:17 +10001007/*
1008 * Maximum size of a SMB2_CLOSE response is 64 (smb2 header) + 60 (data)
1009 */
1010#define MAX_SMB2_CLOSE_RESPONSE_SIZE 124
1011
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +04001012struct smb2_close_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001013 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +04001014 __le16 StructureSize; /* 60 */
1015 __le16 Flags;
1016 __le32 Reserved;
1017 __le64 CreationTime;
1018 __le64 LastAccessTime;
1019 __le64 LastWriteTime;
1020 __le64 ChangeTime;
1021 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
1022 __le64 EndOfFile;
1023 __le32 Attributes;
1024} __packed;
1025
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -07001026struct smb2_flush_req {
Ronnie Sahlberg1f444e42017-11-20 11:24:39 +11001027 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -07001028 __le16 StructureSize; /* Must be 24 */
1029 __le16 Reserved1;
1030 __le32 Reserved2;
1031 __u64 PersistentFileId; /* opaque endianness */
1032 __u64 VolatileFileId; /* opaque endianness */
1033} __packed;
1034
1035struct smb2_flush_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001036 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -07001037 __le16 StructureSize;
1038 __le16 Reserved;
1039} __packed;
1040
Steve French2b5dc282013-06-13 10:51:10 -05001041/* For read request Flags field below, following flag is defined for SMB3.02 */
1042#define SMB2_READFLAG_READ_UNBUFFERED 0x01
1043
1044/* Channel field for read and write: exactly one of following flags can be set*/
Steve French2026b062018-01-24 23:07:41 -06001045#define SMB2_CHANNEL_NONE cpu_to_le32(0x00000000)
1046#define SMB2_CHANNEL_RDMA_V1 cpu_to_le32(0x00000001) /* SMB3 or later */
1047#define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002) /* >= SMB3.02 */
Steve French2b5dc282013-06-13 10:51:10 -05001048
Pavel Shilovskyb8f57ee2016-11-23 15:31:54 -08001049/* SMB2 read request without RFC1001 length at the beginning */
1050struct smb2_read_plain_req {
1051 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001052 __le16 StructureSize; /* Must be 49 */
1053 __u8 Padding; /* offset from start of SMB2 header to place read */
Steve French2b5dc282013-06-13 10:51:10 -05001054 __u8 Flags; /* MBZ unless SMB3.02 or later */
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001055 __le32 Length;
1056 __le64 Offset;
1057 __u64 PersistentFileId; /* opaque endianness */
1058 __u64 VolatileFileId; /* opaque endianness */
1059 __le32 MinimumCount;
Steve French2b5dc282013-06-13 10:51:10 -05001060 __le32 Channel; /* MBZ except for SMB3 or later */
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001061 __le32 RemainingBytes;
Steve French2026b062018-01-24 23:07:41 -06001062 __le16 ReadChannelInfoOffset;
1063 __le16 ReadChannelInfoLength;
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001064 __u8 Buffer[1];
1065} __packed;
1066
1067struct smb2_read_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001068 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky09a47072012-09-18 16:20:29 -07001069 __le16 StructureSize; /* Must be 17 */
1070 __u8 DataOffset;
1071 __u8 Reserved;
1072 __le32 DataLength;
1073 __le32 DataRemaining;
1074 __u32 Reserved2;
1075 __u8 Buffer[1];
1076} __packed;
1077
Steve French2b5dc282013-06-13 10:51:10 -05001078/* For write request Flags field below the following flags are defined: */
1079#define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 /* SMB2.1 or later */
1080#define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002 /* SMB3.02 or later */
Pavel Shilovsky33319142012-09-18 16:20:29 -07001081
1082struct smb2_write_req {
Ronnie Sahlbergf5688a62017-11-20 11:24:41 +11001083 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky33319142012-09-18 16:20:29 -07001084 __le16 StructureSize; /* Must be 49 */
1085 __le16 DataOffset; /* offset from start of SMB2 header to write data */
1086 __le32 Length;
1087 __le64 Offset;
1088 __u64 PersistentFileId; /* opaque endianness */
1089 __u64 VolatileFileId; /* opaque endianness */
1090 __le32 Channel; /* Reserved MBZ */
1091 __le32 RemainingBytes;
Steve French2026b062018-01-24 23:07:41 -06001092 __le16 WriteChannelInfoOffset;
1093 __le16 WriteChannelInfoLength;
Pavel Shilovsky33319142012-09-18 16:20:29 -07001094 __le32 Flags;
1095 __u8 Buffer[1];
1096} __packed;
1097
1098struct smb2_write_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001099 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky33319142012-09-18 16:20:29 -07001100 __le16 StructureSize; /* Must be 17 */
1101 __u8 DataOffset;
1102 __u8 Reserved;
1103 __le32 DataLength;
1104 __le32 DataRemaining;
1105 __u32 Reserved2;
1106 __u8 Buffer[1];
1107} __packed;
1108
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -07001109#define SMB2_LOCKFLAG_SHARED_LOCK 0x0001
1110#define SMB2_LOCKFLAG_EXCLUSIVE_LOCK 0x0002
1111#define SMB2_LOCKFLAG_UNLOCK 0x0004
1112#define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010
1113
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07001114struct smb2_lock_element {
1115 __le64 Offset;
1116 __le64 Length;
1117 __le32 Flags;
1118 __le32 Reserved;
1119} __packed;
1120
1121struct smb2_lock_req {
Ronnie Sahlbergced93672017-11-21 10:07:27 +11001122 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07001123 __le16 StructureSize; /* Must be 48 */
1124 __le16 LockCount;
1125 __le32 Reserved;
1126 __u64 PersistentFileId; /* opaque endianness */
1127 __u64 VolatileFileId; /* opaque endianness */
1128 /* Followed by at least one */
1129 struct smb2_lock_element locks[1];
1130} __packed;
1131
1132struct smb2_lock_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001133 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -07001134 __le16 StructureSize; /* Must be 4 */
1135 __le16 Reserved;
1136} __packed;
1137
Pavel Shilovsky9094fad2012-07-12 18:30:44 +04001138struct smb2_echo_req {
Ronnie Sahlberg7f7ae752017-11-09 12:14:21 +11001139 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky9094fad2012-07-12 18:30:44 +04001140 __le16 StructureSize; /* Must be 4 */
1141 __u16 Reserved;
1142} __packed;
1143
1144struct smb2_echo_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001145 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky9094fad2012-07-12 18:30:44 +04001146 __le16 StructureSize; /* Must be 4 */
1147 __u16 Reserved;
1148} __packed;
1149
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001150/* search (query_directory) Flags field */
1151#define SMB2_RESTART_SCANS 0x01
1152#define SMB2_RETURN_SINGLE_ENTRY 0x02
1153#define SMB2_INDEX_SPECIFIED 0x04
1154#define SMB2_REOPEN 0x10
1155
1156struct smb2_query_directory_req {
Ronnie Sahlberg7c00c3a2017-11-20 11:24:45 +11001157 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001158 __le16 StructureSize; /* Must be 33 */
1159 __u8 FileInformationClass;
1160 __u8 Flags;
1161 __le32 FileIndex;
1162 __u64 PersistentFileId; /* opaque endianness */
1163 __u64 VolatileFileId; /* opaque endianness */
1164 __le16 FileNameOffset;
1165 __le16 FileNameLength;
1166 __le32 OutputBufferLength;
1167 __u8 Buffer[1];
1168} __packed;
1169
1170struct smb2_query_directory_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001171 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -07001172 __le16 StructureSize; /* Must be 9 */
1173 __le16 OutputBufferOffset;
1174 __le32 OutputBufferLength;
1175 __u8 Buffer[1];
1176} __packed;
1177
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001178/* Possible InfoType values */
1179#define SMB2_O_INFO_FILE 0x01
1180#define SMB2_O_INFO_FILESYSTEM 0x02
1181#define SMB2_O_INFO_SECURITY 0x03
1182#define SMB2_O_INFO_QUOTA 0x04
1183
Steve French911a8df2014-10-19 19:18:05 -05001184/* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */
1185#define OWNER_SECINFO 0x00000001
1186#define GROUP_SECINFO 0x00000002
1187#define DACL_SECINFO 0x00000004
1188#define SACL_SECINFO 0x00000008
1189#define LABEL_SECINFO 0x00000010
1190#define ATTRIBUTE_SECINFO 0x00000020
1191#define SCOPE_SECINFO 0x00000040
1192#define BACKUP_SECINFO 0x00010000
1193#define UNPROTECTED_SACL_SECINFO 0x10000000
1194#define UNPROTECTED_DACL_SECINFO 0x20000000
1195#define PROTECTED_SACL_SECINFO 0x40000000
1196#define PROTECTED_DACL_SECINFO 0x80000000
1197
1198/* Flags used for FileFullEAinfo */
1199#define SL_RESTART_SCAN 0x00000001
1200#define SL_RETURN_SINGLE_ENTRY 0x00000002
1201#define SL_INDEX_SPECIFIED 0x00000004
1202
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001203struct smb2_query_info_req {
Ronnie Sahlbergb2fb7fe2017-11-20 11:24:46 +11001204 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001205 __le16 StructureSize; /* Must be 41 */
1206 __u8 InfoType;
1207 __u8 FileInfoClass;
1208 __le32 OutputBufferLength;
1209 __le16 InputBufferOffset;
1210 __u16 Reserved;
1211 __le32 InputBufferLength;
1212 __le32 AdditionalInformation;
1213 __le32 Flags;
1214 __u64 PersistentFileId; /* opaque endianness */
1215 __u64 VolatileFileId; /* opaque endianness */
1216 __u8 Buffer[1];
1217} __packed;
1218
1219struct smb2_query_info_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001220 struct smb2_sync_hdr sync_hdr;
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001221 __le16 StructureSize; /* Must be 9 */
1222 __le16 OutputBufferOffset;
1223 __le32 OutputBufferLength;
1224 __u8 Buffer[1];
1225} __packed;
1226
Ronnie Sahlberg14e562a2018-09-03 13:33:50 +10001227/*
1228 * Maximum number of iovs we need for a set-info request.
1229 * The largest one is rename/hardlink
1230 * [0] : struct smb2_set_info_req + smb2_file_[rename|link]_info
1231 * [1] : path
1232 * [2] : compound padding
1233 */
1234#define SMB2_SET_INFO_IOV_SIZE 3
1235
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07001236struct smb2_set_info_req {
Ronnie Sahlberg2fc803e2017-11-20 11:24:44 +11001237 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07001238 __le16 StructureSize; /* Must be 33 */
1239 __u8 InfoType;
1240 __u8 FileInfoClass;
1241 __le32 BufferLength;
1242 __le16 BufferOffset;
1243 __u16 Reserved;
1244 __le32 AdditionalInformation;
1245 __u64 PersistentFileId; /* opaque endianness */
1246 __u64 VolatileFileId; /* opaque endianness */
1247 __u8 Buffer[1];
1248} __packed;
1249
1250struct smb2_set_info_rsp {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001251 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07001252 __le16 StructureSize; /* Must be 2 */
1253} __packed;
1254
Ronnie Sahlberg0d5a2882018-06-01 10:53:03 +10001255struct smb2_oplock_break {
Ronnie Sahlberg21ad9482017-11-20 11:24:43 +11001256 struct smb2_sync_hdr sync_hdr;
1257 __le16 StructureSize; /* Must be 24 */
1258 __u8 OplockLevel;
1259 __u8 Reserved;
1260 __le32 Reserved2;
1261 __u64 PersistentFid;
1262 __u64 VolatileFid;
1263} __packed;
1264
Pavel Shilovsky0822f512012-09-19 06:22:45 -07001265#define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
1266
1267struct smb2_lease_break {
Ronnie Sahlberg49f466b2018-06-01 10:53:06 +10001268 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky0822f512012-09-19 06:22:45 -07001269 __le16 StructureSize; /* Must be 44 */
1270 __le16 Reserved;
1271 __le32 Flags;
1272 __u8 LeaseKey[16];
1273 __le32 CurrentLeaseState;
1274 __le32 NewLeaseState;
1275 __le32 BreakReason;
1276 __le32 AccessMaskHint;
1277 __le32 ShareMaskHint;
1278} __packed;
1279
1280struct smb2_lease_ack {
Ronnie Sahlberg8eb79982017-11-21 11:04:37 +11001281 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky0822f512012-09-19 06:22:45 -07001282 __le16 StructureSize; /* Must be 36 */
1283 __le16 Reserved;
1284 __le32 Flags;
1285 __u8 LeaseKey[16];
1286 __le32 LeaseState;
1287 __le64 LeaseDuration;
1288} __packed;
1289
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001290/*
1291 * PDU infolevel structure definitions
1292 * BB consider moving to a different header
1293 */
1294
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001295/* File System Information Classes */
1296#define FS_VOLUME_INFORMATION 1 /* Query */
Steven Frenchaf6a12e2013-10-09 20:55:53 -05001297#define FS_LABEL_INFORMATION 2 /* Local only */
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001298#define FS_SIZE_INFORMATION 3 /* Query */
1299#define FS_DEVICE_INFORMATION 4 /* Query */
1300#define FS_ATTRIBUTE_INFORMATION 5 /* Query */
1301#define FS_CONTROL_INFORMATION 6 /* Query, Set */
1302#define FS_FULL_SIZE_INFORMATION 7 /* Query */
1303#define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */
Steven Frenchaf6a12e2013-10-09 20:55:53 -05001304#define FS_DRIVER_PATH_INFORMATION 9 /* Local only */
1305#define FS_VOLUME_FLAGS_INFORMATION 10 /* Local only */
1306#define FS_SECTOR_SIZE_INFORMATION 11 /* SMB3 or later. Query */
Steve French2d304212018-06-24 23:28:12 -05001307#define FS_POSIX_INFORMATION 100 /* SMB3.1.1 POSIX. Query */
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001308
1309struct smb2_fs_full_size_info {
1310 __le64 TotalAllocationUnits;
1311 __le64 CallerAvailableAllocationUnits;
1312 __le64 ActualAvailableAllocationUnits;
1313 __le32 SectorsPerAllocationUnit;
1314 __le32 BytesPerSector;
1315} __packed;
1316
Steven Frenchaf6a12e2013-10-09 20:55:53 -05001317#define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001
1318#define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
1319#define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004
1320#define SSINFO_FLAGS_TRIM_ENABLED 0x00000008
1321
1322/* sector size info struct */
1323struct smb3_fs_ss_info {
1324 __le32 LogicalBytesPerSector;
1325 __le32 PhysicalBytesPerSectorForAtomicity;
1326 __le32 PhysicalBytesPerSectorForPerf;
1327 __le32 FileSystemEffectivePhysicalBytesPerSectorForAtomicity;
1328 __le32 Flags;
1329 __le32 ByteOffsetForSectorAlignment;
1330 __le32 ByteOffsetForPartitionAlignment;
1331} __packed;
1332
Steve French21ba3842018-06-24 23:18:52 -05001333/* volume info struct - see MS-FSCC 2.5.9 */
1334#define MAX_VOL_LABEL_LEN 32
1335struct smb3_fs_vol_info {
1336 __le64 VolumeCreationTime;
1337 __u32 VolumeSerialNumber;
1338 __le32 VolumeLabelLength; /* includes trailing null */
1339 __u8 SupportsObjects; /* True if eg like NTFS, supports objects */
1340 __u8 Reserved;
1341 __u8 VolumeLabel[0]; /* variable len */
1342} __packed;
1343
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001344/* partial list of QUERY INFO levels */
1345#define FILE_DIRECTORY_INFORMATION 1
1346#define FILE_FULL_DIRECTORY_INFORMATION 2
1347#define FILE_BOTH_DIRECTORY_INFORMATION 3
1348#define FILE_BASIC_INFORMATION 4
1349#define FILE_STANDARD_INFORMATION 5
1350#define FILE_INTERNAL_INFORMATION 6
1351#define FILE_EA_INFORMATION 7
1352#define FILE_ACCESS_INFORMATION 8
1353#define FILE_NAME_INFORMATION 9
1354#define FILE_RENAME_INFORMATION 10
1355#define FILE_LINK_INFORMATION 11
1356#define FILE_NAMES_INFORMATION 12
1357#define FILE_DISPOSITION_INFORMATION 13
1358#define FILE_POSITION_INFORMATION 14
1359#define FILE_FULL_EA_INFORMATION 15
1360#define FILE_MODE_INFORMATION 16
1361#define FILE_ALIGNMENT_INFORMATION 17
1362#define FILE_ALL_INFORMATION 18
1363#define FILE_ALLOCATION_INFORMATION 19
1364#define FILE_END_OF_FILE_INFORMATION 20
1365#define FILE_ALTERNATE_NAME_INFORMATION 21
1366#define FILE_STREAM_INFORMATION 22
1367#define FILE_PIPE_INFORMATION 23
1368#define FILE_PIPE_LOCAL_INFORMATION 24
1369#define FILE_PIPE_REMOTE_INFORMATION 25
1370#define FILE_MAILSLOT_QUERY_INFORMATION 26
1371#define FILE_MAILSLOT_SET_INFORMATION 27
1372#define FILE_COMPRESSION_INFORMATION 28
1373#define FILE_OBJECT_ID_INFORMATION 29
1374/* Number 30 not defined in documents */
1375#define FILE_MOVE_CLUSTER_INFORMATION 31
1376#define FILE_QUOTA_INFORMATION 32
1377#define FILE_REPARSE_POINT_INFORMATION 33
1378#define FILE_NETWORK_OPEN_INFORMATION 34
1379#define FILE_ATTRIBUTE_TAG_INFORMATION 35
1380#define FILE_TRACKING_INFORMATION 36
1381#define FILEID_BOTH_DIRECTORY_INFORMATION 37
1382#define FILEID_FULL_DIRECTORY_INFORMATION 38
1383#define FILE_VALID_DATA_LENGTH_INFORMATION 39
1384#define FILE_SHORT_NAME_INFORMATION 40
1385#define FILE_SFIO_RESERVE_INFORMATION 44
1386#define FILE_SFIO_VOLUME_INFORMATION 45
1387#define FILE_HARD_LINK_INFORMATION 46
1388#define FILE_NORMALIZED_NAME_INFORMATION 48
1389#define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
1390#define FILE_STANDARD_LINK_INFORMATION 54
1391
Pavel Shilovskyf0df7372012-09-18 16:20:26 -07001392struct smb2_file_internal_info {
1393 __le64 IndexNumber;
1394} __packed; /* level 6 Query */
1395
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07001396struct smb2_file_rename_info { /* encoding of request for level 10 */
1397 __u8 ReplaceIfExists; /* 1 = replace existing target with new */
1398 /* 0 = fail if target already exists */
1399 __u8 Reserved[7];
1400 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1401 __le32 FileNameLength;
1402 char FileName[0]; /* New name to be assigned */
1403} __packed; /* level 10 Set */
1404
Pavel Shilovsky568798c2012-09-18 16:20:31 -07001405struct smb2_file_link_info { /* encoding of request for level 11 */
1406 __u8 ReplaceIfExists; /* 1 = replace existing link with new */
1407 /* 0 = fail if link already exists */
1408 __u8 Reserved[7];
1409 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1410 __le32 FileNameLength;
1411 char FileName[0]; /* Name to be assigned to new link */
1412} __packed; /* level 11 Set */
1413
Ronnie Sahlberg95907fe2017-08-24 11:24:55 +10001414struct smb2_file_full_ea_info { /* encoding of response for level 15 */
1415 __le32 next_entry_offset;
1416 __u8 flags;
1417 __u8 ea_name_length;
1418 __le16 ea_value_length;
1419 char ea_data[0]; /* \0 terminated name plus value */
1420} __packed; /* level 15 Set */
1421
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001422/*
1423 * This level 18, although with struct with same name is different from cifs
1424 * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
1425 * CurrentByteOffset.
1426 */
1427struct smb2_file_all_info { /* data block encoding of response to level 18 */
1428 __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
1429 __le64 LastAccessTime;
1430 __le64 LastWriteTime;
1431 __le64 ChangeTime;
1432 __le32 Attributes;
1433 __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
1434 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
1435 __le64 EndOfFile; /* size ie offset to first free byte in file */
1436 __le32 NumberOfLinks; /* hard links */
1437 __u8 DeletePending;
1438 __u8 Directory;
1439 __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */
1440 __le64 IndexNumber;
1441 __le32 EASize;
1442 __le32 AccessFlags;
1443 __le64 CurrentByteOffset;
1444 __le32 Mode;
1445 __le32 AlignmentRequirement;
1446 __le32 FileNameLength;
1447 char FileName[1];
1448} __packed; /* level 18 Query */
1449
Pavel Shilovskyc839ff22012-09-18 16:20:32 -07001450struct smb2_file_eof_info { /* encoding of request for level 10 */
1451 __le64 EndOfFile; /* new end of file value */
1452} __packed; /* level 20 Set */
1453
Ronnie Sahlberg730928c2018-08-08 15:07:49 +10001454extern char smb2_padding[7];
1455
Steve Frenchddfbefb2011-03-15 02:08:48 +00001456#endif /* _SMB2PDU_H */