4 * Copyright (c) International Business Machines Corp., 2009, 2013
6 * Author(s): Steve French (sfrench@us.ibm.com)
7 * Pavel Shilovsky (pshilovsky@samba.org) 2012
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.
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.
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
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.
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.
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
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)
83 #define SMB2_INTERNAL_CMD cpu_to_le16(0xFFFF)
85 #define NUMBER_OF_SMB2_COMMANDS 0x0013
87 /* 4 len + 52 transform hdr + 64 hdr + 56 create rsp */
88 #define MAX_SMB2_HDR_SIZE 0x00b0
90 #define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)
91 #define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
94 * SMB2 Header Definition
96 * "MBZ" : Must be Zero
97 * "BB" : BugBug, Something to check/review/analyze later
98 * "PDU" : "Protocol Data Unit" (ie a network "frame")
102 #define SMB2_HEADER_STRUCTURE_SIZE cpu_to_le16(64)
105 __be32 smb2_buf_length
; /* big endian on wire */
106 /* length is only two or three bytes - with
107 one or two byte type preceding it that MBZ */
108 __le32 ProtocolId
; /* 0xFE 'S' 'M' 'B' */
109 __le16 StructureSize
; /* 64 */
110 __le16 CreditCharge
; /* MBZ */
111 __le32 Status
; /* Error from server */
113 __le16 CreditRequest
; /* CreditResponse */
118 __u32 TreeId
; /* opaque - so do not make little endian */
119 __u64 SessionId
; /* opaque - so do not make little endian */
125 __le16 StructureSize2
; /* size of wct area (varies, request specific) */
128 struct smb2_transform_hdr
{
129 __be32 smb2_buf_length
; /* big endian on wire */
130 /* length is only two or three bytes - with
131 one or two byte type preceding it that MBZ */
132 __u8 ProtocolId
[4]; /* 0xFD 'S' 'M' 'B' */
135 __le32 OriginalMessageSize
;
137 __le16 Flags
; /* EncryptionAlgorithm */
142 * SMB2 flag definitions
144 #define SMB2_FLAGS_SERVER_TO_REDIR cpu_to_le32(0x00000001)
145 #define SMB2_FLAGS_ASYNC_COMMAND cpu_to_le32(0x00000002)
146 #define SMB2_FLAGS_RELATED_OPERATIONS cpu_to_le32(0x00000004)
147 #define SMB2_FLAGS_SIGNED cpu_to_le32(0x00000008)
148 #define SMB2_FLAGS_DFS_OPERATIONS cpu_to_le32(0x10000000)
151 * Definitions for SMB2 Protocol Data Units (network frames)
153 * See MS-SMB2.PDF specification for protocol details.
154 * The Naming convention is the lower case version of the SMB2
155 * command code name for the struct. Note that structures must be packed.
159 #define SMB2_ERROR_STRUCTURE_SIZE2 cpu_to_le16(9)
161 struct smb2_err_rsp
{
163 __le16 StructureSize
;
164 __le16 Reserved
; /* MBZ */
165 __le32 ByteCount
; /* even if zero, at least one byte follows */
166 __u8 ErrorData
[1]; /* variable length */
169 struct smb2_symlink_err_rsp
{
170 __le32 SymLinkLength
;
171 __le32 SymLinkErrorTag
;
173 __le16 ReparseDataLength
;
174 __le16 UnparsedPathLength
;
175 __le16 SubstituteNameOffset
;
176 __le16 SubstituteNameLength
;
177 __le16 PrintNameOffset
;
178 __le16 PrintNameLength
;
183 #define SMB2_CLIENT_GUID_SIZE 16
185 struct smb2_negotiate_req
{
187 __le16 StructureSize
; /* Must be 36 */
190 __le16 Reserved
; /* MBZ */
192 __u8 ClientGUID
[SMB2_CLIENT_GUID_SIZE
];
193 /* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */
194 __le32 NegotiateContextOffset
; /* SMB3.1.1 only. MBZ earlier */
195 __le16 NegotiateContextCount
; /* SMB3.1.1 only. MBZ earlier */
197 __le16 Dialects
[1]; /* One dialect (vers=) at a time for now */
201 #define SMB20_PROT_ID 0x0202
202 #define SMB21_PROT_ID 0x0210
203 #define SMB30_PROT_ID 0x0300
204 #define SMB302_PROT_ID 0x0302
205 #define SMB311_PROT_ID 0x0311
206 #define BAD_PROT_ID 0xFFFF
208 /* SecurityMode flags */
209 #define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001
210 #define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
211 /* Capabilities flags */
212 #define SMB2_GLOBAL_CAP_DFS 0x00000001
213 #define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */
214 #define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */
215 #define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */
216 #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
217 #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */
218 #define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */
220 #define SMB2_NT_FIND 0x00100000
221 #define SMB2_LARGE_FILES 0x00200000
223 #define SMB311_SALT_SIZE 32
224 /* Hash Algorithm Types */
225 #define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001)
227 struct smb2_preauth_neg_context
{
228 __le16 ContextType
; /* 1 */
231 __le16 HashAlgorithmCount
; /* 1 */
233 __le16 HashAlgorithms
; /* HashAlgorithms[0] since only one defined */
234 __u8 Salt
[SMB311_SALT_SIZE
];
237 /* Encryption Algorithms Ciphers */
238 #define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001)
239 #define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002)
241 struct smb2_encryption_neg_context
{
242 __le16 ContextType
; /* 2 */
245 __le16 CipherCount
; /* AES-128-GCM and AES-128-CCM */
246 __le16 Ciphers
[2]; /* Ciphers[0] since only one used now */
249 struct smb2_negotiate_rsp
{
251 __le16 StructureSize
; /* Must be 65 */
253 __le16 DialectRevision
;
254 __le16 NegotiateContextCount
; /* Prior to SMB3.1.1 was Reserved & MBZ */
257 __le32 MaxTransactSize
;
260 __le64 SystemTime
; /* MBZ */
261 __le64 ServerStartTime
;
262 __le16 SecurityBufferOffset
;
263 __le16 SecurityBufferLength
;
264 __le32 NegotiateContextOffset
; /* Pre:SMB3.1.1 was reserved/ignored */
265 __u8 Buffer
[1]; /* variable length GSS security buffer */
269 #define SMB2_SESSION_REQ_FLAG_BINDING 0x01
270 #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04
272 struct smb2_sess_setup_req
{
274 __le16 StructureSize
; /* Must be 25 */
279 __le16 SecurityBufferOffset
;
280 __le16 SecurityBufferLength
;
281 __u64 PreviousSessionId
;
282 __u8 Buffer
[1]; /* variable length GSS security buffer */
285 /* Currently defined SessionFlags */
286 #define SMB2_SESSION_FLAG_IS_GUEST 0x0001
287 #define SMB2_SESSION_FLAG_IS_NULL 0x0002
288 #define SMB2_SESSION_FLAG_ENCRYPT_DATA 0x0004
289 struct smb2_sess_setup_rsp
{
291 __le16 StructureSize
; /* Must be 9 */
293 __le16 SecurityBufferOffset
;
294 __le16 SecurityBufferLength
;
295 __u8 Buffer
[1]; /* variable length GSS security buffer */
298 struct smb2_logoff_req
{
300 __le16 StructureSize
; /* Must be 4 */
304 struct smb2_logoff_rsp
{
306 __le16 StructureSize
; /* Must be 4 */
310 /* Flags/Reserved for SMB3.1.1 */
311 #define SMB2_SHAREFLAG_CLUSTER_RECONNECT 0x0001
313 struct smb2_tree_connect_req
{
315 __le16 StructureSize
; /* Must be 9 */
316 __le16 Reserved
; /* Flags in SMB3.1.1 */
319 __u8 Buffer
[1]; /* variable length */
322 struct smb2_tree_connect_rsp
{
324 __le16 StructureSize
; /* Must be 16 */
325 __u8 ShareType
; /* see below */
327 __le32 ShareFlags
; /* see below */
328 __le32 Capabilities
; /* see below */
329 __le32 MaximalAccess
;
332 /* Possible ShareType values */
333 #define SMB2_SHARE_TYPE_DISK 0x01
334 #define SMB2_SHARE_TYPE_PIPE 0x02
335 #define SMB2_SHARE_TYPE_PRINT 0x03
338 * Possible ShareFlags - exactly one and only one of the first 4 caching flags
339 * must be set (any of the remaining, SHI1005, flags may be set individually
342 #define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000
343 #define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010
344 #define SMB2_SHAREFLAG_VDO_CACHING 0x00000020
345 #define SMB2_SHAREFLAG_NO_CACHING 0x00000030
346 #define SHI1005_FLAGS_DFS 0x00000001
347 #define SHI1005_FLAGS_DFS_ROOT 0x00000002
348 #define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS 0x00000100
349 #define SHI1005_FLAGS_FORCE_SHARED_DELETE 0x00000200
350 #define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING 0x00000400
351 #define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM 0x00000800
352 #define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK 0x00001000
353 #define SHI1005_FLAGS_ENABLE_HASH_V1 0x00002000
354 #define SHI1005_FLAGS_ENABLE_HASH_V2 0x00004000
355 #define SHI1005_FLAGS_ENCRYPT_DATA 0x00008000
356 #define SHI1005_FLAGS_ALL 0x0000FF33
358 /* Possible share capabilities */
359 #define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008) /* all dialects */
360 #define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY cpu_to_le32(0x00000010) /* 3.0 */
361 #define SMB2_SHARE_CAP_SCALEOUT cpu_to_le32(0x00000020) /* 3.0 */
362 #define SMB2_SHARE_CAP_CLUSTER cpu_to_le32(0x00000040) /* 3.0 */
363 #define SMB2_SHARE_CAP_ASYMMETRIC cpu_to_le32(0x00000080) /* 3.02 */
365 struct smb2_tree_disconnect_req
{
367 __le16 StructureSize
; /* Must be 4 */
371 struct smb2_tree_disconnect_rsp
{
373 __le16 StructureSize
; /* Must be 4 */
377 /* File Attrubutes */
378 #define FILE_ATTRIBUTE_READONLY 0x00000001
379 #define FILE_ATTRIBUTE_HIDDEN 0x00000002
380 #define FILE_ATTRIBUTE_SYSTEM 0x00000004
381 #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
382 #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
383 #define FILE_ATTRIBUTE_NORMAL 0x00000080
384 #define FILE_ATTRIBUTE_TEMPORARY 0x00000100
385 #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
386 #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
387 #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
388 #define FILE_ATTRIBUTE_OFFLINE 0x00001000
389 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
390 #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
391 #define FILE_ATTRIBUTE_INTEGRITY_STREAM 0x00008000
392 #define FILE_ATTRIBUTE_NO_SCRUB_DATA 0x00020000
395 #define SMB2_OPLOCK_LEVEL_NONE 0x00
396 #define SMB2_OPLOCK_LEVEL_II 0x01
397 #define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
398 #define SMB2_OPLOCK_LEVEL_BATCH 0x09
399 #define SMB2_OPLOCK_LEVEL_LEASE 0xFF
400 /* Non-spec internal type */
401 #define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99
403 /* Desired Access Flags */
404 #define FILE_READ_DATA_LE cpu_to_le32(0x00000001)
405 #define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002)
406 #define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004)
407 #define FILE_READ_EA_LE cpu_to_le32(0x00000008)
408 #define FILE_WRITE_EA_LE cpu_to_le32(0x00000010)
409 #define FILE_EXECUTE_LE cpu_to_le32(0x00000020)
410 #define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080)
411 #define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100)
412 #define FILE_DELETE_LE cpu_to_le32(0x00010000)
413 #define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000)
414 #define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000)
415 #define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000)
416 #define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000)
417 #define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000)
418 #define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000)
419 #define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000)
420 #define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000)
421 #define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000)
422 #define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000)
424 /* ShareAccess Flags */
425 #define FILE_SHARE_READ_LE cpu_to_le32(0x00000001)
426 #define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002)
427 #define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004)
428 #define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007)
430 /* CreateDisposition Flags */
431 #define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000)
432 #define FILE_OPEN_LE cpu_to_le32(0x00000001)
433 #define FILE_CREATE_LE cpu_to_le32(0x00000002)
434 #define FILE_OPEN_IF_LE cpu_to_le32(0x00000003)
435 #define FILE_OVERWRITE_LE cpu_to_le32(0x00000004)
436 #define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005)
438 /* CreateOptions Flags */
439 #define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001)
440 /* same as #define CREATE_NOT_FILE_LE cpu_to_le32(0x00000001) */
441 #define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002)
442 #define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004)
443 #define FILE_NO_INTERMEDIATE_BUFFERRING_LE cpu_to_le32(0x00000008)
444 #define FILE_SYNCHRONOUS_IO_ALERT_LE cpu_to_le32(0x00000010)
445 #define FILE_SYNCHRONOUS_IO_NON_ALERT_LE cpu_to_le32(0x00000020)
446 #define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040)
447 #define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100)
448 #define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200)
449 #define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800)
450 #define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000)
451 #define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000)
452 #define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000)
453 #define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000)
454 #define FILE_RESERVE_OPFILTER_LE cpu_to_le32(0x00100000)
455 #define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000)
456 #define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000)
457 #define FILE_OPEN_FOR_FREE_SPACE_QUERY_LE cpu_to_le32(0x00800000)
459 #define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \
460 | FILE_READ_ATTRIBUTES_LE)
461 #define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \
462 | FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
463 #define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
465 /* Impersonation Levels */
466 #define IL_ANONYMOUS cpu_to_le32(0x00000000)
467 #define IL_IDENTIFICATION cpu_to_le32(0x00000001)
468 #define IL_IMPERSONATION cpu_to_le32(0x00000002)
469 #define IL_DELEGATE cpu_to_le32(0x00000003)
471 /* Create Context Values */
472 #define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */
473 #define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */
474 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ"
475 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC"
476 #define SMB2_CREATE_ALLOCATION_SIZE "AISi"
477 #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
478 #define SMB2_CREATE_TIMEWARP_REQUEST "TWrp"
479 #define SMB2_CREATE_QUERY_ON_DISK_ID "QFid"
480 #define SMB2_CREATE_REQUEST_LEASE "RqLs"
481 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 "DH2Q"
482 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 "DH2C"
483 #define SMB2_CREATE_APP_INSTANCE_ID 0x45BCA66AEFA7F74A9008FA462E144D74
484 #define SVHDX_OPEN_DEVICE_CONTEXT 0x83CE6F1AD851E0986E34401CC9BCFCE9
486 struct smb2_create_req
{
488 __le16 StructureSize
; /* Must be 57 */
490 __u8 RequestedOplockLevel
;
491 __le32 ImpersonationLevel
;
492 __le64 SmbCreateFlags
;
494 __le32 DesiredAccess
;
495 __le32 FileAttributes
;
497 __le32 CreateDisposition
;
498 __le32 CreateOptions
;
501 __le32 CreateContextsOffset
;
502 __le32 CreateContextsLength
;
506 struct smb2_create_rsp
{
508 __le16 StructureSize
; /* Must be 89 */
513 __le64 LastAccessTime
;
514 __le64 LastWriteTime
;
516 __le64 AllocationSize
;
518 __le32 FileAttributes
;
520 __u64 PersistentFileId
; /* opaque endianness */
521 __u64 VolatileFileId
; /* opaque endianness */
522 __le32 CreateContextsOffset
;
523 __le32 CreateContextsLength
;
527 struct create_context
{
537 #define SMB2_LEASE_READ_CACHING_HE 0x01
538 #define SMB2_LEASE_HANDLE_CACHING_HE 0x02
539 #define SMB2_LEASE_WRITE_CACHING_HE 0x04
541 #define SMB2_LEASE_NONE cpu_to_le32(0x00)
542 #define SMB2_LEASE_READ_CACHING cpu_to_le32(0x01)
543 #define SMB2_LEASE_HANDLE_CACHING cpu_to_le32(0x02)
544 #define SMB2_LEASE_WRITE_CACHING cpu_to_le32(0x04)
546 #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS cpu_to_le32(0x02)
548 #define SMB2_LEASE_KEY_SIZE 16
550 struct lease_context
{
555 __le64 LeaseDuration
;
558 struct lease_context_v2
{
563 __le64 LeaseDuration
;
564 __le64 ParentLeaseKeyLow
;
565 __le64 ParentLeaseKeyHigh
;
570 struct create_lease
{
571 struct create_context ccontext
;
573 struct lease_context lcontext
;
576 struct create_lease_v2
{
577 struct create_context ccontext
;
579 struct lease_context_v2 lcontext
;
583 struct create_durable
{
584 struct create_context ccontext
;
589 __u64 PersistentFileId
;
590 __u64 VolatileFileId
;
595 /* See MS-SMB2 2.2.13.2.11 */
597 #define SMB2_DHANDLE_FLAG_PERSISTENT 0x00000002
598 struct durable_context_v2
{
605 struct create_durable_v2
{
606 struct create_context ccontext
;
608 struct durable_context_v2 dcontext
;
611 /* See MS-SMB2 2.2.13.2.12 */
612 struct durable_reconnect_context_v2
{
614 __u64 PersistentFileId
;
615 __u64 VolatileFileId
;
618 __le32 Flags
; /* see above DHANDLE_FLAG_PERSISTENT */
621 /* See MS-SMB2 2.2.14.2.12 */
622 struct durable_reconnect_context_v2_rsp
{
624 __le32 Flags
; /* see above DHANDLE_FLAG_PERSISTENT */
627 struct create_durable_handle_reconnect_v2
{
628 struct create_context ccontext
;
630 struct durable_reconnect_context_v2 dcontext
;
633 #define COPY_CHUNK_RES_KEY_SIZE 24
634 struct resume_key_req
{
635 char ResumeKey
[COPY_CHUNK_RES_KEY_SIZE
];
636 __le32 ContextLength
; /* MBZ */
637 char Context
[0]; /* ignored, Windows sets to 4 bytes of zero */
640 /* this goes in the ioctl buffer when doing a copychunk request */
641 struct copychunk_ioctl
{
642 char SourceKey
[COPY_CHUNK_RES_KEY_SIZE
];
643 __le32 ChunkCount
; /* we are only sending 1 */
645 /* array will only be one chunk long for us */
648 __le32 Length
; /* how many bytes to copy */
652 /* this goes in the ioctl buffer when doing FSCTL_SET_ZERO_DATA */
653 struct file_zero_data_information
{
655 __le64 BeyondFinalZero
;
658 struct copychunk_ioctl_rsp
{
659 __le32 ChunksWritten
;
660 __le32 ChunkBytesWritten
;
661 __le32 TotalBytesWritten
;
664 struct fsctl_set_integrity_information_req
{
665 __le16 ChecksumAlgorithm
;
670 struct fsctl_get_integrity_information_rsp
{
671 __le16 ChecksumAlgorithm
;
674 __le32 ChecksumChunkSizeInBytes
;
675 __le32 ClusterSizeInBytes
;
678 /* Integrity ChecksumAlgorithm choices for above */
679 #define CHECKSUM_TYPE_NONE 0x0000
680 #define CHECKSUM_TYPE_CRC64 0x0002
681 #define CHECKSUM_TYPE_UNCHANGED 0xFFFF /* set only */
683 /* Integrity flags for above */
684 #define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF 0x00000001
686 /* See MS-SMB2 2.2.31.3 */
687 struct network_resiliency_req
{
691 /* There is no buffer for the response ie no struct network_resiliency_rsp */
694 struct validate_negotiate_info_req
{
696 __u8 Guid
[SMB2_CLIENT_GUID_SIZE
];
699 __le16 Dialects
[1]; /* dialect (someday maybe list) client asked for */
702 struct validate_negotiate_info_rsp
{
704 __u8 Guid
[SMB2_CLIENT_GUID_SIZE
];
706 __le16 Dialect
; /* Dialect in use for the connection */
709 #define RSS_CAPABLE 0x00000001
710 #define RDMA_CAPABLE 0x00000002
712 struct network_interface_info_ioctl_rsp
{
713 __le32 Next
; /* next interface. zero if this is last one */
715 __le32 Capability
; /* RSS or RDMA Capable */
718 char SockAddr_Storage
[128];
721 #define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */
723 struct compress_ioctl
{
724 __le16 CompressionState
; /* See cifspdu.h for possible flag values */
727 struct duplicate_extents_to_file
{
728 __u64 PersistentFileHandle
; /* source file handle, opaque endianness */
729 __u64 VolatileFileHandle
;
730 __le64 SourceFileOffset
;
731 __le64 TargetFileOffset
;
732 __le64 ByteCount
; /* Bytes to be copied */
735 struct smb2_ioctl_req
{
737 __le16 StructureSize
; /* Must be 57 */
740 __u64 PersistentFileId
; /* opaque endianness */
741 __u64 VolatileFileId
; /* opaque endianness */
744 __le32 MaxInputResponse
;
747 __le32 MaxOutputResponse
;
753 struct smb2_ioctl_rsp
{
755 __le16 StructureSize
; /* Must be 57 */
758 __u64 PersistentFileId
; /* opaque endianness */
759 __u64 VolatileFileId
; /* opaque endianness */
766 /* char * buffer[] */
769 /* Currently defined values for close flags */
770 #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
771 struct smb2_close_req
{
773 __le16 StructureSize
; /* Must be 24 */
776 __u64 PersistentFileId
; /* opaque endianness */
777 __u64 VolatileFileId
; /* opaque endianness */
780 struct smb2_close_rsp
{
782 __le16 StructureSize
; /* 60 */
786 __le64 LastAccessTime
;
787 __le64 LastWriteTime
;
789 __le64 AllocationSize
; /* Beginning of FILE_STANDARD_INFO equivalent */
794 struct smb2_flush_req
{
796 __le16 StructureSize
; /* Must be 24 */
799 __u64 PersistentFileId
; /* opaque endianness */
800 __u64 VolatileFileId
; /* opaque endianness */
803 struct smb2_flush_rsp
{
805 __le16 StructureSize
;
809 /* For read request Flags field below, following flag is defined for SMB3.02 */
810 #define SMB2_READFLAG_READ_UNBUFFERED 0x01
812 /* Channel field for read and write: exactly one of following flags can be set*/
813 #define SMB2_CHANNEL_NONE 0x00000000
814 #define SMB2_CHANNEL_RDMA_V1 0x00000001 /* SMB3 or later */
815 #define SMB2_CHANNEL_RDMA_V1_INVALIDATE 0x00000001 /* SMB3.02 or later */
817 struct smb2_read_req
{
819 __le16 StructureSize
; /* Must be 49 */
820 __u8 Padding
; /* offset from start of SMB2 header to place read */
821 __u8 Flags
; /* MBZ unless SMB3.02 or later */
824 __u64 PersistentFileId
; /* opaque endianness */
825 __u64 VolatileFileId
; /* opaque endianness */
827 __le32 Channel
; /* MBZ except for SMB3 or later */
828 __le32 RemainingBytes
;
829 __le16 ReadChannelInfoOffset
; /* Reserved MBZ */
830 __le16 ReadChannelInfoLength
; /* Reserved MBZ */
834 struct smb2_read_rsp
{
836 __le16 StructureSize
; /* Must be 17 */
840 __le32 DataRemaining
;
845 /* For write request Flags field below the following flags are defined: */
846 #define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 /* SMB2.1 or later */
847 #define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002 /* SMB3.02 or later */
849 struct smb2_write_req
{
851 __le16 StructureSize
; /* Must be 49 */
852 __le16 DataOffset
; /* offset from start of SMB2 header to write data */
855 __u64 PersistentFileId
; /* opaque endianness */
856 __u64 VolatileFileId
; /* opaque endianness */
857 __le32 Channel
; /* Reserved MBZ */
858 __le32 RemainingBytes
;
859 __le16 WriteChannelInfoOffset
; /* Reserved MBZ */
860 __le16 WriteChannelInfoLength
; /* Reserved MBZ */
865 struct smb2_write_rsp
{
867 __le16 StructureSize
; /* Must be 17 */
871 __le32 DataRemaining
;
876 #define SMB2_LOCKFLAG_SHARED_LOCK 0x0001
877 #define SMB2_LOCKFLAG_EXCLUSIVE_LOCK 0x0002
878 #define SMB2_LOCKFLAG_UNLOCK 0x0004
879 #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010
881 struct smb2_lock_element
{
888 struct smb2_lock_req
{
890 __le16 StructureSize
; /* Must be 48 */
893 __u64 PersistentFileId
; /* opaque endianness */
894 __u64 VolatileFileId
; /* opaque endianness */
895 /* Followed by at least one */
896 struct smb2_lock_element locks
[1];
899 struct smb2_lock_rsp
{
901 __le16 StructureSize
; /* Must be 4 */
905 struct smb2_echo_req
{
907 __le16 StructureSize
; /* Must be 4 */
911 struct smb2_echo_rsp
{
913 __le16 StructureSize
; /* Must be 4 */
917 /* search (query_directory) Flags field */
918 #define SMB2_RESTART_SCANS 0x01
919 #define SMB2_RETURN_SINGLE_ENTRY 0x02
920 #define SMB2_INDEX_SPECIFIED 0x04
921 #define SMB2_REOPEN 0x10
923 struct smb2_query_directory_req
{
925 __le16 StructureSize
; /* Must be 33 */
926 __u8 FileInformationClass
;
929 __u64 PersistentFileId
; /* opaque endianness */
930 __u64 VolatileFileId
; /* opaque endianness */
931 __le16 FileNameOffset
;
932 __le16 FileNameLength
;
933 __le32 OutputBufferLength
;
937 struct smb2_query_directory_rsp
{
939 __le16 StructureSize
; /* Must be 9 */
940 __le16 OutputBufferOffset
;
941 __le32 OutputBufferLength
;
945 /* Possible InfoType values */
946 #define SMB2_O_INFO_FILE 0x01
947 #define SMB2_O_INFO_FILESYSTEM 0x02
948 #define SMB2_O_INFO_SECURITY 0x03
949 #define SMB2_O_INFO_QUOTA 0x04
951 /* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */
952 #define OWNER_SECINFO 0x00000001
953 #define GROUP_SECINFO 0x00000002
954 #define DACL_SECINFO 0x00000004
955 #define SACL_SECINFO 0x00000008
956 #define LABEL_SECINFO 0x00000010
957 #define ATTRIBUTE_SECINFO 0x00000020
958 #define SCOPE_SECINFO 0x00000040
959 #define BACKUP_SECINFO 0x00010000
960 #define UNPROTECTED_SACL_SECINFO 0x10000000
961 #define UNPROTECTED_DACL_SECINFO 0x20000000
962 #define PROTECTED_SACL_SECINFO 0x40000000
963 #define PROTECTED_DACL_SECINFO 0x80000000
965 /* Flags used for FileFullEAinfo */
966 #define SL_RESTART_SCAN 0x00000001
967 #define SL_RETURN_SINGLE_ENTRY 0x00000002
968 #define SL_INDEX_SPECIFIED 0x00000004
970 struct smb2_query_info_req
{
972 __le16 StructureSize
; /* Must be 41 */
975 __le32 OutputBufferLength
;
976 __le16 InputBufferOffset
;
978 __le32 InputBufferLength
;
979 __le32 AdditionalInformation
;
981 __u64 PersistentFileId
; /* opaque endianness */
982 __u64 VolatileFileId
; /* opaque endianness */
986 struct smb2_query_info_rsp
{
988 __le16 StructureSize
; /* Must be 9 */
989 __le16 OutputBufferOffset
;
990 __le32 OutputBufferLength
;
994 struct smb2_set_info_req
{
996 __le16 StructureSize
; /* Must be 33 */
1000 __le16 BufferOffset
;
1002 __le32 AdditionalInformation
;
1003 __u64 PersistentFileId
; /* opaque endianness */
1004 __u64 VolatileFileId
; /* opaque endianness */
1008 struct smb2_set_info_rsp
{
1009 struct smb2_hdr hdr
;
1010 __le16 StructureSize
; /* Must be 2 */
1013 struct smb2_oplock_break
{
1014 struct smb2_hdr hdr
;
1015 __le16 StructureSize
; /* Must be 24 */
1019 __u64 PersistentFid
;
1023 #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
1025 struct smb2_lease_break
{
1026 struct smb2_hdr hdr
;
1027 __le16 StructureSize
; /* Must be 44 */
1031 __le32 CurrentLeaseState
;
1032 __le32 NewLeaseState
;
1034 __le32 AccessMaskHint
;
1035 __le32 ShareMaskHint
;
1038 struct smb2_lease_ack
{
1039 struct smb2_hdr hdr
;
1040 __le16 StructureSize
; /* Must be 36 */
1045 __le64 LeaseDuration
;
1049 * PDU infolevel structure definitions
1050 * BB consider moving to a different header
1053 /* File System Information Classes */
1054 #define FS_VOLUME_INFORMATION 1 /* Query */
1055 #define FS_LABEL_INFORMATION 2 /* Local only */
1056 #define FS_SIZE_INFORMATION 3 /* Query */
1057 #define FS_DEVICE_INFORMATION 4 /* Query */
1058 #define FS_ATTRIBUTE_INFORMATION 5 /* Query */
1059 #define FS_CONTROL_INFORMATION 6 /* Query, Set */
1060 #define FS_FULL_SIZE_INFORMATION 7 /* Query */
1061 #define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */
1062 #define FS_DRIVER_PATH_INFORMATION 9 /* Local only */
1063 #define FS_VOLUME_FLAGS_INFORMATION 10 /* Local only */
1064 #define FS_SECTOR_SIZE_INFORMATION 11 /* SMB3 or later. Query */
1066 struct smb2_fs_full_size_info
{
1067 __le64 TotalAllocationUnits
;
1068 __le64 CallerAvailableAllocationUnits
;
1069 __le64 ActualAvailableAllocationUnits
;
1070 __le32 SectorsPerAllocationUnit
;
1071 __le32 BytesPerSector
;
1074 #define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001
1075 #define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
1076 #define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004
1077 #define SSINFO_FLAGS_TRIM_ENABLED 0x00000008
1079 /* sector size info struct */
1080 struct smb3_fs_ss_info
{
1081 __le32 LogicalBytesPerSector
;
1082 __le32 PhysicalBytesPerSectorForAtomicity
;
1083 __le32 PhysicalBytesPerSectorForPerf
;
1084 __le32 FileSystemEffectivePhysicalBytesPerSectorForAtomicity
;
1086 __le32 ByteOffsetForSectorAlignment
;
1087 __le32 ByteOffsetForPartitionAlignment
;
1090 /* partial list of QUERY INFO levels */
1091 #define FILE_DIRECTORY_INFORMATION 1
1092 #define FILE_FULL_DIRECTORY_INFORMATION 2
1093 #define FILE_BOTH_DIRECTORY_INFORMATION 3
1094 #define FILE_BASIC_INFORMATION 4
1095 #define FILE_STANDARD_INFORMATION 5
1096 #define FILE_INTERNAL_INFORMATION 6
1097 #define FILE_EA_INFORMATION 7
1098 #define FILE_ACCESS_INFORMATION 8
1099 #define FILE_NAME_INFORMATION 9
1100 #define FILE_RENAME_INFORMATION 10
1101 #define FILE_LINK_INFORMATION 11
1102 #define FILE_NAMES_INFORMATION 12
1103 #define FILE_DISPOSITION_INFORMATION 13
1104 #define FILE_POSITION_INFORMATION 14
1105 #define FILE_FULL_EA_INFORMATION 15
1106 #define FILE_MODE_INFORMATION 16
1107 #define FILE_ALIGNMENT_INFORMATION 17
1108 #define FILE_ALL_INFORMATION 18
1109 #define FILE_ALLOCATION_INFORMATION 19
1110 #define FILE_END_OF_FILE_INFORMATION 20
1111 #define FILE_ALTERNATE_NAME_INFORMATION 21
1112 #define FILE_STREAM_INFORMATION 22
1113 #define FILE_PIPE_INFORMATION 23
1114 #define FILE_PIPE_LOCAL_INFORMATION 24
1115 #define FILE_PIPE_REMOTE_INFORMATION 25
1116 #define FILE_MAILSLOT_QUERY_INFORMATION 26
1117 #define FILE_MAILSLOT_SET_INFORMATION 27
1118 #define FILE_COMPRESSION_INFORMATION 28
1119 #define FILE_OBJECT_ID_INFORMATION 29
1120 /* Number 30 not defined in documents */
1121 #define FILE_MOVE_CLUSTER_INFORMATION 31
1122 #define FILE_QUOTA_INFORMATION 32
1123 #define FILE_REPARSE_POINT_INFORMATION 33
1124 #define FILE_NETWORK_OPEN_INFORMATION 34
1125 #define FILE_ATTRIBUTE_TAG_INFORMATION 35
1126 #define FILE_TRACKING_INFORMATION 36
1127 #define FILEID_BOTH_DIRECTORY_INFORMATION 37
1128 #define FILEID_FULL_DIRECTORY_INFORMATION 38
1129 #define FILE_VALID_DATA_LENGTH_INFORMATION 39
1130 #define FILE_SHORT_NAME_INFORMATION 40
1131 #define FILE_SFIO_RESERVE_INFORMATION 44
1132 #define FILE_SFIO_VOLUME_INFORMATION 45
1133 #define FILE_HARD_LINK_INFORMATION 46
1134 #define FILE_NORMALIZED_NAME_INFORMATION 48
1135 #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
1136 #define FILE_STANDARD_LINK_INFORMATION 54
1138 struct smb2_file_internal_info
{
1140 } __packed
; /* level 6 Query */
1142 struct smb2_file_rename_info
{ /* encoding of request for level 10 */
1143 __u8 ReplaceIfExists
; /* 1 = replace existing target with new */
1144 /* 0 = fail if target already exists */
1146 __u64 RootDirectory
; /* MBZ for network operations (why says spec?) */
1147 __le32 FileNameLength
;
1148 char FileName
[0]; /* New name to be assigned */
1149 } __packed
; /* level 10 Set */
1151 struct smb2_file_link_info
{ /* encoding of request for level 11 */
1152 __u8 ReplaceIfExists
; /* 1 = replace existing link with new */
1153 /* 0 = fail if link already exists */
1155 __u64 RootDirectory
; /* MBZ for network operations (why says spec?) */
1156 __le32 FileNameLength
;
1157 char FileName
[0]; /* Name to be assigned to new link */
1158 } __packed
; /* level 11 Set */
1161 * This level 18, although with struct with same name is different from cifs
1162 * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
1163 * CurrentByteOffset.
1165 struct smb2_file_all_info
{ /* data block encoding of response to level 18 */
1166 __le64 CreationTime
; /* Beginning of FILE_BASIC_INFO equivalent */
1167 __le64 LastAccessTime
;
1168 __le64 LastWriteTime
;
1171 __u32 Pad1
; /* End of FILE_BASIC_INFO_INFO equivalent */
1172 __le64 AllocationSize
; /* Beginning of FILE_STANDARD_INFO equivalent */
1173 __le64 EndOfFile
; /* size ie offset to first free byte in file */
1174 __le32 NumberOfLinks
; /* hard links */
1177 __u16 Pad2
; /* End of FILE_STANDARD_INFO equivalent */
1181 __le64 CurrentByteOffset
;
1183 __le32 AlignmentRequirement
;
1184 __le32 FileNameLength
;
1186 } __packed
; /* level 18 Query */
1188 struct smb2_file_eof_info
{ /* encoding of request for level 10 */
1189 __le64 EndOfFile
; /* new end of file value */
1190 } __packed
; /* level 20 Set */
1192 #endif /* _SMB2PDU_H */