hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/cifs/smb2pdu.h
....@@ -25,12 +25,13 @@
2525 #define _SMB2PDU_H
2626
2727 #include <net/sock.h>
28
+#include <cifsacl.h>
2829
2930 /*
3031 * Note that, due to trying to use names similar to the protocol specifications,
3132 * there are many mixed case field names in the structures below. Although
3233 * this does not match typical Linux kernel style, it is necessary to be
33
- * be able to match against the protocol specfication.
34
+ * able to match against the protocol specfication.
3435 *
3536 * SMB2 commands
3637 * Some commands have minimal (wct=0,bcc=0), or uninteresting, responses
....@@ -85,10 +86,12 @@
8586 #define NUMBER_OF_SMB2_COMMANDS 0x0013
8687
8788 /* 52 transform hdr + 64 hdr + 88 create rsp */
89
+#define SMB2_TRANSFORM_HEADER_SIZE 52
8890 #define MAX_SMB2_HDR_SIZE 204
8991
9092 #define SMB2_PROTO_NUMBER cpu_to_le32(0x424d53fe)
9193 #define SMB2_TRANSFORM_PROTO_NUM cpu_to_le32(0x424d53fd)
94
+#define SMB2_COMPRESSION_TRANSFORM_ID cpu_to_le32(0x424d53fc)
9295
9396 /*
9497 * SMB2 Header Definition
....@@ -117,22 +120,75 @@
117120 __u8 Signature[16];
118121 } __packed;
119122
123
+/* The total header size for SMB2 read and write */
124
+#define SMB2_READWRITE_PDU_HEADER_SIZE (48 + sizeof(struct smb2_sync_hdr))
125
+
120126 struct smb2_sync_pdu {
121127 struct smb2_sync_hdr sync_hdr;
122128 __le16 StructureSize2; /* size of wct area (varies, request specific) */
123129 } __packed;
124130
125
-#define SMB3_AES128CMM_NONCE 11
126
-#define SMB3_AES128GCM_NONCE 12
131
+#define SMB3_AES_CCM_NONCE 11
132
+#define SMB3_AES_GCM_NONCE 12
127133
134
+/* Transform flags (for 3.0 dialect this flag indicates CCM */
135
+#define TRANSFORM_FLAG_ENCRYPTED 0x0001
128136 struct smb2_transform_hdr {
129137 __le32 ProtocolId; /* 0xFD 'S' 'M' 'B' */
130138 __u8 Signature[16];
131139 __u8 Nonce[16];
132140 __le32 OriginalMessageSize;
133141 __u16 Reserved1;
134
- __le16 Flags; /* EncryptionAlgorithm */
142
+ __le16 Flags; /* EncryptionAlgorithm for 3.0, enc enabled for 3.1.1 */
135143 __u64 SessionId;
144
+} __packed;
145
+
146
+/* See MS-SMB2 2.2.42 */
147
+struct smb2_compression_transform_hdr {
148
+ __le32 ProtocolId; /* 0xFC 'S' 'M' 'B' */
149
+ __le32 OriginalCompressedSegmentSize;
150
+ __le16 CompressionAlgorithm;
151
+ __le16 Flags;
152
+ __le16 Length; /* if chained it is length, else offset */
153
+} __packed;
154
+
155
+/* See MS-SMB2 2.2.42.1 */
156
+#define SMB2_COMPRESSION_FLAG_NONE 0x0000
157
+#define SMB2_COMPRESSION_FLAG_CHAINED 0x0001
158
+
159
+struct compression_payload_header {
160
+ __le16 CompressionAlgorithm;
161
+ __le16 Flags;
162
+ __le32 Length; /* length of compressed playload including field below if present */
163
+ /* __le32 OriginalPayloadSize; */ /* optional */
164
+} __packed;
165
+
166
+/* See MS-SMB2 2.2.42.2 */
167
+struct compression_pattern_payload_v1 {
168
+ __le16 Pattern;
169
+ __le16 Reserved1;
170
+ __le16 Reserved2;
171
+ __le32 Repetitions;
172
+} __packed;
173
+
174
+/* See MS-SMB2 2.2.43 */
175
+struct smb2_rdma_transform {
176
+ __le16 RdmaDescriptorOffset;
177
+ __le16 RdmaDescriptorLength;
178
+ __le32 Channel; /* for values see channel description in smb2 read above */
179
+ __le16 TransformCount;
180
+ __le16 Reserved1;
181
+ __le32 Reserved2;
182
+} __packed;
183
+
184
+struct smb2_rdma_encryption_transform {
185
+ __le16 TransformType;
186
+ __le16 SignatureLength;
187
+ __le16 NonceLength;
188
+ __u16 Reserved;
189
+ __u8 Signature[]; /* variable length */
190
+ /* u8 Nonce[] */
191
+ /* followed by padding */
136192 } __packed;
137193
138194 /*
....@@ -142,7 +198,9 @@
142198 #define SMB2_FLAGS_ASYNC_COMMAND cpu_to_le32(0x00000002)
143199 #define SMB2_FLAGS_RELATED_OPERATIONS cpu_to_le32(0x00000004)
144200 #define SMB2_FLAGS_SIGNED cpu_to_le32(0x00000008)
201
+#define SMB2_FLAGS_PRIORITY_MASK cpu_to_le32(0x00000070) /* SMB3.1.1 */
145202 #define SMB2_FLAGS_DFS_OPERATIONS cpu_to_le32(0x10000000)
203
+#define SMB2_FLAGS_REPLAY_OPERATION cpu_to_le32(0x20000000) /* SMB3 & up */
146204
147205 /*
148206 * Definitions for SMB2 Protocol Data Units (network frames)
....@@ -165,6 +223,8 @@
165223 __u8 ErrorData[1]; /* variable length */
166224 } __packed;
167225
226
+#define SYMLINK_ERROR_TAG 0x4c4d5953
227
+
168228 struct smb2_symlink_err_rsp {
169229 __le32 SymLinkLength;
170230 __le32 SymLinkErrorTag;
....@@ -176,7 +236,7 @@
176236 __le16 PrintNameOffset;
177237 __le16 PrintNameLength;
178238 __le32 Flags;
179
- __u8 PathBuffer[0];
239
+ __u8 PathBuffer[];
180240 } __packed;
181241
182242 /* SMB 3.1.1 and later dialects. See MS-SMB2 section 2.2.2.1 */
....@@ -185,6 +245,10 @@
185245 __le32 ErrorId;
186246 __u8 ErrorContextData; /* ErrorDataLength long array */
187247 } __packed;
248
+
249
+/* ErrorId values */
250
+#define SMB2_ERROR_ID_DEFAULT 0x00000000
251
+#define SMB2_ERROR_ID_SHARE_REDIRECT cpu_to_le32(0x72645253) /* "rdRS" */
188252
189253 /* Defines for Type field below (see MS-SMB2 2.2.2.2.2.1) */
190254 #define MOVE_DST_IPADDR_V4 cpu_to_le32(0x00000001)
....@@ -204,7 +268,7 @@
204268 __le16 Flags;
205269 __le16 TargetType;
206270 __le32 IPAddrCount;
207
- struct move_dst_ipaddr IpAddrMoveList[0];
271
+ struct move_dst_ipaddr IpAddrMoveList[];
208272 /* __u8 ResourceName[] */ /* Name of share as counted Unicode string */
209273 } __packed;
210274
....@@ -226,6 +290,7 @@
226290 } __packed;
227291
228292 /* Dialects */
293
+#define SMB10_PROT_ID 0x0000 /* local only, not sent on wire w/CIFS negprot */
229294 #define SMB20_PROT_ID 0x0202
230295 #define SMB21_PROT_ID 0x0210
231296 #define SMB30_PROT_ID 0x0300
....@@ -249,6 +314,17 @@
249314 /* Internal types */
250315 #define SMB2_NT_FIND 0x00100000
251316 #define SMB2_LARGE_FILES 0x00200000
317
+
318
+
319
+/* Negotiate Contexts - ContextTypes. See MS-SMB2 section 2.2.3.1 for details */
320
+#define SMB2_PREAUTH_INTEGRITY_CAPABILITIES cpu_to_le16(1)
321
+#define SMB2_ENCRYPTION_CAPABILITIES cpu_to_le16(2)
322
+#define SMB2_COMPRESSION_CAPABILITIES cpu_to_le16(3)
323
+#define SMB2_NETNAME_NEGOTIATE_CONTEXT_ID cpu_to_le16(5)
324
+#define SMB2_TRANSPORT_CAPABILITIES cpu_to_le16(6)
325
+#define SMB2_RDMA_TRANSFORM_CAPABILITIES cpu_to_le16(7)
326
+#define SMB2_SIGNING_CAPABILITIES cpu_to_le16(8)
327
+#define SMB2_POSIX_EXTENSIONS_AVAILABLE cpu_to_le16(0x100)
252328
253329 struct smb2_neg_context {
254330 __le16 ContextType;
....@@ -284,6 +360,9 @@
284360 /* Encryption Algorithms Ciphers */
285361 #define SMB2_ENCRYPTION_AES128_CCM cpu_to_le16(0x0001)
286362 #define SMB2_ENCRYPTION_AES128_GCM cpu_to_le16(0x0002)
363
+/* we currently do not request AES256_CCM since presumably GCM faster */
364
+#define SMB2_ENCRYPTION_AES256_CCM cpu_to_le16(0x0003)
365
+#define SMB2_ENCRYPTION_AES256_GCM cpu_to_le16(0x0004)
287366
288367 /* Min encrypt context data is one cipher so 2 bytes + 2 byte count field */
289368 #define MIN_ENCRYPT_CTXT_DATA_LEN 4
....@@ -291,16 +370,82 @@
291370 __le16 ContextType; /* 2 */
292371 __le16 DataLength;
293372 __le32 Reserved;
294
- __le16 CipherCount; /* AES-128-GCM and AES-128-CCM */
295
- __le16 Ciphers[1]; /* Ciphers[0] since only one used now */
373
+ /* CipherCount usally 2, but can be 3 when AES256-GCM enabled */
374
+ __le16 CipherCount; /* AES128-GCM and AES128-CCM by default */
375
+ __le16 Ciphers[3];
296376 } __packed;
297377
298
-#define POSIX_CTXT_DATA_LEN 8
378
+/* See MS-SMB2 2.2.3.1.3 */
379
+#define SMB3_COMPRESS_NONE cpu_to_le16(0x0000)
380
+#define SMB3_COMPRESS_LZNT1 cpu_to_le16(0x0001)
381
+#define SMB3_COMPRESS_LZ77 cpu_to_le16(0x0002)
382
+#define SMB3_COMPRESS_LZ77_HUFF cpu_to_le16(0x0003)
383
+/* Pattern scanning algorithm See MS-SMB2 3.1.4.4.1 */
384
+#define SMB3_COMPRESS_PATTERN cpu_to_le16(0x0004) /* Pattern_V1 */
385
+
386
+/* Compression Flags */
387
+#define SMB2_COMPRESSION_CAPABILITIES_FLAG_NONE cpu_to_le32(0x00000000)
388
+#define SMB2_COMPRESSION_CAPABILITIES_FLAG_CHAINED cpu_to_le32(0x00000001)
389
+
390
+struct smb2_compression_capabilities_context {
391
+ __le16 ContextType; /* 3 */
392
+ __le16 DataLength;
393
+ __u32 Reserved;
394
+ __le16 CompressionAlgorithmCount;
395
+ __u16 Padding;
396
+ __u32 Flags;
397
+ __le16 CompressionAlgorithms[3];
398
+} __packed;
399
+
400
+/*
401
+ * For smb2_netname_negotiate_context_id See MS-SMB2 2.2.3.1.4.
402
+ * Its struct simply contains NetName, an array of Unicode characters
403
+ */
404
+struct smb2_netname_neg_context {
405
+ __le16 ContextType; /* 5 */
406
+ __le16 DataLength;
407
+ __le32 Reserved;
408
+ __le16 NetName[]; /* hostname of target converted to UCS-2 */
409
+} __packed;
410
+
411
+/*
412
+ * For rdma transform capabilities context see MS-SMB2 2.2.3.1.6
413
+ * and 2.2.4.1.5
414
+ */
415
+
416
+/* RDMA Transform IDs */
417
+#define SMB2_RDMA_TRANSFORM_NONE 0x0000
418
+#define SMB2_RDMA_TRANSFORM_ENCRYPTION 0x0001
419
+
420
+struct smb2_rdma_transform_capabilities_context {
421
+ __le16 ContextType; /* 7 */
422
+ __le16 DataLength;
423
+ __u32 Reserved;
424
+ __le16 TransformCount;
425
+ __u16 Reserved1;
426
+ __u32 Reserved2;
427
+ __le16 RDMATransformIds[1];
428
+} __packed;
429
+
430
+/* Signing algorithms */
431
+#define SIGNING_ALG_HMAC_SHA256 0
432
+#define SIGNING_ALG_AES_CMAC 1
433
+#define SIGNING_ALG_AES_GMAC 2
434
+
435
+struct smb2_signing_capabilities {
436
+ __le16 ContextType; /* 8 */
437
+ __le16 DataLength;
438
+ __u32 Reserved;
439
+ __le16 SigningAlgorithmCount;
440
+ __le16 SigningAlgorithms[];
441
+} __packed;
442
+
443
+#define POSIX_CTXT_DATA_LEN 16
299444 struct smb2_posix_neg_context {
300445 __le16 ContextType; /* 0x100 */
301446 __le16 DataLength;
302447 __le32 Reserved;
303
- __le64 Reserved1; /* In case needed for future (eg version or caps) */
448
+ __u8 Name[16]; /* POSIX ctxt GUID 93AD25509CB411E7B42383DE968BCD7C */
304449 } __packed;
305450
306451 struct smb2_negotiate_rsp {
....@@ -372,7 +517,7 @@
372517 struct smb2_tree_connect_req {
373518 struct smb2_sync_hdr sync_hdr;
374519 __le16 StructureSize; /* Must be 9 */
375
- __le16 Reserved; /* Flags in SMB3.1.1 */
520
+ __le16 Flags; /* Reserved MBZ for dialects prior to SMB3.1.1 */
376521 __le16 PathOffset;
377522 __le16 PathLength;
378523 __u8 Buffer[1]; /* variable length */
....@@ -387,13 +532,13 @@
387532 __le16 ContextType;
388533 __le16 DataLength;
389534 __le32 Reserved;
390
- __u8 Data[0];
535
+ __u8 Data[];
391536 } __packed;
392537
393538 /* Remoted identity tree connect context structures - see MS-SMB2 2.2.9.2.1 */
394539 struct smb3_blob_data {
395540 __le16 BlobSize;
396
- __u8 BlobData[0];
541
+ __u8 BlobData[];
397542 } __packed;
398543
399544 /* Valid values for Attr */
....@@ -443,14 +588,14 @@
443588 __le16 DeviceGroups; /* offset to SID_ARRAY_DATA struct */
444589 __le16 UserClaims; /* offset to BLOB_DATA struct */
445590 __le16 DeviceClaims; /* offset to BLOB_DATA struct */
446
- __u8 TicketInfo[0]; /* variable length buf - remoted identity data */
591
+ __u8 TicketInfo[]; /* variable length buf - remoted identity data */
447592 } __packed;
448593
449594 struct smb2_tree_connect_req_extension {
450595 __le32 TreeConnectContextOffset;
451596 __le16 TreeConnectContextCount;
452597 __u8 Reserved[10];
453
- __u8 PathName[0]; /* variable sized array */
598
+ __u8 PathName[]; /* variable sized array */
454599 /* followed by array of TreeConnectContexts */
455600 } __packed;
456601
....@@ -599,7 +744,7 @@
599744 | FILE_WRITE_EA_LE | FILE_WRITE_ATTRIBUTES_LE)
600745 #define FILE_EXEC_RIGHTS_LE (FILE_EXECUTE_LE)
601746
602
-/* Impersonation Levels */
747
+/* Impersonation Levels. See MS-WPO section 9.7 and MSDN-IMPERS */
603748 #define IL_ANONYMOUS cpu_to_le32(0x00000000)
604749 #define IL_IDENTIFICATION cpu_to_le32(0x00000001)
605750 #define IL_IMPERSONATION cpu_to_le32(0x00000002)
....@@ -618,9 +763,12 @@
618763 #define SMB2_CREATE_DURABLE_HANDLE_REQUEST_V2 "DH2Q"
619764 #define SMB2_CREATE_DURABLE_HANDLE_RECONNECT_V2 "DH2C"
620765 #define SMB2_CREATE_APP_INSTANCE_ID 0x45BCA66AEFA7F74A9008FA462E144D74
766
+#define SMB2_CREATE_APP_INSTANCE_VERSION 0xB982D0B73B56074FA07B524A8116A010
621767 #define SVHDX_OPEN_DEVICE_CONTEX 0x9CCBCF9E04C1E643980E158DA1F6EC83
622768 #define SMB2_CREATE_TAG_POSIX 0x93AD25509CB411E7B42383DE968BCD7C
623769
770
+/* Flag (SMB3 open response) values */
771
+#define SMB2_CREATE_FLAG_REPARSEPOINT 0x01
624772
625773 /*
626774 * Maximum number of iovs we need for an open/create request.
....@@ -630,9 +778,10 @@
630778 * [3] : durable context
631779 * [4] : posix context
632780 * [5] : time warp context
633
- * [6] : compound padding
781
+ * [6] : query id context
782
+ * [7] : compound padding
634783 */
635
-#define SMB2_CREATE_IOV_SIZE 7
784
+#define SMB2_CREATE_IOV_SIZE 8
636785
637786 struct smb2_create_req {
638787 struct smb2_sync_hdr sync_hdr;
....@@ -651,14 +800,21 @@
651800 __le16 NameLength;
652801 __le32 CreateContextsOffset;
653802 __le32 CreateContextsLength;
654
- __u8 Buffer[0];
803
+ __u8 Buffer[];
655804 } __packed;
805
+
806
+/*
807
+ * Maximum size of a SMB2_CREATE response is 64 (smb2 header) +
808
+ * 88 (fixed part of create response) + 520 (path) + 208 (contexts) +
809
+ * 2 bytes of padding.
810
+ */
811
+#define MAX_SMB2_CREATE_RESPONSE_SIZE 880
656812
657813 struct smb2_create_rsp {
658814 struct smb2_sync_hdr sync_hdr;
659815 __le16 StructureSize; /* Must be 89 */
660816 __u8 OplockLevel;
661
- __u8 Reserved;
817
+ __u8 Flag; /* 0x01 if reparse point */
662818 __le32 CreateAction;
663819 __le64 CreationTime;
664820 __le64 LastAccessTime;
....@@ -682,7 +838,7 @@
682838 __le16 Reserved;
683839 __le16 DataOffset;
684840 __le32 DataLength;
685
- __u8 Buffer[0];
841
+ __u8 Buffer[];
686842 } __packed;
687843
688844 #define SMB2_LEASE_READ_CACHING_HE 0x01
....@@ -694,7 +850,7 @@
694850 #define SMB2_LEASE_HANDLE_CACHING cpu_to_le32(0x02)
695851 #define SMB2_LEASE_WRITE_CACHING cpu_to_le32(0x04)
696852
697
-#define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS cpu_to_le32(0x02)
853
+#define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS cpu_to_le32(0x00000002)
698854 #define SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET cpu_to_le32(0x00000004)
699855
700856 #define SMB2_LEASE_KEY_SIZE 16
....@@ -775,6 +931,15 @@
775931 __le32 Flags; /* see above DHANDLE_FLAG_PERSISTENT */
776932 } __packed;
777933
934
+/* See MS-SMB2 2.2.14.2.9 */
935
+struct create_on_disk_id {
936
+ struct create_context ccontext;
937
+ __u8 Name[8];
938
+ __le64 DiskFileId;
939
+ __le64 VolumeId;
940
+ __u32 Reserved[4];
941
+} __packed;
942
+
778943 /* See MS-SMB2 2.2.14.2.12 */
779944 struct durable_reconnect_context_v2_rsp {
780945 __le32 Timeout;
....@@ -796,11 +961,24 @@
796961
797962 } __packed;
798963
964
+/* See MS-SMB2 2.2.13.2.9 */
965
+struct crt_query_id_ctxt {
966
+ struct create_context ccontext;
967
+ __u8 Name[8];
968
+} __packed;
969
+
970
+struct crt_sd_ctxt {
971
+ struct create_context ccontext;
972
+ __u8 Name[8];
973
+ struct smb3_sd sd;
974
+} __packed;
975
+
976
+
799977 #define COPY_CHUNK_RES_KEY_SIZE 24
800978 struct resume_key_req {
801979 char ResumeKey[COPY_CHUNK_RES_KEY_SIZE];
802980 __le32 ContextLength; /* MBZ */
803
- char Context[0]; /* ignored, Windows sets to 4 bytes of zero */
981
+ char Context[]; /* ignored, Windows sets to 4 bytes of zero */
804982 } __packed;
805983
806984 /* this goes in the ioctl buffer when doing a copychunk request */
....@@ -827,6 +1005,31 @@
8271005 __le32 TotalBytesWritten;
8281006 } __packed;
8291007
1008
+/* See MS-FSCC 2.3.29 and 2.3.30 */
1009
+struct get_retrieval_pointer_count_req {
1010
+ __le64 StartingVcn; /* virtual cluster number (signed) */
1011
+} __packed;
1012
+
1013
+struct get_retrieval_pointer_count_rsp {
1014
+ __le32 ExtentCount;
1015
+} __packed;
1016
+
1017
+/*
1018
+ * See MS-FSCC 2.3.33 and 2.3.34
1019
+ * request is the same as get_retrieval_point_count_req struct above
1020
+ */
1021
+struct smb3_extents {
1022
+ __le64 NextVcn;
1023
+ __le64 Lcn; /* logical cluster number */
1024
+} __packed;
1025
+
1026
+struct get_retrieval_pointers_refcount_rsp {
1027
+ __le32 ExtentCount;
1028
+ __u32 Reserved;
1029
+ __le64 StartingVcn;
1030
+ struct smb3_extents extents[];
1031
+} __packed;
1032
+
8301033 struct fsctl_set_integrity_information_req {
8311034 __le16 ChecksumAlgorithm;
8321035 __le16 Reserved;
....@@ -841,6 +1044,11 @@
8411044 __le32 ClusterSizeInBytes;
8421045 } __packed;
8431046
1047
+struct file_allocated_range_buffer {
1048
+ __le64 file_offset;
1049
+ __le64 length;
1050
+} __packed;
1051
+
8441052 /* Integrity ChecksumAlgorithm choices for above */
8451053 #define CHECKSUM_TYPE_NONE 0x0000
8461054 #define CHECKSUM_TYPE_CRC64 0x0002
....@@ -848,6 +1056,53 @@
8481056
8491057 /* Integrity flags for above */
8501058 #define FSCTL_INTEGRITY_FLAG_CHECKSUM_ENFORCEMENT_OFF 0x00000001
1059
+
1060
+/* Reparse structures - see MS-FSCC 2.1.2 */
1061
+
1062
+/* struct fsctl_reparse_info_req is empty, only response structs (see below) */
1063
+
1064
+struct reparse_data_buffer {
1065
+ __le32 ReparseTag;
1066
+ __le16 ReparseDataLength;
1067
+ __u16 Reserved;
1068
+ __u8 DataBuffer[]; /* Variable Length */
1069
+} __packed;
1070
+
1071
+struct reparse_guid_data_buffer {
1072
+ __le32 ReparseTag;
1073
+ __le16 ReparseDataLength;
1074
+ __u16 Reserved;
1075
+ __u8 ReparseGuid[16];
1076
+ __u8 DataBuffer[]; /* Variable Length */
1077
+} __packed;
1078
+
1079
+struct reparse_mount_point_data_buffer {
1080
+ __le32 ReparseTag;
1081
+ __le16 ReparseDataLength;
1082
+ __u16 Reserved;
1083
+ __le16 SubstituteNameOffset;
1084
+ __le16 SubstituteNameLength;
1085
+ __le16 PrintNameOffset;
1086
+ __le16 PrintNameLength;
1087
+ __u8 PathBuffer[]; /* Variable Length */
1088
+} __packed;
1089
+
1090
+#define SYMLINK_FLAG_RELATIVE 0x00000001
1091
+
1092
+struct reparse_symlink_data_buffer {
1093
+ __le32 ReparseTag;
1094
+ __le16 ReparseDataLength;
1095
+ __u16 Reserved;
1096
+ __le16 SubstituteNameOffset;
1097
+ __le16 SubstituteNameLength;
1098
+ __le16 PrintNameOffset;
1099
+ __le16 PrintNameLength;
1100
+ __le32 Flags;
1101
+ __u8 PathBuffer[]; /* Variable Length */
1102
+} __packed;
1103
+
1104
+/* See MS-FSCC 2.1.2.6 and cifspdu.h for struct reparse_posix_data */
1105
+
8511106
8521107 /* See MS-DFSC 2.2.2 */
8531108 struct fsctl_get_dfs_referral_req {
....@@ -870,7 +1125,7 @@
8701125 __u8 Guid[SMB2_CLIENT_GUID_SIZE];
8711126 __le16 SecurityMode;
8721127 __le16 DialectCount;
873
- __le16 Dialects[3]; /* BB expand this if autonegotiate > 3 dialects */
1128
+ __le16 Dialects[4]; /* BB expand this if autonegotiate > 4 dialects */
8741129 } __packed;
8751130
8761131 struct validate_negotiate_info_rsp {
....@@ -923,6 +1178,13 @@
9231178 __le64 ByteCount; /* Bytes to be copied */
9241179 } __packed;
9251180
1181
+/*
1182
+ * Maximum number of iovs we need for an ioctl request.
1183
+ * [0] : struct smb2_ioctl_req
1184
+ * [1] : in_data
1185
+ */
1186
+#define SMB2_IOCTL_IOV_SIZE 2
1187
+
9261188 struct smb2_ioctl_req {
9271189 struct smb2_sync_hdr sync_hdr;
9281190 __le16 StructureSize; /* Must be 57 */
....@@ -938,7 +1200,7 @@
9381200 __le32 MaxOutputResponse;
9391201 __le32 Flags;
9401202 __u32 Reserved2;
941
- __u8 Buffer[0];
1203
+ __u8 Buffer[];
9421204 } __packed;
9431205
9441206 struct smb2_ioctl_rsp {
....@@ -967,6 +1229,11 @@
9671229 __u64 PersistentFileId; /* opaque endianness */
9681230 __u64 VolatileFileId; /* opaque endianness */
9691231 } __packed;
1232
+
1233
+/*
1234
+ * Maximum size of a SMB2_CLOSE response is 64 (smb2 header) + 60 (data)
1235
+ */
1236
+#define MAX_SMB2_CLOSE_RESPONSE_SIZE 124
9701237
9711238 struct smb2_close_rsp {
9721239 struct smb2_sync_hdr sync_hdr;
....@@ -999,11 +1266,13 @@
9991266
10001267 /* For read request Flags field below, following flag is defined for SMB3.02 */
10011268 #define SMB2_READFLAG_READ_UNBUFFERED 0x01
1269
+#define SMB2_READFLAG_REQUEST_COMPRESSED 0x02 /* See MS-SMB2 2.2.19 */
10021270
10031271 /* Channel field for read and write: exactly one of following flags can be set*/
10041272 #define SMB2_CHANNEL_NONE cpu_to_le32(0x00000000)
10051273 #define SMB2_CHANNEL_RDMA_V1 cpu_to_le32(0x00000001) /* SMB3 or later */
10061274 #define SMB2_CHANNEL_RDMA_V1_INVALIDATE cpu_to_le32(0x00000002) /* >= SMB3.02 */
1275
+#define SMB2_CHANNEL_RDMA_TRANSFORM cpu_to_le32(0x00000003) /* >= SMB3.02, only used on write */
10071276
10081277 /* SMB2 read request without RFC1001 length at the beginning */
10091278 struct smb2_read_plain_req {
....@@ -1023,6 +1292,10 @@
10231292 __u8 Buffer[1];
10241293 } __packed;
10251294
1295
+/* Read flags */
1296
+#define SMB2_READFLAG_RESPONSE_NONE 0x00000000
1297
+#define SMB2_READFLAG_RESPONSE_RDMA_TRANSFORM 0x00000001
1298
+
10261299 struct smb2_read_rsp {
10271300 struct smb2_sync_hdr sync_hdr;
10281301 __le16 StructureSize; /* Must be 17 */
....@@ -1030,7 +1303,7 @@
10301303 __u8 Reserved;
10311304 __le32 DataLength;
10321305 __le32 DataRemaining;
1033
- __u32 Reserved2;
1306
+ __u32 Flags;
10341307 __u8 Buffer[1];
10351308 } __packed;
10361309
....@@ -1046,7 +1319,7 @@
10461319 __le64 Offset;
10471320 __u64 PersistentFileId; /* opaque endianness */
10481321 __u64 VolatileFileId; /* opaque endianness */
1049
- __le32 Channel; /* Reserved MBZ */
1322
+ __le32 Channel; /* MBZ unless SMB3.02 or later */
10501323 __le32 RemainingBytes;
10511324 __le16 WriteChannelInfoOffset;
10521325 __le16 WriteChannelInfoLength;
....@@ -1063,6 +1336,42 @@
10631336 __le32 DataRemaining;
10641337 __u32 Reserved2;
10651338 __u8 Buffer[1];
1339
+} __packed;
1340
+
1341
+/* notify flags */
1342
+#define SMB2_WATCH_TREE 0x0001
1343
+
1344
+/* notify completion filter flags. See MS-FSCC 2.6 and MS-SMB2 2.2.35 */
1345
+#define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001
1346
+#define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002
1347
+#define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004
1348
+#define FILE_NOTIFY_CHANGE_SIZE 0x00000008
1349
+#define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010
1350
+#define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020
1351
+#define FILE_NOTIFY_CHANGE_CREATION 0x00000040
1352
+#define FILE_NOTIFY_CHANGE_EA 0x00000080
1353
+#define FILE_NOTIFY_CHANGE_SECURITY 0x00000100
1354
+#define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200
1355
+#define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400
1356
+#define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800
1357
+
1358
+struct smb2_change_notify_req {
1359
+ struct smb2_sync_hdr sync_hdr;
1360
+ __le16 StructureSize;
1361
+ __le16 Flags;
1362
+ __le32 OutputBufferLength;
1363
+ __u64 PersistentFileId; /* opaque endianness */
1364
+ __u64 VolatileFileId; /* opaque endianness */
1365
+ __le32 CompletionFilter;
1366
+ __u32 Reserved;
1367
+} __packed;
1368
+
1369
+struct smb2_change_notify_rsp {
1370
+ struct smb2_sync_hdr sync_hdr;
1371
+ __le16 StructureSize; /* Must be 9 */
1372
+ __le16 OutputBufferOffset;
1373
+ __le32 OutputBufferLength;
1374
+ __u8 Buffer[1]; /* array of file notify structs */
10661375 } __packed;
10671376
10681377 #define SMB2_LOCKFLAG_SHARED_LOCK 0x0001
....@@ -1111,6 +1420,8 @@
11111420 #define SMB2_RETURN_SINGLE_ENTRY 0x02
11121421 #define SMB2_INDEX_SPECIFIED 0x04
11131422 #define SMB2_REOPEN 0x10
1423
+
1424
+#define SMB2_QUERY_DIRECTORY_IOV_SIZE 2
11141425
11151426 struct smb2_query_directory_req {
11161427 struct smb2_sync_hdr sync_hdr;
....@@ -1182,6 +1493,15 @@
11821493 __le32 OutputBufferLength;
11831494 __u8 Buffer[1];
11841495 } __packed;
1496
+
1497
+/*
1498
+ * Maximum number of iovs we need for a set-info request.
1499
+ * The largest one is rename/hardlink
1500
+ * [0] : struct smb2_set_info_req + smb2_file_[rename|link]_info
1501
+ * [1] : path
1502
+ * [2] : compound padding
1503
+ */
1504
+#define SMB2_SET_INFO_IOV_SIZE 3
11851505
11861506 struct smb2_set_info_req {
11871507 struct smb2_sync_hdr sync_hdr;
....@@ -1288,7 +1608,7 @@
12881608 __le32 VolumeLabelLength; /* includes trailing null */
12891609 __u8 SupportsObjects; /* True if eg like NTFS, supports objects */
12901610 __u8 Reserved;
1291
- __u8 VolumeLabel[0]; /* variable len */
1611
+ __u8 VolumeLabel[]; /* variable len */
12921612 } __packed;
12931613
12941614 /* partial list of QUERY INFO levels */
....@@ -1338,6 +1658,7 @@
13381658 #define FILE_NORMALIZED_NAME_INFORMATION 48
13391659 #define FILEID_GLOBAL_TX_DIRECTORY_INFORMATION 50
13401660 #define FILE_STANDARD_LINK_INFORMATION 54
1661
+#define FILE_ID_INFORMATION 59
13411662
13421663 struct smb2_file_internal_info {
13431664 __le64 IndexNumber;
....@@ -1349,7 +1670,8 @@
13491670 __u8 Reserved[7];
13501671 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
13511672 __le32 FileNameLength;
1352
- char FileName[0]; /* New name to be assigned */
1673
+ char FileName[]; /* New name to be assigned */
1674
+ /* padding - overall struct size must be >= 24 so filename + pad >= 6 */
13531675 } __packed; /* level 10 Set */
13541676
13551677 struct smb2_file_link_info { /* encoding of request for level 11 */
....@@ -1358,18 +1680,15 @@
13581680 __u8 Reserved[7];
13591681 __u64 RootDirectory; /* MBZ for network operations (why says spec?) */
13601682 __le32 FileNameLength;
1361
- char FileName[0]; /* Name to be assigned to new link */
1683
+ char FileName[]; /* Name to be assigned to new link */
13621684 } __packed; /* level 11 Set */
1363
-
1364
-#define SMB2_MIN_EA_BUF 2048
1365
-#define SMB2_MAX_EA_BUF 65536
13661685
13671686 struct smb2_file_full_ea_info { /* encoding of response for level 15 */
13681687 __le32 next_entry_offset;
13691688 __u8 flags;
13701689 __u8 ea_name_length;
13711690 __le16 ea_value_length;
1372
- char ea_data[0]; /* \0 terminated name plus value */
1691
+ char ea_data[]; /* \0 terminated name plus value */
13731692 } __packed; /* level 15 Set */
13741693
13751694 /*
....@@ -1404,6 +1723,107 @@
14041723 __le64 EndOfFile; /* new end of file value */
14051724 } __packed; /* level 20 Set */
14061725
1726
+struct smb2_file_reparse_point_info {
1727
+ __le64 IndexNumber;
1728
+ __le32 Tag;
1729
+} __packed;
1730
+
1731
+struct smb2_file_network_open_info {
1732
+ __le64 CreationTime;
1733
+ __le64 LastAccessTime;
1734
+ __le64 LastWriteTime;
1735
+ __le64 ChangeTime;
1736
+ __le64 AllocationSize;
1737
+ __le64 EndOfFile;
1738
+ __le32 Attributes;
1739
+ __le32 Reserved;
1740
+} __packed; /* level 34 Query also similar returned in close rsp and open rsp */
1741
+
1742
+/* See MS-FSCC 2.4.43 */
1743
+struct smb2_file_id_information {
1744
+ __le64 VolumeSerialNumber;
1745
+ __u64 PersistentFileId; /* opaque endianness */
1746
+ __u64 VolatileFileId; /* opaque endianness */
1747
+} __packed; /* level 59 */
1748
+
14071749 extern char smb2_padding[7];
14081750
1751
+/* equivalent of the contents of SMB3.1.1 POSIX open context response */
1752
+struct create_posix_rsp {
1753
+ u32 nlink;
1754
+ u32 reparse_tag;
1755
+ u32 mode;
1756
+ struct cifs_sid owner; /* var-sized on the wire */
1757
+ struct cifs_sid group; /* var-sized on the wire */
1758
+} __packed;
1759
+
1760
+/*
1761
+ * SMB2-only POSIX info level for query dir
1762
+ *
1763
+ * See posix_info_sid_size(), posix_info_extra_size() and
1764
+ * posix_info_parse() to help with the handling of this struct.
1765
+ */
1766
+struct smb2_posix_info {
1767
+ __le32 NextEntryOffset;
1768
+ __u32 Ignored;
1769
+ __le64 CreationTime;
1770
+ __le64 LastAccessTime;
1771
+ __le64 LastWriteTime;
1772
+ __le64 ChangeTime;
1773
+ __le64 EndOfFile;
1774
+ __le64 AllocationSize;
1775
+ __le32 DosAttributes;
1776
+ __le64 Inode;
1777
+ __le32 DeviceId;
1778
+ __le32 Zero;
1779
+ /* beginning of POSIX Create Context Response */
1780
+ __le32 HardLinks;
1781
+ __le32 ReparseTag;
1782
+ __le32 Mode;
1783
+ /*
1784
+ * var sized owner SID
1785
+ * var sized group SID
1786
+ * le32 filenamelength
1787
+ * u8 filename[]
1788
+ */
1789
+} __packed;
1790
+
1791
+/* Level 100 query info */
1792
+struct smb311_posix_qinfo {
1793
+ __le64 CreationTime;
1794
+ __le64 LastAccessTime;
1795
+ __le64 LastWriteTime;
1796
+ __le64 ChangeTime;
1797
+ __le64 EndOfFile;
1798
+ __le64 AllocationSize;
1799
+ __le32 DosAttributes;
1800
+ __le64 Inode;
1801
+ __le32 DeviceId;
1802
+ __le32 Zero;
1803
+ /* beginning of POSIX Create Context Response */
1804
+ __le32 HardLinks;
1805
+ __le32 ReparseTag;
1806
+ __le32 Mode;
1807
+ u8 Sids[];
1808
+ /*
1809
+ * var sized owner SID
1810
+ * var sized group SID
1811
+ * le32 filenamelength
1812
+ * u8 filename[]
1813
+ */
1814
+} __packed;
1815
+
1816
+/*
1817
+ * Parsed version of the above struct. Allows direct access to the
1818
+ * variable length fields
1819
+ */
1820
+struct smb2_posix_info_parsed {
1821
+ const struct smb2_posix_info *base;
1822
+ size_t size;
1823
+ struct cifs_sid owner;
1824
+ struct cifs_sid group;
1825
+ int name_len;
1826
+ const u8 *name;
1827
+};
1828
+
14091829 #endif /* _SMB2PDU_H */