1 /* SPDX-License-Identifier: LGPL-2.1 */
2 #ifndef _COMMON_SMB2PDU_H
3 #define _COMMON_SMB2PDU_H
6 * Note that, due to trying to use names similar to the protocol specifications,
7 * there are many mixed case field names in the structures below. Although
8 * this does not match typical Linux kernel style, it is necessary to be
9 * able to match against the protocol specfication.
12 * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses
13 * (ie no useful data other than the SMB error code itself) and are marked such.
14 * Knowing this helps avoid response buffer allocations and copy in some cases.
17 /* List of commands in host endian */
18 #define SMB2_NEGOTIATE_HE 0x0000
19 #define SMB2_SESSION_SETUP_HE 0x0001
20 #define SMB2_LOGOFF_HE 0x0002 /* trivial request/resp */
21 #define SMB2_TREE_CONNECT_HE 0x0003
22 #define SMB2_TREE_DISCONNECT_HE 0x0004 /* trivial req/resp */
23 #define SMB2_CREATE_HE 0x0005
24 #define SMB2_CLOSE_HE 0x0006
25 #define SMB2_FLUSH_HE 0x0007 /* trivial resp */
26 #define SMB2_READ_HE 0x0008
27 #define SMB2_WRITE_HE 0x0009
28 #define SMB2_LOCK_HE 0x000A
29 #define SMB2_IOCTL_HE 0x000B
30 #define SMB2_CANCEL_HE 0x000C
31 #define SMB2_ECHO_HE 0x000D
32 #define SMB2_QUERY_DIRECTORY_HE 0x000E
33 #define SMB2_CHANGE_NOTIFY_HE 0x000F
34 #define SMB2_QUERY_INFO_HE 0x0010
35 #define SMB2_SET_INFO_HE 0x0011
36 #define SMB2_OPLOCK_BREAK_HE 0x0012
38 /* The same list in little endian */
39 #define SMB2_NEGOTIATE cpu_to_le16(SMB2_NEGOTIATE_HE)
40 #define SMB2_SESSION_SETUP cpu_to_le16(SMB2_SESSION_SETUP_HE)
41 #define SMB2_LOGOFF cpu_to_le16(SMB2_LOGOFF_HE)
42 #define SMB2_TREE_CONNECT cpu_to_le16(SMB2_TREE_CONNECT_HE)
43 #define SMB2_TREE_DISCONNECT cpu_to_le16(SMB2_TREE_DISCONNECT_HE)
44 #define SMB2_CREATE cpu_to_le16(SMB2_CREATE_HE)
45 #define SMB2_CLOSE cpu_to_le16(SMB2_CLOSE_HE)
46 #define SMB2_FLUSH cpu_to_le16(SMB2_FLUSH_HE)
47 #define SMB2_READ cpu_to_le16(SMB2_READ_HE)
48 #define SMB2_WRITE cpu_to_le16(SMB2_WRITE_HE)
49 #define SMB2_LOCK cpu_to_le16(SMB2_LOCK_HE)
50 #define SMB2_IOCTL cpu_to_le16(SMB2_IOCTL_HE)
51 #define SMB2_CANCEL cpu_to_le16(SMB2_CANCEL_HE)
52 #define SMB2_ECHO cpu_to_le16(SMB2_ECHO_HE)
53 #define SMB2_QUERY_DIRECTORY cpu_to_le16(SMB2_QUERY_DIRECTORY_HE)
54 #define SMB2_CHANGE_NOTIFY cpu_to_le16(SMB2_CHANGE_NOTIFY_HE)
55 #define SMB2_QUERY_INFO cpu_to_le16(SMB2_QUERY_INFO_HE)
56 #define SMB2_SET_INFO cpu_to_le16(SMB2_SET_INFO_HE)
57 #define SMB2_OPLOCK_BREAK cpu_to_le16(SMB2_OPLOCK_BREAK_HE)
59 #define SMB2_INTERNAL_CMD cpu_to_le16(0xFFFF)
61 #define NUMBER_OF_SMB2_COMMANDS 0x0013
64 * Size of the session key (crypto key encrypted with the password
66 #define SMB2_NTLMV2_SESSKEY_SIZE 16
67 #define SMB2_SIGNATURE_SIZE 16
68 #define SMB2_HMACSHA256_SIZE 32
69 #define SMB2_CMACAES_SIZE 16
70 #define SMB3_GCM128_CRYPTKEY_SIZE 16
71 #define SMB3_GCM256_CRYPTKEY_SIZE 32
74 * Size of the smb3 encryption/decryption keys
75 * This size is big enough to store any cipher key types.
77 #define SMB3_ENC_DEC_KEY_SIZE 32
80 * Size of the smb3 signing key
82 #define SMB3_SIGN_KEY_SIZE 16
84 #define CIFS_CLIENT_CHALLENGE_SIZE 8
86 /* Maximum buffer size value we can send with 1 credit */
87 #define SMB2_MAX_BUFFER_SIZE 65536
90 * The default wsize is 1M for SMB2 (and for some CIFS cases).
91 * find_get_pages seems to return a maximum of 256
92 * pages in a single call. With PAGE_SIZE == 4k, this means we can
93 * fill a single wsize request with a single call.
95 #define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024)
98 * SMB2 Header Definition
100 * "MBZ" : Must be Zero
101 * "BB" : BugBug, Something to check/review/analyze later
102 * "PDU" : "Protocol Data Unit" (ie a network "frame")
106 #define __SMB2_HEADER_STRUCTURE_SIZE 64
107 #define SMB2_HEADER_STRUCTURE_SIZE \
108 cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE)
110 #define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)
111 #define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
112 #define SMB2_COMPRESSION_TRANSFORM_ID cpu_to_le32(0x424d53fc)
115 * SMB2 flag definitions
117 #define SMB2_FLAGS_SERVER_TO_REDIR cpu_to_le32(0x00000001)
118 #define SMB2_FLAGS_ASYNC_COMMAND cpu_to_le32(0x00000002)
119 #define SMB2_FLAGS_RELATED_OPERATIONS cpu_to_le32(0x00000004)
120 #define SMB2_FLAGS_SIGNED cpu_to_le32(0x00000008)
121 #define SMB2_FLAGS_PRIORITY_MASK cpu_to_le32(0x00000070) /* SMB3.1.1 */
122 #define SMB2_FLAGS_DFS_OPERATIONS cpu_to_le32(0x10000000)
123 #define SMB2_FLAGS_REPLAY_OPERATION cpu_to_le32(0x20000000) /* SMB3 & up */
126 * Definitions for SMB2 Protocol Data Units (network frames)
128 * See MS-SMB2.PDF specification for protocol details.
129 * The Naming convention is the lower case version of the SMB2
130 * command code name for the struct. Note that structures must be packed.
134 /* See MS-SMB2 section 2.2.1 */
136 __le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */
137 __le16 StructureSize; /* 64 */
138 __le16 CreditCharge; /* MBZ */
139 __le32 Status; /* Error from server */
141 __le16 CreditRequest; /* CreditResponse */
156 struct smb3_hdr_req {
157 __le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */
158 __le16 StructureSize; /* 64 */
159 __le16 CreditCharge; /* MBZ */
160 __le16 ChannelSequence; /* See MS-SMB2 3.2.4.1 and 3.2.7.1 */
163 __le16 CreditRequest; /* CreditResponse */
180 __le16 StructureSize2; /* size of wct area (varies, request specific) */
183 #define SMB2_ERROR_STRUCTURE_SIZE2 9
184 #define SMB2_ERROR_STRUCTURE_SIZE2_LE cpu_to_le16(SMB2_ERROR_STRUCTURE_SIZE2)
186 struct smb2_err_rsp {
188 __le16 StructureSize;
189 __u8 ErrorContextCount;
191 __le32 ByteCount; /* even if zero, at least one byte follows */
192 __u8 ErrorData[]; /* variable length */
195 #define SMB3_AES_CCM_NONCE 11
196 #define SMB3_AES_GCM_NONCE 12
198 /* Transform flags (for 3.0 dialect this flag indicates CCM */
199 #define TRANSFORM_FLAG_ENCRYPTED 0x0001
200 struct smb2_transform_hdr {
201 __le32 ProtocolId; /* 0xFD 'S' 'M' 'B' */
204 __le32 OriginalMessageSize;
206 __le16 Flags; /* EncryptionAlgorithm for 3.0, enc enabled for 3.1.1 */
211 /* See MS-SMB2 2.2.42 */
212 struct smb2_compression_transform_hdr_unchained {
213 __le32 ProtocolId; /* 0xFC 'S' 'M' 'B' */
214 __le32 OriginalCompressedSegmentSize;
215 __le16 CompressionAlgorithm;
217 __le16 Length; /* if chained it is length, else offset */
220 /* See MS-SMB2 2.2.42.1 */
221 #define SMB2_COMPRESSION_FLAG_NONE 0x0000
222 #define SMB2_COMPRESSION_FLAG_CHAINED 0x0001
224 struct compression_payload_header {
225 __le16 CompressionAlgorithm;
227 __le32 Length; /* length of compressed playload including field below if present */
228 /* __le32 OriginalPayloadSize; */ /* optional, present when LZNT1, LZ77, LZ77+Huffman */
231 /* See MS-SMB2 2.2.42.2 */
232 struct smb2_compression_transform_hdr_chained {
233 __le32 ProtocolId; /* 0xFC 'S' 'M' 'B' */
234 __le32 OriginalCompressedSegmentSize;
235 /* struct compression_payload_header[] */
238 /* See MS-SMB2 2.2.42.2.2 */
239 struct compression_pattern_payload_v1 {
246 /* See MS-SMB2 section 2.2.9.2 */
248 #define SMB2_RESERVED_TREE_CONNECT_CONTEXT_ID 0x0000
249 #define SMB2_REMOTED_IDENTITY_TREE_CONNECT_CONTEXT_ID cpu_to_le16(0x0001)
251 struct tree_connect_contexts {
258 /* Remoted identity tree connect context structures - see MS-SMB2 2.2.9.2.1 */
259 struct smb3_blob_data {
264 /* Valid values for Attr */
265 #define SE_GROUP_MANDATORY 0x00000001
266 #define SE_GROUP_ENABLED_BY_DEFAULT 0x00000002
267 #define SE_GROUP_ENABLED 0x00000004
268 #define SE_GROUP_OWNER 0x00000008
269 #define SE_GROUP_USE_FOR_DENY_ONLY 0x00000010
270 #define SE_GROUP_INTEGRITY 0x00000020
271 #define SE_GROUP_INTEGRITY_ENABLED 0x00000040
272 #define SE_GROUP_RESOURCE 0x20000000
273 #define SE_GROUP_LOGON_ID 0xC0000000
275 /* struct sid_attr_data is SidData array in BlobData format then le32 Attr */
277 struct sid_array_data {
279 /* SidAttrList - array of sid_attr_data structs */
282 struct luid_attr_data {
287 * struct privilege_data is the same as BLOB_DATA - see MS-SMB2 2.2.9.2.1.5
288 * but with size of LUID_ATTR_DATA struct and BlobData set to LUID_ATTR DATA
291 struct privilege_array_data {
292 __le16 PrivilegeCount;
293 /* array of privilege_data structs */
296 struct remoted_identity_tcon_context {
297 __le16 TicketType; /* must be 0x0001 */
298 __le16 TicketSize; /* total size of this struct */
299 __le16 User; /* offset to SID_ATTR_DATA struct with user info */
300 __le16 UserName; /* offset to null terminated Unicode username string */
301 __le16 Domain; /* offset to null terminated Unicode domain name */
302 __le16 Groups; /* offset to SID_ARRAY_DATA struct with group info */
303 __le16 RestrictedGroups; /* similar to above */
304 __le16 Privileges; /* offset to PRIVILEGE_ARRAY_DATA struct */
305 __le16 PrimaryGroup; /* offset to SID_ARRAY_DATA struct */
306 __le16 Owner; /* offset to BLOB_DATA struct */
307 __le16 DefaultDacl; /* offset to BLOB_DATA struct */
308 __le16 DeviceGroups; /* offset to SID_ARRAY_DATA struct */
309 __le16 UserClaims; /* offset to BLOB_DATA struct */
310 __le16 DeviceClaims; /* offset to BLOB_DATA struct */
311 __u8 TicketInfo[]; /* variable length buf - remoted identity data */
314 struct smb2_tree_connect_req_extension {
315 __le32 TreeConnectContextOffset;
316 __le16 TreeConnectContextCount;
318 __u8 PathName[]; /* variable sized array */
319 /* followed by array of TreeConnectContexts */
322 /* Flags/Reserved for SMB3.1.1 */
323 #define SMB2_TREE_CONNECT_FLAG_CLUSTER_RECONNECT cpu_to_le16(0x0001)
324 #define SMB2_TREE_CONNECT_FLAG_REDIRECT_TO_OWNER cpu_to_le16(0x0002)
325 #define SMB2_TREE_CONNECT_FLAG_EXTENSION_PRESENT cpu_to_le16(0x0004)
327 struct smb2_tree_connect_req {
329 __le16 StructureSize; /* Must be 9 */
330 __le16 Flags; /* Flags in SMB3.1.1 */
333 __u8 Buffer[]; /* variable length */
336 /* Possible ShareType values */
337 #define SMB2_SHARE_TYPE_DISK 0x01
338 #define SMB2_SHARE_TYPE_PIPE 0x02
339 #define SMB2_SHARE_TYPE_PRINT 0x03
342 * Possible ShareFlags - exactly one and only one of the first 4 caching flags
343 * must be set (any of the remaining, SHI1005, flags may be set individually
346 #define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000
347 #define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010
348 #define SMB2_SHAREFLAG_VDO_CACHING 0x00000020
349 #define SMB2_SHAREFLAG_NO_CACHING 0x00000030
350 #define SHI1005_FLAGS_DFS 0x00000001
351 #define SHI1005_FLAGS_DFS_ROOT 0x00000002
352 #define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS 0x00000100
353 #define SHI1005_FLAGS_FORCE_SHARED_DELETE 0x00000200
354 #define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING 0x00000400
355 #define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM 0x00000800
356 #define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK 0x00001000
357 #define SHI1005_FLAGS_ENABLE_HASH_V1 0x00002000
358 #define SHI1005_FLAGS_ENABLE_HASH_V2 0x00004000
359 #define SHI1005_FLAGS_ENCRYPT_DATA 0x00008000
360 #define SMB2_SHAREFLAG_IDENTITY_REMOTING 0x00040000 /* 3.1.1 */
361 #define SMB2_SHAREFLAG_COMPRESS_DATA 0x00100000 /* 3.1.1 */
362 #define SHI1005_FLAGS_ALL 0x0014FF33
364 /* Possible share capabilities */
365 #define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008) /* all dialects */
366 #define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY cpu_to_le32(0x00000010) /* 3.0 */
367 #define SMB2_SHARE_CAP_SCALEOUT cpu_to_le32(0x00000020) /* 3.0 */
368 #define SMB2_SHARE_CAP_CLUSTER cpu_to_le32(0x00000040) /* 3.0 */
369 #define SMB2_SHARE_CAP_ASYMMETRIC cpu_to_le32(0x00000080) /* 3.02 */
370 #define SMB2_SHARE_CAP_REDIRECT_TO_OWNER cpu_to_le32(0x00000100) /* 3.1.1 */
372 struct smb2_tree_connect_rsp {
374 __le16 StructureSize; /* Must be 16 */
375 __u8 ShareType; /* see below */
377 __le32 ShareFlags; /* see below */
378 __le32 Capabilities; /* see below */
379 __le32 MaximalAccess;
382 struct smb2_tree_disconnect_req {
384 __le16 StructureSize; /* Must be 4 */
388 struct smb2_tree_disconnect_rsp {
390 __le16 StructureSize; /* Must be 4 */
396 * SMB2_NEGOTIATE_PROTOCOL See MS-SMB2 section 2.2.3
398 /* SecurityMode flags */
399 #define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001
400 #define SMB2_NEGOTIATE_SIGNING_ENABLED_LE cpu_to_le16(0x0001)
401 #define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
402 #define SMB2_NEGOTIATE_SIGNING_REQUIRED_LE cpu_to_le16(0x0002)
403 #define SMB2_SEC_MODE_FLAGS_ALL 0x0003
405 /* Capabilities flags */
406 #define SMB2_GLOBAL_CAP_DFS 0x00000001
407 #define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */
408 #define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */
409 #define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */
410 #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
411 #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */
412 #define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */
414 #define SMB2_NT_FIND 0x00100000
415 #define SMB2_LARGE_FILES 0x00200000
417 #define SMB2_CLIENT_GUID_SIZE 16
418 #define SMB2_CREATE_GUID_SIZE 16
421 #define SMB10_PROT_ID 0x0000 /* local only, not sent on wire w/CIFS negprot */
422 #define SMB20_PROT_ID 0x0202
423 #define SMB21_PROT_ID 0x0210
424 #define SMB2X_PROT_ID 0x02FF
425 #define SMB30_PROT_ID 0x0300
426 #define SMB302_PROT_ID 0x0302
427 #define SMB311_PROT_ID 0x0311
428 #define BAD_PROT_ID 0xFFFF
430 #define SMB311_SALT_SIZE 32
431 /* Hash Algorithm Types */
432 #define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001)
433 #define SMB2_PREAUTH_HASH_SIZE 64
435 /* Negotiate Contexts - ContextTypes. See MS-SMB2 section 2.2.3.1 for details */
436 #define SMB2_PREAUTH_INTEGRITY_CAPABILITIES cpu_to_le16(1)
437 #define SMB2_ENCRYPTION_CAPABILITIES cpu_to_le16(2)
438 #define SMB2_COMPRESSION_CAPABILITIES cpu_to_le16(3)
439 #define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID cpu_to_le16(5)
440 #define SMB2_TRANSPORT_CAPABILITIES cpu_to_le16(6)
441 #define SMB2_RDMA_TRANSFORM_CAPABILITIES cpu_to_le16(7)
442 #define SMB2_SIGNING_CAPABILITIES cpu_to_le16(8)
443 #define SMB2_POSIX_EXTENSIONS_AVAILABLE cpu_to_le16(0x100)
445 struct smb2_neg_context {
449 /* Followed by array of data. NOTE: some servers require padding to 8 byte boundary */
453 * SaltLength that the server send can be zero, so the only three required
454 * fields (all __le16) end up six bytes total, so the minimum context data len
455 * in the response is six bytes which accounts for
457 * HashAlgorithmCount, SaltLength, and 1 HashAlgorithm.
459 #define MIN_PREAUTH_CTXT_DATA_LEN 6
461 struct smb2_preauth_neg_context {
462 __le16 ContextType; /* 1 */
465 __le16 HashAlgorithmCount; /* 1 */
467 __le16 HashAlgorithms; /* HashAlgorithms[0] since only one defined */
468 __u8 Salt[SMB311_SALT_SIZE];
471 /* Encryption Algorithms Ciphers */
472 #define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001)
473 #define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002)
474 #define SMB2_ENCRYPTION_AES256_CCM cpu_to_le16(0x0003)
475 #define SMB2_ENCRYPTION_AES256_GCM cpu_to_le16(0x0004)
477 /* Min encrypt context data is one cipher so 2 bytes + 2 byte count field */
478 #define MIN_ENCRYPT_CTXT_DATA_LEN 4
479 struct smb2_encryption_neg_context {
480 __le16 ContextType; /* 2 */
483 /* CipherCount usally 2, but can be 3 when AES256-GCM enabled */
484 __le16 CipherCount; /* AES128-GCM and AES128-CCM by default */
488 /* See MS-SMB2 2.2.3.1.3 */
489 #define SMB3_COMPRESS_NONE cpu_to_le16(0x0000)
490 #define SMB3_COMPRESS_LZNT1 cpu_to_le16(0x0001)
491 #define SMB3_COMPRESS_LZ77 cpu_to_le16(0x0002)
492 #define SMB3_COMPRESS_LZ77_HUFF cpu_to_le16(0x0003)
493 /* Pattern scanning algorithm See MS-SMB2 3.1.4.4.1 */
494 #define SMB3_COMPRESS_PATTERN cpu_to_le16(0x0004) /* Pattern_V1 */
496 /* Compression Flags */
497 #define SMB2_COMPRESSION_CAPABILITIES_FLAG_NONE cpu_to_le32(0x00000000)
498 #define SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED cpu_to_le32(0x00000001)
500 struct smb2_compression_capabilities_context {
501 __le16 ContextType; /* 3 */
504 __le16 CompressionAlgorithmCount;
507 __le16 CompressionAlgorithms[3];
508 __u16 Pad; /* Some servers require pad to DataLen multiple of 8 */
509 /* Check if pad needed */
513 * For smb2_netname_negotiate_context_id See MS-SMB2 2.2.3.1.4.
514 * Its struct simply contains NetName, an array of Unicode characters
516 struct smb2_netname_neg_context {
517 __le16 ContextType; /* 5 */
520 __le16 NetName[]; /* hostname of target converted to UCS-2 */
524 * For smb2_transport_capabilities context see MS-SMB2 2.2.3.1.5
529 #define SMB2_ACCEPT_TRANSPORT_LEVEL_SECURITY 0x00000001
531 struct smb2_transport_capabilities_context {
532 __le16 ContextType; /* 6 */
540 * For rdma transform capabilities context see MS-SMB2 2.2.3.1.6
544 /* RDMA Transform IDs */
545 #define SMB2_RDMA_TRANSFORM_NONE 0x0000
546 #define SMB2_RDMA_TRANSFORM_ENCRYPTION 0x0001
547 #define SMB2_RDMA_TRANSFORM_SIGNING 0x0002
549 struct smb2_rdma_transform_capabilities_context {
550 __le16 ContextType; /* 7 */
553 __le16 TransformCount;
556 __le16 RDMATransformIds[];
560 * For signing capabilities context see MS-SMB2 2.2.3.1.7
564 /* Signing algorithms */
565 #define SIGNING_ALG_HMAC_SHA256 0
566 #define SIGNING_ALG_HMAC_SHA256_LE cpu_to_le16(0)
567 #define SIGNING_ALG_AES_CMAC 1
568 #define SIGNING_ALG_AES_CMAC_LE cpu_to_le16(1)
569 #define SIGNING_ALG_AES_GMAC 2
570 #define SIGNING_ALG_AES_GMAC_LE cpu_to_le16(2)
572 struct smb2_signing_capabilities {
573 __le16 ContextType; /* 8 */
576 __le16 SigningAlgorithmCount;
577 __le16 SigningAlgorithms[];
578 /* Followed by padding to 8 byte boundary (required by some servers) */
581 #define POSIX_CTXT_DATA_LEN 16
582 struct smb2_posix_neg_context {
583 __le16 ContextType; /* 0x100 */
586 __u8 Name[16]; /* POSIX ctxt GUID 93AD25509CB411E7B42383DE968BCD7C */
589 struct smb2_negotiate_req {
591 __le16 StructureSize; /* Must be 36 */
594 __le16 Reserved; /* MBZ */
596 __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE];
597 /* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */
598 __le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */
599 __le16 NegotiateContextCount; /* SMB3.1.1 only. MBZ earlier */
604 struct smb2_negotiate_rsp {
606 __le16 StructureSize; /* Must be 65 */
608 __le16 DialectRevision;
609 __le16 NegotiateContextCount; /* Prior to SMB3.1.1 was Reserved & MBZ */
612 __le32 MaxTransactSize;
615 __le64 SystemTime; /* MBZ */
616 __le64 ServerStartTime;
617 __le16 SecurityBufferOffset;
618 __le16 SecurityBufferLength;
619 __le32 NegotiateContextOffset; /* Pre:SMB3.1.1 was reserved/ignored */
620 __u8 Buffer[]; /* variable length GSS security buffer */
625 * SMB2_SESSION_SETUP See MS-SMB2 section 2.2.5
628 #define SMB2_SESSION_REQ_FLAG_BINDING 0x01
629 #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04
631 struct smb2_sess_setup_req {
633 __le16 StructureSize; /* Must be 25 */
638 __le16 SecurityBufferOffset;
639 __le16 SecurityBufferLength;
640 __le64 PreviousSessionId;
641 __u8 Buffer[]; /* variable length GSS security buffer */
644 /* Currently defined SessionFlags */
645 #define SMB2_SESSION_FLAG_IS_GUEST 0x0001
646 #define SMB2_SESSION_FLAG_IS_GUEST_LE cpu_to_le16(0x0001)
647 #define SMB2_SESSION_FLAG_IS_NULL 0x0002
648 #define SMB2_SESSION_FLAG_IS_NULL_LE cpu_to_le16(0x0002)
649 #define SMB2_SESSION_FLAG_ENCRYPT_DATA 0x0004
650 #define SMB2_SESSION_FLAG_ENCRYPT_DATA_LE cpu_to_le16(0x0004)
652 struct smb2_sess_setup_rsp {
654 __le16 StructureSize; /* Must be 9 */
656 __le16 SecurityBufferOffset;
657 __le16 SecurityBufferLength;
658 __u8 Buffer[]; /* variable length GSS security buffer */
663 * SMB2_LOGOFF See MS-SMB2 section 2.2.7
665 struct smb2_logoff_req {
667 __le16 StructureSize; /* Must be 4 */
671 struct smb2_logoff_rsp {
673 __le16 StructureSize; /* Must be 4 */
679 * SMB2_CLOSE See MS-SMB2 section 2.2.15
681 /* Currently defined values for close flags */
682 #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
683 struct smb2_close_req {
685 __le16 StructureSize; /* Must be 24 */
688 __u64 PersistentFileId; /* opaque endianness */
689 __u64 VolatileFileId; /* opaque endianness */
693 * Maximum size of a SMB2_CLOSE response is 64 (smb2 header) + 60 (data)
695 #define MAX_SMB2_CLOSE_RESPONSE_SIZE 124
697 struct smb2_close_rsp {
699 __le16 StructureSize; /* 60 */
702 struct_group(network_open_info,
704 __le64 LastAccessTime;
705 __le64 LastWriteTime;
707 /* Beginning of FILE_STANDARD_INFO equivalent */
708 __le64 AllocationSize;
716 * SMB2_READ See MS-SMB2 section 2.2.19
718 /* For read request Flags field below, following flag is defined for SMB3.02 */
719 #define SMB2_READFLAG_READ_UNBUFFERED 0x01
720 #define SMB2_READFLAG_REQUEST_COMPRESSED 0x02 /* See MS-SMB2 2.2.19 */
722 /* Channel field for read and write: exactly one of following flags can be set*/
723 #define SMB2_CHANNEL_NONE cpu_to_le32(0x00000000)
724 #define SMB2_CHANNEL_RDMA_V1 cpu_to_le32(0x00000001)
725 #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002)
726 #define SMB2_CHANNEL_RDMA_TRANSFORM cpu_to_le32(0x00000003)
728 /* SMB2 read request without RFC1001 length at the beginning */
729 struct smb2_read_req {
731 __le16 StructureSize; /* Must be 49 */
732 __u8 Padding; /* offset from start of SMB2 header to place read */
733 __u8 Flags; /* MBZ unless SMB3.02 or later */
736 __u64 PersistentFileId;
737 __u64 VolatileFileId;
739 __le32 Channel; /* MBZ except for SMB3 or later */
740 __le32 RemainingBytes;
741 __le16 ReadChannelInfoOffset;
742 __le16 ReadChannelInfoLength;
747 #define SMB2_READFLAG_RESPONSE_NONE cpu_to_le32(0x00000000)
748 #define SMB2_READFLAG_RESPONSE_RDMA_TRANSFORM cpu_to_le32(0x00000001)
750 struct smb2_read_rsp {
752 __le16 StructureSize; /* Must be 17 */
756 __le32 DataRemaining;
763 * SMB2_WRITE See MS-SMB2 section 2.2.21
765 /* For write request Flags field below the following flags are defined: */
766 #define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 /* SMB2.1 or later */
767 #define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002 /* SMB3.02 or later */
769 struct smb2_write_req {
771 __le16 StructureSize; /* Must be 49 */
772 __le16 DataOffset; /* offset from start of SMB2 header to write data */
775 __u64 PersistentFileId; /* opaque endianness */
776 __u64 VolatileFileId; /* opaque endianness */
777 __le32 Channel; /* MBZ unless SMB3.02 or later */
778 __le32 RemainingBytes;
779 __le16 WriteChannelInfoOffset;
780 __le16 WriteChannelInfoLength;
785 struct smb2_write_rsp {
787 __le16 StructureSize; /* Must be 17 */
791 __le32 DataRemaining;
798 * SMB2_FLUSH See MS-SMB2 section 2.2.17
800 struct smb2_flush_req {
802 __le16 StructureSize; /* Must be 24 */
805 __u64 PersistentFileId;
806 __u64 VolatileFileId;
809 struct smb2_flush_rsp {
811 __le16 StructureSize;
815 #define SMB2_LOCKFLAG_SHARED 0x0001
816 #define SMB2_LOCKFLAG_EXCLUSIVE 0x0002
817 #define SMB2_LOCKFLAG_UNLOCK 0x0004
818 #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010
819 #define SMB2_LOCKFLAG_MASK 0x0007
821 struct smb2_lock_element {
828 struct smb2_lock_req {
830 __le16 StructureSize; /* Must be 48 */
833 * The least significant four bits are the index, the other 28 bits are
834 * the lock sequence number (0 to 64). See MS-SMB2 2.2.26
836 __le32 LockSequenceNumber;
837 __u64 PersistentFileId;
838 __u64 VolatileFileId;
839 /* Followed by at least one */
841 struct smb2_lock_element lock;
842 DECLARE_FLEX_ARRAY(struct smb2_lock_element, locks);
846 struct smb2_lock_rsp {
848 __le16 StructureSize; /* Must be 4 */
852 struct smb2_echo_req {
854 __le16 StructureSize; /* Must be 4 */
858 struct smb2_echo_rsp {
860 __le16 StructureSize; /* Must be 4 */
865 * Valid FileInformation classes for query directory
867 * Note that these are a subset of the (file) QUERY_INFO levels defined
868 * later in this file (but since QUERY_DIRECTORY uses equivalent numbers
869 * we do not redefine them here)
871 * FileDirectoryInfomation 0x01
872 * FileFullDirectoryInformation 0x02
873 * FileIdFullDirectoryInformation 0x26
874 * FileBothDirectoryInformation 0x03
875 * FileIdBothDirectoryInformation 0x25
876 * FileNamesInformation 0x0C
877 * FileIdExtdDirectoryInformation 0x3C
880 /* search (query_directory) Flags field */
881 #define SMB2_RESTART_SCANS 0x01
882 #define SMB2_RETURN_SINGLE_ENTRY 0x02
883 #define SMB2_INDEX_SPECIFIED 0x04
884 #define SMB2_REOPEN 0x10
886 struct smb2_query_directory_req {
888 __le16 StructureSize; /* Must be 33 */
889 __u8 FileInformationClass;
892 __u64 PersistentFileId;
893 __u64 VolatileFileId;
894 __le16 FileNameOffset;
895 __le16 FileNameLength;
896 __le32 OutputBufferLength;
900 struct smb2_query_directory_rsp {
902 __le16 StructureSize; /* Must be 9 */
903 __le16 OutputBufferOffset;
904 __le32 OutputBufferLength;
909 * Maximum number of iovs we need for a set-info request.
910 * The largest one is rename/hardlink
911 * [0] : struct smb2_set_info_req + smb2_file_[rename|link]_info
913 * [2] : compound padding
915 #define SMB2_SET_INFO_IOV_SIZE 3
917 struct smb2_set_info_req {
919 __le16 StructureSize; /* Must be 33 */
925 __le32 AdditionalInformation;
926 __u64 PersistentFileId;
927 __u64 VolatileFileId;
931 struct smb2_set_info_rsp {
933 __le16 StructureSize; /* Must be 2 */
937 * SMB2_NOTIFY See MS-SMB2 section 2.2.35
940 #define SMB2_WATCH_TREE 0x0001
942 /* notify completion filter flags. See MS-FSCC 2.6 and MS-SMB2 2.2.35 */
943 #define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001
944 #define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002
945 #define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004
946 #define FILE_NOTIFY_CHANGE_SIZE 0x00000008
947 #define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010
948 #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020
949 #define FILE_NOTIFY_CHANGE_CREATION 0x00000040
950 #define FILE_NOTIFY_CHANGE_EA 0x00000080
951 #define FILE_NOTIFY_CHANGE_SECURITY 0x00000100
952 #define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200
953 #define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400
954 #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
956 /* SMB2 Notify Action Flags */
957 #define FILE_ACTION_ADDED 0x00000001
958 #define FILE_ACTION_REMOVED 0x00000002
959 #define FILE_ACTION_MODIFIED 0x00000003
960 #define FILE_ACTION_RENAMED_OLD_NAME 0x00000004
961 #define FILE_ACTION_RENAMED_NEW_NAME 0x00000005
962 #define FILE_ACTION_ADDED_STREAM 0x00000006
963 #define FILE_ACTION_REMOVED_STREAM 0x00000007
964 #define FILE_ACTION_MODIFIED_STREAM 0x00000008
965 #define FILE_ACTION_REMOVED_BY_DELETE 0x00000009
967 struct smb2_change_notify_req {
969 __le16 StructureSize;
971 __le32 OutputBufferLength;
972 __u64 PersistentFileId; /* opaque endianness */
973 __u64 VolatileFileId; /* opaque endianness */
974 __le32 CompletionFilter;
978 struct smb2_change_notify_rsp {
980 __le16 StructureSize; /* Must be 9 */
981 __le16 OutputBufferOffset;
982 __le32 OutputBufferLength;
983 __u8 Buffer[]; /* array of file notify structs */
988 * SMB2_CREATE See MS-SMB2 section 2.2.13
991 #define SMB2_OPLOCK_LEVEL_NONE 0x00
992 #define SMB2_OPLOCK_LEVEL_II 0x01
993 #define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
994 #define SMB2_OPLOCK_LEVEL_BATCH 0x09
995 #define SMB2_OPLOCK_LEVEL_LEASE 0xFF
996 /* Non-spec internal type */
997 #define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99
999 /* Impersonation Levels. See MS-WPO section 9.7 and MSDN-IMPERS */
1000 #define IL_ANONYMOUS cpu_to_le32(0x00000000)
1001 #define IL_IDENTIFICATION cpu_to_le32(0x00000001)
1002 #define IL_IMPERSONATION cpu_to_le32(0x00000002)
1003 #define IL_DELEGATE cpu_to_le32(0x00000003)
1005 /* File Attrubutes */
1006 #define FILE_ATTRIBUTE_READONLY 0x00000001
1007 #define FILE_ATTRIBUTE_HIDDEN 0x00000002
1008 #define FILE_ATTRIBUTE_SYSTEM 0x00000004
1009 #define FILE_ATTRIBUTE_DIRECTORY 0x00000010
1010 #define FILE_ATTRIBUTE_ARCHIVE 0x00000020
1011 #define FILE_ATTRIBUTE_NORMAL 0x00000080
1012 #define FILE_ATTRIBUTE_TEMPORARY 0x00000100
1013 #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
1014 #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
1015 #define FILE_ATTRIBUTE_COMPRESSED 0x00000800
1016 #define FILE_ATTRIBUTE_OFFLINE 0x00001000
1017 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
1018 #define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
1019 #define FILE_ATTRIBUTE_INTEGRITY_STREAM 0x00008000
1020 #define FILE_ATTRIBUTE_NO_SCRUB_DATA 0x00020000
1021 #define FILE_ATTRIBUTE__MASK 0x00007FB7
1023 #define FILE_ATTRIBUTE_READONLY_LE cpu_to_le32(0x00000001)
1024 #define FILE_ATTRIBUTE_HIDDEN_LE cpu_to_le32(0x00000002)
1025 #define FILE_ATTRIBUTE_SYSTEM_LE cpu_to_le32(0x00000004)
1026 #define FILE_ATTRIBUTE_DIRECTORY_LE cpu_to_le32(0x00000010)
1027 #define FILE_ATTRIBUTE_ARCHIVE_LE cpu_to_le32(0x00000020)
1028 #define FILE_ATTRIBUTE_NORMAL_LE cpu_to_le32(0x00000080)
1029 #define FILE_ATTRIBUTE_TEMPORARY_LE cpu_to_le32(0x00000100)
1030 #define FILE_ATTRIBUTE_SPARSE_FILE_LE cpu_to_le32(0x00000200)
1031 #define FILE_ATTRIBUTE_REPARSE_POINT_LE cpu_to_le32(0x00000400)
1032 #define FILE_ATTRIBUTE_COMPRESSED_LE cpu_to_le32(0x00000800)
1033 #define FILE_ATTRIBUTE_OFFLINE_LE cpu_to_le32(0x00001000)
1034 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED_LE cpu_to_le32(0x00002000)
1035 #define FILE_ATTRIBUTE_ENCRYPTED_LE cpu_to_le32(0x00004000)
1036 #define FILE_ATTRIBUTE_INTEGRITY_STREAM_LE cpu_to_le32(0x00008000)
1037 #define FILE_ATTRIBUTE_NO_SCRUB_DATA_LE cpu_to_le32(0x00020000)
1038 #define FILE_ATTRIBUTE_MASK_LE cpu_to_le32(0x00007FB7)
1040 /* Desired Access Flags */
1041 #define FILE_READ_DATA_LE cpu_to_le32(0x00000001)
1042 #define FILE_LIST_DIRECTORY_LE cpu_to_le32(0x00000001)
1043 #define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002)
1044 #define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004)
1045 #define FILE_ADD_SUBDIRECTORY_LE cpu_to_le32(0x00000004)
1046 #define FILE_READ_EA_LE cpu_to_le32(0x00000008)
1047 #define FILE_WRITE_EA_LE cpu_to_le32(0x00000010)
1048 #define FILE_EXECUTE_LE cpu_to_le32(0x00000020)
1049 #define FILE_DELETE_CHILD_LE cpu_to_le32(0x00000040)
1050 #define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080)
1051 #define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100)
1052 #define FILE_DELETE_LE cpu_to_le32(0x00010000)
1053 #define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000)
1054 #define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000)
1055 #define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000)
1056 #define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000)
1057 #define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000)
1058 #define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000)
1059 #define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000)
1060 #define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000)
1061 #define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000)
1062 #define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000)
1063 #define DESIRED_ACCESS_MASK cpu_to_le32(0xF21F01FF)
1066 #define FILE_READ_DESIRED_ACCESS_LE (FILE_READ_DATA_LE | \
1068 FILE_GENERIC_READ_LE)
1069 #define FILE_WRITE_DESIRE_ACCESS_LE (FILE_WRITE_DATA_LE | \
1070 FILE_APPEND_DATA_LE | \
1071 FILE_WRITE_EA_LE | \
1072 FILE_WRITE_ATTRIBUTES_LE | \
1073 FILE_GENERIC_WRITE_LE)
1075 /* ShareAccess Flags */
1076 #define FILE_SHARE_READ_LE cpu_to_le32(0x00000001)
1077 #define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002)
1078 #define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004)
1079 #define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007)
1081 /* CreateDisposition Flags */
1082 #define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000)
1083 #define FILE_OPEN_LE cpu_to_le32(0x00000001)
1084 #define FILE_CREATE_LE cpu_to_le32(0x00000002)
1085 #define FILE_OPEN_IF_LE cpu_to_le32(0x00000003)
1086 #define FILE_OVERWRITE_LE cpu_to_le32(0x00000004)
1087 #define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005)
1088 #define FILE_CREATE_MASK_LE cpu_to_le32(0x00000007)
1090 #define FILE_READ_RIGHTS (FILE_READ_DATA | FILE_READ_EA \
1091 | FILE_READ_ATTRIBUTES)
1092 #define FILE_WRITE_RIGHTS (FILE_WRITE_DATA | FILE_APPEND_DATA \
1093 | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES)
1094 #define FILE_EXEC_RIGHTS (FILE_EXECUTE)
1096 /* CreateOptions Flags */
1097 #define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001)
1098 /* same as #define CREATE_NOT_FILE_LE cpu_to_le32(0x00000001) */
1099 #define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002)
1100 #define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004)
1101 #define FILE_NO_INTERMEDIATE_BUFFERING_LE cpu_to_le32(0x00000008)
1102 #define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040)
1103 #define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100)
1104 #define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200)
1105 #define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800)
1106 #define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000)
1107 #define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000)
1108 #define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000)
1109 #define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000)
1110 #define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000)
1111 #define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000)
1112 #define CREATE_OPTIONS_MASK_LE cpu_to_le32(0x00FFFFFF)
1114 #define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \
1115 | FILE_READ_ATTRIBUTES_LE)
1116 #define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \
1117 | FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
1118 #define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
1120 /* Create Context Values */
1121 #define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */
1122 #define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */
1123 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ"
1124 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC"
1125 #define SMB2_CREATE_ALLOCATION_SIZE "AlSi"
1126 #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
1127 #define SMB2_CREATE_TIMEWARP_REQUEST "TWrp"
1128 #define SMB2_CREATE_QUERY_ON_DISK_ID "QFid"
1129 #define SMB2_CREATE_REQUEST_LEASE "RqLs"
1130 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 "DH2Q"
1131 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 "DH2C"
1132 #define SMB2_CREATE_TAG_POSIX "\x93\xAD\x25\x50\x9C\xB4\x11\xE7\xB4\x23\x83\xDE\x96\x8B\xCD\x7C"
1133 #define SMB2_CREATE_APP_INSTANCE_ID "\x45\xBC\xA6\x6A\xEF\xA7\xF7\x4A\x90\x08\xFA\x46\x2E\x14\x4D\x74"
1134 #define SMB2_CREATE_APP_INSTANCE_VERSION "\xB9\x82\xD0\xB7\x3B\x56\x07\x4F\xA0\x7B\x52\x4A\x81\x16\xA0\x10"
1135 #define SVHDX_OPEN_DEVICE_CONTEXT "\x9C\xCB\xCF\x9E\x04\xC1\xE6\x43\x98\x0E\x15\x8D\xA1\xF6\xEC\x83"
1136 #define SMB2_CREATE_TAG_AAPL "AAPL"
1138 /* Flag (SMB3 open response) values */
1139 #define SMB2_CREATE_FLAG_REPARSEPOINT 0x01
1141 struct create_context {
1151 struct smb2_create_req {
1152 struct smb2_hdr hdr;
1153 __le16 StructureSize; /* Must be 57 */
1155 __u8 RequestedOplockLevel;
1156 __le32 ImpersonationLevel;
1157 __le64 SmbCreateFlags;
1159 __le32 DesiredAccess;
1160 __le32 FileAttributes;
1162 __le32 CreateDisposition;
1163 __le32 CreateOptions;
1166 __le32 CreateContextsOffset;
1167 __le32 CreateContextsLength;
1171 struct smb2_create_rsp {
1172 struct smb2_hdr hdr;
1173 __le16 StructureSize; /* Must be 89 */
1175 __u8 Flags; /* 0x01 if reparse point */
1176 __le32 CreateAction;
1177 __le64 CreationTime;
1178 __le64 LastAccessTime;
1179 __le64 LastWriteTime;
1181 __le64 AllocationSize;
1183 __le32 FileAttributes;
1185 __u64 PersistentFileId;
1186 __u64 VolatileFileId;
1187 __le32 CreateContextsOffset;
1188 __le32 CreateContextsLength;
1192 struct create_posix {
1193 struct create_context ccontext;
1199 #define SMB2_LEASE_NONE_LE cpu_to_le32(0x00)
1200 #define SMB2_LEASE_READ_CACHING_LE cpu_to_le32(0x01)
1201 #define SMB2_LEASE_HANDLE_CACHING_LE cpu_to_le32(0x02)
1202 #define SMB2_LEASE_WRITE_CACHING_LE cpu_to_le32(0x04)
1204 #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE cpu_to_le32(0x02)
1205 #define SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET_LE cpu_to_le32(0x04)
1207 #define SMB2_LEASE_KEY_SIZE 16
1209 struct lease_context {
1210 __u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
1213 __le64 LeaseDuration;
1216 struct lease_context_v2 {
1217 __u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
1220 __le64 LeaseDuration;
1221 __u8 ParentLeaseKey[SMB2_LEASE_KEY_SIZE];
1226 struct create_lease {
1227 struct create_context ccontext;
1229 struct lease_context lcontext;
1232 struct create_lease_v2 {
1233 struct create_context ccontext;
1235 struct lease_context_v2 lcontext;
1239 /* See MS-SMB2 2.2.31 and 2.2.32 */
1240 struct smb2_ioctl_req {
1241 struct smb2_hdr hdr;
1242 __le16 StructureSize; /* Must be 57 */
1243 __le16 Reserved; /* offset from start of SMB2 header to write data */
1245 __u64 PersistentFileId;
1246 __u64 VolatileFileId;
1247 __le32 InputOffset; /* Reserved MBZ */
1249 __le32 MaxInputResponse;
1250 __le32 OutputOffset;
1252 __le32 MaxOutputResponse;
1258 struct smb2_ioctl_rsp {
1259 struct smb2_hdr hdr;
1260 __le16 StructureSize; /* Must be 49 */
1263 __u64 PersistentFileId;
1264 __u64 VolatileFileId;
1265 __le32 InputOffset; /* Reserved MBZ */
1267 __le32 OutputOffset;
1274 /* this goes in the ioctl buffer when doing FSCTL_SET_ZERO_DATA */
1275 struct file_zero_data_information {
1277 __le64 BeyondFinalZero;
1280 /* See MS-FSCC 2.3.7 */
1281 struct duplicate_extents_to_file {
1282 __u64 PersistentFileHandle; /* source file handle, opaque endianness */
1283 __u64 VolatileFileHandle;
1284 __le64 SourceFileOffset;
1285 __le64 TargetFileOffset;
1286 __le64 ByteCount; /* Bytes to be copied */
1289 /* See MS-FSCC 2.3.8 */
1290 #define DUPLICATE_EXTENTS_DATA_EX_SOURCE_ATOMIC 0x00000001
1291 struct duplicate_extents_to_file_ex {
1292 __u64 PersistentFileHandle; /* source file handle, opaque endianness */
1293 __u64 VolatileFileHandle;
1294 __le64 SourceFileOffset;
1295 __le64 TargetFileOffset;
1296 __le64 ByteCount; /* Bytes to be copied */
1302 /* See MS-FSCC 2.3.20 */
1303 struct fsctl_get_integrity_information_rsp {
1304 __le16 ChecksumAlgorithm;
1307 __le32 ChecksumChunkSizeInBytes;
1308 __le32 ClusterSizeInBytes;
1311 /* See MS-FSCC 2.3.55 */
1312 struct fsctl_query_file_regions_req {
1315 __le32 DesiredUsage;
1319 /* DesiredUsage flags see MS-FSCC 2.3.56.1 */
1320 #define FILE_USAGE_INVALID_RANGE 0x00000000
1321 #define FILE_USAGE_VALID_CACHED_DATA 0x00000001
1322 #define FILE_USAGE_NONCACHED_DATA 0x00000002
1324 struct file_region_info {
1327 __le32 DesiredUsage;
1331 /* See MS-FSCC 2.3.56 */
1332 struct fsctl_query_file_region_rsp {
1334 __le32 TotalRegionEntryCount;
1335 __le32 RegionEntryCount;
1337 struct file_region_info Regions[];
1340 /* See MS-FSCC 2.3.58 */
1341 struct fsctl_query_on_disk_vol_info_rsp {
1342 __le64 DirectoryCount;
1344 __le16 FsFormatMajVersion;
1345 __le16 FsFormatMinVersion;
1346 __u8 FsFormatName[24];
1348 __le64 LastUpdateTime;
1349 __u8 CopyrightInfo[68];
1350 __u8 AbstractInfo[68];
1351 __u8 FormatImplInfo[68];
1352 __u8 LastModifyImplInfo[68];
1355 /* See MS-FSCC 2.3.73 */
1356 struct fsctl_set_integrity_information_req {
1357 __le16 ChecksumAlgorithm;
1362 /* See MS-FSCC 2.3.75 */
1363 struct fsctl_set_integrity_info_ex_req {
1364 __u8 EnableIntegrity;
1372 /* Integrity ChecksumAlgorithm choices for above */
1373 #define CHECKSUM_TYPE_NONE 0x0000
1374 #define CHECKSUM_TYPE_CRC64 0x0002
1375 #define CHECKSUM_TYPE_UNCHANGED 0xFFFF /* set only */
1377 /* Integrity flags for above */
1378 #define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF 0x00000001
1380 /* Reparse structures - see MS-FSCC 2.1.2 */
1382 /* struct fsctl_reparse_info_req is empty, only response structs (see below) */
1383 struct reparse_data_buffer {
1385 __le16 ReparseDataLength;
1387 __u8 DataBuffer[]; /* Variable Length */
1390 struct reparse_guid_data_buffer {
1392 __le16 ReparseDataLength;
1394 __u8 ReparseGuid[16];
1395 __u8 DataBuffer[]; /* Variable Length */
1398 struct reparse_mount_point_data_buffer {
1400 __le16 ReparseDataLength;
1402 __le16 SubstituteNameOffset;
1403 __le16 SubstituteNameLength;
1404 __le16 PrintNameOffset;
1405 __le16 PrintNameLength;
1406 __u8 PathBuffer[]; /* Variable Length */
1409 #define SYMLINK_FLAG_RELATIVE 0x00000001
1411 struct reparse_symlink_data_buffer {
1413 __le16 ReparseDataLength;
1415 __le16 SubstituteNameOffset;
1416 __le16 SubstituteNameLength;
1417 __le16 PrintNameOffset;
1418 __le16 PrintNameLength;
1420 __u8 PathBuffer[]; /* Variable Length */
1423 /* See MS-FSCC 2.1.2.6 and cifspdu.h for struct reparse_posix_data */
1425 struct validate_negotiate_info_req {
1426 __le32 Capabilities;
1427 __u8 Guid[SMB2_CLIENT_GUID_SIZE];
1428 __le16 SecurityMode;
1429 __le16 DialectCount;
1430 __le16 Dialects[4]; /* BB expand this if autonegotiate > 4 dialects */
1433 struct validate_negotiate_info_rsp {
1434 __le32 Capabilities;
1435 __u8 Guid[SMB2_CLIENT_GUID_SIZE];
1436 __le16 SecurityMode;
1437 __le16 Dialect; /* Dialect in use for the connection */
1441 /* Possible InfoType values */
1442 #define SMB2_O_INFO_FILE 0x01
1443 #define SMB2_O_INFO_FILESYSTEM 0x02
1444 #define SMB2_O_INFO_SECURITY 0x03
1445 #define SMB2_O_INFO_QUOTA 0x04
1447 /* SMB2 Query Info see MS-SMB2 (2.2.37) or MS-DTYP */
1449 /* List of QUERY INFO levels (those also valid for QUERY_DIR are noted below */
1450 #define FILE_DIRECTORY_INFORMATION 1 /* also for QUERY_DIR */
1451 #define FILE_FULL_DIRECTORY_INFORMATION 2 /* also for QUERY_DIR */
1452 #define FILE_BOTH_DIRECTORY_INFORMATION 3 /* also for QUERY_DIR */
1453 #define FILE_BASIC_INFORMATION 4
1454 #define FILE_STANDARD_INFORMATION 5
1455 #define FILE_INTERNAL_INFORMATION 6
1456 #define FILE_EA_INFORMATION 7
1457 #define FILE_ACCESS_INFORMATION 8
1458 #define FILE_NAME_INFORMATION 9
1459 #define FILE_RENAME_INFORMATION 10
1460 #define FILE_LINK_INFORMATION 11
1461 #define FILE_NAMES_INFORMATION 12 /* also for QUERY_DIR */
1462 #define FILE_DISPOSITION_INFORMATION 13
1463 #define FILE_POSITION_INFORMATION 14
1464 #define FILE_FULL_EA_INFORMATION 15
1465 #define FILE_MODE_INFORMATION 16
1466 #define FILE_ALIGNMENT_INFORMATION 17
1467 #define FILE_ALL_INFORMATION 18
1468 #define FILE_ALLOCATION_INFORMATION 19
1469 #define FILE_END_OF_FILE_INFORMATION 20
1470 #define FILE_ALTERNATE_NAME_INFORMATION 21
1471 #define FILE_STREAM_INFORMATION 22
1472 #define FILE_PIPE_INFORMATION 23
1473 #define FILE_PIPE_LOCAL_INFORMATION 24
1474 #define FILE_PIPE_REMOTE_INFORMATION 25
1475 #define FILE_MAILSLOT_QUERY_INFORMATION 26
1476 #define FILE_MAILSLOT_SET_INFORMATION 27
1477 #define FILE_COMPRESSION_INFORMATION 28
1478 #define FILE_OBJECT_ID_INFORMATION 29
1479 /* Number 30 not defined in documents */
1480 #define FILE_MOVE_CLUSTER_INFORMATION 31
1481 #define FILE_QUOTA_INFORMATION 32
1482 #define FILE_REPARSE_POINT_INFORMATION 33
1483 #define FILE_NETWORK_OPEN_INFORMATION 34
1484 #define FILE_ATTRIBUTE_TAG_INFORMATION 35
1485 #define FILE_TRACKING_INFORMATION 36
1486 #define FILEID_BOTH_DIRECTORY_INFORMATION 37 /* also for QUERY_DIR */
1487 #define FILEID_FULL_DIRECTORY_INFORMATION 38 /* also for QUERY_DIR */
1488 #define FILE_VALID_DATA_LENGTH_INFORMATION 39
1489 #define FILE_SHORT_NAME_INFORMATION 40
1490 #define FILE_SFIO_RESERVE_INFORMATION 44
1491 #define FILE_SFIO_VOLUME_INFORMATION 45
1492 #define FILE_HARD_LINK_INFORMATION 46
1493 #define FILE_NORMALIZED_NAME_INFORMATION 48
1494 #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
1495 #define FILE_STANDARD_LINK_INFORMATION 54
1496 #define FILE_ID_INFORMATION 59
1497 #define FILE_ID_EXTD_DIRECTORY_INFORMATION 60 /* also for QUERY_DIR */
1498 /* Used for Query Info and Find File POSIX Info for SMB3.1.1 and SMB1 */
1499 #define SMB_FIND_FILE_POSIX_INFO 0x064
1501 /* Security info type additionalinfo flags. */
1502 #define OWNER_SECINFO 0x00000001
1503 #define GROUP_SECINFO 0x00000002
1504 #define DACL_SECINFO 0x00000004
1505 #define SACL_SECINFO 0x00000008
1506 #define LABEL_SECINFO 0x00000010
1507 #define ATTRIBUTE_SECINFO 0x00000020
1508 #define SCOPE_SECINFO 0x00000040
1509 #define BACKUP_SECINFO 0x00010000
1510 #define UNPROTECTED_SACL_SECINFO 0x10000000
1511 #define UNPROTECTED_DACL_SECINFO 0x20000000
1512 #define PROTECTED_SACL_SECINFO 0x40000000
1513 #define PROTECTED_DACL_SECINFO 0x80000000
1515 /* Flags used for FileFullEAinfo */
1516 #define SL_RESTART_SCAN 0x00000001
1517 #define SL_RETURN_SINGLE_ENTRY 0x00000002
1518 #define SL_INDEX_SPECIFIED 0x00000004
1520 struct smb2_query_info_req {
1521 struct smb2_hdr hdr;
1522 __le16 StructureSize; /* Must be 41 */
1525 __le32 OutputBufferLength;
1526 __le16 InputBufferOffset;
1528 __le32 InputBufferLength;
1529 __le32 AdditionalInformation;
1531 __u64 PersistentFileId;
1532 __u64 VolatileFileId;
1536 struct smb2_query_info_rsp {
1537 struct smb2_hdr hdr;
1538 __le16 StructureSize; /* Must be 9 */
1539 __le16 OutputBufferOffset;
1540 __le32 OutputBufferLength;
1545 * PDU query infolevel structure definitions
1548 /* See MS-FSCC 2.3.52 */
1549 struct file_allocated_range_buffer {
1554 struct smb2_file_internal_info {
1556 } __packed; /* level 6 Query */
1558 struct smb2_file_rename_info { /* encoding of request for level 10 */
1559 __u8 ReplaceIfExists; /* 1 = replace existing target with new */
1560 /* 0 = fail if target already exists */
1562 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1563 __le32 FileNameLength;
1564 char FileName[]; /* New name to be assigned */
1565 /* padding - overall struct size must be >= 24 so filename + pad >= 6 */
1566 } __packed; /* level 10 Set */
1568 struct smb2_file_link_info { /* encoding of request for level 11 */
1569 __u8 ReplaceIfExists; /* 1 = replace existing link with new */
1570 /* 0 = fail if link already exists */
1572 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1573 __le32 FileNameLength;
1574 char FileName[]; /* Name to be assigned to new link */
1575 } __packed; /* level 11 Set */
1578 * This level 18, although with struct with same name is different from cifs
1579 * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
1580 * CurrentByteOffset.
1582 struct smb2_file_all_info { /* data block encoding of response to level 18 */
1583 __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
1584 __le64 LastAccessTime;
1585 __le64 LastWriteTime;
1588 __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
1589 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
1590 __le64 EndOfFile; /* size ie offset to first free byte in file */
1591 __le32 NumberOfLinks; /* hard links */
1594 __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */
1598 __le64 CurrentByteOffset;
1600 __le32 AlignmentRequirement;
1601 __le32 FileNameLength;
1603 char __pad; /* Legacy structure padding */
1604 DECLARE_FLEX_ARRAY(char, FileName);
1606 } __packed; /* level 18 Query */
1608 struct smb2_file_eof_info { /* encoding of request for level 10 */
1609 __le64 EndOfFile; /* new end of file value */
1610 } __packed; /* level 20 Set */
1612 /* Level 100 query info */
1613 struct smb311_posix_qinfo {
1614 __le64 CreationTime;
1615 __le64 LastAccessTime;
1616 __le64 LastWriteTime;
1619 __le64 AllocationSize;
1620 __le32 DosAttributes;
1624 /* beginning of POSIX Create Context Response */
1630 * var sized owner SID
1631 * var sized group SID
1632 * le32 filenamelength
1637 /* File System Information Classes */
1638 #define FS_VOLUME_INFORMATION 1 /* Query */
1639 #define FS_LABEL_INFORMATION 2 /* Set */
1640 #define FS_SIZE_INFORMATION 3 /* Query */
1641 #define FS_DEVICE_INFORMATION 4 /* Query */
1642 #define FS_ATTRIBUTE_INFORMATION 5 /* Query */
1643 #define FS_CONTROL_INFORMATION 6 /* Query, Set */
1644 #define FS_FULL_SIZE_INFORMATION 7 /* Query */
1645 #define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */
1646 #define FS_DRIVER_PATH_INFORMATION 9 /* Query */
1647 #define FS_SECTOR_SIZE_INFORMATION 11 /* SMB3 or later. Query */
1648 #define FS_POSIX_INFORMATION 100 /* SMB3.1.1 POSIX. Query */
1650 struct smb2_fs_full_size_info {
1651 __le64 TotalAllocationUnits;
1652 __le64 CallerAvailableAllocationUnits;
1653 __le64 ActualAvailableAllocationUnits;
1654 __le32 SectorsPerAllocationUnit;
1655 __le32 BytesPerSector;
1658 #define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001
1659 #define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
1660 #define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004
1661 #define SSINFO_FLAGS_TRIM_ENABLED 0x00000008
1663 /* sector size info struct */
1664 struct smb3_fs_ss_info {
1665 __le32 LogicalBytesPerSector;
1666 __le32 PhysicalBytesPerSectorForAtomicity;
1667 __le32 PhysicalBytesPerSectorForPerf;
1668 __le32 FSEffPhysicalBytesPerSectorForAtomicity;
1670 __le32 ByteOffsetForSectorAlignment;
1671 __le32 ByteOffsetForPartitionAlignment;
1674 /* File System Control Information */
1675 struct smb2_fs_control_info {
1676 __le64 FreeSpaceStartFiltering;
1677 __le64 FreeSpaceThreshold;
1678 __le64 FreeSpaceStopFiltering;
1679 __le64 DefaultQuotaThreshold;
1680 __le64 DefaultQuotaLimit;
1681 __le32 FileSystemControlFlags;
1685 /* volume info struct - see MS-FSCC 2.5.9 */
1686 #define MAX_VOL_LABEL_LEN 32
1687 struct smb3_fs_vol_info {
1688 __le64 VolumeCreationTime;
1689 __u32 VolumeSerialNumber;
1690 __le32 VolumeLabelLength; /* includes trailing null */
1691 __u8 SupportsObjects; /* True if eg like NTFS, supports objects */
1693 __u8 VolumeLabel[]; /* variable len */
1696 /* See MS-SMB2 2.2.23 through 2.2.25 */
1697 struct smb2_oplock_break {
1698 struct smb2_hdr hdr;
1699 __le16 StructureSize; /* Must be 24 */
1703 __u64 PersistentFid;
1707 #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
1709 struct smb2_lease_break {
1710 struct smb2_hdr hdr;
1711 __le16 StructureSize; /* Must be 44 */
1715 __le32 CurrentLeaseState;
1716 __le32 NewLeaseState;
1718 __le32 AccessMaskHint;
1719 __le32 ShareMaskHint;
1722 struct smb2_lease_ack {
1723 struct smb2_hdr hdr;
1724 __le16 StructureSize; /* Must be 36 */
1729 __le64 LeaseDuration;
1732 #define OP_BREAK_STRUCT_SIZE_20 24
1733 #define OP_BREAK_STRUCT_SIZE_21 36
1734 #endif /* _COMMON_SMB2PDU_H */