Merge tag 'locking-core-2023-05-05' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-block.git] / fs / smbfs_common / smb2pdu.h
CommitLineData
0d35e382
RS
1/* SPDX-License-Identifier: LGPL-2.1 */
2#ifndef _COMMON_SMB2PDU_H
3#define _COMMON_SMB2PDU_H
4
5/*
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.
10 *
11 * SMB2 commands
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.
15 */
16
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
37
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)
58
59#define SMB2_INTERNAL_CMD cpu_to_le16(0xFFFF)
60
61#define NUMBER_OF_SMB2_COMMANDS 0x0013
62
15e7b6d7
SF
63/*
64 * Size of the session key (crypto key encrypted with the password
65 */
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
72
73/*
74 * Size of the smb3 encryption/decryption keys
75 * This size is big enough to store any cipher key types.
76 */
77#define SMB3_ENC_DEC_KEY_SIZE 32
78
79/*
80 * Size of the smb3 signing key
81 */
82#define SMB3_SIGN_KEY_SIZE 16
83
84#define CIFS_CLIENT_CHALLENGE_SIZE 8
85
86/* Maximum buffer size value we can send with 1 credit */
87#define SMB2_MAX_BUFFER_SIZE 65536
88
89/*
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.
94 */
95#define SMB3_DEFAULT_IOSIZE (4 * 1024 * 1024)
96
0d35e382
RS
97/*
98 * SMB2 Header Definition
99 *
100 * "MBZ" : Must be Zero
101 * "BB" : BugBug, Something to check/review/analyze later
102 * "PDU" : "Protocol Data Unit" (ie a network "frame")
103 *
104 */
105
106#define __SMB2_HEADER_STRUCTURE_SIZE 64
107#define SMB2_HEADER_STRUCTURE_SIZE \
108 cpu_to_le16(__SMB2_HEADER_STRUCTURE_SIZE)
109
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)
113
114/*
115 * SMB2 flag definitions
116 */
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 */
124
15e7b6d7
SF
125/*
126 * Definitions for SMB2 Protocol Data Units (network frames)
127 *
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.
131 *
132 */
133
0d35e382
RS
134/* See MS-SMB2 section 2.2.1 */
135struct smb2_hdr {
136 __le32 ProtocolId; /* 0xFE 'S' 'M' 'B' */
137 __le16 StructureSize; /* 64 */
138 __le16 CreditCharge; /* MBZ */
139 __le32 Status; /* Error from server */
140 __le16 Command;
141 __le16 CreditRequest; /* CreditResponse */
142 __le32 Flags;
143 __le32 NextCommand;
144 __le64 MessageId;
145 union {
146 struct {
147 __le32 ProcessId;
148 __le32 TreeId;
149 } __packed SyncId;
150 __le64 AsyncId;
151 } __packed Id;
152 __le64 SessionId;
153 __u8 Signature[16];
154} __packed;
155
156struct smb2_pdu {
157 struct smb2_hdr hdr;
158 __le16 StructureSize2; /* size of wct area (varies, request specific) */
159} __packed;
160
113be37d
SF
161#define SMB2_ERROR_STRUCTURE_SIZE2 9
162#define SMB2_ERROR_STRUCTURE_SIZE2_LE cpu_to_le16(SMB2_ERROR_STRUCTURE_SIZE2)
163
164struct smb2_err_rsp {
165 struct smb2_hdr hdr;
166 __le16 StructureSize;
167 __u8 ErrorContextCount;
168 __u8 Reserved;
169 __le32 ByteCount; /* even if zero, at least one byte follows */
eb3e28c1 170 __u8 ErrorData[]; /* variable length */
113be37d
SF
171} __packed;
172
0d35e382
RS
173#define SMB3_AES_CCM_NONCE 11
174#define SMB3_AES_GCM_NONCE 12
175
176/* Transform flags (for 3.0 dialect this flag indicates CCM */
177#define TRANSFORM_FLAG_ENCRYPTED 0x0001
178struct smb2_transform_hdr {
179 __le32 ProtocolId; /* 0xFD 'S' 'M' 'B' */
180 __u8 Signature[16];
181 __u8 Nonce[16];
182 __le32 OriginalMessageSize;
183 __u16 Reserved1;
184 __le16 Flags; /* EncryptionAlgorithm for 3.0, enc enabled for 3.1.1 */
185 __le64 SessionId;
186} __packed;
187
188
189/* See MS-SMB2 2.2.42 */
190struct smb2_compression_transform_hdr_unchained {
191 __le32 ProtocolId; /* 0xFC 'S' 'M' 'B' */
192 __le32 OriginalCompressedSegmentSize;
193 __le16 CompressionAlgorithm;
194 __le16 Flags;
195 __le16 Length; /* if chained it is length, else offset */
196} __packed;
197
198/* See MS-SMB2 2.2.42.1 */
199#define SMB2_COMPRESSION_FLAG_NONE 0x0000
200#define SMB2_COMPRESSION_FLAG_CHAINED 0x0001
201
202struct compression_payload_header {
203 __le16 CompressionAlgorithm;
204 __le16 Flags;
205 __le32 Length; /* length of compressed playload including field below if present */
206 /* __le32 OriginalPayloadSize; */ /* optional, present when LZNT1, LZ77, LZ77+Huffman */
207} __packed;
208
209/* See MS-SMB2 2.2.42.2 */
210struct smb2_compression_transform_hdr_chained {
211 __le32 ProtocolId; /* 0xFC 'S' 'M' 'B' */
212 __le32 OriginalCompressedSegmentSize;
213 /* struct compression_payload_header[] */
214} __packed;
215
216/* See MS-SMB2 2.2.42.2.2 */
217struct compression_pattern_payload_v1 {
218 __le16 Pattern;
219 __le16 Reserved1;
220 __le16 Reserved2;
221 __le32 Repetitions;
222} __packed;
223
224/* See MS-SMB2 section 2.2.9.2 */
225/* Context Types */
226#define SMB2_RESERVED_TREE_CONNECT_CONTEXT_ID 0x0000
227#define SMB2_REMOTED_IDENTITY_TREE_CONNECT_CONTEXT_ID cpu_to_le16(0x0001)
228
229struct tree_connect_contexts {
230 __le16 ContextType;
231 __le16 DataLength;
232 __le32 Reserved;
233 __u8 Data[];
234} __packed;
235
236/* Remoted identity tree connect context structures - see MS-SMB2 2.2.9.2.1 */
237struct smb3_blob_data {
238 __le16 BlobSize;
239 __u8 BlobData[];
240} __packed;
241
242/* Valid values for Attr */
243#define SE_GROUP_MANDATORY 0x00000001
244#define SE_GROUP_ENABLED_BY_DEFAULT 0x00000002
245#define SE_GROUP_ENABLED 0x00000004
246#define SE_GROUP_OWNER 0x00000008
247#define SE_GROUP_USE_FOR_DENY_ONLY 0x00000010
248#define SE_GROUP_INTEGRITY 0x00000020
249#define SE_GROUP_INTEGRITY_ENABLED 0x00000040
250#define SE_GROUP_RESOURCE 0x20000000
251#define SE_GROUP_LOGON_ID 0xC0000000
252
253/* struct sid_attr_data is SidData array in BlobData format then le32 Attr */
254
255struct sid_array_data {
256 __le16 SidAttrCount;
257 /* SidAttrList - array of sid_attr_data structs */
258} __packed;
259
260struct luid_attr_data {
261
262} __packed;
263
264/*
265 * struct privilege_data is the same as BLOB_DATA - see MS-SMB2 2.2.9.2.1.5
266 * but with size of LUID_ATTR_DATA struct and BlobData set to LUID_ATTR DATA
267 */
268
269struct privilege_array_data {
270 __le16 PrivilegeCount;
271 /* array of privilege_data structs */
272} __packed;
273
274struct remoted_identity_tcon_context {
275 __le16 TicketType; /* must be 0x0001 */
276 __le16 TicketSize; /* total size of this struct */
277 __le16 User; /* offset to SID_ATTR_DATA struct with user info */
278 __le16 UserName; /* offset to null terminated Unicode username string */
279 __le16 Domain; /* offset to null terminated Unicode domain name */
280 __le16 Groups; /* offset to SID_ARRAY_DATA struct with group info */
281 __le16 RestrictedGroups; /* similar to above */
282 __le16 Privileges; /* offset to PRIVILEGE_ARRAY_DATA struct */
283 __le16 PrimaryGroup; /* offset to SID_ARRAY_DATA struct */
284 __le16 Owner; /* offset to BLOB_DATA struct */
285 __le16 DefaultDacl; /* offset to BLOB_DATA struct */
286 __le16 DeviceGroups; /* offset to SID_ARRAY_DATA struct */
287 __le16 UserClaims; /* offset to BLOB_DATA struct */
288 __le16 DeviceClaims; /* offset to BLOB_DATA struct */
289 __u8 TicketInfo[]; /* variable length buf - remoted identity data */
290} __packed;
291
292struct smb2_tree_connect_req_extension {
293 __le32 TreeConnectContextOffset;
294 __le16 TreeConnectContextCount;
295 __u8 Reserved[10];
296 __u8 PathName[]; /* variable sized array */
297 /* followed by array of TreeConnectContexts */
298} __packed;
299
300/* Flags/Reserved for SMB3.1.1 */
301#define SMB2_TREE_CONNECT_FLAG_CLUSTER_RECONNECT cpu_to_le16(0x0001)
302#define SMB2_TREE_CONNECT_FLAG_REDIRECT_TO_OWNER cpu_to_le16(0x0002)
303#define SMB2_TREE_CONNECT_FLAG_EXTENSION_PRESENT cpu_to_le16(0x0004)
304
305struct smb2_tree_connect_req {
306 struct smb2_hdr hdr;
307 __le16 StructureSize; /* Must be 9 */
308 __le16 Flags; /* Flags in SMB3.1.1 */
309 __le16 PathOffset;
310 __le16 PathLength;
eb3e28c1 311 __u8 Buffer[]; /* variable length */
0d35e382
RS
312} __packed;
313
314/* Possible ShareType values */
315#define SMB2_SHARE_TYPE_DISK 0x01
316#define SMB2_SHARE_TYPE_PIPE 0x02
317#define SMB2_SHARE_TYPE_PRINT 0x03
318
319/*
320 * Possible ShareFlags - exactly one and only one of the first 4 caching flags
321 * must be set (any of the remaining, SHI1005, flags may be set individually
322 * or in combination.
323 */
324#define SMB2_SHAREFLAG_MANUAL_CACHING 0x00000000
325#define SMB2_SHAREFLAG_AUTO_CACHING 0x00000010
326#define SMB2_SHAREFLAG_VDO_CACHING 0x00000020
327#define SMB2_SHAREFLAG_NO_CACHING 0x00000030
328#define SHI1005_FLAGS_DFS 0x00000001
329#define SHI1005_FLAGS_DFS_ROOT 0x00000002
c09ba02c
SF
330#define SMB2_SHAREFLAG_RESTRICT_EXCLUSIVE_OPENS 0x00000100
331#define SMB2_SHAREFLAG_FORCE_SHARED_DELETE 0x00000200
332#define SMB2_SHAREFLAG_ALLOW_NAMESPACE_CACHING 0x00000400
333#define SMB2_SHAREFLAG_ACCESS_BASED_DIRECTORY_ENUM 0x00000800
334#define SMB2_SHAREFLAG_FORCE_LEVELII_OPLOCK 0x00001000
335#define SMB2_SHAREFLAG_ENABLE_HASH_V1 0x00002000
336#define SMB2_SHAREFLAG_ENABLE_HASH_V2 0x00004000
0d35e382
RS
337#define SHI1005_FLAGS_ENCRYPT_DATA 0x00008000
338#define SMB2_SHAREFLAG_IDENTITY_REMOTING 0x00040000 /* 3.1.1 */
339#define SMB2_SHAREFLAG_COMPRESS_DATA 0x00100000 /* 3.1.1 */
c09ba02c
SF
340#define SMB2_SHAREFLAG_ISOLATED_TRANSPORT 0x00200000
341#define SHI1005_FLAGS_ALL 0x0034FF33
0d35e382
RS
342
343/* Possible share capabilities */
344#define SMB2_SHARE_CAP_DFS cpu_to_le32(0x00000008) /* all dialects */
345#define SMB2_SHARE_CAP_CONTINUOUS_AVAILABILITY cpu_to_le32(0x00000010) /* 3.0 */
346#define SMB2_SHARE_CAP_SCALEOUT cpu_to_le32(0x00000020) /* 3.0 */
347#define SMB2_SHARE_CAP_CLUSTER cpu_to_le32(0x00000040) /* 3.0 */
348#define SMB2_SHARE_CAP_ASYMMETRIC cpu_to_le32(0x00000080) /* 3.02 */
349#define SMB2_SHARE_CAP_REDIRECT_TO_OWNER cpu_to_le32(0x00000100) /* 3.1.1 */
350
351struct smb2_tree_connect_rsp {
352 struct smb2_hdr hdr;
353 __le16 StructureSize; /* Must be 16 */
354 __u8 ShareType; /* see below */
355 __u8 Reserved;
356 __le32 ShareFlags; /* see below */
357 __le32 Capabilities; /* see below */
358 __le32 MaximalAccess;
359} __packed;
360
361struct smb2_tree_disconnect_req {
362 struct smb2_hdr hdr;
363 __le16 StructureSize; /* Must be 4 */
364 __le16 Reserved;
365} __packed;
366
367struct smb2_tree_disconnect_rsp {
368 struct smb2_hdr hdr;
369 __le16 StructureSize; /* Must be 4 */
370 __le16 Reserved;
371} __packed;
372
373
fc0b3844
RS
374/*
375 * SMB2_NEGOTIATE_PROTOCOL See MS-SMB2 section 2.2.3
376 */
377/* SecurityMode flags */
378#define SMB2_NEGOTIATE_SIGNING_ENABLED 0x0001
379#define SMB2_NEGOTIATE_SIGNING_ENABLED_LE cpu_to_le16(0x0001)
380#define SMB2_NEGOTIATE_SIGNING_REQUIRED 0x0002
381#define SMB2_NEGOTIATE_SIGNING_REQUIRED_LE cpu_to_le16(0x0002)
382#define SMB2_SEC_MODE_FLAGS_ALL 0x0003
383
384/* Capabilities flags */
385#define SMB2_GLOBAL_CAP_DFS 0x00000001
386#define SMB2_GLOBAL_CAP_LEASING 0x00000002 /* Resp only New to SMB2.1 */
387#define SMB2_GLOBAL_CAP_LARGE_MTU 0X00000004 /* Resp only New to SMB2.1 */
388#define SMB2_GLOBAL_CAP_MULTI_CHANNEL 0x00000008 /* New to SMB3 */
389#define SMB2_GLOBAL_CAP_PERSISTENT_HANDLES 0x00000010 /* New to SMB3 */
390#define SMB2_GLOBAL_CAP_DIRECTORY_LEASING 0x00000020 /* New to SMB3 */
391#define SMB2_GLOBAL_CAP_ENCRYPTION 0x00000040 /* New to SMB3 */
392/* Internal types */
393#define SMB2_NT_FIND 0x00100000
394#define SMB2_LARGE_FILES 0x00200000
395
396#define SMB2_CLIENT_GUID_SIZE 16
397#define SMB2_CREATE_GUID_SIZE 16
398
399/* Dialects */
400#define SMB10_PROT_ID 0x0000 /* local only, not sent on wire w/CIFS negprot */
401#define SMB20_PROT_ID 0x0202
402#define SMB21_PROT_ID 0x0210
403#define SMB2X_PROT_ID 0x02FF
404#define SMB30_PROT_ID 0x0300
405#define SMB302_PROT_ID 0x0302
406#define SMB311_PROT_ID 0x0311
407#define BAD_PROT_ID 0xFFFF
408
409#define SMB311_SALT_SIZE 32
410/* Hash Algorithm Types */
411#define SMB2_PREAUTH_INTEGRITY_SHA512 cpu_to_le16(0x0001)
412#define SMB2_PREAUTH_HASH_SIZE 64
413
414/* Negotiate Contexts - ContextTypes. See MS-SMB2 section 2.2.3.1 for details */
415#define SMB2_PREAUTH_INTEGRITY_CAPABILITIES cpu_to_le16(1)
416#define SMB2_ENCRYPTION_CAPABILITIES cpu_to_le16(2)
417#define SMB2_COMPRESSION_CAPABILITIES cpu_to_le16(3)
418#define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID cpu_to_le16(5)
419#define SMB2_TRANSPORT_CAPABILITIES cpu_to_le16(6)
420#define SMB2_RDMA_TRANSFORM_CAPABILITIES cpu_to_le16(7)
421#define SMB2_SIGNING_CAPABILITIES cpu_to_le16(8)
422#define SMB2_POSIX_EXTENSIONS_AVAILABLE cpu_to_le16(0x100)
423
424struct smb2_neg_context {
425 __le16 ContextType;
426 __le16 DataLength;
427 __le32 Reserved;
428 /* Followed by array of data. NOTE: some servers require padding to 8 byte boundary */
429} __packed;
430
431/*
432 * SaltLength that the server send can be zero, so the only three required
433 * fields (all __le16) end up six bytes total, so the minimum context data len
434 * in the response is six bytes which accounts for
435 *
436 * HashAlgorithmCount, SaltLength, and 1 HashAlgorithm.
437 */
438#define MIN_PREAUTH_CTXT_DATA_LEN 6
439
440struct smb2_preauth_neg_context {
441 __le16 ContextType; /* 1 */
442 __le16 DataLength;
443 __le32 Reserved;
444 __le16 HashAlgorithmCount; /* 1 */
445 __le16 SaltLength;
446 __le16 HashAlgorithms; /* HashAlgorithms[0] since only one defined */
447 __u8 Salt[SMB311_SALT_SIZE];
448} __packed;
449
450/* Encryption Algorithms Ciphers */
451#define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001)
452#define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002)
453#define SMB2_ENCRYPTION_AES256_CCM cpu_to_le16(0x0003)
454#define SMB2_ENCRYPTION_AES256_GCM cpu_to_le16(0x0004)
455
456/* Min encrypt context data is one cipher so 2 bytes + 2 byte count field */
457#define MIN_ENCRYPT_CTXT_DATA_LEN 4
458struct smb2_encryption_neg_context {
459 __le16 ContextType; /* 2 */
460 __le16 DataLength;
461 __le32 Reserved;
462 /* CipherCount usally 2, but can be 3 when AES256-GCM enabled */
463 __le16 CipherCount; /* AES128-GCM and AES128-CCM by default */
464 __le16 Ciphers[];
465} __packed;
466
467/* See MS-SMB2 2.2.3.1.3 */
468#define SMB3_COMPRESS_NONE cpu_to_le16(0x0000)
469#define SMB3_COMPRESS_LZNT1 cpu_to_le16(0x0001)
470#define SMB3_COMPRESS_LZ77 cpu_to_le16(0x0002)
471#define SMB3_COMPRESS_LZ77_HUFF cpu_to_le16(0x0003)
472/* Pattern scanning algorithm See MS-SMB2 3.1.4.4.1 */
473#define SMB3_COMPRESS_PATTERN cpu_to_le16(0x0004) /* Pattern_V1 */
474
475/* Compression Flags */
476#define SMB2_COMPRESSION_CAPABILITIES_FLAG_NONE cpu_to_le32(0x00000000)
477#define SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED cpu_to_le32(0x00000001)
478
479struct smb2_compression_capabilities_context {
480 __le16 ContextType; /* 3 */
481 __le16 DataLength;
482 __le32 Reserved;
483 __le16 CompressionAlgorithmCount;
484 __le16 Padding;
485 __le32 Flags;
486 __le16 CompressionAlgorithms[3];
487 __u16 Pad; /* Some servers require pad to DataLen multiple of 8 */
488 /* Check if pad needed */
489} __packed;
490
491/*
492 * For smb2_netname_negotiate_context_id See MS-SMB2 2.2.3.1.4.
493 * Its struct simply contains NetName, an array of Unicode characters
494 */
495struct smb2_netname_neg_context {
496 __le16 ContextType; /* 5 */
497 __le16 DataLength;
498 __le32 Reserved;
499 __le16 NetName[]; /* hostname of target converted to UCS-2 */
500} __packed;
501
502/*
503 * For smb2_transport_capabilities context see MS-SMB2 2.2.3.1.5
504 * and 2.2.4.1.5
505 */
506
507/* Flags */
e4e2787b 508#define SMB2_ACCEPT_TRANSPORT_LEVEL_SECURITY 0x00000001
fc0b3844
RS
509
510struct smb2_transport_capabilities_context {
511 __le16 ContextType; /* 6 */
512 __le16 DataLength;
513 __u32 Reserved;
514 __le32 Flags;
515 __u32 Pad;
516} __packed;
517
518/*
519 * For rdma transform capabilities context see MS-SMB2 2.2.3.1.6
520 * and 2.2.4.1.6
521 */
522
523/* RDMA Transform IDs */
524#define SMB2_RDMA_TRANSFORM_NONE 0x0000
525#define SMB2_RDMA_TRANSFORM_ENCRYPTION 0x0001
526#define SMB2_RDMA_TRANSFORM_SIGNING 0x0002
527
528struct smb2_rdma_transform_capabilities_context {
529 __le16 ContextType; /* 7 */
530 __le16 DataLength;
531 __u32 Reserved;
532 __le16 TransformCount;
533 __u16 Reserved1;
534 __u32 Reserved2;
535 __le16 RDMATransformIds[];
536} __packed;
537
538/*
539 * For signing capabilities context see MS-SMB2 2.2.3.1.7
540 * and 2.2.4.1.7
541 */
542
543/* Signing algorithms */
544#define SIGNING_ALG_HMAC_SHA256 0
545#define SIGNING_ALG_HMAC_SHA256_LE cpu_to_le16(0)
546#define SIGNING_ALG_AES_CMAC 1
547#define SIGNING_ALG_AES_CMAC_LE cpu_to_le16(1)
548#define SIGNING_ALG_AES_GMAC 2
549#define SIGNING_ALG_AES_GMAC_LE cpu_to_le16(2)
550
551struct smb2_signing_capabilities {
552 __le16 ContextType; /* 8 */
553 __le16 DataLength;
554 __le32 Reserved;
555 __le16 SigningAlgorithmCount;
556 __le16 SigningAlgorithms[];
557 /* Followed by padding to 8 byte boundary (required by some servers) */
558} __packed;
559
560#define POSIX_CTXT_DATA_LEN 16
561struct smb2_posix_neg_context {
562 __le16 ContextType; /* 0x100 */
563 __le16 DataLength;
564 __le32 Reserved;
565 __u8 Name[16]; /* POSIX ctxt GUID 93AD25509CB411E7B42383DE968BCD7C */
566} __packed;
567
568struct smb2_negotiate_req {
569 struct smb2_hdr hdr;
570 __le16 StructureSize; /* Must be 36 */
571 __le16 DialectCount;
572 __le16 SecurityMode;
573 __le16 Reserved; /* MBZ */
574 __le32 Capabilities;
575 __u8 ClientGUID[SMB2_CLIENT_GUID_SIZE];
576 /* In SMB3.02 and earlier next three were MBZ le64 ClientStartTime */
577 __le32 NegotiateContextOffset; /* SMB3.1.1 only. MBZ earlier */
578 __le16 NegotiateContextCount; /* SMB3.1.1 only. MBZ earlier */
579 __le16 Reserved2;
580 __le16 Dialects[];
581} __packed;
582
583struct smb2_negotiate_rsp {
584 struct smb2_hdr hdr;
585 __le16 StructureSize; /* Must be 65 */
586 __le16 SecurityMode;
587 __le16 DialectRevision;
588 __le16 NegotiateContextCount; /* Prior to SMB3.1.1 was Reserved & MBZ */
589 __u8 ServerGUID[16];
590 __le32 Capabilities;
591 __le32 MaxTransactSize;
592 __le32 MaxReadSize;
593 __le32 MaxWriteSize;
594 __le64 SystemTime; /* MBZ */
595 __le64 ServerStartTime;
596 __le16 SecurityBufferOffset;
597 __le16 SecurityBufferLength;
598 __le32 NegotiateContextOffset; /* Pre:SMB3.1.1 was reserved/ignored */
eb3e28c1 599 __u8 Buffer[]; /* variable length GSS security buffer */
fc0b3844
RS
600} __packed;
601
602
d8d9de53
RS
603/*
604 * SMB2_SESSION_SETUP See MS-SMB2 section 2.2.5
605 */
606/* Flags */
607#define SMB2_SESSION_REQ_FLAG_BINDING 0x01
608#define SMB2_SESSION_REQ_FLAG_ENCRYPT_DATA 0x04
609
610struct smb2_sess_setup_req {
611 struct smb2_hdr hdr;
612 __le16 StructureSize; /* Must be 25 */
613 __u8 Flags;
614 __u8 SecurityMode;
615 __le32 Capabilities;
616 __le32 Channel;
617 __le16 SecurityBufferOffset;
618 __le16 SecurityBufferLength;
619 __le64 PreviousSessionId;
eb3e28c1 620 __u8 Buffer[]; /* variable length GSS security buffer */
d8d9de53
RS
621} __packed;
622
623/* Currently defined SessionFlags */
624#define SMB2_SESSION_FLAG_IS_GUEST 0x0001
625#define SMB2_SESSION_FLAG_IS_GUEST_LE cpu_to_le16(0x0001)
626#define SMB2_SESSION_FLAG_IS_NULL 0x0002
627#define SMB2_SESSION_FLAG_IS_NULL_LE cpu_to_le16(0x0002)
628#define SMB2_SESSION_FLAG_ENCRYPT_DATA 0x0004
629#define SMB2_SESSION_FLAG_ENCRYPT_DATA_LE cpu_to_le16(0x0004)
630
631struct smb2_sess_setup_rsp {
632 struct smb2_hdr hdr;
633 __le16 StructureSize; /* Must be 9 */
634 __le16 SessionFlags;
635 __le16 SecurityBufferOffset;
636 __le16 SecurityBufferLength;
eb3e28c1 637 __u8 Buffer[]; /* variable length GSS security buffer */
d8d9de53
RS
638} __packed;
639
640
641/*
642 * SMB2_LOGOFF See MS-SMB2 section 2.2.7
643 */
644struct smb2_logoff_req {
645 struct smb2_hdr hdr;
646 __le16 StructureSize; /* Must be 4 */
647 __le16 Reserved;
648} __packed;
649
650struct smb2_logoff_rsp {
651 struct smb2_hdr hdr;
652 __le16 StructureSize; /* Must be 4 */
653 __le16 Reserved;
654} __packed;
655
656
657/*
658 * SMB2_CLOSE See MS-SMB2 section 2.2.15
659 */
660/* Currently defined values for close flags */
661#define SMB2_CLOSE_FLAG_POSTQUERY_ATTRIB cpu_to_le16(0x0001)
662struct smb2_close_req {
663 struct smb2_hdr hdr;
664 __le16 StructureSize; /* Must be 24 */
665 __le16 Flags;
666 __le32 Reserved;
351a59da
PA
667 __u64 PersistentFileId; /* opaque endianness */
668 __u64 VolatileFileId; /* opaque endianness */
d8d9de53
RS
669} __packed;
670
671/*
672 * Maximum size of a SMB2_CLOSE response is 64 (smb2 header) + 60 (data)
673 */
674#define MAX_SMB2_CLOSE_RESPONSE_SIZE 124
675
676struct smb2_close_rsp {
677 struct smb2_hdr hdr;
678 __le16 StructureSize; /* 60 */
679 __le16 Flags;
680 __le32 Reserved;
681 __le64 CreationTime;
682 __le64 LastAccessTime;
683 __le64 LastWriteTime;
684 __le64 ChangeTime;
685 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
686 __le64 EndOfFile;
687 __le32 Attributes;
688} __packed;
689
690
691/*
692 * SMB2_READ See MS-SMB2 section 2.2.19
693 */
694/* For read request Flags field below, following flag is defined for SMB3.02 */
695#define SMB2_READFLAG_READ_UNBUFFERED 0x01
696#define SMB2_READFLAG_REQUEST_COMPRESSED 0x02 /* See MS-SMB2 2.2.19 */
697
698/* Channel field for read and write: exactly one of following flags can be set*/
699#define SMB2_CHANNEL_NONE cpu_to_le32(0x00000000)
700#define SMB2_CHANNEL_RDMA_V1 cpu_to_le32(0x00000001)
701#define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002)
702#define SMB2_CHANNEL_RDMA_TRANSFORM cpu_to_le32(0x00000003)
703
704/* SMB2 read request without RFC1001 length at the beginning */
705struct smb2_read_req {
706 struct smb2_hdr hdr;
707 __le16 StructureSize; /* Must be 49 */
708 __u8 Padding; /* offset from start of SMB2 header to place read */
709 __u8 Flags; /* MBZ unless SMB3.02 or later */
710 __le32 Length;
711 __le64 Offset;
351a59da
PA
712 __u64 PersistentFileId;
713 __u64 VolatileFileId;
d8d9de53
RS
714 __le32 MinimumCount;
715 __le32 Channel; /* MBZ except for SMB3 or later */
716 __le32 RemainingBytes;
717 __le16 ReadChannelInfoOffset;
718 __le16 ReadChannelInfoLength;
eb3e28c1 719 __u8 Buffer[];
d8d9de53
RS
720} __packed;
721
722/* Read flags */
723#define SMB2_READFLAG_RESPONSE_NONE cpu_to_le32(0x00000000)
724#define SMB2_READFLAG_RESPONSE_RDMA_TRANSFORM cpu_to_le32(0x00000001)
725
726struct smb2_read_rsp {
727 struct smb2_hdr hdr;
728 __le16 StructureSize; /* Must be 17 */
729 __u8 DataOffset;
730 __u8 Reserved;
731 __le32 DataLength;
732 __le32 DataRemaining;
733 __le32 Flags;
eb3e28c1 734 __u8 Buffer[];
d8d9de53
RS
735} __packed;
736
737
738/*
739 * SMB2_WRITE See MS-SMB2 section 2.2.21
740 */
741/* For write request Flags field below the following flags are defined: */
742#define SMB2_WRITEFLAG_WRITE_THROUGH 0x00000001 /* SMB2.1 or later */
743#define SMB2_WRITEFLAG_WRITE_UNBUFFERED 0x00000002 /* SMB3.02 or later */
744
745struct smb2_write_req {
746 struct smb2_hdr hdr;
747 __le16 StructureSize; /* Must be 49 */
748 __le16 DataOffset; /* offset from start of SMB2 header to write data */
749 __le32 Length;
750 __le64 Offset;
351a59da
PA
751 __u64 PersistentFileId; /* opaque endianness */
752 __u64 VolatileFileId; /* opaque endianness */
d8d9de53
RS
753 __le32 Channel; /* MBZ unless SMB3.02 or later */
754 __le32 RemainingBytes;
755 __le16 WriteChannelInfoOffset;
756 __le16 WriteChannelInfoLength;
757 __le32 Flags;
eb3e28c1 758 __u8 Buffer[];
d8d9de53
RS
759} __packed;
760
761struct smb2_write_rsp {
762 struct smb2_hdr hdr;
763 __le16 StructureSize; /* Must be 17 */
764 __u8 DataOffset;
765 __u8 Reserved;
766 __le32 DataLength;
767 __le32 DataRemaining;
768 __u32 Reserved2;
eb3e28c1 769 __u8 Buffer[];
d8d9de53
RS
770} __packed;
771
772
773/*
774 * SMB2_FLUSH See MS-SMB2 section 2.2.17
775 */
776struct smb2_flush_req {
777 struct smb2_hdr hdr;
778 __le16 StructureSize; /* Must be 24 */
779 __le16 Reserved1;
780 __le32 Reserved2;
351a59da
PA
781 __u64 PersistentFileId;
782 __u64 VolatileFileId;
d8d9de53
RS
783} __packed;
784
785struct smb2_flush_rsp {
786 struct smb2_hdr hdr;
787 __le16 StructureSize;
788 __le16 Reserved;
789} __packed;
790
be135000
SF
791#define SMB2_LOCKFLAG_SHARED 0x0001
792#define SMB2_LOCKFLAG_EXCLUSIVE 0x0002
793#define SMB2_LOCKFLAG_UNLOCK 0x0004
794#define SMB2_LOCKFLAG_FAIL_IMMEDIATELY 0x0010
795#define SMB2_LOCKFLAG_MASK 0x0007
796
797struct smb2_lock_element {
798 __le64 Offset;
799 __le64 Length;
800 __le32 Flags;
801 __le32 Reserved;
802} __packed;
803
804struct smb2_lock_req {
805 struct smb2_hdr hdr;
806 __le16 StructureSize; /* Must be 48 */
807 __le16 LockCount;
808 /*
809 * The least significant four bits are the index, the other 28 bits are
810 * the lock sequence number (0 to 64). See MS-SMB2 2.2.26
811 */
812 __le32 LockSequenceNumber;
813 __u64 PersistentFileId;
814 __u64 VolatileFileId;
815 /* Followed by at least one */
eb3e28c1
KC
816 union {
817 struct smb2_lock_element lock;
818 DECLARE_FLEX_ARRAY(struct smb2_lock_element, locks);
819 };
be135000
SF
820} __packed;
821
822struct smb2_lock_rsp {
823 struct smb2_hdr hdr;
824 __le16 StructureSize; /* Must be 4 */
825 __le16 Reserved;
826} __packed;
827
828struct smb2_echo_req {
829 struct smb2_hdr hdr;
830 __le16 StructureSize; /* Must be 4 */
831 __u16 Reserved;
832} __packed;
833
834struct smb2_echo_rsp {
835 struct smb2_hdr hdr;
836 __le16 StructureSize; /* Must be 4 */
837 __u16 Reserved;
838} __packed;
839
840/*
841 * Valid FileInformation classes for query directory
842 *
843 * Note that these are a subset of the (file) QUERY_INFO levels defined
844 * later in this file (but since QUERY_DIRECTORY uses equivalent numbers
845 * we do not redefine them here)
846 *
847 * FileDirectoryInfomation 0x01
848 * FileFullDirectoryInformation 0x02
849 * FileIdFullDirectoryInformation 0x26
850 * FileBothDirectoryInformation 0x03
851 * FileIdBothDirectoryInformation 0x25
852 * FileNamesInformation 0x0C
853 * FileIdExtdDirectoryInformation 0x3C
854 */
855
856/* search (query_directory) Flags field */
857#define SMB2_RESTART_SCANS 0x01
858#define SMB2_RETURN_SINGLE_ENTRY 0x02
859#define SMB2_INDEX_SPECIFIED 0x04
860#define SMB2_REOPEN 0x10
861
862struct smb2_query_directory_req {
863 struct smb2_hdr hdr;
864 __le16 StructureSize; /* Must be 33 */
865 __u8 FileInformationClass;
866 __u8 Flags;
867 __le32 FileIndex;
868 __u64 PersistentFileId;
869 __u64 VolatileFileId;
870 __le16 FileNameOffset;
871 __le16 FileNameLength;
872 __le32 OutputBufferLength;
eb3e28c1 873 __u8 Buffer[];
be135000
SF
874} __packed;
875
876struct smb2_query_directory_rsp {
877 struct smb2_hdr hdr;
878 __le16 StructureSize; /* Must be 9 */
879 __le16 OutputBufferOffset;
880 __le32 OutputBufferLength;
eb3e28c1 881 __u8 Buffer[];
be135000
SF
882} __packed;
883
884/*
885 * Maximum number of iovs we need for a set-info request.
886 * The largest one is rename/hardlink
887 * [0] : struct smb2_set_info_req + smb2_file_[rename|link]_info
888 * [1] : path
889 * [2] : compound padding
890 */
891#define SMB2_SET_INFO_IOV_SIZE 3
892
893struct smb2_set_info_req {
894 struct smb2_hdr hdr;
895 __le16 StructureSize; /* Must be 33 */
896 __u8 InfoType;
897 __u8 FileInfoClass;
898 __le32 BufferLength;
899 __le16 BufferOffset;
900 __u16 Reserved;
901 __le32 AdditionalInformation;
902 __u64 PersistentFileId;
903 __u64 VolatileFileId;
eb3e28c1 904 __u8 Buffer[];
be135000
SF
905} __packed;
906
907struct smb2_set_info_rsp {
908 struct smb2_hdr hdr;
909 __le16 StructureSize; /* Must be 2 */
910} __packed;
d8d9de53
RS
911
912/*
913 * SMB2_NOTIFY See MS-SMB2 section 2.2.35
914 */
915/* notify flags */
916#define SMB2_WATCH_TREE 0x0001
917
918/* notify completion filter flags. See MS-FSCC 2.6 and MS-SMB2 2.2.35 */
919#define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001
920#define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002
921#define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004
922#define FILE_NOTIFY_CHANGE_SIZE 0x00000008
923#define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010
924#define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020
925#define FILE_NOTIFY_CHANGE_CREATION 0x00000040
926#define FILE_NOTIFY_CHANGE_EA 0x00000080
927#define FILE_NOTIFY_CHANGE_SECURITY 0x00000100
928#define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200
929#define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400
930#define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
931
932/* SMB2 Notify Action Flags */
933#define FILE_ACTION_ADDED 0x00000001
934#define FILE_ACTION_REMOVED 0x00000002
935#define FILE_ACTION_MODIFIED 0x00000003
936#define FILE_ACTION_RENAMED_OLD_NAME 0x00000004
937#define FILE_ACTION_RENAMED_NEW_NAME 0x00000005
938#define FILE_ACTION_ADDED_STREAM 0x00000006
939#define FILE_ACTION_REMOVED_STREAM 0x00000007
940#define FILE_ACTION_MODIFIED_STREAM 0x00000008
941#define FILE_ACTION_REMOVED_BY_DELETE 0x00000009
942
943struct smb2_change_notify_req {
944 struct smb2_hdr hdr;
945 __le16 StructureSize;
946 __le16 Flags;
947 __le32 OutputBufferLength;
351a59da
PA
948 __u64 PersistentFileId; /* opaque endianness */
949 __u64 VolatileFileId; /* opaque endianness */
d8d9de53
RS
950 __le32 CompletionFilter;
951 __u32 Reserved;
952} __packed;
953
954struct smb2_change_notify_rsp {
955 struct smb2_hdr hdr;
956 __le16 StructureSize; /* Must be 9 */
957 __le16 OutputBufferOffset;
958 __le32 OutputBufferLength;
eb3e28c1 959 __u8 Buffer[]; /* array of file notify structs */
d8d9de53
RS
960} __packed;
961
962
c462870b
RS
963/*
964 * SMB2_CREATE See MS-SMB2 section 2.2.13
965 */
966/* Oplock levels */
967#define SMB2_OPLOCK_LEVEL_NONE 0x00
968#define SMB2_OPLOCK_LEVEL_II 0x01
969#define SMB2_OPLOCK_LEVEL_EXCLUSIVE 0x08
970#define SMB2_OPLOCK_LEVEL_BATCH 0x09
971#define SMB2_OPLOCK_LEVEL_LEASE 0xFF
972/* Non-spec internal type */
973#define SMB2_OPLOCK_LEVEL_NOCHANGE 0x99
974
975/* Impersonation Levels. See MS-WPO section 9.7 and MSDN-IMPERS */
976#define IL_ANONYMOUS cpu_to_le32(0x00000000)
977#define IL_IDENTIFICATION cpu_to_le32(0x00000001)
978#define IL_IMPERSONATION cpu_to_le32(0x00000002)
979#define IL_DELEGATE cpu_to_le32(0x00000003)
980
981/* File Attrubutes */
982#define FILE_ATTRIBUTE_READONLY 0x00000001
983#define FILE_ATTRIBUTE_HIDDEN 0x00000002
984#define FILE_ATTRIBUTE_SYSTEM 0x00000004
985#define FILE_ATTRIBUTE_DIRECTORY 0x00000010
986#define FILE_ATTRIBUTE_ARCHIVE 0x00000020
987#define FILE_ATTRIBUTE_NORMAL 0x00000080
988#define FILE_ATTRIBUTE_TEMPORARY 0x00000100
989#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
990#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
991#define FILE_ATTRIBUTE_COMPRESSED 0x00000800
992#define FILE_ATTRIBUTE_OFFLINE 0x00001000
993#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
994#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000
995#define FILE_ATTRIBUTE_INTEGRITY_STREAM 0x00008000
996#define FILE_ATTRIBUTE_NO_SCRUB_DATA 0x00020000
997#define FILE_ATTRIBUTE__MASK 0x00007FB7
998
999#define FILE_ATTRIBUTE_READONLY_LE cpu_to_le32(0x00000001)
1000#define FILE_ATTRIBUTE_HIDDEN_LE cpu_to_le32(0x00000002)
1001#define FILE_ATTRIBUTE_SYSTEM_LE cpu_to_le32(0x00000004)
1002#define FILE_ATTRIBUTE_DIRECTORY_LE cpu_to_le32(0x00000010)
1003#define FILE_ATTRIBUTE_ARCHIVE_LE cpu_to_le32(0x00000020)
1004#define FILE_ATTRIBUTE_NORMAL_LE cpu_to_le32(0x00000080)
1005#define FILE_ATTRIBUTE_TEMPORARY_LE cpu_to_le32(0x00000100)
1006#define FILE_ATTRIBUTE_SPARSE_FILE_LE cpu_to_le32(0x00000200)
1007#define FILE_ATTRIBUTE_REPARSE_POINT_LE cpu_to_le32(0x00000400)
1008#define FILE_ATTRIBUTE_COMPRESSED_LE cpu_to_le32(0x00000800)
1009#define FILE_ATTRIBUTE_OFFLINE_LE cpu_to_le32(0x00001000)
1010#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED_LE cpu_to_le32(0x00002000)
1011#define FILE_ATTRIBUTE_ENCRYPTED_LE cpu_to_le32(0x00004000)
1012#define FILE_ATTRIBUTE_INTEGRITY_STREAM_LE cpu_to_le32(0x00008000)
1013#define FILE_ATTRIBUTE_NO_SCRUB_DATA_LE cpu_to_le32(0x00020000)
1014#define FILE_ATTRIBUTE_MASK_LE cpu_to_le32(0x00007FB7)
1015
1016/* Desired Access Flags */
1017#define FILE_READ_DATA_LE cpu_to_le32(0x00000001)
1018#define FILE_LIST_DIRECTORY_LE cpu_to_le32(0x00000001)
1019#define FILE_WRITE_DATA_LE cpu_to_le32(0x00000002)
1020#define FILE_APPEND_DATA_LE cpu_to_le32(0x00000004)
1021#define FILE_ADD_SUBDIRECTORY_LE cpu_to_le32(0x00000004)
1022#define FILE_READ_EA_LE cpu_to_le32(0x00000008)
1023#define FILE_WRITE_EA_LE cpu_to_le32(0x00000010)
1024#define FILE_EXECUTE_LE cpu_to_le32(0x00000020)
1025#define FILE_DELETE_CHILD_LE cpu_to_le32(0x00000040)
1026#define FILE_READ_ATTRIBUTES_LE cpu_to_le32(0x00000080)
1027#define FILE_WRITE_ATTRIBUTES_LE cpu_to_le32(0x00000100)
1028#define FILE_DELETE_LE cpu_to_le32(0x00010000)
1029#define FILE_READ_CONTROL_LE cpu_to_le32(0x00020000)
1030#define FILE_WRITE_DAC_LE cpu_to_le32(0x00040000)
1031#define FILE_WRITE_OWNER_LE cpu_to_le32(0x00080000)
1032#define FILE_SYNCHRONIZE_LE cpu_to_le32(0x00100000)
1033#define FILE_ACCESS_SYSTEM_SECURITY_LE cpu_to_le32(0x01000000)
1034#define FILE_MAXIMAL_ACCESS_LE cpu_to_le32(0x02000000)
1035#define FILE_GENERIC_ALL_LE cpu_to_le32(0x10000000)
1036#define FILE_GENERIC_EXECUTE_LE cpu_to_le32(0x20000000)
1037#define FILE_GENERIC_WRITE_LE cpu_to_le32(0x40000000)
1038#define FILE_GENERIC_READ_LE cpu_to_le32(0x80000000)
1039#define DESIRED_ACCESS_MASK cpu_to_le32(0xF21F01FF)
1040
1041
1042#define FILE_READ_DESIRED_ACCESS_LE (FILE_READ_DATA_LE | \
1043 FILE_READ_EA_LE | \
1044 FILE_GENERIC_READ_LE)
1045#define FILE_WRITE_DESIRE_ACCESS_LE (FILE_WRITE_DATA_LE | \
1046 FILE_APPEND_DATA_LE | \
1047 FILE_WRITE_EA_LE | \
1048 FILE_WRITE_ATTRIBUTES_LE | \
1049 FILE_GENERIC_WRITE_LE)
1050
1051/* ShareAccess Flags */
1052#define FILE_SHARE_READ_LE cpu_to_le32(0x00000001)
1053#define FILE_SHARE_WRITE_LE cpu_to_le32(0x00000002)
1054#define FILE_SHARE_DELETE_LE cpu_to_le32(0x00000004)
1055#define FILE_SHARE_ALL_LE cpu_to_le32(0x00000007)
1056
1057/* CreateDisposition Flags */
1058#define FILE_SUPERSEDE_LE cpu_to_le32(0x00000000)
1059#define FILE_OPEN_LE cpu_to_le32(0x00000001)
1060#define FILE_CREATE_LE cpu_to_le32(0x00000002)
1061#define FILE_OPEN_IF_LE cpu_to_le32(0x00000003)
1062#define FILE_OVERWRITE_LE cpu_to_le32(0x00000004)
1063#define FILE_OVERWRITE_IF_LE cpu_to_le32(0x00000005)
1064#define FILE_CREATE_MASK_LE cpu_to_le32(0x00000007)
1065
1066#define FILE_READ_RIGHTS (FILE_READ_DATA | FILE_READ_EA \
1067 | FILE_READ_ATTRIBUTES)
1068#define FILE_WRITE_RIGHTS (FILE_WRITE_DATA | FILE_APPEND_DATA \
1069 | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES)
1070#define FILE_EXEC_RIGHTS (FILE_EXECUTE)
1071
1072/* CreateOptions Flags */
1073#define FILE_DIRECTORY_FILE_LE cpu_to_le32(0x00000001)
1074/* same as #define CREATE_NOT_FILE_LE cpu_to_le32(0x00000001) */
1075#define FILE_WRITE_THROUGH_LE cpu_to_le32(0x00000002)
1076#define FILE_SEQUENTIAL_ONLY_LE cpu_to_le32(0x00000004)
1077#define FILE_NO_INTERMEDIATE_BUFFERING_LE cpu_to_le32(0x00000008)
1078#define FILE_NON_DIRECTORY_FILE_LE cpu_to_le32(0x00000040)
1079#define FILE_COMPLETE_IF_OPLOCKED_LE cpu_to_le32(0x00000100)
1080#define FILE_NO_EA_KNOWLEDGE_LE cpu_to_le32(0x00000200)
1081#define FILE_RANDOM_ACCESS_LE cpu_to_le32(0x00000800)
1082#define FILE_DELETE_ON_CLOSE_LE cpu_to_le32(0x00001000)
1083#define FILE_OPEN_BY_FILE_ID_LE cpu_to_le32(0x00002000)
1084#define FILE_OPEN_FOR_BACKUP_INTENT_LE cpu_to_le32(0x00004000)
1085#define FILE_NO_COMPRESSION_LE cpu_to_le32(0x00008000)
1086#define FILE_OPEN_REPARSE_POINT_LE cpu_to_le32(0x00200000)
1087#define FILE_OPEN_NO_RECALL_LE cpu_to_le32(0x00400000)
1088#define CREATE_OPTIONS_MASK_LE cpu_to_le32(0x00FFFFFF)
1089
1090#define FILE_READ_RIGHTS_LE (FILE_READ_DATA_LE | FILE_READ_EA_LE \
1091 | FILE_READ_ATTRIBUTES_LE)
1092#define FILE_WRITE_RIGHTS_LE (FILE_WRITE_DATA_LE | FILE_APPEND_DATA_LE \
1093 | FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
1094#define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
1095
1096/* Create Context Values */
1097#define SMB2_CREATE_EA_BUFFER "ExtA" /* extended attributes */
1098#define SMB2_CREATE_SD_BUFFER "SecD" /* security descriptor */
1099#define SMB2_CREATE_DURABLE_HANDLE_REQUEST "DHnQ"
1100#define SMB2_CREATE_DURABLE_HANDLE_RECONNECT "DHnC"
1101#define SMB2_CREATE_ALLOCATION_SIZE "AISi"
1102#define SMB2_CREATE_QUERY_MAXIMAL_ACCESS_REQUEST "MxAc"
1103#define SMB2_CREATE_TIMEWARP_REQUEST "TWrp"
1104#define SMB2_CREATE_QUERY_ON_DISK_ID "QFid"
1105#define SMB2_CREATE_REQUEST_LEASE "RqLs"
1106#define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 "DH2Q"
1107#define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 "DH2C"
3afdfb0d
SF
1108#define SMB2_CREATE_TAG_POSIX "\x93\xAD\x25\x50\x9C\xB4\x11\xE7\xB4\x23\x83\xDE\x96\x8B\xCD\x7C"
1109#define SMB2_CREATE_APP_INSTANCE_ID "\x45\xBC\xA6\x6A\xEF\xA7\xF7\x4A\x90\x08\xFA\x46\x2E\x14\x4D\x74"
1110#define SMB2_CREATE_APP_INSTANCE_VERSION "\xB9\x82\xD0\xB7\x3B\x56\x07\x4F\xA0\x7B\x52\x4A\x81\x16\xA0\x10"
1111#define SVHDX_OPEN_DEVICE_CONTEXT "\x9C\xCB\xCF\x9E\x04\xC1\xE6\x43\x98\x0E\x15\x8D\xA1\xF6\xEC\x83"
1112#define SMB2_CREATE_TAG_AAPL "AAPL"
c462870b
RS
1113
1114/* Flag (SMB3 open response) values */
1115#define SMB2_CREATE_FLAG_REPARSEPOINT 0x01
1116
1117struct create_context {
1118 __le32 Next;
1119 __le16 NameOffset;
1120 __le16 NameLength;
1121 __le16 Reserved;
1122 __le16 DataOffset;
1123 __le32 DataLength;
1124 __u8 Buffer[];
1125} __packed;
1126
1127struct smb2_create_req {
1128 struct smb2_hdr hdr;
1129 __le16 StructureSize; /* Must be 57 */
1130 __u8 SecurityFlags;
1131 __u8 RequestedOplockLevel;
1132 __le32 ImpersonationLevel;
1133 __le64 SmbCreateFlags;
1134 __le64 Reserved;
1135 __le32 DesiredAccess;
1136 __le32 FileAttributes;
1137 __le32 ShareAccess;
1138 __le32 CreateDisposition;
1139 __le32 CreateOptions;
1140 __le16 NameOffset;
1141 __le16 NameLength;
1142 __le32 CreateContextsOffset;
1143 __le32 CreateContextsLength;
1144 __u8 Buffer[];
1145} __packed;
1146
1147struct smb2_create_rsp {
1148 struct smb2_hdr hdr;
1149 __le16 StructureSize; /* Must be 89 */
1150 __u8 OplockLevel;
1151 __u8 Flags; /* 0x01 if reparse point */
1152 __le32 CreateAction;
1153 __le64 CreationTime;
1154 __le64 LastAccessTime;
1155 __le64 LastWriteTime;
1156 __le64 ChangeTime;
1157 __le64 AllocationSize;
1158 __le64 EndofFile;
1159 __le32 FileAttributes;
1160 __le32 Reserved2;
351a59da
PA
1161 __u64 PersistentFileId;
1162 __u64 VolatileFileId;
c462870b
RS
1163 __le32 CreateContextsOffset;
1164 __le32 CreateContextsLength;
eb3e28c1 1165 __u8 Buffer[];
c462870b
RS
1166} __packed;
1167
15e7b6d7
SF
1168struct create_posix {
1169 struct create_context ccontext;
1170 __u8 Name[16];
1171 __le32 Mode;
1172 __u32 Reserved;
1173} __packed;
1174
2fe187dc
SF
1175/* See MS-SMB2 2.2.13.2.3 and MS-SMB2 2.2.13.2.4 */
1176struct create_durable {
1177 struct create_context ccontext;
1178 __u8 Name[8];
1179 union {
1180 __u8 Reserved[16];
1181 struct {
1182 __u64 PersistentFileId;
1183 __u64 VolatileFileId;
1184 } Fid;
1185 } Data;
1186} __packed;
1187
1188/* See MS-SMB2 2.2.13.2.5 */
1189struct create_mxac_req {
1190 struct create_context ccontext;
1191 __u8 Name[8];
1192 __le64 Timestamp;
1193} __packed;
1194
1195/* See MS-SMB2 2.2.14.2.5 */
1196struct create_mxac_rsp {
1197 struct create_context ccontext;
1198 __u8 Name[8];
1199 __le32 QueryStatus;
1200 __le32 MaximalAccess;
1201} __packed;
1202
113be37d
SF
1203#define SMB2_LEASE_NONE_LE cpu_to_le32(0x00)
1204#define SMB2_LEASE_READ_CACHING_LE cpu_to_le32(0x01)
1205#define SMB2_LEASE_HANDLE_CACHING_LE cpu_to_le32(0x02)
1206#define SMB2_LEASE_WRITE_CACHING_LE cpu_to_le32(0x04)
1207
1208#define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE cpu_to_le32(0x02)
1209
1210#define SMB2_LEASE_KEY_SIZE 16
1211
1149c846 1212/* See MS-SMB2 2.2.13.2.8 */
113be37d
SF
1213struct lease_context {
1214 __u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
1215 __le32 LeaseState;
1216 __le32 LeaseFlags;
1217 __le64 LeaseDuration;
1218} __packed;
1219
1149c846 1220/* See MS-SMB2 2.2.13.2.10 */
113be37d
SF
1221struct lease_context_v2 {
1222 __u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
1223 __le32 LeaseState;
1224 __le32 LeaseFlags;
1225 __le64 LeaseDuration;
1226 __u8 ParentLeaseKey[SMB2_LEASE_KEY_SIZE];
1227 __le16 Epoch;
1228 __le16 Reserved;
1229} __packed;
1230
1231struct create_lease {
1232 struct create_context ccontext;
1233 __u8 Name[8];
1234 struct lease_context lcontext;
1235} __packed;
1236
1237struct create_lease_v2 {
1238 struct create_context ccontext;
1239 __u8 Name[8];
1240 struct lease_context_v2 lcontext;
1241 __u8 Pad[4];
1242} __packed;
1243
1149c846
SF
1244/* See MS-SMB2 2.2.14.2.9 */
1245struct create_disk_id_rsp {
1246 struct create_context ccontext;
1247 __u8 Name[8];
1248 __le64 DiskFileId;
1249 __le64 VolumeId;
1250 __u8 Reserved[16];
1251} __packed;
1252
15e7b6d7
SF
1253/* See MS-SMB2 2.2.31 and 2.2.32 */
1254struct smb2_ioctl_req {
1255 struct smb2_hdr hdr;
1256 __le16 StructureSize; /* Must be 57 */
1257 __le16 Reserved; /* offset from start of SMB2 header to write data */
1258 __le32 CtlCode;
1259 __u64 PersistentFileId;
1260 __u64 VolatileFileId;
1261 __le32 InputOffset; /* Reserved MBZ */
1262 __le32 InputCount;
1263 __le32 MaxInputResponse;
1264 __le32 OutputOffset;
1265 __le32 OutputCount;
1266 __le32 MaxOutputResponse;
1267 __le32 Flags;
1268 __le32 Reserved2;
1269 __u8 Buffer[];
1270} __packed;
1271
1272struct smb2_ioctl_rsp {
1273 struct smb2_hdr hdr;
1274 __le16 StructureSize; /* Must be 49 */
1275 __le16 Reserved;
1276 __le32 CtlCode;
1277 __u64 PersistentFileId;
1278 __u64 VolatileFileId;
1279 __le32 InputOffset; /* Reserved MBZ */
1280 __le32 InputCount;
1281 __le32 OutputOffset;
1282 __le32 OutputCount;
1283 __le32 Flags;
1284 __le32 Reserved2;
1285 __u8 Buffer[];
1286} __packed;
1287
c7803b05
SF
1288/* this goes in the ioctl buffer when doing FSCTL_SET_ZERO_DATA */
1289struct file_zero_data_information {
1290 __le64 FileOffset;
1291 __le64 BeyondFinalZero;
1292} __packed;
1293
a42078b9
SF
1294/* See MS-FSCC 2.3.7 */
1295struct duplicate_extents_to_file {
1296 __u64 PersistentFileHandle; /* source file handle, opaque endianness */
1297 __u64 VolatileFileHandle;
1298 __le64 SourceFileOffset;
1299 __le64 TargetFileOffset;
1300 __le64 ByteCount; /* Bytes to be copied */
1301} __packed;
1302
1303/* See MS-FSCC 2.3.8 */
1304#define DUPLICATE_EXTENTS_DATA_EX_SOURCE_ATOMIC 0x00000001
1305struct duplicate_extents_to_file_ex {
1306 __u64 PersistentFileHandle; /* source file handle, opaque endianness */
1307 __u64 VolatileFileHandle;
1308 __le64 SourceFileOffset;
1309 __le64 TargetFileOffset;
1310 __le64 ByteCount; /* Bytes to be copied */
1311 __le32 Flags;
1312 __le32 Reserved;
1313} __packed;
1314
1315
1316/* See MS-FSCC 2.3.20 */
1317struct fsctl_get_integrity_information_rsp {
1318 __le16 ChecksumAlgorithm;
1319 __le16 Reserved;
1320 __le32 Flags;
1321 __le32 ChecksumChunkSizeInBytes;
1322 __le32 ClusterSizeInBytes;
1323} __packed;
1324
1325/* See MS-FSCC 2.3.55 */
1326struct fsctl_query_file_regions_req {
1327 __le64 FileOffset;
1328 __le64 Length;
1329 __le32 DesiredUsage;
1330 __le32 Reserved;
1331} __packed;
1332
1333/* DesiredUsage flags see MS-FSCC 2.3.56.1 */
1334#define FILE_USAGE_INVALID_RANGE 0x00000000
1335#define FILE_USAGE_VALID_CACHED_DATA 0x00000001
1336#define FILE_USAGE_NONCACHED_DATA 0x00000002
1337
1338struct file_region_info {
1339 __le64 FileOffset;
1340 __le64 Length;
1341 __le32 DesiredUsage;
1342 __le32 Reserved;
1343} __packed;
1344
1345/* See MS-FSCC 2.3.56 */
1346struct fsctl_query_file_region_rsp {
1347 __le32 Flags;
1348 __le32 TotalRegionEntryCount;
1349 __le32 RegionEntryCount;
1350 __u32 Reserved;
1351 struct file_region_info Regions[];
1352} __packed;
1353
1354/* See MS-FSCC 2.3.58 */
1355struct fsctl_query_on_disk_vol_info_rsp {
1356 __le64 DirectoryCount;
1357 __le64 FileCount;
1358 __le16 FsFormatMajVersion;
1359 __le16 FsFormatMinVersion;
1360 __u8 FsFormatName[24];
1361 __le64 FormatTime;
1362 __le64 LastUpdateTime;
1363 __u8 CopyrightInfo[68];
1364 __u8 AbstractInfo[68];
1365 __u8 FormatImplInfo[68];
1366 __u8 LastModifyImplInfo[68];
1367} __packed;
1368
1369/* See MS-FSCC 2.3.73 */
1370struct fsctl_set_integrity_information_req {
1371 __le16 ChecksumAlgorithm;
1372 __le16 Reserved;
1373 __le32 Flags;
1374} __packed;
1375
1376/* See MS-FSCC 2.3.75 */
1377struct fsctl_set_integrity_info_ex_req {
1378 __u8 EnableIntegrity;
1379 __u8 KeepState;
1380 __u16 Reserved;
1381 __le32 Flags;
1382 __u8 Version;
1383 __u8 Reserved2[7];
1384} __packed;
1385
1386/* Integrity ChecksumAlgorithm choices for above */
1387#define CHECKSUM_TYPE_NONE 0x0000
1388#define CHECKSUM_TYPE_CRC64 0x0002
1389#define CHECKSUM_TYPE_UNCHANGED 0xFFFF /* set only */
1390
1391/* Integrity flags for above */
1392#define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF 0x00000001
1393
c7803b05
SF
1394/* Reparse structures - see MS-FSCC 2.1.2 */
1395
1396/* struct fsctl_reparse_info_req is empty, only response structs (see below) */
1397struct reparse_data_buffer {
1398 __le32 ReparseTag;
1399 __le16 ReparseDataLength;
1400 __u16 Reserved;
1401 __u8 DataBuffer[]; /* Variable Length */
1402} __packed;
1403
1404struct reparse_guid_data_buffer {
1405 __le32 ReparseTag;
1406 __le16 ReparseDataLength;
1407 __u16 Reserved;
1408 __u8 ReparseGuid[16];
1409 __u8 DataBuffer[]; /* Variable Length */
1410} __packed;
1411
1412struct reparse_mount_point_data_buffer {
1413 __le32 ReparseTag;
1414 __le16 ReparseDataLength;
1415 __u16 Reserved;
1416 __le16 SubstituteNameOffset;
1417 __le16 SubstituteNameLength;
1418 __le16 PrintNameOffset;
1419 __le16 PrintNameLength;
1420 __u8 PathBuffer[]; /* Variable Length */
1421} __packed;
1422
1423#define SYMLINK_FLAG_RELATIVE 0x00000001
1424
1425struct reparse_symlink_data_buffer {
1426 __le32 ReparseTag;
1427 __le16 ReparseDataLength;
1428 __u16 Reserved;
1429 __le16 SubstituteNameOffset;
1430 __le16 SubstituteNameLength;
1431 __le16 PrintNameOffset;
1432 __le16 PrintNameLength;
1433 __le32 Flags;
1434 __u8 PathBuffer[]; /* Variable Length */
1435} __packed;
1436
1437/* See MS-FSCC 2.1.2.6 and cifspdu.h for struct reparse_posix_data */
1438
1439struct validate_negotiate_info_req {
1440 __le32 Capabilities;
1441 __u8 Guid[SMB2_CLIENT_GUID_SIZE];
1442 __le16 SecurityMode;
1443 __le16 DialectCount;
1444 __le16 Dialects[4]; /* BB expand this if autonegotiate > 4 dialects */
1445} __packed;
1446
1447struct validate_negotiate_info_rsp {
1448 __le32 Capabilities;
1449 __u8 Guid[SMB2_CLIENT_GUID_SIZE];
1450 __le16 SecurityMode;
1451 __le16 Dialect; /* Dialect in use for the connection */
1452} __packed;
1453
c7803b05 1454
113be37d
SF
1455/* Possible InfoType values */
1456#define SMB2_O_INFO_FILE 0x01
1457#define SMB2_O_INFO_FILESYSTEM 0x02
1458#define SMB2_O_INFO_SECURITY 0x03
1459#define SMB2_O_INFO_QUOTA 0x04
1460
1461/* SMB2 Query Info see MS-SMB2 (2.2.37) or MS-DTYP */
1462
be135000
SF
1463/* List of QUERY INFO levels (those also valid for QUERY_DIR are noted below */
1464#define FILE_DIRECTORY_INFORMATION 1 /* also for QUERY_DIR */
1465#define FILE_FULL_DIRECTORY_INFORMATION 2 /* also for QUERY_DIR */
1466#define FILE_BOTH_DIRECTORY_INFORMATION 3 /* also for QUERY_DIR */
1467#define FILE_BASIC_INFORMATION 4
1468#define FILE_STANDARD_INFORMATION 5
1469#define FILE_INTERNAL_INFORMATION 6
1470#define FILE_EA_INFORMATION 7
1471#define FILE_ACCESS_INFORMATION 8
1472#define FILE_NAME_INFORMATION 9
1473#define FILE_RENAME_INFORMATION 10
1474#define FILE_LINK_INFORMATION 11
1475#define FILE_NAMES_INFORMATION 12 /* also for QUERY_DIR */
1476#define FILE_DISPOSITION_INFORMATION 13
1477#define FILE_POSITION_INFORMATION 14
1478#define FILE_FULL_EA_INFORMATION 15
1479#define FILE_MODE_INFORMATION 16
1480#define FILE_ALIGNMENT_INFORMATION 17
1481#define FILE_ALL_INFORMATION 18
1482#define FILE_ALLOCATION_INFORMATION 19
1483#define FILE_END_OF_FILE_INFORMATION 20
1484#define FILE_ALTERNATE_NAME_INFORMATION 21
1485#define FILE_STREAM_INFORMATION 22
1486#define FILE_PIPE_INFORMATION 23
1487#define FILE_PIPE_LOCAL_INFORMATION 24
1488#define FILE_PIPE_REMOTE_INFORMATION 25
1489#define FILE_MAILSLOT_QUERY_INFORMATION 26
1490#define FILE_MAILSLOT_SET_INFORMATION 27
1491#define FILE_COMPRESSION_INFORMATION 28
1492#define FILE_OBJECT_ID_INFORMATION 29
1493/* Number 30 not defined in documents */
1494#define FILE_MOVE_CLUSTER_INFORMATION 31
1495#define FILE_QUOTA_INFORMATION 32
1496#define FILE_REPARSE_POINT_INFORMATION 33
1497#define FILE_NETWORK_OPEN_INFORMATION 34
1498#define FILE_ATTRIBUTE_TAG_INFORMATION 35
1499#define FILE_TRACKING_INFORMATION 36
1500#define FILEID_BOTH_DIRECTORY_INFORMATION 37 /* also for QUERY_DIR */
1501#define FILEID_FULL_DIRECTORY_INFORMATION 38 /* also for QUERY_DIR */
1502#define FILE_VALID_DATA_LENGTH_INFORMATION 39
1503#define FILE_SHORT_NAME_INFORMATION 40
1504#define FILE_SFIO_RESERVE_INFORMATION 44
1505#define FILE_SFIO_VOLUME_INFORMATION 45
1506#define FILE_HARD_LINK_INFORMATION 46
1507#define FILE_NORMALIZED_NAME_INFORMATION 48
1508#define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
1509#define FILE_STANDARD_LINK_INFORMATION 54
1510#define FILE_ID_INFORMATION 59
1511#define FILE_ID_EXTD_DIRECTORY_INFORMATION 60 /* also for QUERY_DIR */
1512/* Used for Query Info and Find File POSIX Info for SMB3.1.1 and SMB1 */
1513#define SMB_FIND_FILE_POSIX_INFO 0x064
1514
113be37d
SF
1515/* Security info type additionalinfo flags. */
1516#define OWNER_SECINFO 0x00000001
1517#define GROUP_SECINFO 0x00000002
1518#define DACL_SECINFO 0x00000004
1519#define SACL_SECINFO 0x00000008
1520#define LABEL_SECINFO 0x00000010
1521#define ATTRIBUTE_SECINFO 0x00000020
1522#define SCOPE_SECINFO 0x00000040
1523#define BACKUP_SECINFO 0x00010000
1524#define UNPROTECTED_SACL_SECINFO 0x10000000
1525#define UNPROTECTED_DACL_SECINFO 0x20000000
1526#define PROTECTED_SACL_SECINFO 0x40000000
1527#define PROTECTED_DACL_SECINFO 0x80000000
1528
1529/* Flags used for FileFullEAinfo */
1530#define SL_RESTART_SCAN 0x00000001
1531#define SL_RETURN_SINGLE_ENTRY 0x00000002
1532#define SL_INDEX_SPECIFIED 0x00000004
1533
1534struct smb2_query_info_req {
1535 struct smb2_hdr hdr;
1536 __le16 StructureSize; /* Must be 41 */
1537 __u8 InfoType;
1538 __u8 FileInfoClass;
1539 __le32 OutputBufferLength;
1540 __le16 InputBufferOffset;
1541 __u16 Reserved;
1542 __le32 InputBufferLength;
1543 __le32 AdditionalInformation;
1544 __le32 Flags;
1545 __u64 PersistentFileId;
1546 __u64 VolatileFileId;
eb3e28c1 1547 __u8 Buffer[];
113be37d
SF
1548} __packed;
1549
1550struct smb2_query_info_rsp {
1551 struct smb2_hdr hdr;
1552 __le16 StructureSize; /* Must be 9 */
1553 __le16 OutputBufferOffset;
1554 __le32 OutputBufferLength;
eb3e28c1 1555 __u8 Buffer[];
113be37d 1556} __packed;
d8d9de53 1557
be135000
SF
1558/*
1559 * PDU query infolevel structure definitions
1560 */
1561
a42078b9 1562/* See MS-FSCC 2.3.52 */
be135000
SF
1563struct file_allocated_range_buffer {
1564 __le64 file_offset;
1565 __le64 length;
1566} __packed;
1567
1568struct smb2_file_internal_info {
1569 __le64 IndexNumber;
1570} __packed; /* level 6 Query */
1571
1572struct smb2_file_rename_info { /* encoding of request for level 10 */
1573 __u8 ReplaceIfExists; /* 1 = replace existing target with new */
1574 /* 0 = fail if target already exists */
1575 __u8 Reserved[7];
1576 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1577 __le32 FileNameLength;
1578 char FileName[]; /* New name to be assigned */
1579 /* padding - overall struct size must be >= 24 so filename + pad >= 6 */
1580} __packed; /* level 10 Set */
1581
1582struct smb2_file_link_info { /* encoding of request for level 11 */
1583 __u8 ReplaceIfExists; /* 1 = replace existing link with new */
1584 /* 0 = fail if link already exists */
1585 __u8 Reserved[7];
1586 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
1587 __le32 FileNameLength;
1588 char FileName[]; /* Name to be assigned to new link */
1589} __packed; /* level 11 Set */
1590
1591/*
1592 * This level 18, although with struct with same name is different from cifs
1593 * level 0x107. Level 0x107 has an extra u64 between AccessFlags and
1594 * CurrentByteOffset.
1595 */
1596struct smb2_file_all_info { /* data block encoding of response to level 18 */
1597 __le64 CreationTime; /* Beginning of FILE_BASIC_INFO equivalent */
1598 __le64 LastAccessTime;
1599 __le64 LastWriteTime;
1600 __le64 ChangeTime;
1601 __le32 Attributes;
1602 __u32 Pad1; /* End of FILE_BASIC_INFO_INFO equivalent */
1603 __le64 AllocationSize; /* Beginning of FILE_STANDARD_INFO equivalent */
1604 __le64 EndOfFile; /* size ie offset to first free byte in file */
1605 __le32 NumberOfLinks; /* hard links */
1606 __u8 DeletePending;
1607 __u8 Directory;
1608 __u16 Pad2; /* End of FILE_STANDARD_INFO equivalent */
1609 __le64 IndexNumber;
1610 __le32 EASize;
1611 __le32 AccessFlags;
1612 __le64 CurrentByteOffset;
1613 __le32 Mode;
1614 __le32 AlignmentRequirement;
1615 __le32 FileNameLength;
eb3e28c1
KC
1616 union {
1617 char __pad; /* Legacy structure padding */
1618 DECLARE_FLEX_ARRAY(char, FileName);
1619 };
be135000
SF
1620} __packed; /* level 18 Query */
1621
1622struct smb2_file_eof_info { /* encoding of request for level 10 */
1623 __le64 EndOfFile; /* new end of file value */
1624} __packed; /* level 20 Set */
1625
1626/* Level 100 query info */
1627struct smb311_posix_qinfo {
1628 __le64 CreationTime;
1629 __le64 LastAccessTime;
1630 __le64 LastWriteTime;
1631 __le64 ChangeTime;
1632 __le64 EndOfFile;
1633 __le64 AllocationSize;
1634 __le32 DosAttributes;
1635 __le64 Inode;
1636 __le32 DeviceId;
1637 __le32 Zero;
1638 /* beginning of POSIX Create Context Response */
1639 __le32 HardLinks;
1640 __le32 ReparseTag;
1641 __le32 Mode;
1642 u8 Sids[];
1643 /*
1644 * var sized owner SID
1645 * var sized group SID
1646 * le32 filenamelength
1647 * u8 filename[]
1648 */
1649} __packed;
1650
1651/* File System Information Classes */
1652#define FS_VOLUME_INFORMATION 1 /* Query */
1653#define FS_LABEL_INFORMATION 2 /* Set */
1654#define FS_SIZE_INFORMATION 3 /* Query */
1655#define FS_DEVICE_INFORMATION 4 /* Query */
1656#define FS_ATTRIBUTE_INFORMATION 5 /* Query */
1657#define FS_CONTROL_INFORMATION 6 /* Query, Set */
1658#define FS_FULL_SIZE_INFORMATION 7 /* Query */
1659#define FS_OBJECT_ID_INFORMATION 8 /* Query, Set */
1660#define FS_DRIVER_PATH_INFORMATION 9 /* Query */
1661#define FS_SECTOR_SIZE_INFORMATION 11 /* SMB3 or later. Query */
1662#define FS_POSIX_INFORMATION 100 /* SMB3.1.1 POSIX. Query */
1663
1664struct smb2_fs_full_size_info {
1665 __le64 TotalAllocationUnits;
1666 __le64 CallerAvailableAllocationUnits;
1667 __le64 ActualAvailableAllocationUnits;
1668 __le32 SectorsPerAllocationUnit;
1669 __le32 BytesPerSector;
1670} __packed;
1671
1672#define SSINFO_FLAGS_ALIGNED_DEVICE 0x00000001
1673#define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE 0x00000002
1674#define SSINFO_FLAGS_NO_SEEK_PENALTY 0x00000004
1675#define SSINFO_FLAGS_TRIM_ENABLED 0x00000008
1676
1677/* sector size info struct */
1678struct smb3_fs_ss_info {
1679 __le32 LogicalBytesPerSector;
1680 __le32 PhysicalBytesPerSectorForAtomicity;
1681 __le32 PhysicalBytesPerSectorForPerf;
1682 __le32 FSEffPhysicalBytesPerSectorForAtomicity;
1683 __le32 Flags;
1684 __le32 ByteOffsetForSectorAlignment;
1685 __le32 ByteOffsetForPartitionAlignment;
1686} __packed;
1687
1688/* File System Control Information */
1689struct smb2_fs_control_info {
1690 __le64 FreeSpaceStartFiltering;
1691 __le64 FreeSpaceThreshold;
1692 __le64 FreeSpaceStopFiltering;
1693 __le64 DefaultQuotaThreshold;
1694 __le64 DefaultQuotaLimit;
1695 __le32 FileSystemControlFlags;
1696 __le32 Padding;
1697} __packed;
1698
1699/* volume info struct - see MS-FSCC 2.5.9 */
1700#define MAX_VOL_LABEL_LEN 32
1701struct smb3_fs_vol_info {
1702 __le64 VolumeCreationTime;
1703 __u32 VolumeSerialNumber;
1704 __le32 VolumeLabelLength; /* includes trailing null */
1705 __u8 SupportsObjects; /* True if eg like NTFS, supports objects */
1706 __u8 Reserved;
1707 __u8 VolumeLabel[]; /* variable len */
1708} __packed;
c7803b05
SF
1709
1710/* See MS-SMB2 2.2.23 through 2.2.25 */
1711struct smb2_oplock_break {
1712 struct smb2_hdr hdr;
1713 __le16 StructureSize; /* Must be 24 */
1714 __u8 OplockLevel;
1715 __u8 Reserved;
1716 __le32 Reserved2;
1717 __u64 PersistentFid;
1718 __u64 VolatileFid;
1719} __packed;
1720
1721#define SMB2_NOTIFY_BREAK_LEASE_FLAG_ACK_REQUIRED cpu_to_le32(0x01)
1722
1723struct smb2_lease_break {
1724 struct smb2_hdr hdr;
1725 __le16 StructureSize; /* Must be 44 */
1726 __le16 Epoch;
1727 __le32 Flags;
1728 __u8 LeaseKey[16];
1729 __le32 CurrentLeaseState;
1730 __le32 NewLeaseState;
1731 __le32 BreakReason;
1732 __le32 AccessMaskHint;
1733 __le32 ShareMaskHint;
1734} __packed;
1735
1736struct smb2_lease_ack {
1737 struct smb2_hdr hdr;
1738 __le16 StructureSize; /* Must be 36 */
1739 __le16 Reserved;
1740 __le32 Flags;
1741 __u8 LeaseKey[16];
1742 __le32 LeaseState;
1743 __le64 LeaseDuration;
1744} __packed;
1745
1746#define OP_BREAK_STRUCT_SIZE_20 24
1747#define OP_BREAK_STRUCT_SIZE_21 36
0d35e382 1748#endif /* _COMMON_SMB2PDU_H */