]> git.ipfire.org Git - thirdparty/linux.git/blame - fs/cifs/smb2pdu.h
cifs: obtain file access during backup intent lookup (resend)
[thirdparty/linux.git] / fs / cifs / smb2pdu.h
CommitLineData
ddfbefbd
SF
1/*
2 * fs/cifs/smb2pdu.h
3 *
4 * Copyright (c) International Business Machines Corp., 2009, 2010
5 * Etersoft, 2012
6 * Author(s): Steve French (sfrench@us.ibm.com)
7 * Pavel Shilovsky (pshilovsky@samba.org) 2012
8 *
9 * This library is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published
11 * by the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
17 * the GNU Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#ifndef _SMB2PDU_H
25#define _SMB2PDU_H
26
27#include <net/sock.h>
28
2dc7e1c0
PS
29/*
30 * Note that, due to trying to use names similar to the protocol specifications,
31 * there are many mixed case field names in the structures below. Although
32 * this does not match typical Linux kernel style, it is necessary to be
33 * be able to match against the protocol specfication.
34 *
35 * SMB2 commands
36 * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses
37 * (ie no useful data other than the SMB error code itself) and are marked such.
38 * Knowing this helps avoid response buffer allocations and copy in some cases.
39 */
40
41/* List of commands in host endian */
42#define SMB2_NEGOTIATE_HE 0x0000
43#define SMB2_SESSION_SETUP_HE 0x0001
44#define SMB2_LOGOFF_HE 0x0002 /* trivial request/resp */
45#define SMB2_TREE_CONNECT_HE 0x0003
46#define SMB2_TREE_DISCONNECT_HE 0x0004 /* trivial req/resp */
47#define SMB2_CREATE_HE 0x0005
48#define SMB2_CLOSE_HE 0x0006
49#define SMB2_FLUSH_HE 0x0007 /* trivial resp */
50#define SMB2_READ_HE 0x0008
51#define SMB2_WRITE_HE 0x0009
52#define SMB2_LOCK_HE 0x000A
53#define SMB2_IOCTL_HE 0x000B
54#define SMB2_CANCEL_HE 0x000C
55#define SMB2_ECHO_HE 0x000D
56#define SMB2_QUERY_DIRECTORY_HE 0x000E
57#define SMB2_CHANGE_NOTIFY_HE 0x000F
58#define SMB2_QUERY_INFO_HE 0x0010
59#define SMB2_SET_INFO_HE 0x0011
60#define SMB2_OPLOCK_BREAK_HE 0x0012
61
62/* The same list in little endian */
63#define SMB2_NEGOTIATE cpu_to_le16(SMB2_NEGOTIATE_HE)
64#define SMB2_SESSION_SETUP cpu_to_le16(SMB2_SESSION_SETUP_HE)
65#define SMB2_LOGOFF cpu_to_le16(SMB2_LOGOFF_HE)
66#define SMB2_TREE_CONNECT cpu_to_le16(SMB2_TREE_CONNECT_HE)
67#define SMB2_TREE_DISCONNECT cpu_to_le16(SMB2_TREE_DISCONNECT_HE)
68#define SMB2_CREATE cpu_to_le16(SMB2_CREATE_HE)
69#define SMB2_CLOSE cpu_to_le16(SMB2_CLOSE_HE)
70#define SMB2_FLUSH cpu_to_le16(SMB2_FLUSH_HE)
71#define SMB2_READ cpu_to_le16(SMB2_READ_HE)
72#define SMB2_WRITE cpu_to_le16(SMB2_WRITE_HE)
73#define SMB2_LOCK cpu_to_le16(SMB2_LOCK_HE)
74#define SMB2_IOCTL cpu_to_le16(SMB2_IOCTL_HE)
75#define SMB2_CANCEL cpu_to_le16(SMB2_CANCEL_HE)
76#define SMB2_ECHO cpu_to_le16(SMB2_ECHO_HE)
77#define SMB2_QUERY_DIRECTORY cpu_to_le16(SMB2_QUERY_DIRECTORY_HE)
78#define SMB2_CHANGE_NOTIFY cpu_to_le16(SMB2_CHANGE_NOTIFY_HE)
79#define SMB2_QUERY_INFO cpu_to_le16(SMB2_QUERY_INFO_HE)
80#define SMB2_SET_INFO cpu_to_le16(SMB2_SET_INFO_HE)
81#define SMB2_OPLOCK_BREAK cpu_to_le16(SMB2_OPLOCK_BREAK_HE)
82
83#define NUMBER_OF_SMB2_COMMANDS 0x0013
84
85/* BB FIXME - analyze following length BB */
86#define MAX_SMB2_HDR_SIZE 0x78 /* 4 len + 64 hdr + (2*24 wct) + 2 bct + 2 pad */
87
093b2bda
PS
88#define SMB2_PROTO_NUMBER __constant_cpu_to_le32(0x424d53fe)
89
ddfbefbd
SF
90/*
91 * SMB2 Header Definition
92 *
93 * "MBZ" : Must be Zero
94 * "BB" : BugBug, Something to check/review/analyze later
95 * "PDU" : "Protocol Data Unit" (ie a network "frame")
96 *
97 */
74112860 98
b2ede58e 99#define SMB2_HEADER_STRUCTURE_SIZE __constant_cpu_to_le16(64)
74112860 100
ddfbefbd
SF
101struct smb2_hdr {
102 __be32 smb2_buf_length; /* big endian on wire */
103 /* length is only two or three bytes - with
104 one or two byte type preceding it that MBZ */
105 __u8 ProtocolId[4]; /* 0xFE 'S' 'M' 'B' */
106 __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;
113 __u64 MessageId; /* opaque - so can stay little endian */
114 __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
093b2bda
PS
120struct smb2_pdu {
121 struct smb2_hdr hdr;
122 __le16 StructureSize2; /* size of wct area (varies, request specific) */
123} __packed;
124
125/*
126 * SMB2 flag definitions
127 */
128#define SMB2_FLAGS_SERVER_TO_REDIR __constant_cpu_to_le32(0x00000001)
129#define SMB2_FLAGS_ASYNC_COMMAND __constant_cpu_to_le32(0x00000002)
130#define SMB2_FLAGS_RELATED_OPERATIONS __constant_cpu_to_le32(0x00000004)
131#define SMB2_FLAGS_SIGNED __constant_cpu_to_le32(0x00000008)
132#define SMB2_FLAGS_DFS_OPERATIONS __constant_cpu_to_le32(0x10000000)
133
134/*
135 * Definitions for SMB2 Protocol Data Units (network frames)
136 *
137 * See MS-SMB2.PDF specification for protocol details.
138 * The Naming convention is the lower case version of the SMB2
139 * command code name for the struct. Note that structures must be packed.
140 *
141 */
74112860 142
b2ede58e 143#define SMB2_ERROR_STRUCTURE_SIZE2 __constant_cpu_to_le16(9)
74112860 144
093b2bda
PS
145struct smb2_err_rsp {
146 struct smb2_hdr hdr;
147 __le16 StructureSize;
148 __le16 Reserved; /* MBZ */
149 __le32 ByteCount; /* even if zero, at least one byte follows */
150 __u8 ErrorData[1]; /* variable length */
151} __packed;
152
b8c32dbb
PS
153#define SMB2_CLIENT_GUID_SIZE 16
154
155extern __u8 cifs_client_guid[SMB2_CLIENT_GUID_SIZE];
156
ec2e4523
PS
157struct smb2_negotiate_req {
158 struct smb2_hdr hdr;
159 __le16 StructureSize; /* Must be 36 */
160 __le16 DialectCount;
161 __le16 SecurityMode;
162 __le16 Reserved; /* MBZ */
163 __le32 Capabilities;
b8c32dbb 164 __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE];
ec2e4523
PS
165 __le64 ClientStartTime; /* MBZ */
166 __le16 Dialects[2]; /* variable length */
167} __packed;
168
169/* SecurityMode flags */
170#define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001
171#define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
172/* Capabilities flags */
173#define SMB2_GLOBAL_CAP_DFS 0x00000001
174#define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */
175#define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */
29e20f9c
PS
176/* Internal types */
177#define SMB2_NT_FIND 0x00100000
178#define SMB2_LARGE_FILES 0x00200000
ec2e4523
PS
179
180struct smb2_negotiate_rsp {
181 struct smb2_hdr hdr;
182 __le16 StructureSize; /* Must be 65 */
183 __le16 SecurityMode;
184 __le16 DialectRevision;
185 __le16 Reserved; /* MBZ */
186 __u8 ServerGUID[16];
187 __le32 Capabilities;
188 __le32 MaxTransactSize;
189 __le32 MaxReadSize;
190 __le32 MaxWriteSize;
191 __le64 SystemTime; /* MBZ */
192 __le64 ServerStartTime;
193 __le16 SecurityBufferOffset;
194 __le16 SecurityBufferLength;
195 __le32 Reserved2; /* may be any value, ignore */
196 __u8 Buffer[1]; /* variable length GSS security buffer */
197} __packed;
198
5478f9ba
PS
199struct smb2_sess_setup_req {
200 struct smb2_hdr hdr;
201 __le16 StructureSize; /* Must be 25 */
202 __u8 VcNumber;
203 __u8 SecurityMode;
204 __le32 Capabilities;
205 __le32 Channel;
206 __le16 SecurityBufferOffset;
207 __le16 SecurityBufferLength;
208 __le64 PreviousSessionId;
209 __u8 Buffer[1]; /* variable length GSS security buffer */
210} __packed;
211
212/* Currently defined SessionFlags */
213#define SMB2_SESSION_FLAG_IS_GUEST 0x0001
214#define SMB2_SESSION_FLAG_IS_NULL 0x0002
215struct smb2_sess_setup_rsp {
216 struct smb2_hdr hdr;
217 __le16 StructureSize; /* Must be 9 */
218 __le16 SessionFlags;
219 __le16 SecurityBufferOffset;
220 __le16 SecurityBufferLength;
221 __u8 Buffer[1]; /* variable length GSS security buffer */
222} __packed;
223
224struct smb2_logoff_req {
225 struct smb2_hdr hdr;
226 __le16 StructureSize; /* Must be 4 */
227 __le16 Reserved;
228} __packed;
229
230struct smb2_logoff_rsp {
231 struct smb2_hdr hdr;
232 __le16 StructureSize; /* Must be 4 */
233 __le16 Reserved;
234} __packed;
235
faaf946a
PS
236struct smb2_tree_connect_req {
237 struct smb2_hdr hdr;
238 __le16 StructureSize; /* Must be 9 */
239 __le16 Reserved;
240 __le16 PathOffset;
241 __le16 PathLength;
242 __u8 Buffer[1]; /* variable length */
243} __packed;
244
245struct smb2_tree_connect_rsp {
246 struct smb2_hdr hdr;
247 __le16 StructureSize; /* Must be 16 */
248 __u8 ShareType; /* see below */
249 __u8 Reserved;
250 __le32 ShareFlags; /* see below */
251 __le32 Capabilities; /* see below */
252 __le32 MaximalAccess;
253} __packed;
254
255/* Possible ShareType values */
256#define SMB2_SHARE_TYPE_DISK 0x01
257#define SMB2_SHARE_TYPE_PIPE 0x02
258#define SMB2_SHARE_TYPE_PRINT 0x03
259
260/*
261 * Possible ShareFlags - exactly one and only one of the first 4 caching flags
262 * must be set (any of the remaining, SHI1005, flags may be set individually
263 * or in combination.
264 */
265#define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000
266#define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010
267#define SMB2_SHAREFLAG_VDO_CACHING 0x00000020
268#define SMB2_SHAREFLAG_NO_CACHING 0x00000030
269#define SHI1005_FLAGS_DFS 0x00000001
270#define SHI1005_FLAGS_DFS_ROOT 0x00000002
271#define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS 0x00000100
272#define SHI1005_FLAGS_FORCE_SHARED_DELETE 0x00000200
273#define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING 0x00000400
274#define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM 0x00000800
275#define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK 0x00001000
276#define SHI1005_FLAGS_ENABLE_HASH 0x00002000
277
278/* Possible share capabilities */
279#define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008)
280
281struct smb2_tree_disconnect_req {
282 struct smb2_hdr hdr;
283 __le16 StructureSize; /* Must be 4 */
284 __le16 Reserved;
285} __packed;
286
287struct smb2_tree_disconnect_rsp {
288 struct smb2_hdr hdr;
289 __le16 StructureSize; /* Must be 4 */
290 __le16 Reserved;
291} __packed;
292
2503a0db
PS
293/* File Attrubutes */
294#define FILE_ATTRIBUTE_READONLY 0x00000001
295#define FILE_ATTRIBUTE_HIDDEN 0x00000002
296#define FILE_ATTRIBUTE_SYSTEM 0x00000004
297#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
298#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
299#define FILE_ATTRIBUTE_NORMAL 0x00000080
300#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
301#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
302#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
303#define FILE_ATTRIBUTE_COMPRESSED 0x00000800
304#define FILE_ATTRIBUTE_OFFLINE 0x00001000
305#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
306#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
307
308/* Oplock levels */
309#define SMB2_OPLOCK_LEVEL_NONE 0x00
310#define SMB2_OPLOCK_LEVEL_II 0x01
311#define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
312#define SMB2_OPLOCK_LEVEL_BATCH 0x09
313#define SMB2_OPLOCK_LEVEL_LEASE 0xFF
b8c32dbb
PS
314/* Non-spec internal type */
315#define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99
2503a0db
PS
316
317/* Desired Access Flags */
318#define FILE_READ_DATA_LE cpu_to_le32(0x00000001)
319#define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002)
320#define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004)
321#define FILE_READ_EA_LE cpu_to_le32(0x00000008)
322#define FILE_WRITE_EA_LE cpu_to_le32(0x00000010)
323#define FILE_EXECUTE_LE cpu_to_le32(0x00000020)
324#define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080)
325#define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100)
326#define FILE_DELETE_LE cpu_to_le32(0x00010000)
327#define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000)
328#define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000)
329#define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000)
330#define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000)
331#define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000)
332#define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000)
333#define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000)
334#define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000)
335#define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000)
336#define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000)
337
338/* ShareAccess Flags */
339#define FILE_SHARE_READ_LE cpu_to_le32(0x00000001)
340#define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002)
341#define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004)
342#define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007)
343
344/* CreateDisposition Flags */
345#define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000)
346#define FILE_OPEN_LE cpu_to_le32(0x00000001)
347#define FILE_CREATE_LE cpu_to_le32(0x00000002)
348#define FILE_OPEN_IF_LE cpu_to_le32(0x00000003)
349#define FILE_OVERWRITE_LE cpu_to_le32(0x00000004)
350#define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005)
351
352/* CreateOptions Flags */
353#define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001)
354/* same as #define CREATE_NOT_FILE_LE cpu_to_le32(0x00000001) */
355#define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002)
356#define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004)
357#define FILE_NO_INTERMEDIATE_BUFFERRING_LE cpu_to_le32(0x00000008)
358#define FILE_SYNCHRONOUS_IO_ALERT_LE cpu_to_le32(0x00000010)
359#define FILE_SYNCHRONOUS_IO_NON_ALERT_LE cpu_to_le32(0x00000020)
360#define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040)
361#define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100)
362#define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200)
363#define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800)
364#define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000)
365#define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000)
366#define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000)
367#define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000)
368#define FILE_RESERVE_OPFILTER_LE cpu_to_le32(0x00100000)
369#define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000)
370#define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000)
371#define FILE_OPEN_FOR_FREE_SPACE_QUERY_LE cpu_to_le32(0x00800000)
372
373#define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \
374 | FILE_READ_ATTRIBUTES_LE)
375#define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \
376 | FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
377#define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
378
379/* Impersonation Levels */
380#define IL_ANONYMOUS cpu_to_le32(0x00000000)
381#define IL_IDENTIFICATION cpu_to_le32(0x00000001)
382#define IL_IMPERSONATION cpu_to_le32(0x00000002)
383#define IL_DELEGATE cpu_to_le32(0x00000003)
384
385/* Create Context Values */
386#define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */
387#define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */
388#define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ"
389#define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC"
390#define SMB2_CREATE_ALLOCATION_SIZE "AlSi"
391#define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
392#define SMB2_CREATE_TIMEWARP_REQUEST "TWrp"
393#define SMB2_CREATE_QUERY_ON_DISK_ID "QFid"
394#define SMB2_CREATE_REQUEST_LEASE "RqLs"
395
396struct smb2_create_req {
397 struct smb2_hdr hdr;
398 __le16 StructureSize; /* Must be 57 */
399 __u8 SecurityFlags;
400 __u8 RequestedOplockLevel;
401 __le32 ImpersonationLevel;
402 __le64 SmbCreateFlags;
403 __le64 Reserved;
404 __le32 DesiredAccess;
405 __le32 FileAttributes;
406 __le32 ShareAccess;
407 __le32 CreateDisposition;
408 __le32 CreateOptions;
409 __le16 NameOffset;
410 __le16 NameLength;
411 __le32 CreateContextsOffset;
412 __le32 CreateContextsLength;
b8c32dbb 413 __u8 Buffer[8];
2503a0db
PS
414} __packed;
415
416struct smb2_create_rsp {
417 struct smb2_hdr hdr;
418 __le16 StructureSize; /* Must be 89 */
419 __u8 OplockLevel;
420 __u8 Reserved;
421 __le32 CreateAction;
422 __le64 CreationTime;
423 __le64 LastAccessTime;
424 __le64 LastWriteTime;
425 __le64 ChangeTime;
426 __le64 AllocationSize;
427 __le64 EndofFile;
428 __le32 FileAttributes;
429 __le32 Reserved2;
430 __u64 PersistentFileId; /* opaque endianness */
431 __u64 VolatileFileId; /* opaque endianness */
432 __le32 CreateContextsOffset;
433 __le32 CreateContextsLength;
434 __u8 Buffer[1];
435} __packed;
436
b8c32dbb
PS
437struct create_context {
438 __le32 Next;
439 __le16 NameOffset;
440 __le16 NameLength;
441 __le16 Reserved;
442 __le16 DataOffset;
443 __le32 DataLength;
444 __u8 Buffer[0];
445} __packed;
446
447#define SMB2_LEASE_NONE __constant_cpu_to_le32(0x00)
448#define SMB2_LEASE_READ_CACHING __constant_cpu_to_le32(0x01)
449#define SMB2_LEASE_HANDLE_CACHING __constant_cpu_to_le32(0x02)
450#define SMB2_LEASE_WRITE_CACHING __constant_cpu_to_le32(0x04)
451
452#define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS __constant_cpu_to_le32(0x02)
453
454#define SMB2_LEASE_KEY_SIZE 16
455
456struct lease_context {
457 __le64 LeaseKeyLow;
458 __le64 LeaseKeyHigh;
459 __le32 LeaseState;
460 __le32 LeaseFlags;
461 __le64 LeaseDuration;
462} __packed;
463
464struct create_lease {
465 struct create_context ccontext;
466 __u8 Name[8];
467 struct lease_context lcontext;
468} __packed;
469
2503a0db
PS
470/* Currently defined values for close flags */
471#define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
472struct smb2_close_req {
473 struct smb2_hdr hdr;
474 __le16 StructureSize; /* Must be 24 */
475 __le16 Flags;
476 __le32 Reserved;
477 __u64 PersistentFileId; /* opaque endianness */
478 __u64 VolatileFileId; /* opaque endianness */
479} __packed;
480
481struct smb2_close_rsp {
482 struct smb2_hdr hdr;
483 __le16 StructureSize; /* 60 */
484 __le16 Flags;
485 __le32 Reserved;
486 __le64 CreationTime;
487 __le64 LastAccessTime;
488 __le64 LastWriteTime;
489 __le64 ChangeTime;
490 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
491 __le64 EndOfFile;
492 __le32 Attributes;
493} __packed;
494
7a5cfb19
PS
495struct smb2_flush_req {
496 struct smb2_hdr hdr;
497 __le16 StructureSize; /* Must be 24 */
498 __le16 Reserved1;
499 __le32 Reserved2;
500 __u64 PersistentFileId; /* opaque endianness */
501 __u64 VolatileFileId; /* opaque endianness */
502} __packed;
503
504struct smb2_flush_rsp {
505 struct smb2_hdr hdr;
506 __le16 StructureSize;
507 __le16 Reserved;
508} __packed;
509
09a4707e
PS
510struct smb2_read_req {
511 struct smb2_hdr hdr;
512 __le16 StructureSize; /* Must be 49 */
513 __u8 Padding; /* offset from start of SMB2 header to place read */
514 __u8 Reserved;
515 __le32 Length;
516 __le64 Offset;
517 __u64 PersistentFileId; /* opaque endianness */
518 __u64 VolatileFileId; /* opaque endianness */
519 __le32 MinimumCount;
520 __le32 Channel; /* Reserved MBZ */
521 __le32 RemainingBytes;
522 __le16 ReadChannelInfoOffset; /* Reserved MBZ */
523 __le16 ReadChannelInfoLength; /* Reserved MBZ */
524 __u8 Buffer[1];
525} __packed;
526
527struct smb2_read_rsp {
528 struct smb2_hdr hdr;
529 __le16 StructureSize; /* Must be 17 */
530 __u8 DataOffset;
33319141
PS
531 __u8 Reserved;
532 __le32 DataLength;
533 __le32 DataRemaining;
534 __u32 Reserved2;
535 __u8 Buffer[1];
536} __packed;
537
538/* For write request Flags field below the following flag is defined: */
539#define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001
540
541struct smb2_write_req {
542 struct smb2_hdr hdr;
543 __le16 StructureSize; /* Must be 49 */
544 __le16 DataOffset; /* offset from start of SMB2 header to write data */
545 __le32 Length;
546 __le64 Offset;
547 __u64 PersistentFileId; /* opaque endianness */
548 __u64 VolatileFileId; /* opaque endianness */
549 __le32 Channel; /* Reserved MBZ */
550 __le32 RemainingBytes;
551 __le16 WriteChannelInfoOffset; /* Reserved MBZ */
552 __le16 WriteChannelInfoLength; /* Reserved MBZ */
553 __le32 Flags;
554 __u8 Buffer[1];
555} __packed;
556
557struct smb2_write_rsp {
558 struct smb2_hdr hdr;
559 __le16 StructureSize; /* Must be 17 */
560 __u8 DataOffset;
09a4707e
PS
561 __u8 Reserved;
562 __le32 DataLength;
563 __le32 DataRemaining;
564 __u32 Reserved2;
565 __u8 Buffer[1];
566} __packed;
567
027e8eec
PS
568#define SMB2_LOCKFLAG_SHARED_LOCK 0x0001
569#define SMB2_LOCKFLAG_EXCLUSIVE_LOCK 0x0002
570#define SMB2_LOCKFLAG_UNLOCK 0x0004
571#define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010
572
f7ba7fe6
PS
573struct smb2_lock_element {
574 __le64 Offset;
575 __le64 Length;
576 __le32 Flags;
577 __le32 Reserved;
578} __packed;
579
580struct smb2_lock_req {
581 struct smb2_hdr hdr;
582 __le16 StructureSize; /* Must be 48 */
583 __le16 LockCount;
584 __le32 Reserved;
585 __u64 PersistentFileId; /* opaque endianness */
586 __u64 VolatileFileId; /* opaque endianness */
587 /* Followed by at least one */
588 struct smb2_lock_element locks[1];
589} __packed;
590
591struct smb2_lock_rsp {
592 struct smb2_hdr hdr;
593 __le16 StructureSize; /* Must be 4 */
594 __le16 Reserved;
595} __packed;
596
9094fad1
PS
597struct smb2_echo_req {
598 struct smb2_hdr hdr;
599 __le16 StructureSize; /* Must be 4 */
600 __u16 Reserved;
601} __packed;
602
603struct smb2_echo_rsp {
604 struct smb2_hdr hdr;
605 __le16 StructureSize; /* Must be 4 */
606 __u16 Reserved;
607} __packed;
608
d324f08d
PS
609/* search (query_directory) Flags field */
610#define SMB2_RESTART_SCANS 0x01
611#define SMB2_RETURN_SINGLE_ENTRY 0x02
612#define SMB2_INDEX_SPECIFIED 0x04
613#define SMB2_REOPEN 0x10
614
615struct smb2_query_directory_req {
616 struct smb2_hdr hdr;
617 __le16 StructureSize; /* Must be 33 */
618 __u8 FileInformationClass;
619 __u8 Flags;
620 __le32 FileIndex;
621 __u64 PersistentFileId; /* opaque endianness */
622 __u64 VolatileFileId; /* opaque endianness */
623 __le16 FileNameOffset;
624 __le16 FileNameLength;
625 __le32 OutputBufferLength;
626 __u8 Buffer[1];
627} __packed;
628
629struct smb2_query_directory_rsp {
630 struct smb2_hdr hdr;
631 __le16 StructureSize; /* Must be 9 */
632 __le16 OutputBufferOffset;
633 __le32 OutputBufferLength;
634 __u8 Buffer[1];
635} __packed;
636
be4cb9e3
PS
637/* Possible InfoType values */
638#define SMB2_O_INFO_FILE 0x01
639#define SMB2_O_INFO_FILESYSTEM 0x02
640#define SMB2_O_INFO_SECURITY 0x03
641#define SMB2_O_INFO_QUOTA 0x04
642
643struct smb2_query_info_req {
644 struct smb2_hdr hdr;
645 __le16 StructureSize; /* Must be 41 */
646 __u8 InfoType;
647 __u8 FileInfoClass;
648 __le32 OutputBufferLength;
649 __le16 InputBufferOffset;
650 __u16 Reserved;
651 __le32 InputBufferLength;
652 __le32 AdditionalInformation;
653 __le32 Flags;
654 __u64 PersistentFileId; /* opaque endianness */
655 __u64 VolatileFileId; /* opaque endianness */
656 __u8 Buffer[1];
657} __packed;
658
659struct smb2_query_info_rsp {
660 struct smb2_hdr hdr;
661 __le16 StructureSize; /* Must be 9 */
662 __le16 OutputBufferOffset;
663 __le32 OutputBufferLength;
664 __u8 Buffer[1];
665} __packed;
666
35143eb5
PS
667struct smb2_set_info_req {
668 struct smb2_hdr hdr;
669 __le16 StructureSize; /* Must be 33 */
670 __u8 InfoType;
671 __u8 FileInfoClass;
672 __le32 BufferLength;
673 __le16 BufferOffset;
674 __u16 Reserved;
675 __le32 AdditionalInformation;
676 __u64 PersistentFileId; /* opaque endianness */
677 __u64 VolatileFileId; /* opaque endianness */
678 __u8 Buffer[1];
679} __packed;
680
681struct smb2_set_info_rsp {
682 struct smb2_hdr hdr;
683 __le16 StructureSize; /* Must be 2 */
684} __packed;
685
983c88a4
PS
686struct smb2_oplock_break {
687 struct smb2_hdr hdr;
688 __le16 StructureSize; /* Must be 24 */
689 __u8 OplockLevel;
690 __u8 Reserved;
691 __le32 Reserved2;
692 __u64 PersistentFid;
693 __u64 VolatileFid;
694} __packed;
695
0822f514
PS
696#define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
697
698struct smb2_lease_break {
699 struct smb2_hdr hdr;
700 __le16 StructureSize; /* Must be 44 */
701 __le16 Reserved;
702 __le32 Flags;
703 __u8 LeaseKey[16];
704 __le32 CurrentLeaseState;
705 __le32 NewLeaseState;
706 __le32 BreakReason;
707 __le32 AccessMaskHint;
708 __le32 ShareMaskHint;
709} __packed;
710
711struct smb2_lease_ack {
712 struct smb2_hdr hdr;
713 __le16 StructureSize; /* Must be 36 */
714 __le16 Reserved;
715 __le32 Flags;
716 __u8 LeaseKey[16];
717 __le32 LeaseState;
718 __le64 LeaseDuration;
719} __packed;
720
be4cb9e3
PS
721/*
722 * PDU infolevel structure definitions
723 * BB consider moving to a different header
724 */
725
6fc05c25
PS
726/* File System Information Classes */
727#define FS_VOLUME_INFORMATION 1 /* Query */
728#define FS_LABEL_INFORMATION 2 /* Set */
729#define FS_SIZE_INFORMATION 3 /* Query */
730#define FS_DEVICE_INFORMATION 4 /* Query */
731#define FS_ATTRIBUTE_INFORMATION 5 /* Query */
732#define FS_CONTROL_INFORMATION 6 /* Query, Set */
733#define FS_FULL_SIZE_INFORMATION 7 /* Query */
734#define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */
735#define FS_DRIVER_PATH_INFORMATION 9 /* Query */
736
737struct smb2_fs_full_size_info {
738 __le64 TotalAllocationUnits;
739 __le64 CallerAvailableAllocationUnits;
740 __le64 ActualAvailableAllocationUnits;
741 __le32 SectorsPerAllocationUnit;
742 __le32 BytesPerSector;
743} __packed;
744
be4cb9e3
PS
745/* partial list of QUERY INFO levels */
746#define FILE_DIRECTORY_INFORMATION 1
747#define FILE_FULL_DIRECTORY_INFORMATION 2
748#define FILE_BOTH_DIRECTORY_INFORMATION 3
749#define FILE_BASIC_INFORMATION 4
750#define FILE_STANDARD_INFORMATION 5
751#define FILE_INTERNAL_INFORMATION 6
752#define FILE_EA_INFORMATION 7
753#define FILE_ACCESS_INFORMATION 8
754#define FILE_NAME_INFORMATION 9
755#define FILE_RENAME_INFORMATION 10
756#define FILE_LINK_INFORMATION 11
757#define FILE_NAMES_INFORMATION 12
758#define FILE_DISPOSITION_INFORMATION 13
759#define FILE_POSITION_INFORMATION 14
760#define FILE_FULL_EA_INFORMATION 15
761#define FILE_MODE_INFORMATION 16
762#define FILE_ALIGNMENT_INFORMATION 17
763#define FILE_ALL_INFORMATION 18
764#define FILE_ALLOCATION_INFORMATION 19
765#define FILE_END_OF_FILE_INFORMATION 20
766#define FILE_ALTERNATE_NAME_INFORMATION 21
767#define FILE_STREAM_INFORMATION 22
768#define FILE_PIPE_INFORMATION 23
769#define FILE_PIPE_LOCAL_INFORMATION 24
770#define FILE_PIPE_REMOTE_INFORMATION 25
771#define FILE_MAILSLOT_QUERY_INFORMATION 26
772#define FILE_MAILSLOT_SET_INFORMATION 27
773#define FILE_COMPRESSION_INFORMATION 28
774#define FILE_OBJECT_ID_INFORMATION 29
775/* Number 30 not defined in documents */
776#define FILE_MOVE_CLUSTER_INFORMATION 31
777#define FILE_QUOTA_INFORMATION 32
778#define FILE_REPARSE_POINT_INFORMATION 33
779#define FILE_NETWORK_OPEN_INFORMATION 34
780#define FILE_ATTRIBUTE_TAG_INFORMATION 35
781#define FILE_TRACKING_INFORMATION 36
782#define FILEID_BOTH_DIRECTORY_INFORMATION 37
783#define FILEID_FULL_DIRECTORY_INFORMATION 38
784#define FILE_VALID_DATA_LENGTH_INFORMATION 39
785#define FILE_SHORT_NAME_INFORMATION 40
786#define FILE_SFIO_RESERVE_INFORMATION 44
787#define FILE_SFIO_VOLUME_INFORMATION 45
788#define FILE_HARD_LINK_INFORMATION 46
789#define FILE_NORMALIZED_NAME_INFORMATION 48
790#define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
791#define FILE_STANDARD_LINK_INFORMATION 54
792
f0df737e
PS
793struct smb2_file_internal_info {
794 __le64 IndexNumber;
795} __packed; /* level 6 Query */
796
35143eb5
PS
797struct smb2_file_rename_info { /* encoding of request for level 10 */
798 __u8 ReplaceIfExists; /* 1 = replace existing target with new */
799 /* 0 = fail if target already exists */
800 __u8 Reserved[7];
801 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
802 __le32 FileNameLength;
803 char FileName[0]; /* New name to be assigned */
804} __packed; /* level 10 Set */
805
568798cc
PS
806struct smb2_file_link_info { /* encoding of request for level 11 */
807 __u8 ReplaceIfExists; /* 1 = replace existing link with new */
808 /* 0 = fail if link already exists */
809 __u8 Reserved[7];
810 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
811 __le32 FileNameLength;
812 char FileName[0]; /* Name to be assigned to new link */
813} __packed; /* level 11 Set */
814
be4cb9e3
PS
815/*
816 * This level 18, although with struct with same name is different from cifs
817 * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
818 * CurrentByteOffset.
819 */
820struct smb2_file_all_info { /* data block encoding of response to level 18 */
821 __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
822 __le64 LastAccessTime;
823 __le64 LastWriteTime;
824 __le64 ChangeTime;
825 __le32 Attributes;
826 __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
827 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
828 __le64 EndOfFile; /* size ie offset to first free byte in file */
829 __le32 NumberOfLinks; /* hard links */
830 __u8 DeletePending;
831 __u8 Directory;
832 __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */
833 __le64 IndexNumber;
834 __le32 EASize;
835 __le32 AccessFlags;
836 __le64 CurrentByteOffset;
837 __le32 Mode;
838 __le32 AlignmentRequirement;
839 __le32 FileNameLength;
840 char FileName[1];
841} __packed; /* level 18 Query */
842
c839ff24
PS
843struct smb2_file_eof_info { /* encoding of request for level 10 */
844 __le64 EndOfFile; /* new end of file value */
845} __packed; /* level 20 Set */
846
ddfbefbd 847#endif /* _SMB2PDU_H */