1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2016 Namjae Jeon <linkinjeon@kernel.org>
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)
118 * SMB2 Header Definition
120 * "MBZ" : Must be Zero
121 * "BB" : BugBug, Something to check/review/analyze later
122 * "PDU" : "Protocol Data Unit" (ie a network "frame")
126 #define __SMB2_HEADER_STRUCTURE_SIZE 64
127 #define SMB2_HEADER_STRUCTURE_SIZE \
128 cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE)
131 __be32 smb2_buf_length; /* big endian on wire */
133 * length is only two or three bytes - with
134 * one or two byte type preceding it that MBZ
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 */
158 __le16 StructureSize2; /* size of wct area (varies, request specific) */
161 #define SMB3_AES_CCM_NONCE 11
162 #define SMB3_AES_GCM_NONCE 12
164 struct smb2_transform_hdr {
165 __be32 smb2_buf_length; /* big endian on wire */
167 * length is only two or three bytes - with
168 * one or two byte type preceding it that MBZ
170 __le32 ProtocolId; /* 0xFD 'S' 'M' 'B' */
173 __le32 OriginalMessageSize;
175 __le16 Flags; /* EncryptionAlgorithm */
180 * SMB2 flag definitions
182 #define SMB2_FLAGS_SERVER_TO_REDIR cpu_to_le32(0x00000001)
183 #define SMB2_FLAGS_ASYNC_COMMAND cpu_to_le32(0x00000002)
184 #define SMB2_FLAGS_RELATED_OPERATIONS cpu_to_le32(0x00000004)
185 #define SMB2_FLAGS_SIGNED cpu_to_le32(0x00000008)
186 #define SMB2_FLAGS_DFS_OPERATIONS cpu_to_le32(0x10000000)
187 #define SMB2_FLAGS_REPLAY_OPERATIONS cpu_to_le32(0x20000000)
190 * Definitions for SMB2 Protocol Data Units (network frames)
192 * See MS-SMB2.PDF specification for protocol details.
193 * The Naming convention is the lower case version of the SMB2
194 * command code name for the struct. Note that structures must be packed.
198 #define SMB2_ERROR_STRUCTURE_SIZE2 9
199 #define SMB2_ERROR_STRUCTURE_SIZE2_LE cpu_to_le16(SMB2_ERROR_STRUCTURE_SIZE2)
201 struct smb2_err_rsp {
203 __le16 StructureSize;
204 __u8 ErrorContextCount;
206 __le32 ByteCount; /* even if zero, at least one byte follows */
207 __u8 ErrorData[1]; /* variable length */
210 struct smb2_negotiate_req {
212 __le16 StructureSize; /* Must be 36 */
215 __le16 Reserved; /* MBZ */
217 __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE];
218 /* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */
219 __le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */
220 __le16 NegotiateContextCount; /* SMB3.1.1 only. MBZ earlier */
222 __le16 Dialects[1]; /* One dialect (vers=) at a time for now */
225 /* SecurityMode flags */
226 #define SMB2_NEGOTIATE_SIGNING_ENABLED_LE cpu_to_le16(0x0001)
227 #define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
228 #define SMB2_NEGOTIATE_SIGNING_REQUIRED_LE cpu_to_le16(0x0002)
229 /* Capabilities flags */
230 #define SMB2_GLOBAL_CAP_DFS 0x00000001
231 #define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */
232 #define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */
233 #define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */
234 #define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
235 #define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */
236 #define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */
238 #define SMB2_NT_FIND 0x00100000
239 #define SMB2_LARGE_FILES 0x00200000
241 #define SMB311_SALT_SIZE 32
242 /* Hash Algorithm Types */
243 #define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001)
245 #define PREAUTH_HASHVALUE_SIZE 64
247 struct preauth_integrity_info {
248 /* PreAuth integrity Hash ID */
249 __le16 Preauth_HashId;
250 /* PreAuth integrity Hash Value */
251 __u8 Preauth_HashValue[PREAUTH_HASHVALUE_SIZE];
254 /* offset is sizeof smb2_negotiate_rsp - 4 but rounded up to 8 bytes. */
255 #ifdef CONFIG_SMB_SERVER_KERBEROS5
256 /* sizeof(struct smb2_negotiate_rsp) - 4 =
257 * header(64) + response(64) + GSS_LENGTH(96) + GSS_PADDING(0)
259 #define OFFSET_OF_NEG_CONTEXT 0xe0
261 /* sizeof(struct smb2_negotiate_rsp) - 4 =
262 * header(64) + response(64) + GSS_LENGTH(74) + GSS_PADDING(6)
264 #define OFFSET_OF_NEG_CONTEXT 0xd0
267 #define SMB2_PREAUTH_INTEGRITY_CAPABILITIES cpu_to_le16(1)
268 #define SMB2_ENCRYPTION_CAPABILITIES cpu_to_le16(2)
269 #define SMB2_COMPRESSION_CAPABILITIES cpu_to_le16(3)
270 #define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID cpu_to_le16(5)
271 #define SMB2_SIGNING_CAPABILITIES cpu_to_le16(8)
272 #define SMB2_POSIX_EXTENSIONS_AVAILABLE cpu_to_le16(0x100)
274 struct smb2_neg_context {
278 /* Followed by array of data */
281 struct smb2_preauth_neg_context {
282 __le16 ContextType; /* 1 */
285 __le16 HashAlgorithmCount; /* 1 */
287 __le16 HashAlgorithms; /* HashAlgorithms[0] since only one defined */
288 __u8 Salt[SMB311_SALT_SIZE];
291 /* Encryption Algorithms Ciphers */
292 #define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001)
293 #define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002)
294 #define SMB2_ENCRYPTION_AES256_CCM cpu_to_le16(0x0003)
295 #define SMB2_ENCRYPTION_AES256_GCM cpu_to_le16(0x0004)
297 struct smb2_encryption_neg_context {
298 __le16 ContextType; /* 2 */
301 /* CipherCount usally 2, but can be 3 when AES256-GCM enabled */
302 __le16 CipherCount; /* AES-128-GCM and AES-128-CCM by default */
306 #define SMB3_COMPRESS_NONE cpu_to_le16(0x0000)
307 #define SMB3_COMPRESS_LZNT1 cpu_to_le16(0x0001)
308 #define SMB3_COMPRESS_LZ77 cpu_to_le16(0x0002)
309 #define SMB3_COMPRESS_LZ77_HUFF cpu_to_le16(0x0003)
311 struct smb2_compression_ctx {
312 __le16 ContextType; /* 3 */
315 __le16 CompressionAlgorithmCount;
318 __le16 CompressionAlgorithms[];
321 #define POSIX_CTXT_DATA_LEN 16
322 struct smb2_posix_neg_context {
323 __le16 ContextType; /* 0x100 */
326 __u8 Name[16]; /* POSIX ctxt GUID 93AD25509CB411E7B42383DE968BCD7C */
329 struct smb2_netname_neg_context {
330 __le16 ContextType; /* 0x100 */
333 __le16 NetName[]; /* hostname of target converted to UCS-2 */
336 /* Signing algorithms */
337 #define SIGNING_ALG_HMAC_SHA256 cpu_to_le16(0)
338 #define SIGNING_ALG_AES_CMAC cpu_to_le16(1)
339 #define SIGNING_ALG_AES_GMAC cpu_to_le16(2)
341 struct smb2_signing_capabilities {
342 __le16 ContextType; /* 8 */
345 __le16 SigningAlgorithmCount;
346 __le16 SigningAlgorithms[];
349 struct smb2_negotiate_rsp {
351 __le16 StructureSize; /* Must be 65 */
353 __le16 DialectRevision;
354 __le16 NegotiateContextCount; /* Prior to SMB3.1.1 was Reserved & MBZ */
357 __le32 MaxTransactSize;
360 __le64 SystemTime; /* MBZ */
361 __le64 ServerStartTime;
362 __le16 SecurityBufferOffset;
363 __le16 SecurityBufferLength;
364 __le32 NegotiateContextOffset; /* Pre:SMB3.1.1 was reserved/ignored */
365 __u8 Buffer[1]; /* variable length GSS security buffer */
369 #define SMB2_SESSION_REQ_FLAG_BINDING 0x01
370 #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04
372 #define SMB2_SESSION_EXPIRED (0)
373 #define SMB2_SESSION_IN_PROGRESS BIT(0)
374 #define SMB2_SESSION_VALID BIT(1)
377 #define SMB2_SESSION_REQ_FLAG_BINDING 0x01
378 #define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04
380 struct smb2_sess_setup_req {
382 __le16 StructureSize; /* Must be 25 */
387 __le16 SecurityBufferOffset;
388 __le16 SecurityBufferLength;
389 __le64 PreviousSessionId;
390 __u8 Buffer[1]; /* variable length GSS security buffer */
393 /* Flags/Reserved for SMB3.1.1 */
394 #define SMB2_SHAREFLAG_CLUSTER_RECONNECT 0x0001
396 /* Currently defined SessionFlags */
397 #define SMB2_SESSION_FLAG_IS_GUEST_LE cpu_to_le16(0x0001)
398 #define SMB2_SESSION_FLAG_IS_NULL_LE cpu_to_le16(0x0002)
399 #define SMB2_SESSION_FLAG_ENCRYPT_DATA_LE cpu_to_le16(0x0004)
400 struct smb2_sess_setup_rsp {
402 __le16 StructureSize; /* Must be 9 */
404 __le16 SecurityBufferOffset;
405 __le16 SecurityBufferLength;
406 __u8 Buffer[1]; /* variable length GSS security buffer */
409 struct smb2_logoff_req {
411 __le16 StructureSize; /* Must be 4 */
415 struct smb2_logoff_rsp {
417 __le16 StructureSize; /* Must be 4 */
421 struct smb2_tree_connect_req {
423 __le16 StructureSize; /* Must be 9 */
424 __le16 Reserved; /* Flags in SMB3.1.1 */
427 __u8 Buffer[1]; /* variable length */
430 struct smb2_tree_connect_rsp {
432 __le16 StructureSize; /* Must be 16 */
433 __u8 ShareType; /* see below */
435 __le32 ShareFlags; /* see below */
436 __le32 Capabilities; /* see below */
437 __le32 MaximalAccess;
440 /* Possible ShareType values */
441 #define SMB2_SHARE_TYPE_DISK 0x01
442 #define SMB2_SHARE_TYPE_PIPE 0x02
443 #define SMB2_SHARE_TYPE_PRINT 0x03
446 * Possible ShareFlags - exactly one and only one of the first 4 caching flags
447 * must be set (any of the remaining, SHI1005, flags may be set individually
450 #define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000
451 #define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010
452 #define SMB2_SHAREFLAG_VDO_CACHING 0x00000020
453 #define SMB2_SHAREFLAG_NO_CACHING 0x00000030
454 #define SHI1005_FLAGS_DFS 0x00000001
455 #define SHI1005_FLAGS_DFS_ROOT 0x00000002
456 #define SHI1005_FLAGS_RESTRICT_EXCLUSIVE_OPENS 0x00000100
457 #define SHI1005_FLAGS_FORCE_SHARED_DELETE 0x00000200
458 #define SHI1005_FLAGS_ALLOW_NAMESPACE_CACHING 0x00000400
459 #define SHI1005_FLAGS_ACCESS_BASED_DIRECTORY_ENUM 0x00000800
460 #define SHI1005_FLAGS_FORCE_LEVELII_OPLOCK 0x00001000
461 #define SHI1005_FLAGS_ENABLE_HASH 0x00002000
463 /* Possible share capabilities */
464 #define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008)
466 struct smb2_tree_disconnect_req {
468 __le16 StructureSize; /* Must be 4 */
472 struct smb2_tree_disconnect_rsp {
474 __le16 StructureSize; /* Must be 4 */
478 #define ATTR_READONLY_LE cpu_to_le32(ATTR_READONLY)
479 #define ATTR_HIDDEN_LE cpu_to_le32(ATTR_HIDDEN)
480 #define ATTR_SYSTEM_LE cpu_to_le32(ATTR_SYSTEM)
481 #define ATTR_DIRECTORY_LE cpu_to_le32(ATTR_DIRECTORY)
482 #define ATTR_ARCHIVE_LE cpu_to_le32(ATTR_ARCHIVE)
483 #define ATTR_NORMAL_LE cpu_to_le32(ATTR_NORMAL)
484 #define ATTR_TEMPORARY_LE cpu_to_le32(ATTR_TEMPORARY)
485 #define ATTR_SPARSE_FILE_LE cpu_to_le32(ATTR_SPARSE)
486 #define ATTR_REPARSE_POINT_LE cpu_to_le32(ATTR_REPARSE)
487 #define ATTR_COMPRESSED_LE cpu_to_le32(ATTR_COMPRESSED)
488 #define ATTR_OFFLINE_LE cpu_to_le32(ATTR_OFFLINE)
489 #define ATTR_NOT_CONTENT_INDEXED_LE cpu_to_le32(ATTR_NOT_CONTENT_INDEXED)
490 #define ATTR_ENCRYPTED_LE cpu_to_le32(ATTR_ENCRYPTED)
491 #define ATTR_INTEGRITY_STREAML_LE cpu_to_le32(0x00008000)
492 #define ATTR_NO_SCRUB_DATA_LE cpu_to_le32(0x00020000)
493 #define ATTR_MASK_LE cpu_to_le32(0x00007FB7)
496 #define SMB2_OPLOCK_LEVEL_NONE 0x00
497 #define SMB2_OPLOCK_LEVEL_II 0x01
498 #define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
499 #define SMB2_OPLOCK_LEVEL_BATCH 0x09
500 #define SMB2_OPLOCK_LEVEL_LEASE 0xFF
501 /* Non-spec internal type */
502 #define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99
504 /* Desired Access Flags */
505 #define FILE_READ_DATA_LE cpu_to_le32(0x00000001)
506 #define FILE_LIST_DIRECTORY_LE cpu_to_le32(0x00000001)
507 #define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002)
508 #define FILE_ADD_FILE_LE cpu_to_le32(0x00000002)
509 #define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004)
510 #define FILE_ADD_SUBDIRECTORY_LE cpu_to_le32(0x00000004)
511 #define FILE_READ_EA_LE cpu_to_le32(0x00000008)
512 #define FILE_WRITE_EA_LE cpu_to_le32(0x00000010)
513 #define FILE_EXECUTE_LE cpu_to_le32(0x00000020)
514 #define FILE_TRAVERSE_LE cpu_to_le32(0x00000020)
515 #define FILE_DELETE_CHILD_LE cpu_to_le32(0x00000040)
516 #define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080)
517 #define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100)
518 #define FILE_DELETE_LE cpu_to_le32(0x00010000)
519 #define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000)
520 #define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000)
521 #define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000)
522 #define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000)
523 #define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000)
524 #define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000)
525 #define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000)
526 #define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000)
527 #define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000)
528 #define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000)
529 #define DESIRED_ACCESS_MASK cpu_to_le32(0xF21F01FF)
531 /* ShareAccess Flags */
532 #define FILE_SHARE_READ_LE cpu_to_le32(0x00000001)
533 #define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002)
534 #define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004)
535 #define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007)
537 /* CreateDisposition Flags */
538 #define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000)
539 #define FILE_OPEN_LE cpu_to_le32(0x00000001)
540 #define FILE_CREATE_LE cpu_to_le32(0x00000002)
541 #define FILE_OPEN_IF_LE cpu_to_le32(0x00000003)
542 #define FILE_OVERWRITE_LE cpu_to_le32(0x00000004)
543 #define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005)
544 #define FILE_CREATE_MASK_LE cpu_to_le32(0x00000007)
546 #define FILE_READ_DESIRED_ACCESS_LE (FILE_READ_DATA_LE | \
548 FILE_GENERIC_READ_LE)
549 #define FILE_WRITE_DESIRE_ACCESS_LE (FILE_WRITE_DATA_LE | \
550 FILE_APPEND_DATA_LE | \
552 FILE_WRITE_ATTRIBUTES_LE | \
553 FILE_GENERIC_WRITE_LE)
555 /* Impersonation Levels */
556 #define IL_ANONYMOUS_LE cpu_to_le32(0x00000000)
557 #define IL_IDENTIFICATION_LE cpu_to_le32(0x00000001)
558 #define IL_IMPERSONATION_LE cpu_to_le32(0x00000002)
559 #define IL_DELEGATE_LE cpu_to_le32(0x00000003)
561 /* Create Context Values */
562 #define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */
563 #define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */
564 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ"
565 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC"
566 #define SMB2_CREATE_ALLOCATION_SIZE "AlSi"
567 #define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
568 #define SMB2_CREATE_TIMEWARP_REQUEST "TWrp"
569 #define SMB2_CREATE_QUERY_ON_DISK_ID "QFid"
570 #define SMB2_CREATE_REQUEST_LEASE "RqLs"
571 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 "DH2Q"
572 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 "DH2C"
573 #define SMB2_CREATE_APP_INSTANCE_ID "\x45\xBC\xA6\x6A\xEF\xA7\xF7\x4A\x90\x08\xFA\x46\x2E\x14\x4D\x74"
574 #define SMB2_CREATE_APP_INSTANCE_VERSION "\xB9\x82\xD0\xB7\x3B\x56\x07\x4F\xA0\x7B\x52\x4A\x81\x16\xA0\x10"
575 #define SVHDX_OPEN_DEVICE_CONTEXT 0x83CE6F1AD851E0986E34401CC9BCFCE9
576 #define SMB2_CREATE_TAG_POSIX "\x93\xAD\x25\x50\x9C\xB4\x11\xE7\xB4\x23\x83\xDE\x96\x8B\xCD\x7C"
578 struct smb2_create_req {
580 __le16 StructureSize; /* Must be 57 */
582 __u8 RequestedOplockLevel;
583 __le32 ImpersonationLevel;
584 __le64 SmbCreateFlags;
586 __le32 DesiredAccess;
587 __le32 FileAttributes;
589 __le32 CreateDisposition;
590 __le32 CreateOptions;
593 __le32 CreateContextsOffset;
594 __le32 CreateContextsLength;
598 struct smb2_create_rsp {
600 __le16 StructureSize; /* Must be 89 */
605 __le64 LastAccessTime;
606 __le64 LastWriteTime;
608 __le64 AllocationSize;
610 __le32 FileAttributes;
612 __le64 PersistentFileId;
613 __le64 VolatileFileId;
614 __le32 CreateContextsOffset;
615 __le32 CreateContextsLength;
619 struct create_context {
629 struct create_durable_req_v2 {
630 struct create_context ccontext;
638 struct create_durable_reconn_req {
639 struct create_context ccontext;
644 __le64 PersistentFileId;
645 __le64 VolatileFileId;
650 struct create_durable_reconn_v2_req {
651 struct create_context ccontext;
654 __le64 PersistentFileId;
655 __le64 VolatileFileId;
661 struct create_app_inst_id {
662 struct create_context ccontext;
665 __u8 AppInstanceId[16];
668 struct create_app_inst_id_vers {
669 struct create_context ccontext;
673 __le64 AppInstanceVersionHigh;
674 __le64 AppInstanceVersionLow;
677 struct create_mxac_req {
678 struct create_context ccontext;
683 struct create_alloc_size_req {
684 struct create_context ccontext;
686 __le64 AllocationSize;
689 struct create_posix {
690 struct create_context ccontext;
696 struct create_durable_rsp {
697 struct create_context ccontext;
705 struct create_durable_v2_rsp {
706 struct create_context ccontext;
712 struct create_mxac_rsp {
713 struct create_context ccontext;
716 __le32 MaximalAccess;
719 struct create_disk_id_rsp {
720 struct create_context ccontext;
727 /* equivalent of the contents of SMB3.1.1 POSIX open context response */
728 struct create_posix_rsp {
729 struct create_context ccontext;
737 #define SMB2_LEASE_NONE_LE cpu_to_le32(0x00)
738 #define SMB2_LEASE_READ_CACHING_LE cpu_to_le32(0x01)
739 #define SMB2_LEASE_HANDLE_CACHING_LE cpu_to_le32(0x02)
740 #define SMB2_LEASE_WRITE_CACHING_LE cpu_to_le32(0x04)
742 #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE cpu_to_le32(0x02)
744 struct lease_context {
749 __le64 LeaseDuration;
752 struct lease_context_v2 {
757 __le64 LeaseDuration;
758 __le64 ParentLeaseKeyLow;
759 __le64 ParentLeaseKeyHigh;
764 struct create_lease {
765 struct create_context ccontext;
767 struct lease_context lcontext;
770 struct create_lease_v2 {
771 struct create_context ccontext;
773 struct lease_context_v2 lcontext;
777 /* Currently defined values for close flags */
778 #define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
779 struct smb2_close_req {
781 __le16 StructureSize; /* Must be 24 */
784 __le64 PersistentFileId;
785 __le64 VolatileFileId;
788 struct smb2_close_rsp {
790 __le16 StructureSize; /* 60 */
794 __le64 LastAccessTime;
795 __le64 LastWriteTime;
797 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
802 struct smb2_flush_req {
804 __le16 StructureSize; /* Must be 24 */
807 __le64 PersistentFileId;
808 __le64 VolatileFileId;
811 struct smb2_flush_rsp {
813 __le16 StructureSize;
817 struct smb2_buffer_desc_v1 {
823 #define SMB2_CHANNEL_NONE cpu_to_le32(0x00000000)
824 #define SMB2_CHANNEL_RDMA_V1 cpu_to_le32(0x00000001)
825 #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002)
827 struct smb2_read_req {
829 __le16 StructureSize; /* Must be 49 */
830 __u8 Padding; /* offset from start of SMB2 header to place read */
834 __le64 PersistentFileId;
835 __le64 VolatileFileId;
837 __le32 Channel; /* Reserved MBZ */
838 __le32 RemainingBytes;
839 __le16 ReadChannelInfoOffset; /* Reserved MBZ */
840 __le16 ReadChannelInfoLength; /* Reserved MBZ */
844 struct smb2_read_rsp {
846 __le16 StructureSize; /* Must be 17 */
850 __le32 DataRemaining;
855 /* For write request Flags field below the following flag is defined: */
856 #define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001
858 struct smb2_write_req {
860 __le16 StructureSize; /* Must be 49 */
861 __le16 DataOffset; /* offset from start of SMB2 header to write data */
864 __le64 PersistentFileId;
865 __le64 VolatileFileId;
866 __le32 Channel; /* Reserved MBZ */
867 __le32 RemainingBytes;
868 __le16 WriteChannelInfoOffset; /* Reserved MBZ */
869 __le16 WriteChannelInfoLength; /* Reserved MBZ */
874 struct smb2_write_rsp {
876 __le16 StructureSize; /* Must be 17 */
880 __le32 DataRemaining;
885 #define SMB2_0_IOCTL_IS_FSCTL 0x00000001
887 struct duplicate_extents_to_file {
888 __u64 PersistentFileHandle; /* source file handle, opaque endianness */
889 __u64 VolatileFileHandle;
890 __le64 SourceFileOffset;
891 __le64 TargetFileOffset;
892 __le64 ByteCount; /* Bytes to be copied */
895 struct smb2_ioctl_req {
897 __le16 StructureSize; /* Must be 57 */
898 __le16 Reserved; /* offset from start of SMB2 header to write data */
900 __le64 PersistentFileId;
901 __le64 VolatileFileId;
902 __le32 InputOffset; /* Reserved MBZ */
904 __le32 MaxInputResponse;
907 __le32 MaxOutputResponse;
913 struct smb2_ioctl_rsp {
915 __le16 StructureSize; /* Must be 49 */
916 __le16 Reserved; /* offset from start of SMB2 header to write data */
918 __le64 PersistentFileId;
919 __le64 VolatileFileId;
920 __le32 InputOffset; /* Reserved MBZ */
929 struct validate_negotiate_info_req {
931 __u8 Guid[SMB2_CLIENT_GUID_SIZE];
934 __le16 Dialects[1]; /* dialect (someday maybe list) client asked for */
937 struct validate_negotiate_info_rsp {
939 __u8 Guid[SMB2_CLIENT_GUID_SIZE];
941 __le16 Dialect; /* Dialect in use for the connection */
944 struct smb_sockaddr_in {
950 struct smb_sockaddr_in6 {
953 __u8 IPv6address[16];
957 #define INTERNETWORK 0x0002
958 #define INTERNETWORKV6 0x0017
960 struct sockaddr_storage_rsp {
963 struct smb_sockaddr_in addr4;
964 struct smb_sockaddr_in6 addr6;
968 #define RSS_CAPABLE 0x00000001
969 #define RDMA_CAPABLE 0x00000002
971 struct network_interface_info_ioctl_rsp {
972 __le32 Next; /* next interface. zero if this is last one */
974 __le32 Capability; /* RSS or RDMA Capable */
977 char SockAddr_Storage[128];
980 struct file_object_buf_type1_ioctl_rsp {
982 __u8 BirthVolumeId[16];
983 __u8 BirthObjectId[16];
987 struct resume_key_ioctl_rsp {
989 __le32 ContextLength;
990 __u8 Context[4]; /* ignored, Windows sets to 4 bytes of zero */
993 struct copychunk_ioctl_req {
997 __u8 Chunks[1]; /* array of srv_copychunk */
1000 struct srv_copychunk {
1001 __le64 SourceOffset;
1002 __le64 TargetOffset;
1007 struct copychunk_ioctl_rsp {
1008 __le32 ChunksWritten;
1009 __le32 ChunkBytesWritten;
1010 __le32 TotalBytesWritten;
1013 struct file_sparse {
1017 struct file_zero_data_information {
1019 __le64 BeyondFinalZero;
1022 struct file_allocated_range_buffer {
1027 struct reparse_data_buffer {
1029 __le16 ReparseDataLength;
1031 __u8 DataBuffer[]; /* Variable Length */
1034 /* Completion Filter flags for Notify */
1035 #define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001
1036 #define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002
1037 #define FILE_NOTIFY_CHANGE_NAME 0x00000003
1038 #define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004
1039 #define FILE_NOTIFY_CHANGE_SIZE 0x00000008
1040 #define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010
1041 #define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020
1042 #define FILE_NOTIFY_CHANGE_CREATION 0x00000040
1043 #define FILE_NOTIFY_CHANGE_EA 0x00000080
1044 #define FILE_NOTIFY_CHANGE_SECURITY 0x00000100
1045 #define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200
1046 #define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400
1047 #define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
1050 #define SMB2_WATCH_TREE 0x0001
1052 struct smb2_notify_req {
1053 struct smb2_hdr hdr;
1054 __le16 StructureSize; /* Must be 32 */
1056 __le32 OutputBufferLength;
1057 __le64 PersistentFileId;
1058 __le64 VolatileFileId;
1059 __u32 CompletionFileter;
1063 struct smb2_notify_rsp {
1064 struct smb2_hdr hdr;
1065 __le16 StructureSize; /* Must be 9 */
1066 __le16 OutputBufferOffset;
1067 __le32 OutputBufferLength;
1071 /* SMB2 Notify Action Flags */
1072 #define FILE_ACTION_ADDED 0x00000001
1073 #define FILE_ACTION_REMOVED 0x00000002
1074 #define FILE_ACTION_MODIFIED 0x00000003
1075 #define FILE_ACTION_RENAMED_OLD_NAME 0x00000004
1076 #define FILE_ACTION_RENAMED_NEW_NAME 0x00000005
1077 #define FILE_ACTION_ADDED_STREAM 0x00000006
1078 #define FILE_ACTION_REMOVED_STREAM 0x00000007
1079 #define FILE_ACTION_MODIFIED_STREAM 0x00000008
1080 #define FILE_ACTION_REMOVED_BY_DELETE 0x00000009
1082 #define SMB2_LOCKFLAG_SHARED 0x0001
1083 #define SMB2_LOCKFLAG_EXCLUSIVE 0x0002
1084 #define SMB2_LOCKFLAG_UNLOCK 0x0004
1085 #define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010
1086 #define SMB2_LOCKFLAG_MASK 0x0007
1088 struct smb2_lock_element {
1095 struct smb2_lock_req {
1096 struct smb2_hdr hdr;
1097 __le16 StructureSize; /* Must be 48 */
1100 __le64 PersistentFileId;
1101 __le64 VolatileFileId;
1102 /* Followed by at least one */
1103 struct smb2_lock_element locks[1];
1106 struct smb2_lock_rsp {
1107 struct smb2_hdr hdr;
1108 __le16 StructureSize; /* Must be 4 */
1112 struct smb2_echo_req {
1113 struct smb2_hdr hdr;
1114 __le16 StructureSize; /* Must be 4 */
1118 struct smb2_echo_rsp {
1119 struct smb2_hdr hdr;
1120 __le16 StructureSize; /* Must be 4 */
1124 /* search (query_directory) Flags field */
1125 #define SMB2_RESTART_SCANS 0x01
1126 #define SMB2_RETURN_SINGLE_ENTRY 0x02
1127 #define SMB2_INDEX_SPECIFIED 0x04
1128 #define SMB2_REOPEN 0x10
1130 struct smb2_query_directory_req {
1131 struct smb2_hdr hdr;
1132 __le16 StructureSize; /* Must be 33 */
1133 __u8 FileInformationClass;
1136 __le64 PersistentFileId;
1137 __le64 VolatileFileId;
1138 __le16 FileNameOffset;
1139 __le16 FileNameLength;
1140 __le32 OutputBufferLength;
1144 struct smb2_query_directory_rsp {
1145 struct smb2_hdr hdr;
1146 __le16 StructureSize; /* Must be 9 */
1147 __le16 OutputBufferOffset;
1148 __le32 OutputBufferLength;
1152 /* Possible InfoType values */
1153 #define SMB2_O_INFO_FILE 0x01
1154 #define SMB2_O_INFO_FILESYSTEM 0x02
1155 #define SMB2_O_INFO_SECURITY 0x03
1156 #define SMB2_O_INFO_QUOTA 0x04
1158 /* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */
1159 #define OWNER_SECINFO 0x00000001
1160 #define GROUP_SECINFO 0x00000002
1161 #define DACL_SECINFO 0x00000004
1162 #define SACL_SECINFO 0x00000008
1163 #define LABEL_SECINFO 0x00000010
1164 #define ATTRIBUTE_SECINFO 0x00000020
1165 #define SCOPE_SECINFO 0x00000040
1166 #define BACKUP_SECINFO 0x00010000
1167 #define UNPROTECTED_SACL_SECINFO 0x10000000
1168 #define UNPROTECTED_DACL_SECINFO 0x20000000
1169 #define PROTECTED_SACL_SECINFO 0x40000000
1170 #define PROTECTED_DACL_SECINFO 0x80000000
1172 struct smb2_query_info_req {
1173 struct smb2_hdr hdr;
1174 __le16 StructureSize; /* Must be 41 */
1177 __le32 OutputBufferLength;
1178 __le16 InputBufferOffset;
1180 __le32 InputBufferLength;
1181 __le32 AdditionalInformation;
1183 __le64 PersistentFileId;
1184 __le64 VolatileFileId;
1188 struct smb2_query_info_rsp {
1189 struct smb2_hdr hdr;
1190 __le16 StructureSize; /* Must be 9 */
1191 __le16 OutputBufferOffset;
1192 __le32 OutputBufferLength;
1196 struct smb2_set_info_req {
1197 struct smb2_hdr hdr;
1198 __le16 StructureSize; /* Must be 33 */
1201 __le32 BufferLength;
1202 __le16 BufferOffset;
1204 __le32 AdditionalInformation;
1205 __le64 PersistentFileId;
1206 __le64 VolatileFileId;
1210 struct smb2_set_info_rsp {
1211 struct smb2_hdr hdr;
1212 __le16 StructureSize; /* Must be 2 */
1215 /* FILE Info response size */
1216 #define FILE_DIRECTORY_INFORMATION_SIZE 1
1217 #define FILE_FULL_DIRECTORY_INFORMATION_SIZE 2
1218 #define FILE_BOTH_DIRECTORY_INFORMATION_SIZE 3
1219 #define FILE_BASIC_INFORMATION_SIZE 40
1220 #define FILE_STANDARD_INFORMATION_SIZE 24
1221 #define FILE_INTERNAL_INFORMATION_SIZE 8
1222 #define FILE_EA_INFORMATION_SIZE 4
1223 #define FILE_ACCESS_INFORMATION_SIZE 4
1224 #define FILE_NAME_INFORMATION_SIZE 9
1225 #define FILE_RENAME_INFORMATION_SIZE 10
1226 #define FILE_LINK_INFORMATION_SIZE 11
1227 #define FILE_NAMES_INFORMATION_SIZE 12
1228 #define FILE_DISPOSITION_INFORMATION_SIZE 13
1229 #define FILE_POSITION_INFORMATION_SIZE 14
1230 #define FILE_FULL_EA_INFORMATION_SIZE 15
1231 #define FILE_MODE_INFORMATION_SIZE 4
1232 #define FILE_ALIGNMENT_INFORMATION_SIZE 4
1233 #define FILE_ALL_INFORMATION_SIZE 104
1234 #define FILE_ALLOCATION_INFORMATION_SIZE 19
1235 #define FILE_END_OF_FILE_INFORMATION_SIZE 20
1236 #define FILE_ALTERNATE_NAME_INFORMATION_SIZE 8
1237 #define FILE_STREAM_INFORMATION_SIZE 32
1238 #define FILE_PIPE_INFORMATION_SIZE 23
1239 #define FILE_PIPE_LOCAL_INFORMATION_SIZE 24
1240 #define FILE_PIPE_REMOTE_INFORMATION_SIZE 25
1241 #define FILE_MAILSLOT_QUERY_INFORMATION_SIZE 26
1242 #define FILE_MAILSLOT_SET_INFORMATION_SIZE 27
1243 #define FILE_COMPRESSION_INFORMATION_SIZE 16
1244 #define FILE_OBJECT_ID_INFORMATION_SIZE 29
1245 /* Number 30 not defined in documents */
1246 #define FILE_MOVE_CLUSTER_INFORMATION_SIZE 31
1247 #define FILE_QUOTA_INFORMATION_SIZE 32
1248 #define FILE_REPARSE_POINT_INFORMATION_SIZE 33
1249 #define FILE_NETWORK_OPEN_INFORMATION_SIZE 56
1250 #define FILE_ATTRIBUTE_TAG_INFORMATION_SIZE 8
1252 /* FS Info response size */
1253 #define FS_DEVICE_INFORMATION_SIZE 8
1254 #define FS_ATTRIBUTE_INFORMATION_SIZE 16
1255 #define FS_VOLUME_INFORMATION_SIZE 24
1256 #define FS_SIZE_INFORMATION_SIZE 24
1257 #define FS_FULL_SIZE_INFORMATION_SIZE 32
1258 #define FS_SECTOR_SIZE_INFORMATION_SIZE 28
1259 #define FS_OBJECT_ID_INFORMATION_SIZE 64
1260 #define FS_CONTROL_INFORMATION_SIZE 48
1261 #define FS_POSIX_INFORMATION_SIZE 56
1263 /* FS_ATTRIBUTE_File_System_Name */
1264 #define FS_TYPE_SUPPORT_SIZE 44
1265 struct fs_type_info {
1270 struct smb2_oplock_break {
1271 struct smb2_hdr hdr;
1272 __le16 StructureSize; /* Must be 24 */
1276 __le64 PersistentFid;
1280 #define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
1282 struct smb2_lease_break {
1283 struct smb2_hdr hdr;
1284 __le16 StructureSize; /* Must be 44 */
1288 __le32 CurrentLeaseState;
1289 __le32 NewLeaseState;
1291 __le32 AccessMaskHint;
1292 __le32 ShareMaskHint;
1295 struct smb2_lease_ack {
1296 struct smb2_hdr hdr;
1297 __le16 StructureSize; /* Must be 36 */
1302 __le64 LeaseDuration;
1306 * PDU infolevel structure definitions
1307 * BB consider moving to a different header
1310 /* File System Information Classes */
1311 #define FS_VOLUME_INFORMATION 1 /* Query */
1312 #define FS_LABEL_INFORMATION 2 /* Set */
1313 #define FS_SIZE_INFORMATION 3 /* Query */
1314 #define FS_DEVICE_INFORMATION 4 /* Query */
1315 #define FS_ATTRIBUTE_INFORMATION 5 /* Query */
1316 #define FS_CONTROL_INFORMATION 6 /* Query, Set */
1317 #define FS_FULL_SIZE_INFORMATION 7 /* Query */
1318 #define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */
1319 #define FS_DRIVER_PATH_INFORMATION 9 /* Query */
1320 #define FS_SECTOR_SIZE_INFORMATION 11 /* SMB3 or later. Query */
1321 #define FS_POSIX_INFORMATION 100 /* SMB3.1.1 POSIX. Query */
1323 struct smb2_fs_full_size_info {
1324 __le64 TotalAllocationUnits;
1325 __le64 CallerAvailableAllocationUnits;
1326 __le64 ActualAvailableAllocationUnits;
1327 __le32 SectorsPerAllocationUnit;
1328 __le32 BytesPerSector;
1331 #define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001
1332 #define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
1333 #define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004
1334 #define SSINFO_FLAGS_TRIM_ENABLED 0x00000008
1336 /* sector size info struct */
1337 struct smb3_fs_ss_info {
1338 __le32 LogicalBytesPerSector;
1339 __le32 PhysicalBytesPerSectorForAtomicity;
1340 __le32 PhysicalBytesPerSectorForPerf;
1341 __le32 FSEffPhysicalBytesPerSectorForAtomicity;
1343 __le32 ByteOffsetForSectorAlignment;
1344 __le32 ByteOffsetForPartitionAlignment;
1347 /* File System Control Information */
1348 struct smb2_fs_control_info {
1349 __le64 FreeSpaceStartFiltering;
1350 __le64 FreeSpaceThreshold;
1351 __le64 FreeSpaceStopFiltering;
1352 __le64 DefaultQuotaThreshold;
1353 __le64 DefaultQuotaLimit;
1354 __le32 FileSystemControlFlags;
1358 /* partial list of QUERY INFO levels */
1359 #define FILE_DIRECTORY_INFORMATION 1
1360 #define FILE_FULL_DIRECTORY_INFORMATION 2
1361 #define FILE_BOTH_DIRECTORY_INFORMATION 3
1362 #define FILE_BASIC_INFORMATION 4
1363 #define FILE_STANDARD_INFORMATION 5
1364 #define FILE_INTERNAL_INFORMATION 6
1365 #define FILE_EA_INFORMATION 7
1366 #define FILE_ACCESS_INFORMATION 8
1367 #define FILE_NAME_INFORMATION 9
1368 #define FILE_RENAME_INFORMATION 10
1369 #define FILE_LINK_INFORMATION 11
1370 #define FILE_NAMES_INFORMATION 12
1371 #define FILE_DISPOSITION_INFORMATION 13
1372 #define FILE_POSITION_INFORMATION 14
1373 #define FILE_FULL_EA_INFORMATION 15
1374 #define FILE_MODE_INFORMATION 16
1375 #define FILE_ALIGNMENT_INFORMATION 17
1376 #define FILE_ALL_INFORMATION 18
1377 #define FILE_ALLOCATION_INFORMATION 19
1378 #define FILE_END_OF_FILE_INFORMATION 20
1379 #define FILE_ALTERNATE_NAME_INFORMATION 21
1380 #define FILE_STREAM_INFORMATION 22
1381 #define FILE_PIPE_INFORMATION 23
1382 #define FILE_PIPE_LOCAL_INFORMATION 24
1383 #define FILE_PIPE_REMOTE_INFORMATION 25
1384 #define FILE_MAILSLOT_QUERY_INFORMATION 26
1385 #define FILE_MAILSLOT_SET_INFORMATION 27
1386 #define FILE_COMPRESSION_INFORMATION 28
1387 #define FILE_OBJECT_ID_INFORMATION 29
1388 /* Number 30 not defined in documents */
1389 #define FILE_MOVE_CLUSTER_INFORMATION 31
1390 #define FILE_QUOTA_INFORMATION 32
1391 #define FILE_REPARSE_POINT_INFORMATION 33
1392 #define FILE_NETWORK_OPEN_INFORMATION 34
1393 #define FILE_ATTRIBUTE_TAG_INFORMATION 35
1394 #define FILE_TRACKING_INFORMATION 36
1395 #define FILEID_BOTH_DIRECTORY_INFORMATION 37
1396 #define FILEID_FULL_DIRECTORY_INFORMATION 38
1397 #define FILE_VALID_DATA_LENGTH_INFORMATION 39
1398 #define FILE_SHORT_NAME_INFORMATION 40
1399 #define FILE_SFIO_RESERVE_INFORMATION 44
1400 #define FILE_SFIO_VOLUME_INFORMATION 45
1401 #define FILE_HARD_LINK_INFORMATION 46
1402 #define FILE_NORMALIZED_NAME_INFORMATION 48
1403 #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
1404 #define FILE_STANDARD_LINK_INFORMATION 54
1406 #define OP_BREAK_STRUCT_SIZE_20 24
1407 #define OP_BREAK_STRUCT_SIZE_21 36
1409 struct smb2_file_access_info {
1413 struct smb2_file_alignment_info {
1414 __le32 AlignmentRequirement;
1417 struct smb2_file_internal_info {
1419 } __packed; /* level 6 Query */
1421 struct smb2_file_rename_info { /* encoding of request for level 10 */
1422 __u8 ReplaceIfExists; /* 1 = replace existing target with new */
1423 /* 0 = fail if target already exists */
1425 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1426 __le32 FileNameLength;
1427 char FileName[0]; /* New name to be assigned */
1428 } __packed; /* level 10 Set */
1430 struct smb2_file_link_info { /* encoding of request for level 11 */
1431 __u8 ReplaceIfExists; /* 1 = replace existing link with new */
1432 /* 0 = fail if link already exists */
1434 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1435 __le32 FileNameLength;
1436 char FileName[0]; /* Name to be assigned to new link */
1437 } __packed; /* level 11 Set */
1440 * This level 18, although with struct with same name is different from cifs
1441 * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
1442 * CurrentByteOffset.
1444 struct smb2_file_all_info { /* data block encoding of response to level 18 */
1445 __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
1446 __le64 LastAccessTime;
1447 __le64 LastWriteTime;
1450 __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
1451 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
1452 __le64 EndOfFile; /* size ie offset to first free byte in file */
1453 __le32 NumberOfLinks; /* hard links */
1456 __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */
1460 __le64 CurrentByteOffset;
1462 __le32 AlignmentRequirement;
1463 __le32 FileNameLength;
1465 } __packed; /* level 18 Query */
1467 struct smb2_file_basic_info { /* data block encoding of response to level 18 */
1468 __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
1469 __le64 LastAccessTime;
1470 __le64 LastWriteTime;
1473 __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
1476 struct smb2_file_alt_name_info {
1477 __le32 FileNameLength;
1481 struct smb2_file_stream_info {
1482 __le32 NextEntryOffset;
1483 __le32 StreamNameLength;
1485 __le64 StreamAllocationSize;
1489 struct smb2_file_eof_info { /* encoding of request for level 10 */
1490 __le64 EndOfFile; /* new end of file value */
1491 } __packed; /* level 20 Set */
1493 struct smb2_file_ntwrk_info {
1494 __le64 CreationTime;
1495 __le64 LastAccessTime;
1496 __le64 LastWriteTime;
1498 __le64 AllocationSize;
1504 struct smb2_file_standard_info {
1505 __le64 AllocationSize;
1507 __le32 NumberOfLinks; /* hard links */
1511 } __packed; /* level 18 Query */
1513 struct smb2_file_ea_info {
1517 struct smb2_file_alloc_info {
1518 __le64 AllocationSize;
1521 struct smb2_file_disposition_info {
1525 struct smb2_file_pos_info {
1526 __le64 CurrentByteOffset;
1529 #define FILE_MODE_INFO_MASK cpu_to_le32(0x0000103e)
1531 struct smb2_file_mode_info {
1535 #define COMPRESSION_FORMAT_NONE 0x0000
1536 #define COMPRESSION_FORMAT_LZNT1 0x0002
1538 struct smb2_file_comp_info {
1539 __le64 CompressedFileSize;
1540 __le16 CompressionFormat;
1541 __u8 CompressionUnitShift;
1547 struct smb2_file_attr_tag_info {
1548 __le32 FileAttributes;
1552 #define SL_RESTART_SCAN 0x00000001
1553 #define SL_RETURN_SINGLE_ENTRY 0x00000002
1554 #define SL_INDEX_SPECIFIED 0x00000004
1556 struct smb2_ea_info_req {
1557 __le32 NextEntryOffset;
1560 } __packed; /* level 15 Query */
1562 struct smb2_ea_info {
1563 __le32 NextEntryOffset;
1566 __le16 EaValueLength;
1568 /* optionally followed by value */
1569 } __packed; /* level 15 Query */
1571 struct create_ea_buf_req {
1572 struct create_context ccontext;
1574 struct smb2_ea_info ea;
1577 struct create_sd_buf_req {
1578 struct create_context ccontext;
1580 struct smb_ntsd ntsd;
1583 /* Find File infolevels */
1584 #define SMB_FIND_FILE_POSIX_INFO 0x064
1586 /* Level 100 query info */
1587 struct smb311_posix_qinfo {
1588 __le64 CreationTime;
1589 __le64 LastAccessTime;
1590 __le64 LastWriteTime;
1593 __le64 AllocationSize;
1594 __le32 DosAttributes;
1598 /* beginning of POSIX Create Context Response */
1604 * var sized owner SID
1605 * var sized group SID
1606 * le32 filenamelength
1611 struct smb2_posix_info {
1612 __le32 NextEntryOffset;
1614 __le64 CreationTime;
1615 __le64 LastAccessTime;
1616 __le64 LastWriteTime;
1619 __le64 AllocationSize;
1620 __le32 DosAttributes;
1624 /* beginning of POSIX Create Context Response */
1632 * var sized owner SID
1633 * var sized group SID
1634 * le32 filenamelength
1640 int init_smb2_0_server(struct ksmbd_conn *conn);
1641 void init_smb2_1_server(struct ksmbd_conn *conn);
1642 void init_smb3_0_server(struct ksmbd_conn *conn);
1643 void init_smb3_02_server(struct ksmbd_conn *conn);
1644 int init_smb3_11_server(struct ksmbd_conn *conn);
1646 void init_smb2_max_read_size(unsigned int sz);
1647 void init_smb2_max_write_size(unsigned int sz);
1648 void init_smb2_max_trans_size(unsigned int sz);
1650 bool is_smb2_neg_cmd(struct ksmbd_work *work);
1651 bool is_smb2_rsp(struct ksmbd_work *work);
1653 u16 get_smb2_cmd_val(struct ksmbd_work *work);
1654 void set_smb2_rsp_status(struct ksmbd_work *work, __le32 err);
1655 int init_smb2_rsp_hdr(struct ksmbd_work *work);
1656 int smb2_allocate_rsp_buf(struct ksmbd_work *work);
1657 bool is_chained_smb2_message(struct ksmbd_work *work);
1658 int init_smb2_neg_rsp(struct ksmbd_work *work);
1659 void smb2_set_err_rsp(struct ksmbd_work *work);
1660 int smb2_check_user_session(struct ksmbd_work *work);
1661 int smb2_get_ksmbd_tcon(struct ksmbd_work *work);
1662 bool smb2_is_sign_req(struct ksmbd_work *work, unsigned int command);
1663 int smb2_check_sign_req(struct ksmbd_work *work);
1664 void smb2_set_sign_rsp(struct ksmbd_work *work);
1665 int smb3_check_sign_req(struct ksmbd_work *work);
1666 void smb3_set_sign_rsp(struct ksmbd_work *work);
1667 int find_matching_smb2_dialect(int start_index, __le16 *cli_dialects,
1668 __le16 dialects_count);
1669 struct file_lock *smb_flock_init(struct file *f);
1670 int setup_async_work(struct ksmbd_work *work, void (*fn)(void **),
1672 void smb2_send_interim_resp(struct ksmbd_work *work, __le32 status);
1673 struct channel *lookup_chann_list(struct ksmbd_session *sess,
1674 struct ksmbd_conn *conn);
1675 void smb3_preauth_hash_rsp(struct ksmbd_work *work);
1676 bool smb3_is_transform_hdr(void *buf);
1677 int smb3_decrypt_req(struct ksmbd_work *work);
1678 int smb3_encrypt_resp(struct ksmbd_work *work);
1679 bool smb3_11_final_sess_setup_resp(struct ksmbd_work *work);
1680 int smb2_set_rsp_credits(struct ksmbd_work *work);
1682 /* smb2 misc functions */
1683 int ksmbd_smb2_check_message(struct ksmbd_work *work);
1685 /* smb2 command handlers */
1686 int smb2_handle_negotiate(struct ksmbd_work *work);
1687 int smb2_negotiate_request(struct ksmbd_work *work);
1688 int smb2_sess_setup(struct ksmbd_work *work);
1689 int smb2_tree_connect(struct ksmbd_work *work);
1690 int smb2_tree_disconnect(struct ksmbd_work *work);
1691 int smb2_session_logoff(struct ksmbd_work *work);
1692 int smb2_open(struct ksmbd_work *work);
1693 int smb2_query_info(struct ksmbd_work *work);
1694 int smb2_query_dir(struct ksmbd_work *work);
1695 int smb2_close(struct ksmbd_work *work);
1696 int smb2_echo(struct ksmbd_work *work);
1697 int smb2_set_info(struct ksmbd_work *work);
1698 int smb2_read(struct ksmbd_work *work);
1699 int smb2_write(struct ksmbd_work *work);
1700 int smb2_flush(struct ksmbd_work *work);
1701 int smb2_cancel(struct ksmbd_work *work);
1702 int smb2_lock(struct ksmbd_work *work);
1703 int smb2_ioctl(struct ksmbd_work *work);
1704 int smb2_oplock_break(struct ksmbd_work *work);
1705 int smb2_notify(struct ksmbd_work *ksmbd_work);
1707 #endif /* _SMB2PDU_H */