blob: 35ff9fae1c27763e7ee089ee012c5474f38d4f2d [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
87/* BB FIXME - analyze following length BB */
88#define MAX_SMB2_HDR_SIZE 0x78 /* 4 len + 64 hdr + (2*24 wct) + 2 bct + 2 pad */
89
Fabian Frederickbc09d142014-12-10 15:41:15 -080090#define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)
Steve French373512e2015-12-18 13:05:30 -060091#define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +040092
Pavel Shilovsky2dc7e1c2011-12-26 22:53:34 +040093/*
Steve Frenchddfbefb2011-03-15 02:08:48 +000094 * SMB2 Header Definition
95 *
96 * "MBZ" : Must be Zero
97 * "BB" : BugBug, Something to check/review/analyze later
98 * "PDU" : "Protocol Data Unit" (ie a network "frame")
99 *
100 */
Pavel Shilovsky74112862012-07-27 01:20:41 +0400101
Fabian Frederickbc09d142014-12-10 15:41:15 -0800102#define SMB2_HEADER_STRUCTURE_SIZE cpu_to_le16(64)
Pavel Shilovsky74112862012-07-27 01:20:41 +0400103
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700104struct smb2_sync_hdr {
Steve French373512e2015-12-18 13:05:30 -0600105 __le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */
Steve Frenchddfbefb2011-03-15 02:08:48 +0000106 __le16 StructureSize; /* 64 */
107 __le16 CreditCharge; /* MBZ */
108 __le32 Status; /* Error from server */
109 __le16 Command;
110 __le16 CreditRequest; /* CreditResponse */
111 __le32 Flags;
112 __le32 NextCommand;
Sachin Prabhu9235d092014-12-09 17:37:00 +0000113 __le64 MessageId;
Steve Frenchddfbefb2011-03-15 02:08:48 +0000114 __le32 ProcessId;
115 __u32 TreeId; /* opaque - so do not make little endian */
116 __u64 SessionId; /* opaque - so do not make little endian */
117 __u8 Signature[16];
118} __packed;
119
Pavel Shilovskycb200bd2016-10-24 16:59:57 -0700120struct smb2_sync_pdu {
121 struct smb2_sync_hdr sync_hdr;
122 __le16 StructureSize2; /* size of wct area (varies, request specific) */
123} __packed;
124
Pavel Shilovsky31473fc2016-10-24 15:33:04 -0700125struct smb2_hdr {
126 __be32 smb2_buf_length; /* big endian on wire */
127 /* length is only two or three bytes - with */
128 /* one or two byte type preceding it that MBZ */
129 struct smb2_sync_hdr sync_hdr;
130} __packed;
131
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400132struct smb2_pdu {
133 struct smb2_hdr hdr;
134 __le16 StructureSize2; /* size of wct area (varies, request specific) */
135} __packed;
136
Steve French0cbaa532013-11-15 23:50:24 -0600137struct smb2_transform_hdr {
138 __be32 smb2_buf_length; /* big endian on wire */
139 /* length is only two or three bytes - with
140 one or two byte type preceding it that MBZ */
141 __u8 ProtocolId[4]; /* 0xFD 'S' 'M' 'B' */
142 __u8 Signature[16];
Steve French373512e2015-12-18 13:05:30 -0600143 __u8 Nonce[16];
Steve French0cbaa532013-11-15 23:50:24 -0600144 __le32 OriginalMessageSize;
145 __u16 Reserved1;
Steve French373512e2015-12-18 13:05:30 -0600146 __le16 Flags; /* EncryptionAlgorithm */
Steve French0cbaa532013-11-15 23:50:24 -0600147 __u64 SessionId;
148} __packed;
149
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400150/*
151 * SMB2 flag definitions
152 */
Fabian Frederickbc09d142014-12-10 15:41:15 -0800153#define SMB2_FLAGS_SERVER_TO_REDIR cpu_to_le32(0x00000001)
154#define SMB2_FLAGS_ASYNC_COMMAND cpu_to_le32(0x00000002)
155#define SMB2_FLAGS_RELATED_OPERATIONS cpu_to_le32(0x00000004)
156#define SMB2_FLAGS_SIGNED cpu_to_le32(0x00000008)
157#define SMB2_FLAGS_DFS_OPERATIONS cpu_to_le32(0x10000000)
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400158
159/*
160 * Definitions for SMB2 Protocol Data Units (network frames)
161 *
162 * See MS-SMB2.PDF specification for protocol details.
163 * The Naming convention is the lower case version of the SMB2
164 * command code name for the struct. Note that structures must be packed.
165 *
166 */
Pavel Shilovsky74112862012-07-27 01:20:41 +0400167
Fabian Frederickbc09d142014-12-10 15:41:15 -0800168#define SMB2_ERROR_STRUCTURE_SIZE2 cpu_to_le16(9)
Pavel Shilovsky74112862012-07-27 01:20:41 +0400169
Pavel Shilovsky093b2bd2011-06-08 15:51:07 +0400170struct smb2_err_rsp {
171 struct smb2_hdr hdr;
172 __le16 StructureSize;
173 __le16 Reserved; /* MBZ */
174 __le32 ByteCount; /* even if zero, at least one byte follows */
175 __u8 ErrorData[1]; /* variable length */
176} __packed;
177
Pavel Shilovskyb42bf882013-08-14 19:25:21 +0400178struct smb2_symlink_err_rsp {
179 __le32 SymLinkLength;
180 __le32 SymLinkErrorTag;
181 __le32 ReparseTag;
182 __le16 ReparseDataLength;
183 __le16 UnparsedPathLength;
184 __le16 SubstituteNameOffset;
185 __le16 SubstituteNameLength;
186 __le16 PrintNameOffset;
187 __le16 PrintNameLength;
188 __le32 Flags;
189 __u8 PathBuffer[0];
190} __packed;
191
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700192#define SMB2_CLIENT_GUID_SIZE 16
193
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400194struct smb2_negotiate_req {
195 struct smb2_hdr hdr;
196 __le16 StructureSize; /* Must be 36 */
197 __le16 DialectCount;
198 __le16 SecurityMode;
199 __le16 Reserved; /* MBZ */
200 __le32 Capabilities;
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700201 __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE];
Steve French5f7fbf72014-12-17 22:52:58 -0600202 /* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */
203 __le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */
204 __le16 NegotiateContextCount; /* SMB3.1.1 only. MBZ earlier */
205 __le16 Reserved2;
Steve Frenche4aa25e2012-10-01 12:26:22 -0500206 __le16 Dialects[1]; /* One dialect (vers=) at a time for now */
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400207} __packed;
208
Steve Frenche4aa25e2012-10-01 12:26:22 -0500209/* Dialects */
210#define SMB20_PROT_ID 0x0202
211#define SMB21_PROT_ID 0x0210
212#define SMB30_PROT_ID 0x0300
Steve French20b6d8b2013-06-12 22:48:41 -0500213#define SMB302_PROT_ID 0x0302
Steve French5f7fbf72014-12-17 22:52:58 -0600214#define SMB311_PROT_ID 0x0311
Steve Frenche4aa25e2012-10-01 12:26:22 -0500215#define BAD_PROT_ID 0xFFFF
216
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400217/* SecurityMode flags */
218#define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001
219#define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
220/* Capabilities flags */
221#define SMB2_GLOBAL_CAP_DFS 0x00000001
222#define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */
223#define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */
Steve Frenche4aa25e2012-10-01 12:26:22 -0500224#define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */
225#define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
226#define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */
227#define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */
Pavel Shilovsky29e20f92012-07-13 13:58:14 +0400228/* Internal types */
229#define SMB2_NT_FIND 0x00100000
230#define SMB2_LARGE_FILES 0x00200000
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400231
Steve Frencheed0e172015-02-06 00:03:52 -0600232#define SMB311_SALT_SIZE 32
233/* Hash Algorithm Types */
Steve Frenchebb3a9d2015-06-18 04:49:47 -0500234#define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001)
Steve Frencheed0e172015-02-06 00:03:52 -0600235
236struct smb2_preauth_neg_context {
237 __le16 ContextType; /* 1 */
238 __le16 DataLength;
239 __le32 Reserved;
240 __le16 HashAlgorithmCount; /* 1 */
241 __le16 SaltLength;
242 __le16 HashAlgorithms; /* HashAlgorithms[0] since only one defined */
243 __u8 Salt[SMB311_SALT_SIZE];
244} __packed;
245
246/* Encryption Algorithms Ciphers */
247#define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001)
248#define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002)
249
250struct smb2_encryption_neg_context {
251 __le16 ContextType; /* 2 */
252 __le16 DataLength;
253 __le32 Reserved;
Steve Frenchebb3a9d2015-06-18 04:49:47 -0500254 __le16 CipherCount; /* AES-128-GCM and AES-128-CCM */
255 __le16 Ciphers[2]; /* Ciphers[0] since only one used now */
Steve Frencheed0e172015-02-06 00:03:52 -0600256} __packed;
257
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400258struct smb2_negotiate_rsp {
259 struct smb2_hdr hdr;
260 __le16 StructureSize; /* Must be 65 */
261 __le16 SecurityMode;
262 __le16 DialectRevision;
Steve French5f7fbf72014-12-17 22:52:58 -0600263 __le16 NegotiateContextCount; /* Prior to SMB3.1.1 was Reserved & MBZ */
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400264 __u8 ServerGUID[16];
265 __le32 Capabilities;
266 __le32 MaxTransactSize;
267 __le32 MaxReadSize;
268 __le32 MaxWriteSize;
269 __le64 SystemTime; /* MBZ */
270 __le64 ServerStartTime;
271 __le16 SecurityBufferOffset;
272 __le16 SecurityBufferLength;
Steve French5f7fbf72014-12-17 22:52:58 -0600273 __le32 NegotiateContextOffset; /* Pre:SMB3.1.1 was reserved/ignored */
Pavel Shilovskyec2e4522011-12-27 16:12:43 +0400274 __u8 Buffer[1]; /* variable length GSS security buffer */
275} __packed;
276
Steve Frencheed0e172015-02-06 00:03:52 -0600277/* Flags */
278#define SMB2_SESSION_REQ_FLAG_BINDING 0x01
279#define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04
280
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400281struct smb2_sess_setup_req {
282 struct smb2_hdr hdr;
283 __le16 StructureSize; /* Must be 25 */
Steve Frencheed0e172015-02-06 00:03:52 -0600284 __u8 Flags;
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400285 __u8 SecurityMode;
286 __le32 Capabilities;
287 __le32 Channel;
288 __le16 SecurityBufferOffset;
289 __le16 SecurityBufferLength;
Steve Frenchc2afb812016-09-20 22:56:13 -0500290 __u64 PreviousSessionId;
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400291 __u8 Buffer[1]; /* variable length GSS security buffer */
292} __packed;
293
294/* Currently defined SessionFlags */
295#define SMB2_SESSION_FLAG_IS_GUEST 0x0001
296#define SMB2_SESSION_FLAG_IS_NULL 0x0002
Steve French0cbaa532013-11-15 23:50:24 -0600297#define SMB2_SESSION_FLAG_ENCRYPT_DATA 0x0004
Pavel Shilovsky5478f9b2011-12-27 16:22:00 +0400298struct smb2_sess_setup_rsp {
299 struct smb2_hdr hdr;
300 __le16 StructureSize; /* Must be 9 */
301 __le16 SessionFlags;
302 __le16 SecurityBufferOffset;
303 __le16 SecurityBufferLength;
304 __u8 Buffer[1]; /* variable length GSS security buffer */
305} __packed;
306
307struct smb2_logoff_req {
308 struct smb2_hdr hdr;
309 __le16 StructureSize; /* Must be 4 */
310 __le16 Reserved;
311} __packed;
312
313struct smb2_logoff_rsp {
314 struct smb2_hdr hdr;
315 __le16 StructureSize; /* Must be 4 */
316 __le16 Reserved;
317} __packed;
318
Steve Frencheed0e172015-02-06 00:03:52 -0600319/* Flags/Reserved for SMB3.1.1 */
320#define SMB2_SHAREFLAG_CLUSTER_RECONNECT 0x0001
321
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400322struct smb2_tree_connect_req {
323 struct smb2_hdr hdr;
324 __le16 StructureSize; /* Must be 9 */
Steve Frencheed0e172015-02-06 00:03:52 -0600325 __le16 Reserved; /* Flags in SMB3.1.1 */
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400326 __le16 PathOffset;
327 __le16 PathLength;
328 __u8 Buffer[1]; /* variable length */
329} __packed;
330
331struct smb2_tree_connect_rsp {
332 struct smb2_hdr hdr;
333 __le16 StructureSize; /* Must be 16 */
334 __u8 ShareType; /* see below */
335 __u8 Reserved;
336 __le32 ShareFlags; /* see below */
337 __le32 Capabilities; /* see below */
338 __le32 MaximalAccess;
339} __packed;
340
341/* Possible ShareType values */
342#define SMB2_SHARE_TYPE_DISK 0x01
343#define SMB2_SHARE_TYPE_PIPE 0x02
344#define SMB2_SHARE_TYPE_PRINT 0x03
345
346/*
347 * Possible ShareFlags - exactly one and only one of the first 4 caching flags
348 * must be set (any of the remaining, SHI1005, flags may be set individually
349 * or in combination.
350 */
351#define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000
352#define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010
353#define SMB2_SHAREFLAG_VDO_CACHING 0x00000020
354#define SMB2_SHAREFLAG_NO_CACHING 0x00000030
355#define SHI1005_FLAGS_DFS 0x00000001
356#define SHI1005_FLAGS_DFS_ROOT 0x00000002
357#define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS 0x00000100
358#define SHI1005_FLAGS_FORCE_SHARED_DELETE 0x00000200
359#define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING 0x00000400
360#define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM 0x00000800
361#define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK 0x00001000
Steve Frenchc8664732013-06-21 15:35:45 -0500362#define SHI1005_FLAGS_ENABLE_HASH_V1 0x00002000
363#define SHI1005_FLAGS_ENABLE_HASH_V2 0x00004000
364#define SHI1005_FLAGS_ENCRYPT_DATA 0x00008000
365#define SHI1005_FLAGS_ALL 0x0000FF33
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400366
367/* Possible share capabilities */
Steve French2b5dc282013-06-13 10:51:10 -0500368#define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008) /* all dialects */
369#define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY cpu_to_le32(0x00000010) /* 3.0 */
370#define SMB2_SHARE_CAP_SCALEOUT cpu_to_le32(0x00000020) /* 3.0 */
371#define SMB2_SHARE_CAP_CLUSTER cpu_to_le32(0x00000040) /* 3.0 */
372#define SMB2_SHARE_CAP_ASYMMETRIC cpu_to_le32(0x00000080) /* 3.02 */
Pavel Shilovskyfaaf9462011-12-27 16:04:00 +0400373
374struct smb2_tree_disconnect_req {
375 struct smb2_hdr hdr;
376 __le16 StructureSize; /* Must be 4 */
377 __le16 Reserved;
378} __packed;
379
380struct smb2_tree_disconnect_rsp {
381 struct smb2_hdr hdr;
382 __le16 StructureSize; /* Must be 4 */
383 __le16 Reserved;
384} __packed;
385
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400386/* File Attrubutes */
387#define FILE_ATTRIBUTE_READONLY 0x00000001
388#define FILE_ATTRIBUTE_HIDDEN 0x00000002
389#define FILE_ATTRIBUTE_SYSTEM 0x00000004
390#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
391#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
392#define FILE_ATTRIBUTE_NORMAL 0x00000080
393#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
394#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
395#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
396#define FILE_ATTRIBUTE_COMPRESSED 0x00000800
397#define FILE_ATTRIBUTE_OFFLINE 0x00001000
398#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
399#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
Steve French73322972014-09-23 19:25:42 -0500400#define FILE_ATTRIBUTE_INTEGRITY_STREAM 0x00008000
401#define FILE_ATTRIBUTE_NO_SCRUB_DATA 0x00020000
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400402
403/* Oplock levels */
404#define SMB2_OPLOCK_LEVEL_NONE 0x00
405#define SMB2_OPLOCK_LEVEL_II 0x01
406#define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
407#define SMB2_OPLOCK_LEVEL_BATCH 0x09
408#define SMB2_OPLOCK_LEVEL_LEASE 0xFF
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700409/* Non-spec internal type */
410#define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400411
412/* Desired Access Flags */
413#define FILE_READ_DATA_LE cpu_to_le32(0x00000001)
414#define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002)
415#define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004)
416#define FILE_READ_EA_LE cpu_to_le32(0x00000008)
417#define FILE_WRITE_EA_LE cpu_to_le32(0x00000010)
418#define FILE_EXECUTE_LE cpu_to_le32(0x00000020)
419#define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080)
420#define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100)
421#define FILE_DELETE_LE cpu_to_le32(0x00010000)
422#define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000)
423#define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000)
424#define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000)
425#define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000)
426#define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000)
427#define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000)
428#define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000)
429#define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000)
430#define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000)
431#define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000)
432
433/* ShareAccess Flags */
434#define FILE_SHARE_READ_LE cpu_to_le32(0x00000001)
435#define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002)
436#define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004)
437#define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007)
438
439/* CreateDisposition Flags */
440#define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000)
441#define FILE_OPEN_LE cpu_to_le32(0x00000001)
442#define FILE_CREATE_LE cpu_to_le32(0x00000002)
443#define FILE_OPEN_IF_LE cpu_to_le32(0x00000003)
444#define FILE_OVERWRITE_LE cpu_to_le32(0x00000004)
445#define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005)
446
447/* CreateOptions Flags */
448#define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001)
449/* same as #define CREATE_NOT_FILE_LE cpu_to_le32(0x00000001) */
450#define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002)
451#define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004)
452#define FILE_NO_INTERMEDIATE_BUFFERRING_LE cpu_to_le32(0x00000008)
453#define FILE_SYNCHRONOUS_IO_ALERT_LE cpu_to_le32(0x00000010)
454#define FILE_SYNCHRONOUS_IO_NON_ALERT_LE cpu_to_le32(0x00000020)
455#define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040)
456#define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100)
457#define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200)
458#define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800)
459#define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000)
460#define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000)
461#define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000)
462#define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000)
463#define FILE_RESERVE_OPFILTER_LE cpu_to_le32(0x00100000)
464#define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000)
465#define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000)
466#define FILE_OPEN_FOR_FREE_SPACE_QUERY_LE cpu_to_le32(0x00800000)
467
468#define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \
469 | FILE_READ_ATTRIBUTES_LE)
470#define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \
471 | FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
472#define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
473
474/* Impersonation Levels */
475#define IL_ANONYMOUS cpu_to_le32(0x00000000)
476#define IL_IDENTIFICATION cpu_to_le32(0x00000001)
477#define IL_IMPERSONATION cpu_to_le32(0x00000002)
478#define IL_DELEGATE cpu_to_le32(0x00000003)
479
480/* Create Context Values */
481#define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */
482#define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */
483#define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ"
484#define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC"
Steve French12197a72014-05-14 05:29:40 -0700485#define SMB2_CREATE_ALLOCATION_SIZE "AISi"
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400486#define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
487#define SMB2_CREATE_TIMEWARP_REQUEST "TWrp"
488#define SMB2_CREATE_QUERY_ON_DISK_ID "QFid"
489#define SMB2_CREATE_REQUEST_LEASE "RqLs"
Steve French12197a72014-05-14 05:29:40 -0700490#define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 "DH2Q"
491#define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 "DH2C"
492#define SMB2_CREATE_APP_INSTANCE_ID 0x45BCA66AEFA7F74A9008FA462E144D74
493#define SVHDX_OPEN_DEVICE_CONTEXT 0x83CE6F1AD851E0986E34401CC9BCFCE9
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400494
495struct smb2_create_req {
496 struct smb2_hdr hdr;
497 __le16 StructureSize; /* Must be 57 */
498 __u8 SecurityFlags;
499 __u8 RequestedOplockLevel;
500 __le32 ImpersonationLevel;
501 __le64 SmbCreateFlags;
502 __le64 Reserved;
503 __le32 DesiredAccess;
504 __le32 FileAttributes;
505 __le32 ShareAccess;
506 __le32 CreateDisposition;
507 __le32 CreateOptions;
508 __le16 NameOffset;
509 __le16 NameLength;
510 __le32 CreateContextsOffset;
511 __le32 CreateContextsLength;
Pavel Shilovsky59aa3712013-07-04 19:41:24 +0400512 __u8 Buffer[0];
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400513} __packed;
514
515struct smb2_create_rsp {
516 struct smb2_hdr hdr;
517 __le16 StructureSize; /* Must be 89 */
518 __u8 OplockLevel;
519 __u8 Reserved;
520 __le32 CreateAction;
521 __le64 CreationTime;
522 __le64 LastAccessTime;
523 __le64 LastWriteTime;
524 __le64 ChangeTime;
525 __le64 AllocationSize;
526 __le64 EndofFile;
527 __le32 FileAttributes;
528 __le32 Reserved2;
529 __u64 PersistentFileId; /* opaque endianness */
530 __u64 VolatileFileId; /* opaque endianness */
531 __le32 CreateContextsOffset;
532 __le32 CreateContextsLength;
533 __u8 Buffer[1];
534} __packed;
535
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700536struct create_context {
537 __le32 Next;
538 __le16 NameOffset;
539 __le16 NameLength;
540 __le16 Reserved;
541 __le16 DataOffset;
542 __le32 DataLength;
543 __u8 Buffer[0];
544} __packed;
545
Pavel Shilovsky53ef1012013-09-05 16:11:28 +0400546#define SMB2_LEASE_READ_CACHING_HE 0x01
547#define SMB2_LEASE_HANDLE_CACHING_HE 0x02
548#define SMB2_LEASE_WRITE_CACHING_HE 0x04
549
Fabian Frederickbc09d142014-12-10 15:41:15 -0800550#define SMB2_LEASE_NONE cpu_to_le32(0x00)
551#define SMB2_LEASE_READ_CACHING cpu_to_le32(0x01)
552#define SMB2_LEASE_HANDLE_CACHING cpu_to_le32(0x02)
553#define SMB2_LEASE_WRITE_CACHING cpu_to_le32(0x04)
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700554
Fabian Frederickbc09d142014-12-10 15:41:15 -0800555#define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS cpu_to_le32(0x02)
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700556
557#define SMB2_LEASE_KEY_SIZE 16
558
559struct lease_context {
560 __le64 LeaseKeyLow;
561 __le64 LeaseKeyHigh;
562 __le32 LeaseState;
563 __le32 LeaseFlags;
564 __le64 LeaseDuration;
565} __packed;
566
Pavel Shilovskyf0473902013-09-04 13:44:05 +0400567struct lease_context_v2 {
568 __le64 LeaseKeyLow;
569 __le64 LeaseKeyHigh;
570 __le32 LeaseState;
571 __le32 LeaseFlags;
572 __le64 LeaseDuration;
573 __le64 ParentLeaseKeyLow;
574 __le64 ParentLeaseKeyHigh;
575 __le16 Epoch;
576 __le16 Reserved;
577} __packed;
578
Pavel Shilovskyb8c32db2012-09-19 06:22:44 -0700579struct create_lease {
580 struct create_context ccontext;
581 __u8 Name[8];
582 struct lease_context lcontext;
583} __packed;
584
Pavel Shilovskyf0473902013-09-04 13:44:05 +0400585struct create_lease_v2 {
586 struct create_context ccontext;
587 __u8 Name[8];
588 struct lease_context_v2 lcontext;
589 __u8 Pad[4];
590} __packed;
591
Pavel Shilovsky63eb3de2013-07-04 18:41:09 +0400592struct create_durable {
593 struct create_context ccontext;
594 __u8 Name[8];
Pavel Shilovsky9cbc0b72013-07-09 18:40:58 +0400595 union {
596 __u8 Reserved[16];
597 struct {
598 __u64 PersistentFileId;
599 __u64 VolatileFileId;
600 } Fid;
601 } Data;
Pavel Shilovsky63eb3de2013-07-04 18:41:09 +0400602} __packed;
603
Steve Frenchb56eae42015-11-03 09:26:27 -0600604/* See MS-SMB2 2.2.13.2.11 */
605/* Flags */
606#define SMB2_DHANDLE_FLAG_PERSISTENT 0x00000002
607struct durable_context_v2 {
608 __le32 Timeout;
609 __le32 Flags;
610 __u64 Reserved;
611 __u8 CreateGuid[16];
612} __packed;
613
614struct create_durable_v2 {
615 struct create_context ccontext;
616 __u8 Name[8];
617 struct durable_context_v2 dcontext;
618} __packed;
619
620/* See MS-SMB2 2.2.13.2.12 */
621struct durable_reconnect_context_v2 {
622 struct {
623 __u64 PersistentFileId;
624 __u64 VolatileFileId;
625 } Fid;
626 __u8 CreateGuid[16];
627 __le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
628} __packed;
629
630/* See MS-SMB2 2.2.14.2.12 */
631struct durable_reconnect_context_v2_rsp {
632 __le32 Timeout;
633 __le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
634} __packed;
635
636struct create_durable_handle_reconnect_v2 {
637 struct create_context ccontext;
638 __u8 Name[8];
639 struct durable_reconnect_context_v2 dcontext;
640} __packed;
641
Steve French41c13582013-11-14 00:05:36 -0600642#define COPY_CHUNK_RES_KEY_SIZE 24
643struct resume_key_req {
644 char ResumeKey[COPY_CHUNK_RES_KEY_SIZE];
645 __le32 ContextLength; /* MBZ */
646 char Context[0]; /* ignored, Windows sets to 4 bytes of zero */
647} __packed;
648
Steve Frenchbe7457d2013-06-19 17:41:10 -0500649/* this goes in the ioctl buffer when doing a copychunk request */
650struct copychunk_ioctl {
Steve French41c13582013-11-14 00:05:36 -0600651 char SourceKey[COPY_CHUNK_RES_KEY_SIZE];
Steve Frenchbe7457d2013-06-19 17:41:10 -0500652 __le32 ChunkCount; /* we are only sending 1 */
653 __le32 Reserved;
654 /* array will only be one chunk long for us */
655 __le64 SourceOffset;
656 __le64 TargetOffset;
Steve Frenchc8664732013-06-21 15:35:45 -0500657 __le32 Length; /* how many bytes to copy */
Steve Frenchbe7457d2013-06-19 17:41:10 -0500658 __u32 Reserved2;
659} __packed;
660
Steve French31742c52014-08-17 08:38:47 -0500661/* this goes in the ioctl buffer when doing FSCTL_SET_ZERO_DATA */
662struct file_zero_data_information {
663 __le64 FileOffset;
664 __le64 BeyondFinalZero;
665} __packed;
666
Steve French41c13582013-11-14 00:05:36 -0600667struct copychunk_ioctl_rsp {
668 __le32 ChunksWritten;
669 __le32 ChunkBytesWritten;
670 __le32 TotalBytesWritten;
671} __packed;
672
Steve French9d1b0662015-06-24 02:12:19 -0500673struct fsctl_set_integrity_information_req {
674 __le16 ChecksumAlgorithm;
675 __le16 Reserved;
676 __le32 Flags;
677} __packed;
678
679struct fsctl_get_integrity_information_rsp {
680 __le16 ChecksumAlgorithm;
681 __le16 Reserved;
682 __le32 Flags;
683 __le32 ChecksumChunkSizeInBytes;
684 __le32 ClusterSizeInBytes;
685} __packed;
686
687/* Integrity ChecksumAlgorithm choices for above */
688#define CHECKSUM_TYPE_NONE 0x0000
689#define CHECKSUM_TYPE_CRC64 0x0002
Steve Frenchb3152e22015-06-24 03:17:02 -0500690#define CHECKSUM_TYPE_UNCHANGED 0xFFFF /* set only */
Steve French9d1b0662015-06-24 02:12:19 -0500691
692/* Integrity flags for above */
693#define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF 0x00000001
694
Steve Frenchb56eae42015-11-03 09:26:27 -0600695/* See MS-SMB2 2.2.31.3 */
696struct network_resiliency_req {
697 __le32 Timeout;
698 __le32 Reserved;
699} __packed;
700/* There is no buffer for the response ie no struct network_resiliency_rsp */
701
Steve French9d1b0662015-06-24 02:12:19 -0500702
Steve Frenchff1c0382013-11-19 23:44:46 -0600703struct validate_negotiate_info_req {
Steve French4a72daf2013-06-25 00:20:49 -0500704 __le32 Capabilities;
705 __u8 Guid[SMB2_CLIENT_GUID_SIZE];
706 __le16 SecurityMode;
707 __le16 DialectCount;
Steve Frenchff1c0382013-11-19 23:44:46 -0600708 __le16 Dialects[1]; /* dialect (someday maybe list) client asked for */
709} __packed;
710
711struct validate_negotiate_info_rsp {
712 __le32 Capabilities;
713 __u8 Guid[SMB2_CLIENT_GUID_SIZE];
714 __le16 SecurityMode;
715 __le16 Dialect; /* Dialect in use for the connection */
Steve French4a72daf2013-06-25 00:20:49 -0500716} __packed;
717
718#define RSS_CAPABLE 0x00000001
719#define RDMA_CAPABLE 0x00000002
720
721struct network_interface_info_ioctl_rsp {
722 __le32 Next; /* next interface. zero if this is last one */
723 __le32 IfIndex;
724 __le32 Capability; /* RSS or RDMA Capable */
725 __le32 Reserved;
726 __le64 LinkSpeed;
727 char SockAddr_Storage[128];
728} __packed;
729
730#define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */
731
Steve French64a5cfa2013-10-14 15:31:32 -0500732struct compress_ioctl {
Steve Frenchc7f508a2013-10-14 15:27:32 -0500733 __le16 CompressionState; /* See cifspdu.h for possible flag values */
Steve French64a5cfa2013-10-14 15:31:32 -0500734} __packed;
735
Steve French02b16662015-06-27 21:18:36 -0700736struct duplicate_extents_to_file {
737 __u64 PersistentFileHandle; /* source file handle, opaque endianness */
738 __u64 VolatileFileHandle;
739 __le64 SourceFileOffset;
740 __le64 TargetFileOffset;
741 __le64 ByteCount; /* Bytes to be copied */
742} __packed;
743
Steve Frenchbe7457d2013-06-19 17:41:10 -0500744struct smb2_ioctl_req {
745 struct smb2_hdr hdr;
746 __le16 StructureSize; /* Must be 57 */
747 __u16 Reserved;
748 __le32 CtlCode;
749 __u64 PersistentFileId; /* opaque endianness */
750 __u64 VolatileFileId; /* opaque endianness */
751 __le32 InputOffset;
752 __le32 InputCount;
753 __le32 MaxInputResponse;
754 __le32 OutputOffset;
755 __le32 OutputCount;
756 __le32 MaxOutputResponse;
757 __le32 Flags;
758 __u32 Reserved2;
Steve French64a5cfa2013-10-14 15:31:32 -0500759 __u8 Buffer[0];
Steve Frenchbe7457d2013-06-19 17:41:10 -0500760} __packed;
761
762struct smb2_ioctl_rsp {
763 struct smb2_hdr hdr;
764 __le16 StructureSize; /* Must be 57 */
765 __u16 Reserved;
766 __le32 CtlCode;
767 __u64 PersistentFileId; /* opaque endianness */
768 __u64 VolatileFileId; /* opaque endianness */
769 __le32 InputOffset;
770 __le32 InputCount;
771 __le32 OutputOffset;
772 __le32 OutputCount;
773 __le32 Flags;
774 __u32 Reserved2;
775 /* char * buffer[] */
776} __packed;
777
Pavel Shilovsky2503a0d2011-12-26 22:58:46 +0400778/* Currently defined values for close flags */
779#define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
780struct smb2_close_req {
781 struct smb2_hdr hdr;
782 __le16 StructureSize; /* Must be 24 */
783 __le16 Flags;
784 __le32 Reserved;
785 __u64 PersistentFileId; /* opaque endianness */
786 __u64 VolatileFileId; /* opaque endianness */
787} __packed;
788
789struct smb2_close_rsp {
790 struct smb2_hdr hdr;
791 __le16 StructureSize; /* 60 */
792 __le16 Flags;
793 __le32 Reserved;
794 __le64 CreationTime;
795 __le64 LastAccessTime;
796 __le64 LastWriteTime;
797 __le64 ChangeTime;
798 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
799 __le64 EndOfFile;
800 __le32 Attributes;
801} __packed;
802
Pavel Shilovsky7a5cfb12012-09-18 16:20:28 -0700803struct smb2_flush_req {
804 struct smb2_hdr hdr;
805 __le16 StructureSize; /* Must be 24 */
806 __le16 Reserved1;
807 __le32 Reserved2;
808 __u64 PersistentFileId; /* opaque endianness */
809 __u64 VolatileFileId; /* opaque endianness */
810} __packed;
811
812struct smb2_flush_rsp {
813 struct smb2_hdr hdr;
814 __le16 StructureSize;
815 __le16 Reserved;
816} __packed;
817
Steve French2b5dc282013-06-13 10:51:10 -0500818/* For read request Flags field below, following flag is defined for SMB3.02 */
819#define SMB2_READFLAG_READ_UNBUFFERED 0x01
820
821/* Channel field for read and write: exactly one of following flags can be set*/
822#define SMB2_CHANNEL_NONE 0x00000000
823#define SMB2_CHANNEL_RDMA_V1 0x00000001 /* SMB3 or later */
824#define SMB2_CHANNEL_RDMA_V1_INVALIDATE 0x00000001 /* SMB3.02 or later */
825
Pavel Shilovskyb8f57ee2016-11-23 15:31:54 -0800826/* SMB2 read request without RFC1001 length at the beginning */
827struct smb2_read_plain_req {
828 struct smb2_sync_hdr sync_hdr;
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700829 __le16 StructureSize; /* Must be 49 */
830 __u8 Padding; /* offset from start of SMB2 header to place read */
Steve French2b5dc282013-06-13 10:51:10 -0500831 __u8 Flags; /* MBZ unless SMB3.02 or later */
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700832 __le32 Length;
833 __le64 Offset;
834 __u64 PersistentFileId; /* opaque endianness */
835 __u64 VolatileFileId; /* opaque endianness */
836 __le32 MinimumCount;
Steve French2b5dc282013-06-13 10:51:10 -0500837 __le32 Channel; /* MBZ except for SMB3 or later */
Pavel Shilovsky09a47072012-09-18 16:20:29 -0700838 __le32 RemainingBytes;
839 __le16 ReadChannelInfoOffset; /* Reserved MBZ */
840 __le16 ReadChannelInfoLength; /* Reserved MBZ */
841 __u8 Buffer[1];
842} __packed;
843
844struct smb2_read_rsp {
845 struct smb2_hdr hdr;
846 __le16 StructureSize; /* Must be 17 */
847 __u8 DataOffset;
848 __u8 Reserved;
849 __le32 DataLength;
850 __le32 DataRemaining;
851 __u32 Reserved2;
852 __u8 Buffer[1];
853} __packed;
854
Steve French2b5dc282013-06-13 10:51:10 -0500855/* For write request Flags field below the following flags are defined: */
856#define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 /* SMB2.1 or later */
857#define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002 /* SMB3.02 or later */
Pavel Shilovsky33319142012-09-18 16:20:29 -0700858
859struct smb2_write_req {
860 struct smb2_hdr hdr;
861 __le16 StructureSize; /* Must be 49 */
862 __le16 DataOffset; /* offset from start of SMB2 header to write data */
863 __le32 Length;
864 __le64 Offset;
865 __u64 PersistentFileId; /* opaque endianness */
866 __u64 VolatileFileId; /* opaque endianness */
867 __le32 Channel; /* Reserved MBZ */
868 __le32 RemainingBytes;
869 __le16 WriteChannelInfoOffset; /* Reserved MBZ */
870 __le16 WriteChannelInfoLength; /* Reserved MBZ */
871 __le32 Flags;
872 __u8 Buffer[1];
873} __packed;
874
875struct smb2_write_rsp {
876 struct smb2_hdr hdr;
877 __le16 StructureSize; /* Must be 17 */
878 __u8 DataOffset;
879 __u8 Reserved;
880 __le32 DataLength;
881 __le32 DataRemaining;
882 __u32 Reserved2;
883 __u8 Buffer[1];
884} __packed;
885
Pavel Shilovsky027e8ee2012-09-19 06:22:43 -0700886#define SMB2_LOCKFLAG_SHARED_LOCK 0x0001
887#define SMB2_LOCKFLAG_EXCLUSIVE_LOCK 0x0002
888#define SMB2_LOCKFLAG_UNLOCK 0x0004
889#define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010
890
Pavel Shilovskyf7ba7fe2012-09-19 06:22:43 -0700891struct smb2_lock_element {
892 __le64 Offset;
893 __le64 Length;
894 __le32 Flags;
895 __le32 Reserved;
896} __packed;
897
898struct smb2_lock_req {
899 struct smb2_hdr hdr;
900 __le16 StructureSize; /* Must be 48 */
901 __le16 LockCount;
902 __le32 Reserved;
903 __u64 PersistentFileId; /* opaque endianness */
904 __u64 VolatileFileId; /* opaque endianness */
905 /* Followed by at least one */
906 struct smb2_lock_element locks[1];
907} __packed;
908
909struct smb2_lock_rsp {
910 struct smb2_hdr hdr;
911 __le16 StructureSize; /* Must be 4 */
912 __le16 Reserved;
913} __packed;
914
Pavel Shilovsky9094fad2012-07-12 18:30:44 +0400915struct smb2_echo_req {
916 struct smb2_hdr hdr;
917 __le16 StructureSize; /* Must be 4 */
918 __u16 Reserved;
919} __packed;
920
921struct smb2_echo_rsp {
922 struct smb2_hdr hdr;
923 __le16 StructureSize; /* Must be 4 */
924 __u16 Reserved;
925} __packed;
926
Pavel Shilovskyd324f08d2012-09-18 16:20:33 -0700927/* search (query_directory) Flags field */
928#define SMB2_RESTART_SCANS 0x01
929#define SMB2_RETURN_SINGLE_ENTRY 0x02
930#define SMB2_INDEX_SPECIFIED 0x04
931#define SMB2_REOPEN 0x10
932
933struct smb2_query_directory_req {
934 struct smb2_hdr hdr;
935 __le16 StructureSize; /* Must be 33 */
936 __u8 FileInformationClass;
937 __u8 Flags;
938 __le32 FileIndex;
939 __u64 PersistentFileId; /* opaque endianness */
940 __u64 VolatileFileId; /* opaque endianness */
941 __le16 FileNameOffset;
942 __le16 FileNameLength;
943 __le32 OutputBufferLength;
944 __u8 Buffer[1];
945} __packed;
946
947struct smb2_query_directory_rsp {
948 struct smb2_hdr hdr;
949 __le16 StructureSize; /* Must be 9 */
950 __le16 OutputBufferOffset;
951 __le32 OutputBufferLength;
952 __u8 Buffer[1];
953} __packed;
954
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +0400955/* Possible InfoType values */
956#define SMB2_O_INFO_FILE 0x01
957#define SMB2_O_INFO_FILESYSTEM 0x02
958#define SMB2_O_INFO_SECURITY 0x03
959#define SMB2_O_INFO_QUOTA 0x04
960
Steve French911a8df2014-10-19 19:18:05 -0500961/* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */
962#define OWNER_SECINFO 0x00000001
963#define GROUP_SECINFO 0x00000002
964#define DACL_SECINFO 0x00000004
965#define SACL_SECINFO 0x00000008
966#define LABEL_SECINFO 0x00000010
967#define ATTRIBUTE_SECINFO 0x00000020
968#define SCOPE_SECINFO 0x00000040
969#define BACKUP_SECINFO 0x00010000
970#define UNPROTECTED_SACL_SECINFO 0x10000000
971#define UNPROTECTED_DACL_SECINFO 0x20000000
972#define PROTECTED_SACL_SECINFO 0x40000000
973#define PROTECTED_DACL_SECINFO 0x80000000
974
975/* Flags used for FileFullEAinfo */
976#define SL_RESTART_SCAN 0x00000001
977#define SL_RETURN_SINGLE_ENTRY 0x00000002
978#define SL_INDEX_SPECIFIED 0x00000004
979
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +0400980struct smb2_query_info_req {
981 struct smb2_hdr hdr;
982 __le16 StructureSize; /* Must be 41 */
983 __u8 InfoType;
984 __u8 FileInfoClass;
985 __le32 OutputBufferLength;
986 __le16 InputBufferOffset;
987 __u16 Reserved;
988 __le32 InputBufferLength;
989 __le32 AdditionalInformation;
990 __le32 Flags;
991 __u64 PersistentFileId; /* opaque endianness */
992 __u64 VolatileFileId; /* opaque endianness */
993 __u8 Buffer[1];
994} __packed;
995
996struct smb2_query_info_rsp {
997 struct smb2_hdr hdr;
998 __le16 StructureSize; /* Must be 9 */
999 __le16 OutputBufferOffset;
1000 __le32 OutputBufferLength;
1001 __u8 Buffer[1];
1002} __packed;
1003
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07001004struct smb2_set_info_req {
1005 struct smb2_hdr hdr;
1006 __le16 StructureSize; /* Must be 33 */
1007 __u8 InfoType;
1008 __u8 FileInfoClass;
1009 __le32 BufferLength;
1010 __le16 BufferOffset;
1011 __u16 Reserved;
1012 __le32 AdditionalInformation;
1013 __u64 PersistentFileId; /* opaque endianness */
1014 __u64 VolatileFileId; /* opaque endianness */
1015 __u8 Buffer[1];
1016} __packed;
1017
1018struct smb2_set_info_rsp {
1019 struct smb2_hdr hdr;
1020 __le16 StructureSize; /* Must be 2 */
1021} __packed;
1022
Pavel Shilovsky983c88a2012-09-18 16:20:33 -07001023struct smb2_oplock_break {
1024 struct smb2_hdr hdr;
1025 __le16 StructureSize; /* Must be 24 */
1026 __u8 OplockLevel;
1027 __u8 Reserved;
1028 __le32 Reserved2;
1029 __u64 PersistentFid;
1030 __u64 VolatileFid;
1031} __packed;
1032
Pavel Shilovsky0822f512012-09-19 06:22:45 -07001033#define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
1034
1035struct smb2_lease_break {
1036 struct smb2_hdr hdr;
1037 __le16 StructureSize; /* Must be 44 */
1038 __le16 Reserved;
1039 __le32 Flags;
1040 __u8 LeaseKey[16];
1041 __le32 CurrentLeaseState;
1042 __le32 NewLeaseState;
1043 __le32 BreakReason;
1044 __le32 AccessMaskHint;
1045 __le32 ShareMaskHint;
1046} __packed;
1047
1048struct smb2_lease_ack {
1049 struct smb2_hdr hdr;
1050 __le16 StructureSize; /* Must be 36 */
1051 __le16 Reserved;
1052 __le32 Flags;
1053 __u8 LeaseKey[16];
1054 __le32 LeaseState;
1055 __le64 LeaseDuration;
1056} __packed;
1057
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001058/*
1059 * PDU infolevel structure definitions
1060 * BB consider moving to a different header
1061 */
1062
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001063/* File System Information Classes */
1064#define FS_VOLUME_INFORMATION 1 /* Query */
Steven Frenchaf6a12e2013-10-09 20:55:53 -05001065#define FS_LABEL_INFORMATION 2 /* Local only */
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001066#define FS_SIZE_INFORMATION 3 /* Query */
1067#define FS_DEVICE_INFORMATION 4 /* Query */
1068#define FS_ATTRIBUTE_INFORMATION 5 /* Query */
1069#define FS_CONTROL_INFORMATION 6 /* Query, Set */
1070#define FS_FULL_SIZE_INFORMATION 7 /* Query */
1071#define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */
Steven Frenchaf6a12e2013-10-09 20:55:53 -05001072#define FS_DRIVER_PATH_INFORMATION 9 /* Local only */
1073#define FS_VOLUME_FLAGS_INFORMATION 10 /* Local only */
1074#define FS_SECTOR_SIZE_INFORMATION 11 /* SMB3 or later. Query */
Pavel Shilovsky6fc05c22012-09-18 16:20:34 -07001075
1076struct smb2_fs_full_size_info {
1077 __le64 TotalAllocationUnits;
1078 __le64 CallerAvailableAllocationUnits;
1079 __le64 ActualAvailableAllocationUnits;
1080 __le32 SectorsPerAllocationUnit;
1081 __le32 BytesPerSector;
1082} __packed;
1083
Steven Frenchaf6a12e2013-10-09 20:55:53 -05001084#define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001
1085#define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
1086#define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004
1087#define SSINFO_FLAGS_TRIM_ENABLED 0x00000008
1088
1089/* sector size info struct */
1090struct smb3_fs_ss_info {
1091 __le32 LogicalBytesPerSector;
1092 __le32 PhysicalBytesPerSectorForAtomicity;
1093 __le32 PhysicalBytesPerSectorForPerf;
1094 __le32 FileSystemEffectivePhysicalBytesPerSectorForAtomicity;
1095 __le32 Flags;
1096 __le32 ByteOffsetForSectorAlignment;
1097 __le32 ByteOffsetForPartitionAlignment;
1098} __packed;
1099
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001100/* partial list of QUERY INFO levels */
1101#define FILE_DIRECTORY_INFORMATION 1
1102#define FILE_FULL_DIRECTORY_INFORMATION 2
1103#define FILE_BOTH_DIRECTORY_INFORMATION 3
1104#define FILE_BASIC_INFORMATION 4
1105#define FILE_STANDARD_INFORMATION 5
1106#define FILE_INTERNAL_INFORMATION 6
1107#define FILE_EA_INFORMATION 7
1108#define FILE_ACCESS_INFORMATION 8
1109#define FILE_NAME_INFORMATION 9
1110#define FILE_RENAME_INFORMATION 10
1111#define FILE_LINK_INFORMATION 11
1112#define FILE_NAMES_INFORMATION 12
1113#define FILE_DISPOSITION_INFORMATION 13
1114#define FILE_POSITION_INFORMATION 14
1115#define FILE_FULL_EA_INFORMATION 15
1116#define FILE_MODE_INFORMATION 16
1117#define FILE_ALIGNMENT_INFORMATION 17
1118#define FILE_ALL_INFORMATION 18
1119#define FILE_ALLOCATION_INFORMATION 19
1120#define FILE_END_OF_FILE_INFORMATION 20
1121#define FILE_ALTERNATE_NAME_INFORMATION 21
1122#define FILE_STREAM_INFORMATION 22
1123#define FILE_PIPE_INFORMATION 23
1124#define FILE_PIPE_LOCAL_INFORMATION 24
1125#define FILE_PIPE_REMOTE_INFORMATION 25
1126#define FILE_MAILSLOT_QUERY_INFORMATION 26
1127#define FILE_MAILSLOT_SET_INFORMATION 27
1128#define FILE_COMPRESSION_INFORMATION 28
1129#define FILE_OBJECT_ID_INFORMATION 29
1130/* Number 30 not defined in documents */
1131#define FILE_MOVE_CLUSTER_INFORMATION 31
1132#define FILE_QUOTA_INFORMATION 32
1133#define FILE_REPARSE_POINT_INFORMATION 33
1134#define FILE_NETWORK_OPEN_INFORMATION 34
1135#define FILE_ATTRIBUTE_TAG_INFORMATION 35
1136#define FILE_TRACKING_INFORMATION 36
1137#define FILEID_BOTH_DIRECTORY_INFORMATION 37
1138#define FILEID_FULL_DIRECTORY_INFORMATION 38
1139#define FILE_VALID_DATA_LENGTH_INFORMATION 39
1140#define FILE_SHORT_NAME_INFORMATION 40
1141#define FILE_SFIO_RESERVE_INFORMATION 44
1142#define FILE_SFIO_VOLUME_INFORMATION 45
1143#define FILE_HARD_LINK_INFORMATION 46
1144#define FILE_NORMALIZED_NAME_INFORMATION 48
1145#define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
1146#define FILE_STANDARD_LINK_INFORMATION 54
1147
Pavel Shilovskyf0df7372012-09-18 16:20:26 -07001148struct smb2_file_internal_info {
1149 __le64 IndexNumber;
1150} __packed; /* level 6 Query */
1151
Pavel Shilovsky35143eb2012-09-18 16:20:31 -07001152struct smb2_file_rename_info { /* encoding of request for level 10 */
1153 __u8 ReplaceIfExists; /* 1 = replace existing target with new */
1154 /* 0 = fail if target already exists */
1155 __u8 Reserved[7];
1156 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1157 __le32 FileNameLength;
1158 char FileName[0]; /* New name to be assigned */
1159} __packed; /* level 10 Set */
1160
Pavel Shilovsky568798c2012-09-18 16:20:31 -07001161struct smb2_file_link_info { /* encoding of request for level 11 */
1162 __u8 ReplaceIfExists; /* 1 = replace existing link with new */
1163 /* 0 = fail if link already exists */
1164 __u8 Reserved[7];
1165 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1166 __le32 FileNameLength;
1167 char FileName[0]; /* Name to be assigned to new link */
1168} __packed; /* level 11 Set */
1169
Pavel Shilovskybe4cb9e2011-12-29 17:06:33 +04001170/*
1171 * This level 18, although with struct with same name is different from cifs
1172 * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
1173 * CurrentByteOffset.
1174 */
1175struct smb2_file_all_info { /* data block encoding of response to level 18 */
1176 __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
1177 __le64 LastAccessTime;
1178 __le64 LastWriteTime;
1179 __le64 ChangeTime;
1180 __le32 Attributes;
1181 __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
1182 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
1183 __le64 EndOfFile; /* size ie offset to first free byte in file */
1184 __le32 NumberOfLinks; /* hard links */
1185 __u8 DeletePending;
1186 __u8 Directory;
1187 __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */
1188 __le64 IndexNumber;
1189 __le32 EASize;
1190 __le32 AccessFlags;
1191 __le64 CurrentByteOffset;
1192 __le32 Mode;
1193 __le32 AlignmentRequirement;
1194 __le32 FileNameLength;
1195 char FileName[1];
1196} __packed; /* level 18 Query */
1197
Pavel Shilovskyc839ff22012-09-18 16:20:32 -07001198struct smb2_file_eof_info { /* encoding of request for level 10 */
1199 __le64 EndOfFile; /* new end of file value */
1200} __packed; /* level 20 Set */
1201
Steve Frenchddfbefb2011-03-15 02:08:48 +00001202#endif /* _SMB2PDU_H */