1 /* SPDX-License-Identifier: GPL-2.0-or-later */
4 * Copyright (C) 2018 Samsung Electronics Co., Ltd.
14 * Note that, due to trying to use names similar to the protocol specifications,
15 * there are many mixed case field names in the structures below. Although
16 * this does not match typical Linux kernel style, it is necessary to be
17 * able to match against the protocol specfication.
20 * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses
21 * (ie no useful data other than the SMB error code itself) and are marked such.
22 * Knowing this helps avoid response buffer allocations and copy in some cases.
25 /* List of commands in host endian */
26 #define SMB2_NEGOTIATE_HE 0x0000
27 #define SMB2_SESSION_SETUP_HE 0x0001
28 #define SMB2_LOGOFF_HE 0x0002 /* trivial request/resp */
29 #define SMB2_TREE_CONNECT_HE 0x0003
30 #define SMB2_TREE_DISCONNECT_HE 0x0004 /* trivial req/resp */
31 #define SMB2_CREATE_HE 0x0005
32 #define SMB2_CLOSE_HE 0x0006
33 #define SMB2_FLUSH_HE 0x0007 /* trivial resp */
34 #define SMB2_READ_HE 0x0008
35 #define SMB2_WRITE_HE 0x0009
36 #define SMB2_LOCK_HE 0x000A
37 #define SMB2_IOCTL_HE 0x000B
38 #define SMB2_CANCEL_HE 0x000C
39 #define SMB2_ECHO_HE 0x000D
40 #define SMB2_QUERY_DIRECTORY_HE 0x000E
41 #define SMB2_CHANGE_NOTIFY_HE 0x000F
42 #define SMB2_QUERY_INFO_HE 0x0010
43 #define SMB2_SET_INFO_HE 0x0011
44 #define SMB2_OPLOCK_BREAK_HE 0x0012
46 /* The same list in little endian */
47 #define SMB2_NEGOTIATE cpu_to_le16(SMB2_NEGOTIATE_HE)
48 #define SMB2_SESSION_SETUP cpu_to_le16(SMB2_SESSION_SETUP_HE)
49 #define SMB2_LOGOFF cpu_to_le16(SMB2_LOGOFF_HE)
50 #define SMB2_TREE_CONNECT cpu_to_le16(SMB2_TREE_CONNECT_HE)
51 #define SMB2_TREE_DISCONNECT cpu_to_le16(SMB2_TREE_DISCONNECT_HE)
52 #define SMB2_CREATE cpu_to_le16(SMB2_CREATE_HE)
53 #define SMB2_CLOSE cpu_to_le16(SMB2_CLOSE_HE)
54 #define SMB2_FLUSH cpu_to_le16(SMB2_FLUSH_HE)
55 #define SMB2_READ cpu_to_le16(SMB2_READ_HE)
56 #define SMB2_WRITE cpu_to_le16(SMB2_WRITE_HE)
57 #define SMB2_LOCK cpu_to_le16(SMB2_LOCK_HE)
58 #define SMB2_IOCTL cpu_to_le16(SMB2_IOCTL_HE)
59 #define SMB2_CANCEL cpu_to_le16(SMB2_CANCEL_HE)
60 #define SMB2_ECHO cpu_to_le16(SMB2_ECHO_HE)
61 #define SMB2_QUERY_DIRECTORY cpu_to_le16(SMB2_QUERY_DIRECTORY_HE)
62 #define SMB2_CHANGE_NOTIFY cpu_to_le16(SMB2_CHANGE_NOTIFY_HE)
63 #define SMB2_QUERY_INFO cpu_to_le16(SMB2_QUERY_INFO_HE)
64 #define SMB2_SET_INFO cpu_to_le16(SMB2_SET_INFO_HE)
65 #define SMB2_OPLOCK_BREAK cpu_to_le16(SMB2_OPLOCK_BREAK_HE)
67 /*Create Action Flags*/
68 #define FILE_SUPERSEDED 0x00000000
69 #define FILE_OPENED 0x00000001
70 #define FILE_CREATED 0x00000002
71 #define FILE_OVERWRITTEN 0x00000003
74 * Size of the session key (crypto key encrypted with the password
76 #define SMB2_NTLMV2_SESSKEY_SIZE 16
77 #define SMB2_SIGNATURE_SIZE 16
78 #define SMB2_HMACSHA256_SIZE 32
79 #define SMB2_CMACAES_SIZE 16
80 #define SMB3_GCM128_CRYPTKEY_SIZE 16
81 #define SMB3_GCM256_CRYPTKEY_SIZE 32
84 * Size of the smb3 encryption/decryption keys
86 #define SMB3_ENC_DEC_KEY_SIZE 32
89 * Size of the smb3 signing key
91 #define SMB3_SIGN_KEY_SIZE 16
93 #define CIFS_CLIENT_CHALLENGE_SIZE 8
94 #define SMB_SERVER_CHALLENGE_SIZE 8
96 /* SMB2 Max Credits */
97 #define SMB2_MAX_CREDITS 8192
99 #define SMB2_CLIENT_GUID_SIZE 16
100 #define SMB2_CREATE_GUID_SIZE 16
102 /* Maximum buffer size value we can send with 1 credit */
103 #define SMB2_MAX_BUFFER_SIZE 65536
105 #define NUMBER_OF_SMB2_COMMANDS 0x0013
107 /* BB FIXME - analyze following length BB */
108 #define MAX_SMB2_HDR_SIZE 0x78 /* 4 len + 64 hdr + (2*24 wct) + 2 bct + 2 pad */
110 #define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe) /* 'B''M''S' */
111 #define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
113 #define SMB21_DEFAULT_IOSIZE (1024 * 1024)
114 #define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024)
115 #define SMB3_DEFAULT_TRANS_SIZE (1024 * 1024)
116 #define SMB3_MIN_IOSIZE (64 * 1024)
117 #define SMB3_MAX_IOSIZE (8 * 1024 * 1024)
120 * SMB2 Header Definition
122 * "MBZ" : Must be Zero
123 * "BB" : BugBug, Something to check/review/analyze later
124 * "PDU" : "Protocol Data Unit" (ie a network "frame")
128 #define __SMB2_HEADER_STRUCTURE_SIZE 64
129 #define SMB2_HEADER_STRUCTURE_SIZE \
130 cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE)
133 __be32 smb2_buf_length; /* big endian on wire */
135 * length is only two or three bytes - with
136 * one or two byte type preceding it that MBZ
138 __le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */
139 __le16 StructureSize; /* 64 */
140 __le16 CreditCharge; /* MBZ */
141 __le32 Status; /* Error from server */
143 __le16 CreditRequest; /* CreditResponse */
160 __le16 StructureSize2; /* size of wct area (varies, request specific) */
163 #define SMB3_AES_CCM_NONCE 11
164 #define SMB3_AES_GCM_NONCE 12
166 struct smb2_transform_hdr {
167 __be32 smb2_buf_length; /* big endian on wire */
169 * length is only two or three bytes - with
170 * one or two byte type preceding it that MBZ
172 __le32 ProtocolId; /* 0xFD 'S' 'M' 'B' */
175 __le32 OriginalMessageSize;
177 __le16 Flags; /* EncryptionAlgorithm */
182 * SMB2 flag definitions
184 #define SMB2_FLAGS_SERVER_TO_REDIR cpu_to_le32(0x00000001)
185 #define SMB2_FLAGS_ASYNC_COMMAND cpu_to_le32(0x00000002)
186 #define SMB2_FLAGS_RELATED_OPERATIONS cpu_to_le32(0x00000004)
187 #define SMB2_FLAGS_SIGNED cpu_to_le32(0x00000008)
188 #define SMB2_FLAGS_DFS_OPERATIONS cpu_to_le32(0x10000000)
189 #define SMB2_FLAGS_REPLAY_OPERATIONS cpu_to_le32(0x20000000)
192 * Definitions for SMB2 Protocol Data Units (network frames)
194 * See MS-SMB2.PDF specification for protocol details.
195 * The Naming convention is the lower case version of the SMB2
196 * command code name for the struct. Note that structures must be packed.
200 #define SMB2_ERROR_STRUCTURE_SIZE2 9
201 #define SMB2_ERROR_STRUCTURE_SIZE2_LE cpu_to_le16(SMB2_ERROR_STRUCTURE_SIZE2)
203 struct smb2_err_rsp {
205 __le16 StructureSize;
206 __u8 ErrorContextCount;
208 __le32 ByteCount; /* even if zero, at least one byte follows */
209 __u8 ErrorData[1]; /* variable length */
212 struct smb2_negotiate_req {
214 __le16 StructureSize; /* Must be 36 */
217 __le16 Reserved; /* MBZ */
219 __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE];
220 /* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */
221 __le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */
222 __le16 NegotiateContextCount; /* SMB3.1.1 only. MBZ earlier */
224 __le16 Dialects[1]; /* One dialect (vers=) at a time for now */
227 /* SecurityMode flags */
228 #define SMB2_NEGOTIATE_SIGNING_ENABLED_LE cpu_to_le16(0x0001)
229 #define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
230 #define SMB2_NEGOTIATE_SIGNING_REQUIRED_LE cpu_to_le16(0x0002)
231 /* Capabilities flags */
232 #define SMB2_GLOBAL_CAP_DFS 0x00000001
233 #define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */
234 #define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */
235 #define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */
236 #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
237 #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */
238 #define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */
240 #define SMB2_NT_FIND 0x00100000
241 #define SMB2_LARGE_FILES 0x00200000
243 #define SMB311_SALT_SIZE 32
244 /* Hash Algorithm Types */
245 #define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001)
247 #define PREAUTH_HASHVALUE_SIZE 64
249 struct preauth_integrity_info {
250 /* PreAuth integrity Hash ID */
251 __le16 Preauth_HashId;
252 /* PreAuth integrity Hash Value */
253 __u8 Preauth_HashValue[PREAUTH_HASHVALUE_SIZE];
256 /* offset is sizeof smb2_negotiate_rsp - 4 but rounded up to 8 bytes. */
257 #ifdef CONFIG_SMB_SERVER_KERBEROS5
258 /* sizeof(struct smb2_negotiate_rsp) - 4 =
259 * header(64) + response(64) + GSS_LENGTH(96) + GSS_PADDING(0)
261 #define OFFSET_OF_NEG_CONTEXT 0xe0
263 /* sizeof(struct smb2_negotiate_rsp) - 4 =
264 * header(64) + response(64) + GSS_LENGTH(74) + GSS_PADDING(6)
266 #define OFFSET_OF_NEG_CONTEXT 0xd0
269 #define SMB2_PREAUTH_INTEGRITY_CAPABILITIES cpu_to_le16(1)
270 #define SMB2_ENCRYPTION_CAPABILITIES cpu_to_le16(2)
271 #define SMB2_COMPRESSION_CAPABILITIES cpu_to_le16(3)
272 #define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID cpu_to_le16(5)
273 #define SMB2_SIGNING_CAPABILITIES cpu_to_le16(8)
274 #define SMB2_POSIX_EXTENSIONS_AVAILABLE cpu_to_le16(0x100)
276 struct smb2_neg_context {
280 /* Followed by array of data */
283 struct smb2_preauth_neg_context {
284 __le16 ContextType; /* 1 */
287 __le16 HashAlgorithmCount; /* 1 */
289 __le16 HashAlgorithms; /* HashAlgorithms[0] since only one defined */
290 __u8 Salt[SMB311_SALT_SIZE];
293 /* Encryption Algorithms Ciphers */
294 #define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001)
295 #define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002)
296 #define SMB2_ENCRYPTION_AES256_CCM cpu_to_le16(0x0003)
297 #define SMB2_ENCRYPTION_AES256_GCM cpu_to_le16(0x0004)
299 struct smb2_encryption_neg_context {
300 __le16 ContextType; /* 2 */
303 /* CipherCount usally 2, but can be 3 when AES256-GCM enabled */
304 __le16 CipherCount; /* AES-128-GCM and AES-128-CCM by default */
308 #define SMB3_COMPRESS_NONE cpu_to_le16(0x0000)
309 #define SMB3_COMPRESS_LZNT1 cpu_to_le16(0x0001)
310 #define SMB3_COMPRESS_LZ77 cpu_to_le16(0x0002)
311 #define SMB3_COMPRESS_LZ77_HUFF cpu_to_le16(0x0003)
313 struct smb2_compression_ctx {
314 __le16 ContextType; /* 3 */
317 __le16 CompressionAlgorithmCount;
320 __le16 CompressionAlgorithms[];
323 #define POSIX_CTXT_DATA_LEN 16
324 struct smb2_posix_neg_context {
325 __le16 ContextType; /* 0x100 */
328 __u8 Name[16]; /* POSIX ctxt GUID 93AD25509CB411E7B42383DE968BCD7C */
331 struct smb2_netname_neg_context {
332 __le16 ContextType; /* 0x100 */
335 __le16 NetName[]; /* hostname of target converted to UCS-2 */
338 /* Signing algorithms */
339 #define SIGNING_ALG_HMAC_SHA256 cpu_to_le16(0)
340 #define SIGNING_ALG_AES_CMAC cpu_to_le16(1)
341 #define SIGNING_ALG_AES_GMAC cpu_to_le16(2)
343 struct smb2_signing_capabilities {
344 __le16 ContextType; /* 8 */
347 __le16 SigningAlgorithmCount;
348 __le16 SigningAlgorithms[];
351 struct smb2_negotiate_rsp {
353 __le16 StructureSize; /* Must be 65 */
355 __le16 DialectRevision;
356 __le16 NegotiateContextCount; /* Prior to SMB3.1.1 was Reserved & MBZ */
359 __le32 MaxTransactSize;
362 __le64 SystemTime; /* MBZ */
363 __le64 ServerStartTime;
364 __le16 SecurityBufferOffset;
365 __le16 SecurityBufferLength;
366 __le32 NegotiateContextOffset; /* Pre:SMB3.1.1 was reserved/ignored */
367 __u8 Buffer[1]; /* variable length GSS security buffer */
371 #define SMB2_SESSION_REQ_FLAG_BINDING 0x01
372 #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04
374 #define SMB2_SESSION_EXPIRED (0)
375 #define SMB2_SESSION_IN_PROGRESS BIT(0)
376 #define SMB2_SESSION_VALID BIT(1)
379 #define SMB2_SESSION_REQ_FLAG_BINDING 0x01
380 #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04
382 struct smb2_sess_setup_req {
384 __le16 StructureSize; /* Must be 25 */
389 __le16 SecurityBufferOffset;
390 __le16 SecurityBufferLength;
391 __le64 PreviousSessionId;
392 __u8 Buffer[1]; /* variable length GSS security buffer */
395 /* Flags/Reserved for SMB3.1.1 */
396 #define SMB2_SHAREFLAG_CLUSTER_RECONNECT 0x0001
398 /* Currently defined SessionFlags */
399 #define SMB2_SESSION_FLAG_IS_GUEST_LE cpu_to_le16(0x0001)
400 #define SMB2_SESSION_FLAG_IS_NULL_LE cpu_to_le16(0x0002)
401 #define SMB2_SESSION_FLAG_ENCRYPT_DATA_LE cpu_to_le16(0x0004)
402 struct smb2_sess_setup_rsp {
404 __le16 StructureSize; /* Must be 9 */
406 __le16 SecurityBufferOffset;
407 __le16 SecurityBufferLength;
408 __u8 Buffer[1]; /* variable length GSS security buffer */
411 struct smb2_logoff_req {
413 __le16 StructureSize; /* Must be 4 */
417 struct smb2_logoff_rsp {
419 __le16 StructureSize; /* Must be 4 */
423 struct smb2_tree_connect_req {
425 __le16 StructureSize; /* Must be 9 */
426 __le16 Reserved; /* Flags in SMB3.1.1 */
429 __u8 Buffer[1]; /* variable length */
432 struct smb2_tree_connect_rsp {
434 __le16 StructureSize; /* Must be 16 */
435 __u8 ShareType; /* see below */
437 __le32 ShareFlags; /* see below */
438 __le32 Capabilities; /* see below */
439 __le32 MaximalAccess;
442 /* Possible ShareType values */
443 #define SMB2_SHARE_TYPE_DISK 0x01
444 #define SMB2_SHARE_TYPE_PIPE 0x02
445 #define SMB2_SHARE_TYPE_PRINT 0x03
448 * Possible ShareFlags - exactly one and only one of the first 4 caching flags
449 * must be set (any of the remaining, SHI1005, flags may be set individually
452 #define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000
453 #define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010
454 #define SMB2_SHAREFLAG_VDO_CACHING 0x00000020
455 #define SMB2_SHAREFLAG_NO_CACHING 0x00000030
456 #define SHI1005_FLAGS_DFS 0x00000001
457 #define SHI1005_FLAGS_DFS_ROOT 0x00000002
458 #define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS 0x00000100
459 #define SHI1005_FLAGS_FORCE_SHARED_DELETE 0x00000200
460 #define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING 0x00000400
461 #define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM 0x00000800
462 #define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK 0x00001000
463 #define SHI1005_FLAGS_ENABLE_HASH 0x00002000
465 /* Possible share capabilities */
466 #define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008)
468 struct smb2_tree_disconnect_req {
470 __le16 StructureSize; /* Must be 4 */
474 struct smb2_tree_disconnect_rsp {
476 __le16 StructureSize; /* Must be 4 */
480 #define ATTR_READONLY_LE cpu_to_le32(ATTR_READONLY)
481 #define ATTR_HIDDEN_LE cpu_to_le32(ATTR_HIDDEN)
482 #define ATTR_SYSTEM_LE cpu_to_le32(ATTR_SYSTEM)
483 #define ATTR_DIRECTORY_LE cpu_to_le32(ATTR_DIRECTORY)
484 #define ATTR_ARCHIVE_LE cpu_to_le32(ATTR_ARCHIVE)
485 #define ATTR_NORMAL_LE cpu_to_le32(ATTR_NORMAL)
486 #define ATTR_TEMPORARY_LE cpu_to_le32(ATTR_TEMPORARY)
487 #define ATTR_SPARSE_FILE_LE cpu_to_le32(ATTR_SPARSE)
488 #define ATTR_REPARSE_POINT_LE cpu_to_le32(ATTR_REPARSE)
489 #define ATTR_COMPRESSED_LE cpu_to_le32(ATTR_COMPRESSED)
490 #define ATTR_OFFLINE_LE cpu_to_le32(ATTR_OFFLINE)
491 #define ATTR_NOT_CONTENT_INDEXED_LE cpu_to_le32(ATTR_NOT_CONTENT_INDEXED)
492 #define ATTR_ENCRYPTED_LE cpu_to_le32(ATTR_ENCRYPTED)
493 #define ATTR_INTEGRITY_STREAML_LE cpu_to_le32(0x00008000)
494 #define ATTR_NO_SCRUB_DATA_LE cpu_to_le32(0x00020000)
495 #define ATTR_MASK_LE cpu_to_le32(0x00007FB7)
498 #define SMB2_OPLOCK_LEVEL_NONE 0x00
499 #define SMB2_OPLOCK_LEVEL_II 0x01
500 #define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
501 #define SMB2_OPLOCK_LEVEL_BATCH 0x09
502 #define SMB2_OPLOCK_LEVEL_LEASE 0xFF
503 /* Non-spec internal type */
504 #define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99
506 /* Desired Access Flags */
507 #define FILE_READ_DATA_LE cpu_to_le32(0x00000001)
508 #define FILE_LIST_DIRECTORY_LE cpu_to_le32(0x00000001)
509 #define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002)
510 #define FILE_ADD_FILE_LE cpu_to_le32(0x00000002)
511 #define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004)
512 #define FILE_ADD_SUBDIRECTORY_LE cpu_to_le32(0x00000004)
513 #define FILE_READ_EA_LE cpu_to_le32(0x00000008)
514 #define FILE_WRITE_EA_LE cpu_to_le32(0x00000010)
515 #define FILE_EXECUTE_LE cpu_to_le32(0x00000020)
516 #define FILE_TRAVERSE_LE cpu_to_le32(0x00000020)
517 #define FILE_DELETE_CHILD_LE cpu_to_le32(0x00000040)
518 #define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080)
519 #define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100)
520 #define FILE_DELETE_LE cpu_to_le32(0x00010000)
521 #define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000)
522 #define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000)
523 #define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000)
524 #define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000)
525 #define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000)
526 #define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000)
527 #define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000)
528 #define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000)
529 #define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000)
530 #define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000)
531 #define DESIRED_ACCESS_MASK cpu_to_le32(0xF21F01FF)
533 /* ShareAccess Flags */
534 #define FILE_SHARE_READ_LE cpu_to_le32(0x00000001)
535 #define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002)
536 #define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004)
537 #define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007)
539 /* CreateDisposition Flags */
540 #define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000)
541 #define FILE_OPEN_LE cpu_to_le32(0x00000001)
542 #define FILE_CREATE_LE cpu_to_le32(0x00000002)
543 #define FILE_OPEN_IF_LE cpu_to_le32(0x00000003)
544 #define FILE_OVERWRITE_LE cpu_to_le32(0x00000004)
545 #define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005)
546 #define FILE_CREATE_MASK_LE cpu_to_le32(0x00000007)
548 #define FILE_READ_DESIRED_ACCESS_LE (FILE_READ_DATA_LE | \
550 FILE_GENERIC_READ_LE)
551 #define FILE_WRITE_DESIRE_ACCESS_LE (FILE_WRITE_DATA_LE | \
552 FILE_APPEND_DATA_LE | \
554 FILE_WRITE_ATTRIBUTES_LE | \
555 FILE_GENERIC_WRITE_LE)
557 /* Impersonation Levels */
558 #define IL_ANONYMOUS_LE cpu_to_le32(0x00000000)
559 #define IL_IDENTIFICATION_LE cpu_to_le32(0x00000001)
560 #define IL_IMPERSONATION_LE cpu_to_le32(0x00000002)
561 #define IL_DELEGATE_LE cpu_to_le32(0x00000003)
563 /* Create Context Values */
564 #define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */
565 #define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */
566 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ"
567 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC"
568 #define SMB2_CREATE_ALLOCATION_SIZE "AlSi"
569 #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
570 #define SMB2_CREATE_TIMEWARP_REQUEST "TWrp"
571 #define SMB2_CREATE_QUERY_ON_DISK_ID "QFid"
572 #define SMB2_CREATE_REQUEST_LEASE "RqLs"
573 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 "DH2Q"
574 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 "DH2C"
575 #define SMB2_CREATE_APP_INSTANCE_ID "\x45\xBC\xA6\x6A\xEF\xA7\xF7\x4A\x90\x08\xFA\x46\x2E\x14\x4D\x74"
576 #define SMB2_CREATE_APP_INSTANCE_VERSION "\xB9\x82\xD0\xB7\x3B\x56\x07\x4F\xA0\x7B\x52\x4A\x81\x16\xA0\x10"
577 #define SVHDX_OPEN_DEVICE_CONTEXT 0x83CE6F1AD851E0986E34401CC9BCFCE9
578 #define SMB2_CREATE_TAG_POSIX "\x93\xAD\x25\x50\x9C\xB4\x11\xE7\xB4\x23\x83\xDE\x96\x8B\xCD\x7C"
580 struct smb2_create_req {
582 __le16 StructureSize; /* Must be 57 */
584 __u8 RequestedOplockLevel;
585 __le32 ImpersonationLevel;
586 __le64 SmbCreateFlags;
588 __le32 DesiredAccess;
589 __le32 FileAttributes;
591 __le32 CreateDisposition;
592 __le32 CreateOptions;
595 __le32 CreateContextsOffset;
596 __le32 CreateContextsLength;
600 struct smb2_create_rsp {
602 __le16 StructureSize; /* Must be 89 */
607 __le64 LastAccessTime;
608 __le64 LastWriteTime;
610 __le64 AllocationSize;
612 __le32 FileAttributes;
614 __le64 PersistentFileId;
615 __le64 VolatileFileId;
616 __le32 CreateContextsOffset;
617 __le32 CreateContextsLength;
621 struct create_context {
631 struct create_durable_req_v2 {
632 struct create_context ccontext;
640 struct create_durable_reconn_req {
641 struct create_context ccontext;
646 __le64 PersistentFileId;
647 __le64 VolatileFileId;
652 struct create_durable_reconn_v2_req {
653 struct create_context ccontext;
656 __le64 PersistentFileId;
657 __le64 VolatileFileId;
663 struct create_app_inst_id {
664 struct create_context ccontext;
667 __u8 AppInstanceId[16];
670 struct create_app_inst_id_vers {
671 struct create_context ccontext;
675 __le64 AppInstanceVersionHigh;
676 __le64 AppInstanceVersionLow;
679 struct create_mxac_req {
680 struct create_context ccontext;
685 struct create_alloc_size_req {
686 struct create_context ccontext;
688 __le64 AllocationSize;
691 struct create_posix {
692 struct create_context ccontext;
698 struct create_durable_rsp {
699 struct create_context ccontext;
707 struct create_durable_v2_rsp {
708 struct create_context ccontext;
714 struct create_mxac_rsp {
715 struct create_context ccontext;
718 __le32 MaximalAccess;
721 struct create_disk_id_rsp {
722 struct create_context ccontext;
729 /* equivalent of the contents of SMB3.1.1 POSIX open context response */
730 struct create_posix_rsp {
731 struct create_context ccontext;
739 #define SMB2_LEASE_NONE_LE cpu_to_le32(0x00)
740 #define SMB2_LEASE_READ_CACHING_LE cpu_to_le32(0x01)
741 #define SMB2_LEASE_HANDLE_CACHING_LE cpu_to_le32(0x02)
742 #define SMB2_LEASE_WRITE_CACHING_LE cpu_to_le32(0x04)
744 #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE cpu_to_le32(0x02)
746 struct lease_context {
751 __le64 LeaseDuration;
754 struct lease_context_v2 {
759 __le64 LeaseDuration;
760 __le64 ParentLeaseKeyLow;
761 __le64 ParentLeaseKeyHigh;
766 struct create_lease {
767 struct create_context ccontext;
769 struct lease_context lcontext;
772 struct create_lease_v2 {
773 struct create_context ccontext;
775 struct lease_context_v2 lcontext;
779 /* Currently defined values for close flags */
780 #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
781 struct smb2_close_req {
783 __le16 StructureSize; /* Must be 24 */
786 __le64 PersistentFileId;
787 __le64 VolatileFileId;
790 struct smb2_close_rsp {
792 __le16 StructureSize; /* 60 */
796 __le64 LastAccessTime;
797 __le64 LastWriteTime;
799 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
804 struct smb2_flush_req {
806 __le16 StructureSize; /* Must be 24 */
809 __le64 PersistentFileId;
810 __le64 VolatileFileId;
813 struct smb2_flush_rsp {
815 __le16 StructureSize;
819 struct smb2_buffer_desc_v1 {
825 #define SMB2_CHANNEL_NONE cpu_to_le32(0x00000000)
826 #define SMB2_CHANNEL_RDMA_V1 cpu_to_le32(0x00000001)
827 #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002)
829 struct smb2_read_req {
831 __le16 StructureSize; /* Must be 49 */
832 __u8 Padding; /* offset from start of SMB2 header to place read */
836 __le64 PersistentFileId;
837 __le64 VolatileFileId;
839 __le32 Channel; /* Reserved MBZ */
840 __le32 RemainingBytes;
841 __le16 ReadChannelInfoOffset; /* Reserved MBZ */
842 __le16 ReadChannelInfoLength; /* Reserved MBZ */
846 struct smb2_read_rsp {
848 __le16 StructureSize; /* Must be 17 */
852 __le32 DataRemaining;
857 /* For write request Flags field below the following flag is defined: */
858 #define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001
860 struct smb2_write_req {
862 __le16 StructureSize; /* Must be 49 */
863 __le16 DataOffset; /* offset from start of SMB2 header to write data */
866 __le64 PersistentFileId;
867 __le64 VolatileFileId;
868 __le32 Channel; /* Reserved MBZ */
869 __le32 RemainingBytes;
870 __le16 WriteChannelInfoOffset; /* Reserved MBZ */
871 __le16 WriteChannelInfoLength; /* Reserved MBZ */
876 struct smb2_write_rsp {
878 __le16 StructureSize; /* Must be 17 */
882 __le32 DataRemaining;
887 #define SMB2_0_IOCTL_IS_FSCTL 0x00000001
889 struct duplicate_extents_to_file {
890 __u64 PersistentFileHandle; /* source file handle, opaque endianness */
891 __u64 VolatileFileHandle;
892 __le64 SourceFileOffset;
893 __le64 TargetFileOffset;
894 __le64 ByteCount; /* Bytes to be copied */
897 struct smb2_ioctl_req {
899 __le16 StructureSize; /* Must be 57 */
900 __le16 Reserved; /* offset from start of SMB2 header to write data */
902 __le64 PersistentFileId;
903 __le64 VolatileFileId;
904 __le32 InputOffset; /* Reserved MBZ */
906 __le32 MaxInputResponse;
909 __le32 MaxOutputResponse;
915 struct smb2_ioctl_rsp {
917 __le16 StructureSize; /* Must be 49 */
918 __le16 Reserved; /* offset from start of SMB2 header to write data */
920 __le64 PersistentFileId;
921 __le64 VolatileFileId;
922 __le32 InputOffset; /* Reserved MBZ */
931 struct validate_negotiate_info_req {
933 __u8 Guid[SMB2_CLIENT_GUID_SIZE];
936 __le16 Dialects[1]; /* dialect (someday maybe list) client asked for */
939 struct validate_negotiate_info_rsp {
941 __u8 Guid[SMB2_CLIENT_GUID_SIZE];
943 __le16 Dialect; /* Dialect in use for the connection */
946 struct smb_sockaddr_in {
952 struct smb_sockaddr_in6 {
955 __u8 IPv6address[16];
959 #define INTERNETWORK 0x0002
960 #define INTERNETWORKV6 0x0017
962 struct sockaddr_storage_rsp {
965 struct smb_sockaddr_in addr4;
966 struct smb_sockaddr_in6 addr6;
970 #define RSS_CAPABLE 0x00000001
971 #define RDMA_CAPABLE 0x00000002
973 struct network_interface_info_ioctl_rsp {
974 __le32 Next; /* next interface. zero if this is last one */
976 __le32 Capability; /* RSS or RDMA Capable */
979 char SockAddr_Storage[128];
982 struct file_object_buf_type1_ioctl_rsp {
984 __u8 BirthVolumeId[16];
985 __u8 BirthObjectId[16];
989 struct resume_key_ioctl_rsp {
991 __le32 ContextLength;
992 __u8 Context[4]; /* ignored, Windows sets to 4 bytes of zero */
995 struct copychunk_ioctl_req {
999 __u8 Chunks[1]; /* array of srv_copychunk */
1002 struct srv_copychunk {
1003 __le64 SourceOffset;
1004 __le64 TargetOffset;
1009 struct copychunk_ioctl_rsp {
1010 __le32 ChunksWritten;
1011 __le32 ChunkBytesWritten;
1012 __le32 TotalBytesWritten;
1015 struct file_sparse {
1019 struct file_zero_data_information {
1021 __le64 BeyondFinalZero;
1024 struct file_allocated_range_buffer {
1029 struct reparse_data_buffer {
1031 __le16 ReparseDataLength;
1033 __u8 DataBuffer[]; /* Variable Length */
1036 /* Completion Filter flags for Notify */
1037 #define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001
1038 #define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002
1039 #define FILE_NOTIFY_CHANGE_NAME 0x00000003
1040 #define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004
1041 #define FILE_NOTIFY_CHANGE_SIZE 0x00000008
1042 #define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010
1043 #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020
1044 #define FILE_NOTIFY_CHANGE_CREATION 0x00000040
1045 #define FILE_NOTIFY_CHANGE_EA 0x00000080
1046 #define FILE_NOTIFY_CHANGE_SECURITY 0x00000100
1047 #define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200
1048 #define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400
1049 #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
1052 #define SMB2_WATCH_TREE 0x0001
1054 struct smb2_notify_req {
1055 struct smb2_hdr hdr;
1056 __le16 StructureSize; /* Must be 32 */
1058 __le32 OutputBufferLength;
1059 __le64 PersistentFileId;
1060 __le64 VolatileFileId;
1061 __u32 CompletionFileter;
1065 struct smb2_notify_rsp {
1066 struct smb2_hdr hdr;
1067 __le16 StructureSize; /* Must be 9 */
1068 __le16 OutputBufferOffset;
1069 __le32 OutputBufferLength;
1073 /* SMB2 Notify Action Flags */
1074 #define FILE_ACTION_ADDED 0x00000001
1075 #define FILE_ACTION_REMOVED 0x00000002
1076 #define FILE_ACTION_MODIFIED 0x00000003
1077 #define FILE_ACTION_RENAMED_OLD_NAME 0x00000004
1078 #define FILE_ACTION_RENAMED_NEW_NAME 0x00000005
1079 #define FILE_ACTION_ADDED_STREAM 0x00000006
1080 #define FILE_ACTION_REMOVED_STREAM 0x00000007
1081 #define FILE_ACTION_MODIFIED_STREAM 0x00000008
1082 #define FILE_ACTION_REMOVED_BY_DELETE 0x00000009
1084 #define SMB2_LOCKFLAG_SHARED 0x0001
1085 #define SMB2_LOCKFLAG_EXCLUSIVE 0x0002
1086 #define SMB2_LOCKFLAG_UNLOCK 0x0004
1087 #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010
1088 #define SMB2_LOCKFLAG_MASK 0x0007
1090 struct smb2_lock_element {
1097 struct smb2_lock_req {
1098 struct smb2_hdr hdr;
1099 __le16 StructureSize; /* Must be 48 */
1102 __le64 PersistentFileId;
1103 __le64 VolatileFileId;
1104 /* Followed by at least one */
1105 struct smb2_lock_element locks[1];
1108 struct smb2_lock_rsp {
1109 struct smb2_hdr hdr;
1110 __le16 StructureSize; /* Must be 4 */
1114 struct smb2_echo_req {
1115 struct smb2_hdr hdr;
1116 __le16 StructureSize; /* Must be 4 */
1120 struct smb2_echo_rsp {
1121 struct smb2_hdr hdr;
1122 __le16 StructureSize; /* Must be 4 */
1126 /* search (query_directory) Flags field */
1127 #define SMB2_RESTART_SCANS 0x01
1128 #define SMB2_RETURN_SINGLE_ENTRY 0x02
1129 #define SMB2_INDEX_SPECIFIED 0x04
1130 #define SMB2_REOPEN 0x10
1132 struct smb2_query_directory_req {
1133 struct smb2_hdr hdr;
1134 __le16 StructureSize; /* Must be 33 */
1135 __u8 FileInformationClass;
1138 __le64 PersistentFileId;
1139 __le64 VolatileFileId;
1140 __le16 FileNameOffset;
1141 __le16 FileNameLength;
1142 __le32 OutputBufferLength;
1146 struct smb2_query_directory_rsp {
1147 struct smb2_hdr hdr;
1148 __le16 StructureSize; /* Must be 9 */
1149 __le16 OutputBufferOffset;
1150 __le32 OutputBufferLength;
1154 /* Possible InfoType values */
1155 #define SMB2_O_INFO_FILE 0x01
1156 #define SMB2_O_INFO_FILESYSTEM 0x02
1157 #define SMB2_O_INFO_SECURITY 0x03
1158 #define SMB2_O_INFO_QUOTA 0x04
1160 /* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */
1161 #define OWNER_SECINFO 0x00000001
1162 #define GROUP_SECINFO 0x00000002
1163 #define DACL_SECINFO 0x00000004
1164 #define SACL_SECINFO 0x00000008
1165 #define LABEL_SECINFO 0x00000010
1166 #define ATTRIBUTE_SECINFO 0x00000020
1167 #define SCOPE_SECINFO 0x00000040
1168 #define BACKUP_SECINFO 0x00010000
1169 #define UNPROTECTED_SACL_SECINFO 0x10000000
1170 #define UNPROTECTED_DACL_SECINFO 0x20000000
1171 #define PROTECTED_SACL_SECINFO 0x40000000
1172 #define PROTECTED_DACL_SECINFO 0x80000000
1174 struct smb2_query_info_req {
1175 struct smb2_hdr hdr;
1176 __le16 StructureSize; /* Must be 41 */
1179 __le32 OutputBufferLength;
1180 __le16 InputBufferOffset;
1182 __le32 InputBufferLength;
1183 __le32 AdditionalInformation;
1185 __le64 PersistentFileId;
1186 __le64 VolatileFileId;
1190 struct smb2_query_info_rsp {
1191 struct smb2_hdr hdr;
1192 __le16 StructureSize; /* Must be 9 */
1193 __le16 OutputBufferOffset;
1194 __le32 OutputBufferLength;
1198 struct smb2_set_info_req {
1199 struct smb2_hdr hdr;
1200 __le16 StructureSize; /* Must be 33 */
1203 __le32 BufferLength;
1204 __le16 BufferOffset;
1206 __le32 AdditionalInformation;
1207 __le64 PersistentFileId;
1208 __le64 VolatileFileId;
1212 struct smb2_set_info_rsp {
1213 struct smb2_hdr hdr;
1214 __le16 StructureSize; /* Must be 2 */
1217 /* FILE Info response size */
1218 #define FILE_DIRECTORY_INFORMATION_SIZE 1
1219 #define FILE_FULL_DIRECTORY_INFORMATION_SIZE 2
1220 #define FILE_BOTH_DIRECTORY_INFORMATION_SIZE 3
1221 #define FILE_BASIC_INFORMATION_SIZE 40
1222 #define FILE_STANDARD_INFORMATION_SIZE 24
1223 #define FILE_INTERNAL_INFORMATION_SIZE 8
1224 #define FILE_EA_INFORMATION_SIZE 4
1225 #define FILE_ACCESS_INFORMATION_SIZE 4
1226 #define FILE_NAME_INFORMATION_SIZE 9
1227 #define FILE_RENAME_INFORMATION_SIZE 10
1228 #define FILE_LINK_INFORMATION_SIZE 11
1229 #define FILE_NAMES_INFORMATION_SIZE 12
1230 #define FILE_DISPOSITION_INFORMATION_SIZE 13
1231 #define FILE_POSITION_INFORMATION_SIZE 14
1232 #define FILE_FULL_EA_INFORMATION_SIZE 15
1233 #define FILE_MODE_INFORMATION_SIZE 4
1234 #define FILE_ALIGNMENT_INFORMATION_SIZE 4
1235 #define FILE_ALL_INFORMATION_SIZE 104
1236 #define FILE_ALLOCATION_INFORMATION_SIZE 19
1237 #define FILE_END_OF_FILE_INFORMATION_SIZE 20
1238 #define FILE_ALTERNATE_NAME_INFORMATION_SIZE 8
1239 #define FILE_STREAM_INFORMATION_SIZE 32
1240 #define FILE_PIPE_INFORMATION_SIZE 23
1241 #define FILE_PIPE_LOCAL_INFORMATION_SIZE 24
1242 #define FILE_PIPE_REMOTE_INFORMATION_SIZE 25
1243 #define FILE_MAILSLOT_QUERY_INFORMATION_SIZE 26
1244 #define FILE_MAILSLOT_SET_INFORMATION_SIZE 27
1245 #define FILE_COMPRESSION_INFORMATION_SIZE 16
1246 #define FILE_OBJECT_ID_INFORMATION_SIZE 29
1247 /* Number 30 not defined in documents */
1248 #define FILE_MOVE_CLUSTER_INFORMATION_SIZE 31
1249 #define FILE_QUOTA_INFORMATION_SIZE 32
1250 #define FILE_REPARSE_POINT_INFORMATION_SIZE 33
1251 #define FILE_NETWORK_OPEN_INFORMATION_SIZE 56
1252 #define FILE_ATTRIBUTE_TAG_INFORMATION_SIZE 8
1254 /* FS Info response size */
1255 #define FS_DEVICE_INFORMATION_SIZE 8
1256 #define FS_ATTRIBUTE_INFORMATION_SIZE 16
1257 #define FS_VOLUME_INFORMATION_SIZE 24
1258 #define FS_SIZE_INFORMATION_SIZE 24
1259 #define FS_FULL_SIZE_INFORMATION_SIZE 32
1260 #define FS_SECTOR_SIZE_INFORMATION_SIZE 28
1261 #define FS_OBJECT_ID_INFORMATION_SIZE 64
1262 #define FS_CONTROL_INFORMATION_SIZE 48
1263 #define FS_POSIX_INFORMATION_SIZE 56
1265 /* FS_ATTRIBUTE_File_System_Name */
1266 #define FS_TYPE_SUPPORT_SIZE 44
1267 struct fs_type_info {
1272 struct smb2_oplock_break {
1273 struct smb2_hdr hdr;
1274 __le16 StructureSize; /* Must be 24 */
1278 __le64 PersistentFid;
1282 #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
1284 struct smb2_lease_break {
1285 struct smb2_hdr hdr;
1286 __le16 StructureSize; /* Must be 44 */
1290 __le32 CurrentLeaseState;
1291 __le32 NewLeaseState;
1293 __le32 AccessMaskHint;
1294 __le32 ShareMaskHint;
1297 struct smb2_lease_ack {
1298 struct smb2_hdr hdr;
1299 __le16 StructureSize; /* Must be 36 */
1304 __le64 LeaseDuration;
1308 * PDU infolevel structure definitions
1309 * BB consider moving to a different header
1312 /* File System Information Classes */
1313 #define FS_VOLUME_INFORMATION 1 /* Query */
1314 #define FS_LABEL_INFORMATION 2 /* Set */
1315 #define FS_SIZE_INFORMATION 3 /* Query */
1316 #define FS_DEVICE_INFORMATION 4 /* Query */
1317 #define FS_ATTRIBUTE_INFORMATION 5 /* Query */
1318 #define FS_CONTROL_INFORMATION 6 /* Query, Set */
1319 #define FS_FULL_SIZE_INFORMATION 7 /* Query */
1320 #define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */
1321 #define FS_DRIVER_PATH_INFORMATION 9 /* Query */
1322 #define FS_SECTOR_SIZE_INFORMATION 11 /* SMB3 or later. Query */
1323 #define FS_POSIX_INFORMATION 100 /* SMB3.1.1 POSIX. Query */
1325 struct smb2_fs_full_size_info {
1326 __le64 TotalAllocationUnits;
1327 __le64 CallerAvailableAllocationUnits;
1328 __le64 ActualAvailableAllocationUnits;
1329 __le32 SectorsPerAllocationUnit;
1330 __le32 BytesPerSector;
1333 #define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001
1334 #define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
1335 #define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004
1336 #define SSINFO_FLAGS_TRIM_ENABLED 0x00000008
1338 /* sector size info struct */
1339 struct smb3_fs_ss_info {
1340 __le32 LogicalBytesPerSector;
1341 __le32 PhysicalBytesPerSectorForAtomicity;
1342 __le32 PhysicalBytesPerSectorForPerf;
1343 __le32 FSEffPhysicalBytesPerSectorForAtomicity;
1345 __le32 ByteOffsetForSectorAlignment;
1346 __le32 ByteOffsetForPartitionAlignment;
1349 /* File System Control Information */
1350 struct smb2_fs_control_info {
1351 __le64 FreeSpaceStartFiltering;
1352 __le64 FreeSpaceThreshold;
1353 __le64 FreeSpaceStopFiltering;
1354 __le64 DefaultQuotaThreshold;
1355 __le64 DefaultQuotaLimit;
1356 __le32 FileSystemControlFlags;
1360 /* partial list of QUERY INFO levels */
1361 #define FILE_DIRECTORY_INFORMATION 1
1362 #define FILE_FULL_DIRECTORY_INFORMATION 2
1363 #define FILE_BOTH_DIRECTORY_INFORMATION 3
1364 #define FILE_BASIC_INFORMATION 4
1365 #define FILE_STANDARD_INFORMATION 5
1366 #define FILE_INTERNAL_INFORMATION 6
1367 #define FILE_EA_INFORMATION 7
1368 #define FILE_ACCESS_INFORMATION 8
1369 #define FILE_NAME_INFORMATION 9
1370 #define FILE_RENAME_INFORMATION 10
1371 #define FILE_LINK_INFORMATION 11
1372 #define FILE_NAMES_INFORMATION 12
1373 #define FILE_DISPOSITION_INFORMATION 13
1374 #define FILE_POSITION_INFORMATION 14
1375 #define FILE_FULL_EA_INFORMATION 15
1376 #define FILE_MODE_INFORMATION 16
1377 #define FILE_ALIGNMENT_INFORMATION 17
1378 #define FILE_ALL_INFORMATION 18
1379 #define FILE_ALLOCATION_INFORMATION 19
1380 #define FILE_END_OF_FILE_INFORMATION 20
1381 #define FILE_ALTERNATE_NAME_INFORMATION 21
1382 #define FILE_STREAM_INFORMATION 22
1383 #define FILE_PIPE_INFORMATION 23
1384 #define FILE_PIPE_LOCAL_INFORMATION 24
1385 #define FILE_PIPE_REMOTE_INFORMATION 25
1386 #define FILE_MAILSLOT_QUERY_INFORMATION 26
1387 #define FILE_MAILSLOT_SET_INFORMATION 27
1388 #define FILE_COMPRESSION_INFORMATION 28
1389 #define FILE_OBJECT_ID_INFORMATION 29
1390 /* Number 30 not defined in documents */
1391 #define FILE_MOVE_CLUSTER_INFORMATION 31
1392 #define FILE_QUOTA_INFORMATION 32
1393 #define FILE_REPARSE_POINT_INFORMATION 33
1394 #define FILE_NETWORK_OPEN_INFORMATION 34
1395 #define FILE_ATTRIBUTE_TAG_INFORMATION 35
1396 #define FILE_TRACKING_INFORMATION 36
1397 #define FILEID_BOTH_DIRECTORY_INFORMATION 37
1398 #define FILEID_FULL_DIRECTORY_INFORMATION 38
1399 #define FILE_VALID_DATA_LENGTH_INFORMATION 39
1400 #define FILE_SHORT_NAME_INFORMATION 40
1401 #define FILE_SFIO_RESERVE_INFORMATION 44
1402 #define FILE_SFIO_VOLUME_INFORMATION 45
1403 #define FILE_HARD_LINK_INFORMATION 46
1404 #define FILE_NORMALIZED_NAME_INFORMATION 48
1405 #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
1406 #define FILE_STANDARD_LINK_INFORMATION 54
1408 #define OP_BREAK_STRUCT_SIZE_20 24
1409 #define OP_BREAK_STRUCT_SIZE_21 36
1411 struct smb2_file_access_info {
1415 struct smb2_file_alignment_info {
1416 __le32 AlignmentRequirement;
1419 struct smb2_file_internal_info {
1421 } __packed; /* level 6 Query */
1423 struct smb2_file_rename_info { /* encoding of request for level 10 */
1424 __u8 ReplaceIfExists; /* 1 = replace existing target with new */
1425 /* 0 = fail if target already exists */
1427 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1428 __le32 FileNameLength;
1429 char FileName[0]; /* New name to be assigned */
1430 } __packed; /* level 10 Set */
1432 struct smb2_file_link_info { /* encoding of request for level 11 */
1433 __u8 ReplaceIfExists; /* 1 = replace existing link with new */
1434 /* 0 = fail if link already exists */
1436 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1437 __le32 FileNameLength;
1438 char FileName[0]; /* Name to be assigned to new link */
1439 } __packed; /* level 11 Set */
1442 * This level 18, although with struct with same name is different from cifs
1443 * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
1444 * CurrentByteOffset.
1446 struct smb2_file_all_info { /* data block encoding of response to level 18 */
1447 __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
1448 __le64 LastAccessTime;
1449 __le64 LastWriteTime;
1452 __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
1453 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
1454 __le64 EndOfFile; /* size ie offset to first free byte in file */
1455 __le32 NumberOfLinks; /* hard links */
1458 __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */
1462 __le64 CurrentByteOffset;
1464 __le32 AlignmentRequirement;
1465 __le32 FileNameLength;
1467 } __packed; /* level 18 Query */
1469 struct smb2_file_basic_info { /* data block encoding of response to level 18 */
1470 __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
1471 __le64 LastAccessTime;
1472 __le64 LastWriteTime;
1475 __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
1478 struct smb2_file_alt_name_info {
1479 __le32 FileNameLength;
1483 struct smb2_file_stream_info {
1484 __le32 NextEntryOffset;
1485 __le32 StreamNameLength;
1487 __le64 StreamAllocationSize;
1491 struct smb2_file_eof_info { /* encoding of request for level 10 */
1492 __le64 EndOfFile; /* new end of file value */
1493 } __packed; /* level 20 Set */
1495 struct smb2_file_ntwrk_info {
1496 __le64 CreationTime;
1497 __le64 LastAccessTime;
1498 __le64 LastWriteTime;
1500 __le64 AllocationSize;
1506 struct smb2_file_standard_info {
1507 __le64 AllocationSize;
1509 __le32 NumberOfLinks; /* hard links */
1513 } __packed; /* level 18 Query */
1515 struct smb2_file_ea_info {
1519 struct smb2_file_alloc_info {
1520 __le64 AllocationSize;
1523 struct smb2_file_disposition_info {
1527 struct smb2_file_pos_info {
1528 __le64 CurrentByteOffset;
1531 #define FILE_MODE_INFO_MASK cpu_to_le32(0x0000103e)
1533 struct smb2_file_mode_info {
1537 #define COMPRESSION_FORMAT_NONE 0x0000
1538 #define COMPRESSION_FORMAT_LZNT1 0x0002
1540 struct smb2_file_comp_info {
1541 __le64 CompressedFileSize;
1542 __le16 CompressionFormat;
1543 __u8 CompressionUnitShift;
1549 struct smb2_file_attr_tag_info {
1550 __le32 FileAttributes;
1554 #define SL_RESTART_SCAN 0x00000001
1555 #define SL_RETURN_SINGLE_ENTRY 0x00000002
1556 #define SL_INDEX_SPECIFIED 0x00000004
1558 struct smb2_ea_info_req {
1559 __le32 NextEntryOffset;
1562 } __packed; /* level 15 Query */
1564 struct smb2_ea_info {
1565 __le32 NextEntryOffset;
1568 __le16 EaValueLength;
1570 /* optionally followed by value */
1571 } __packed; /* level 15 Query */
1573 struct create_ea_buf_req {
1574 struct create_context ccontext;
1576 struct smb2_ea_info ea;
1579 struct create_sd_buf_req {
1580 struct create_context ccontext;
1582 struct smb_ntsd ntsd;
1585 /* Find File infolevels */
1586 #define SMB_FIND_FILE_POSIX_INFO 0x064
1588 /* Level 100 query info */
1589 struct smb311_posix_qinfo {
1590 __le64 CreationTime;
1591 __le64 LastAccessTime;
1592 __le64 LastWriteTime;
1595 __le64 AllocationSize;
1596 __le32 DosAttributes;
1600 /* beginning of POSIX Create Context Response */
1606 * var sized owner SID
1607 * var sized group SID
1608 * le32 filenamelength
1613 struct smb2_posix_info {
1614 __le32 NextEntryOffset;
1616 __le64 CreationTime;
1617 __le64 LastAccessTime;
1618 __le64 LastWriteTime;
1621 __le64 AllocationSize;
1622 __le32 DosAttributes;
1626 /* beginning of POSIX Create Context Response */
1634 * var sized owner SID
1635 * var sized group SID
1636 * le32 filenamelength
1642 void init_smb2_1_server(struct ksmbd_conn *conn);
1643 void init_smb3_0_server(struct ksmbd_conn *conn);
1644 void init_smb3_02_server(struct ksmbd_conn *conn);
1645 int init_smb3_11_server(struct ksmbd_conn *conn);
1647 void init_smb2_max_read_size(unsigned int sz);
1648 void init_smb2_max_write_size(unsigned int sz);
1649 void init_smb2_max_trans_size(unsigned int sz);
1651 bool is_smb2_neg_cmd(struct ksmbd_work *work);
1652 bool is_smb2_rsp(struct ksmbd_work *work);
1654 u16 get_smb2_cmd_val(struct ksmbd_work *work);
1655 void set_smb2_rsp_status(struct ksmbd_work *work, __le32 err);
1656 int init_smb2_rsp_hdr(struct ksmbd_work *work);
1657 int smb2_allocate_rsp_buf(struct ksmbd_work *work);
1658 bool is_chained_smb2_message(struct ksmbd_work *work);
1659 int init_smb2_neg_rsp(struct ksmbd_work *work);
1660 void smb2_set_err_rsp(struct ksmbd_work *work);
1661 int smb2_check_user_session(struct ksmbd_work *work);
1662 int smb2_get_ksmbd_tcon(struct ksmbd_work *work);
1663 bool smb2_is_sign_req(struct ksmbd_work *work, unsigned int command);
1664 int smb2_check_sign_req(struct ksmbd_work *work);
1665 void smb2_set_sign_rsp(struct ksmbd_work *work);
1666 int smb3_check_sign_req(struct ksmbd_work *work);
1667 void smb3_set_sign_rsp(struct ksmbd_work *work);
1668 int find_matching_smb2_dialect(int start_index, __le16 *cli_dialects,
1669 __le16 dialects_count);
1670 struct file_lock *smb_flock_init(struct file *f);
1671 int setup_async_work(struct ksmbd_work *work, void (*fn)(void **),
1673 void smb2_send_interim_resp(struct ksmbd_work *work, __le32 status);
1674 struct channel *lookup_chann_list(struct ksmbd_session *sess,
1675 struct ksmbd_conn *conn);
1676 void smb3_preauth_hash_rsp(struct ksmbd_work *work);
1677 bool smb3_is_transform_hdr(void *buf);
1678 int smb3_decrypt_req(struct ksmbd_work *work);
1679 int smb3_encrypt_resp(struct ksmbd_work *work);
1680 bool smb3_11_final_sess_setup_resp(struct ksmbd_work *work);
1681 int smb2_set_rsp_credits(struct ksmbd_work *work);
1683 /* smb2 misc functions */
1684 int ksmbd_smb2_check_message(struct ksmbd_work *work);
1686 /* smb2 command handlers */
1687 int smb2_handle_negotiate(struct ksmbd_work *work);
1688 int smb2_negotiate_request(struct ksmbd_work *work);
1689 int smb2_sess_setup(struct ksmbd_work *work);
1690 int smb2_tree_connect(struct ksmbd_work *work);
1691 int smb2_tree_disconnect(struct ksmbd_work *work);
1692 int smb2_session_logoff(struct ksmbd_work *work);
1693 int smb2_open(struct ksmbd_work *work);
1694 int smb2_query_info(struct ksmbd_work *work);
1695 int smb2_query_dir(struct ksmbd_work *work);
1696 int smb2_close(struct ksmbd_work *work);
1697 int smb2_echo(struct ksmbd_work *work);
1698 int smb2_set_info(struct ksmbd_work *work);
1699 int smb2_read(struct ksmbd_work *work);
1700 int smb2_write(struct ksmbd_work *work);
1701 int smb2_flush(struct ksmbd_work *work);
1702 int smb2_cancel(struct ksmbd_work *work);
1703 int smb2_lock(struct ksmbd_work *work);
1704 int smb2_ioctl(struct ksmbd_work *work);
1705 int smb2_oplock_break(struct ksmbd_work *work);
1706 int smb2_notify(struct ksmbd_work *ksmbd_work);
1708 #endif /* _SMB2PDU_H */