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 /* BB FIXME - analyze following length BB */
88 #define MAX_SMB2_HDR_SIZE 0x78 /* 4 len + 64 hdr + (2*24 wct) + 2 bct + 2 pad */
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)
104 struct smb2_sync_hdr
{
105 __le32 ProtocolId
; /* 0xFE 'S' 'M' 'B' */
106 __le16 StructureSize
; /* 64 */
107 __le16 CreditCharge
; /* MBZ */
108 __le32 Status
; /* Error from server */
110 __le16 CreditRequest
; /* CreditResponse */
115 __u32 TreeId
; /* opaque - so do not make little endian */
116 __u64 SessionId
; /* opaque - so do not make little endian */
120 struct smb2_sync_pdu
{
121 struct smb2_sync_hdr sync_hdr
;
122 __le16 StructureSize2
; /* size of wct area (varies, request specific) */
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
;
134 __le16 StructureSize2
; /* size of wct area (varies, request specific) */
137 struct 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' */
144 __le32 OriginalMessageSize
;
146 __le16 Flags
; /* EncryptionAlgorithm */
151 * SMB2 flag definitions
153 #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)
160 * Definitions for SMB2 Protocol Data Units (network frames)
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.
168 #define SMB2_ERROR_STRUCTURE_SIZE2 cpu_to_le16(9)
170 struct smb2_err_rsp
{
172 __le16 StructureSize
;
173 __le16 Reserved
; /* MBZ */
174 __le32 ByteCount
; /* even if zero, at least one byte follows */
175 __u8 ErrorData
[1]; /* variable length */
178 struct smb2_symlink_err_rsp
{
179 __le32 SymLinkLength
;
180 __le32 SymLinkErrorTag
;
182 __le16 ReparseDataLength
;
183 __le16 UnparsedPathLength
;
184 __le16 SubstituteNameOffset
;
185 __le16 SubstituteNameLength
;
186 __le16 PrintNameOffset
;
187 __le16 PrintNameLength
;
192 #define SMB2_CLIENT_GUID_SIZE 16
194 struct smb2_negotiate_req
{
196 __le16 StructureSize
; /* Must be 36 */
199 __le16 Reserved
; /* MBZ */
201 __u8 ClientGUID
[SMB2_CLIENT_GUID_SIZE
];
202 /* 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 */
206 __le16 Dialects
[1]; /* One dialect (vers=) at a time for now */
210 #define SMB20_PROT_ID 0x0202
211 #define SMB21_PROT_ID 0x0210
212 #define SMB30_PROT_ID 0x0300
213 #define SMB302_PROT_ID 0x0302
214 #define SMB311_PROT_ID 0x0311
215 #define BAD_PROT_ID 0xFFFF
217 /* 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 */
224 #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 */
229 #define SMB2_NT_FIND 0x00100000
230 #define SMB2_LARGE_FILES 0x00200000
232 #define SMB311_SALT_SIZE 32
233 /* Hash Algorithm Types */
234 #define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001)
236 struct smb2_preauth_neg_context
{
237 __le16 ContextType
; /* 1 */
240 __le16 HashAlgorithmCount
; /* 1 */
242 __le16 HashAlgorithms
; /* HashAlgorithms[0] since only one defined */
243 __u8 Salt
[SMB311_SALT_SIZE
];
246 /* Encryption Algorithms Ciphers */
247 #define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001)
248 #define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002)
250 struct smb2_encryption_neg_context
{
251 __le16 ContextType
; /* 2 */
254 __le16 CipherCount
; /* AES-128-GCM and AES-128-CCM */
255 __le16 Ciphers
[2]; /* Ciphers[0] since only one used now */
258 struct smb2_negotiate_rsp
{
260 __le16 StructureSize
; /* Must be 65 */
262 __le16 DialectRevision
;
263 __le16 NegotiateContextCount
; /* Prior to SMB3.1.1 was Reserved & MBZ */
266 __le32 MaxTransactSize
;
269 __le64 SystemTime
; /* MBZ */
270 __le64 ServerStartTime
;
271 __le16 SecurityBufferOffset
;
272 __le16 SecurityBufferLength
;
273 __le32 NegotiateContextOffset
; /* Pre:SMB3.1.1 was reserved/ignored */
274 __u8 Buffer
[1]; /* variable length GSS security buffer */
278 #define SMB2_SESSION_REQ_FLAG_BINDING 0x01
279 #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04
281 struct smb2_sess_setup_req
{
283 __le16 StructureSize
; /* Must be 25 */
288 __le16 SecurityBufferOffset
;
289 __le16 SecurityBufferLength
;
290 __u64 PreviousSessionId
;
291 __u8 Buffer
[1]; /* variable length GSS security buffer */
294 /* Currently defined SessionFlags */
295 #define SMB2_SESSION_FLAG_IS_GUEST 0x0001
296 #define SMB2_SESSION_FLAG_IS_NULL 0x0002
297 #define SMB2_SESSION_FLAG_ENCRYPT_DATA 0x0004
298 struct smb2_sess_setup_rsp
{
300 __le16 StructureSize
; /* Must be 9 */
302 __le16 SecurityBufferOffset
;
303 __le16 SecurityBufferLength
;
304 __u8 Buffer
[1]; /* variable length GSS security buffer */
307 struct smb2_logoff_req
{
309 __le16 StructureSize
; /* Must be 4 */
313 struct smb2_logoff_rsp
{
315 __le16 StructureSize
; /* Must be 4 */
319 /* Flags/Reserved for SMB3.1.1 */
320 #define SMB2_SHAREFLAG_CLUSTER_RECONNECT 0x0001
322 struct smb2_tree_connect_req
{
324 __le16 StructureSize
; /* Must be 9 */
325 __le16 Reserved
; /* Flags in SMB3.1.1 */
328 __u8 Buffer
[1]; /* variable length */
331 struct smb2_tree_connect_rsp
{
333 __le16 StructureSize
; /* Must be 16 */
334 __u8 ShareType
; /* see below */
336 __le32 ShareFlags
; /* see below */
337 __le32 Capabilities
; /* see below */
338 __le32 MaximalAccess
;
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
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
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
362 #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
367 /* Possible share capabilities */
368 #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 */
374 struct smb2_tree_disconnect_req
{
376 __le16 StructureSize
; /* Must be 4 */
380 struct smb2_tree_disconnect_rsp
{
382 __le16 StructureSize
; /* Must be 4 */
386 /* 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
400 #define FILE_ATTRIBUTE_INTEGRITY_STREAM 0x00008000
401 #define FILE_ATTRIBUTE_NO_SCRUB_DATA 0x00020000
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
409 /* Non-spec internal type */
410 #define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99
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)
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)
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)
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)
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)
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)
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"
485 #define SMB2_CREATE_ALLOCATION_SIZE "AISi"
486 #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"
490 #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
495 struct smb2_create_req
{
497 __le16 StructureSize
; /* Must be 57 */
499 __u8 RequestedOplockLevel
;
500 __le32 ImpersonationLevel
;
501 __le64 SmbCreateFlags
;
503 __le32 DesiredAccess
;
504 __le32 FileAttributes
;
506 __le32 CreateDisposition
;
507 __le32 CreateOptions
;
510 __le32 CreateContextsOffset
;
511 __le32 CreateContextsLength
;
515 struct smb2_create_rsp
{
517 __le16 StructureSize
; /* Must be 89 */
522 __le64 LastAccessTime
;
523 __le64 LastWriteTime
;
525 __le64 AllocationSize
;
527 __le32 FileAttributes
;
529 __u64 PersistentFileId
; /* opaque endianness */
530 __u64 VolatileFileId
; /* opaque endianness */
531 __le32 CreateContextsOffset
;
532 __le32 CreateContextsLength
;
536 struct create_context
{
546 #define SMB2_LEASE_READ_CACHING_HE 0x01
547 #define SMB2_LEASE_HANDLE_CACHING_HE 0x02
548 #define SMB2_LEASE_WRITE_CACHING_HE 0x04
550 #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)
555 #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS cpu_to_le32(0x02)
557 #define SMB2_LEASE_KEY_SIZE 16
559 struct lease_context
{
564 __le64 LeaseDuration
;
567 struct lease_context_v2
{
572 __le64 LeaseDuration
;
573 __le64 ParentLeaseKeyLow
;
574 __le64 ParentLeaseKeyHigh
;
579 struct create_lease
{
580 struct create_context ccontext
;
582 struct lease_context lcontext
;
585 struct create_lease_v2
{
586 struct create_context ccontext
;
588 struct lease_context_v2 lcontext
;
592 struct create_durable
{
593 struct create_context ccontext
;
598 __u64 PersistentFileId
;
599 __u64 VolatileFileId
;
604 /* See MS-SMB2 2.2.13.2.11 */
606 #define SMB2_DHANDLE_FLAG_PERSISTENT 0x00000002
607 struct durable_context_v2
{
614 struct create_durable_v2
{
615 struct create_context ccontext
;
617 struct durable_context_v2 dcontext
;
620 /* See MS-SMB2 2.2.13.2.12 */
621 struct durable_reconnect_context_v2
{
623 __u64 PersistentFileId
;
624 __u64 VolatileFileId
;
627 __le32 Flags
; /* see above DHANDLE_FLAG_PERSISTENT */
630 /* See MS-SMB2 2.2.14.2.12 */
631 struct durable_reconnect_context_v2_rsp
{
633 __le32 Flags
; /* see above DHANDLE_FLAG_PERSISTENT */
636 struct create_durable_handle_reconnect_v2
{
637 struct create_context ccontext
;
639 struct durable_reconnect_context_v2 dcontext
;
642 #define COPY_CHUNK_RES_KEY_SIZE 24
643 struct 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 */
649 /* this goes in the ioctl buffer when doing a copychunk request */
650 struct copychunk_ioctl
{
651 char SourceKey
[COPY_CHUNK_RES_KEY_SIZE
];
652 __le32 ChunkCount
; /* we are only sending 1 */
654 /* array will only be one chunk long for us */
657 __le32 Length
; /* how many bytes to copy */
661 /* this goes in the ioctl buffer when doing FSCTL_SET_ZERO_DATA */
662 struct file_zero_data_information
{
664 __le64 BeyondFinalZero
;
667 struct copychunk_ioctl_rsp
{
668 __le32 ChunksWritten
;
669 __le32 ChunkBytesWritten
;
670 __le32 TotalBytesWritten
;
673 struct fsctl_set_integrity_information_req
{
674 __le16 ChecksumAlgorithm
;
679 struct fsctl_get_integrity_information_rsp
{
680 __le16 ChecksumAlgorithm
;
683 __le32 ChecksumChunkSizeInBytes
;
684 __le32 ClusterSizeInBytes
;
687 /* Integrity ChecksumAlgorithm choices for above */
688 #define CHECKSUM_TYPE_NONE 0x0000
689 #define CHECKSUM_TYPE_CRC64 0x0002
690 #define CHECKSUM_TYPE_UNCHANGED 0xFFFF /* set only */
692 /* Integrity flags for above */
693 #define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF 0x00000001
695 /* See MS-SMB2 2.2.31.3 */
696 struct network_resiliency_req
{
700 /* There is no buffer for the response ie no struct network_resiliency_rsp */
703 struct validate_negotiate_info_req
{
705 __u8 Guid
[SMB2_CLIENT_GUID_SIZE
];
708 __le16 Dialects
[1]; /* dialect (someday maybe list) client asked for */
711 struct validate_negotiate_info_rsp
{
713 __u8 Guid
[SMB2_CLIENT_GUID_SIZE
];
715 __le16 Dialect
; /* Dialect in use for the connection */
718 #define RSS_CAPABLE 0x00000001
719 #define RDMA_CAPABLE 0x00000002
721 struct network_interface_info_ioctl_rsp
{
722 __le32 Next
; /* next interface. zero if this is last one */
724 __le32 Capability
; /* RSS or RDMA Capable */
727 char SockAddr_Storage
[128];
730 #define NO_FILE_ID 0xFFFFFFFFFFFFFFFFULL /* general ioctls to srv not to file */
732 struct compress_ioctl
{
733 __le16 CompressionState
; /* See cifspdu.h for possible flag values */
736 struct 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 */
744 struct smb2_ioctl_req
{
746 __le16 StructureSize
; /* Must be 57 */
749 __u64 PersistentFileId
; /* opaque endianness */
750 __u64 VolatileFileId
; /* opaque endianness */
753 __le32 MaxInputResponse
;
756 __le32 MaxOutputResponse
;
762 struct smb2_ioctl_rsp
{
764 __le16 StructureSize
; /* Must be 57 */
767 __u64 PersistentFileId
; /* opaque endianness */
768 __u64 VolatileFileId
; /* opaque endianness */
775 /* char * buffer[] */
778 /* Currently defined values for close flags */
779 #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
780 struct smb2_close_req
{
782 __le16 StructureSize
; /* Must be 24 */
785 __u64 PersistentFileId
; /* opaque endianness */
786 __u64 VolatileFileId
; /* opaque endianness */
789 struct smb2_close_rsp
{
791 __le16 StructureSize
; /* 60 */
795 __le64 LastAccessTime
;
796 __le64 LastWriteTime
;
798 __le64 AllocationSize
; /* Beginning of FILE_STANDARD_INFO equivalent */
803 struct smb2_flush_req
{
805 __le16 StructureSize
; /* Must be 24 */
808 __u64 PersistentFileId
; /* opaque endianness */
809 __u64 VolatileFileId
; /* opaque endianness */
812 struct smb2_flush_rsp
{
814 __le16 StructureSize
;
818 /* For read request Flags field below, following flag is defined for SMB3.02 */
819 #define SMB2_READFLAG_READ_UNBUFFERED 0x01
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 */
826 /* SMB2 read request without RFC1001 length at the beginning */
827 struct smb2_read_plain_req
{
828 struct smb2_sync_hdr sync_hdr
;
829 __le16 StructureSize
; /* Must be 49 */
830 __u8 Padding
; /* offset from start of SMB2 header to place read */
831 __u8 Flags
; /* MBZ unless SMB3.02 or later */
834 __u64 PersistentFileId
; /* opaque endianness */
835 __u64 VolatileFileId
; /* opaque endianness */
837 __le32 Channel
; /* MBZ except for SMB3 or later */
838 __le32 RemainingBytes
;
839 __le16 ReadChannelInfoOffset
; /* Reserved MBZ */
840 __le16 ReadChannelInfoLength
; /* Reserved MBZ */
844 struct smb2_read_rsp
{
846 __le16 StructureSize
; /* Must be 17 */
850 __le32 DataRemaining
;
855 /* 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 */
859 struct smb2_write_req
{
861 __le16 StructureSize
; /* Must be 49 */
862 __le16 DataOffset
; /* offset from start of SMB2 header to write data */
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 */
875 struct smb2_write_rsp
{
877 __le16 StructureSize
; /* Must be 17 */
881 __le32 DataRemaining
;
886 #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
891 struct smb2_lock_element
{
898 struct smb2_lock_req
{
900 __le16 StructureSize
; /* Must be 48 */
903 __u64 PersistentFileId
; /* opaque endianness */
904 __u64 VolatileFileId
; /* opaque endianness */
905 /* Followed by at least one */
906 struct smb2_lock_element locks
[1];
909 struct smb2_lock_rsp
{
911 __le16 StructureSize
; /* Must be 4 */
915 struct smb2_echo_req
{
917 __le16 StructureSize
; /* Must be 4 */
921 struct smb2_echo_rsp
{
923 __le16 StructureSize
; /* Must be 4 */
927 /* 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
933 struct smb2_query_directory_req
{
935 __le16 StructureSize
; /* Must be 33 */
936 __u8 FileInformationClass
;
939 __u64 PersistentFileId
; /* opaque endianness */
940 __u64 VolatileFileId
; /* opaque endianness */
941 __le16 FileNameOffset
;
942 __le16 FileNameLength
;
943 __le32 OutputBufferLength
;
947 struct smb2_query_directory_rsp
{
949 __le16 StructureSize
; /* Must be 9 */
950 __le16 OutputBufferOffset
;
951 __le32 OutputBufferLength
;
955 /* 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
961 /* 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
975 /* Flags used for FileFullEAinfo */
976 #define SL_RESTART_SCAN 0x00000001
977 #define SL_RETURN_SINGLE_ENTRY 0x00000002
978 #define SL_INDEX_SPECIFIED 0x00000004
980 struct smb2_query_info_req
{
982 __le16 StructureSize
; /* Must be 41 */
985 __le32 OutputBufferLength
;
986 __le16 InputBufferOffset
;
988 __le32 InputBufferLength
;
989 __le32 AdditionalInformation
;
991 __u64 PersistentFileId
; /* opaque endianness */
992 __u64 VolatileFileId
; /* opaque endianness */
996 struct smb2_query_info_rsp
{
998 __le16 StructureSize
; /* Must be 9 */
999 __le16 OutputBufferOffset
;
1000 __le32 OutputBufferLength
;
1004 struct smb2_set_info_req
{
1005 struct smb2_hdr hdr
;
1006 __le16 StructureSize
; /* Must be 33 */
1009 __le32 BufferLength
;
1010 __le16 BufferOffset
;
1012 __le32 AdditionalInformation
;
1013 __u64 PersistentFileId
; /* opaque endianness */
1014 __u64 VolatileFileId
; /* opaque endianness */
1018 struct smb2_set_info_rsp
{
1019 struct smb2_hdr hdr
;
1020 __le16 StructureSize
; /* Must be 2 */
1023 struct smb2_oplock_break
{
1024 struct smb2_hdr hdr
;
1025 __le16 StructureSize
; /* Must be 24 */
1029 __u64 PersistentFid
;
1033 #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
1035 struct smb2_lease_break
{
1036 struct smb2_hdr hdr
;
1037 __le16 StructureSize
; /* Must be 44 */
1041 __le32 CurrentLeaseState
;
1042 __le32 NewLeaseState
;
1044 __le32 AccessMaskHint
;
1045 __le32 ShareMaskHint
;
1048 struct smb2_lease_ack
{
1049 struct smb2_hdr hdr
;
1050 __le16 StructureSize
; /* Must be 36 */
1055 __le64 LeaseDuration
;
1059 * PDU infolevel structure definitions
1060 * BB consider moving to a different header
1063 /* File System Information Classes */
1064 #define FS_VOLUME_INFORMATION 1 /* Query */
1065 #define FS_LABEL_INFORMATION 2 /* Local only */
1066 #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 */
1072 #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 */
1076 struct smb2_fs_full_size_info
{
1077 __le64 TotalAllocationUnits
;
1078 __le64 CallerAvailableAllocationUnits
;
1079 __le64 ActualAvailableAllocationUnits
;
1080 __le32 SectorsPerAllocationUnit
;
1081 __le32 BytesPerSector
;
1084 #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
1089 /* sector size info struct */
1090 struct smb3_fs_ss_info
{
1091 __le32 LogicalBytesPerSector
;
1092 __le32 PhysicalBytesPerSectorForAtomicity
;
1093 __le32 PhysicalBytesPerSectorForPerf
;
1094 __le32 FileSystemEffectivePhysicalBytesPerSectorForAtomicity
;
1096 __le32 ByteOffsetForSectorAlignment
;
1097 __le32 ByteOffsetForPartitionAlignment
;
1100 /* 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
1148 struct smb2_file_internal_info
{
1150 } __packed
; /* level 6 Query */
1152 struct 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 */
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 */
1161 struct 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 */
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 */
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.
1175 struct 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
;
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 */
1187 __u16 Pad2
; /* End of FILE_STANDARD_INFO equivalent */
1191 __le64 CurrentByteOffset
;
1193 __le32 AlignmentRequirement
;
1194 __le32 FileNameLength
;
1196 } __packed
; /* level 18 Query */
1198 struct smb2_file_eof_info
{ /* encoding of request for level 10 */
1199 __le64 EndOfFile
; /* new end of file value */
1200 } __packed
; /* level 20 Set */
1202 #endif /* _SMB2PDU_H */