Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[smb3] move more common protocol header definitions to smbfs_common

We have duplicated definitions for various SMB3 PDUs in
fs/ksmbd and fs/cifs. Some had already been moved to
fs/smbfs_common/smb2pdu.h

Move definitions for
- error response
- query info and various related protocol flags
- various lease handling flags and the create lease context

to smbfs_common/smb2pdu.h to reduce code duplication

Reviewed-by: Namjae Jeon <linkinjeon@kernel.org>
Signed-off-by: Steve French <stfrench@microsoft.com>

+112 -206
+5 -5
fs/cifs/smb2misc.c
··· 203 203 204 204 if (smb2_rsp_struct_sizes[command] != pdu->StructureSize2) { 205 205 if (command != SMB2_OPLOCK_BREAK_HE && (shdr->Status == 0 || 206 - pdu->StructureSize2 != SMB2_ERROR_STRUCTURE_SIZE2)) { 206 + pdu->StructureSize2 != SMB2_ERROR_STRUCTURE_SIZE2_LE)) { 207 207 /* error packets have 9 byte structure size */ 208 208 cifs_dbg(VFS, "Invalid response size %u for command %d\n", 209 209 le16_to_cpu(pdu->StructureSize2), command); ··· 303 303 /* error responses do not have data area */ 304 304 if (shdr->Status && shdr->Status != STATUS_MORE_PROCESSING_REQUIRED && 305 305 (((struct smb2_err_rsp *)shdr)->StructureSize) == 306 - SMB2_ERROR_STRUCTURE_SIZE2) 306 + SMB2_ERROR_STRUCTURE_SIZE2_LE) 307 307 return NULL; 308 308 309 309 /* ··· 478 478 __le32 lease = 0; 479 479 480 480 if (CIFS_CACHE_WRITE(cinode)) 481 - lease |= SMB2_LEASE_WRITE_CACHING; 481 + lease |= SMB2_LEASE_WRITE_CACHING_LE; 482 482 if (CIFS_CACHE_HANDLE(cinode)) 483 - lease |= SMB2_LEASE_HANDLE_CACHING; 483 + lease |= SMB2_LEASE_HANDLE_CACHING_LE; 484 484 if (CIFS_CACHE_READ(cinode)) 485 - lease |= SMB2_LEASE_READ_CACHING; 485 + lease |= SMB2_LEASE_READ_CACHING_LE; 486 486 return lease; 487 487 } 488 488
+6 -6
fs/cifs/smb2ops.c
··· 4319 4319 map_oplock_to_lease(u8 oplock) 4320 4320 { 4321 4321 if (oplock == SMB2_OPLOCK_LEVEL_EXCLUSIVE) 4322 - return SMB2_LEASE_WRITE_CACHING | SMB2_LEASE_READ_CACHING; 4322 + return SMB2_LEASE_WRITE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE; 4323 4323 else if (oplock == SMB2_OPLOCK_LEVEL_II) 4324 - return SMB2_LEASE_READ_CACHING; 4324 + return SMB2_LEASE_READ_CACHING_LE; 4325 4325 else if (oplock == SMB2_OPLOCK_LEVEL_BATCH) 4326 - return SMB2_LEASE_HANDLE_CACHING | SMB2_LEASE_READ_CACHING | 4327 - SMB2_LEASE_WRITE_CACHING; 4326 + return SMB2_LEASE_HANDLE_CACHING_LE | SMB2_LEASE_READ_CACHING_LE | 4327 + SMB2_LEASE_WRITE_CACHING_LE; 4328 4328 return 0; 4329 4329 } 4330 4330 ··· 4386 4386 struct create_lease *lc = (struct create_lease *)buf; 4387 4387 4388 4388 *epoch = 0; /* not used */ 4389 - if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) 4389 + if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE) 4390 4390 return SMB2_OPLOCK_LEVEL_NOCHANGE; 4391 4391 return le32_to_cpu(lc->lcontext.LeaseState); 4392 4392 } ··· 4397 4397 struct create_lease_v2 *lc = (struct create_lease_v2 *)buf; 4398 4398 4399 4399 *epoch = le16_to_cpu(lc->lcontext.Epoch); 4400 - if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS) 4400 + if (lc->lcontext.LeaseFlags & SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE) 4401 4401 return SMB2_OPLOCK_LEVEL_NOCHANGE; 4402 4402 if (lease_key) 4403 4403 memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);
-100
fs/cifs/smb2pdu.h
··· 56 56 57 57 #define COMPOUND_FID 0xFFFFFFFFFFFFFFFFULL 58 58 59 - #define SMB2_ERROR_STRUCTURE_SIZE2 cpu_to_le16(9) 60 - 61 - struct smb2_err_rsp { 62 - struct smb2_hdr hdr; 63 - __le16 StructureSize; 64 - __le16 Reserved; /* MBZ */ 65 - __le32 ByteCount; /* even if zero, at least one byte follows */ 66 - __u8 ErrorData[1]; /* variable length */ 67 - } __packed; 68 - 69 59 #define SYMLINK_ERROR_TAG 0x4c4d5953 70 60 71 61 struct smb2_symlink_err_rsp { ··· 128 138 #define SMB2_LEASE_READ_CACHING_HE 0x01 129 139 #define SMB2_LEASE_HANDLE_CACHING_HE 0x02 130 140 #define SMB2_LEASE_WRITE_CACHING_HE 0x04 131 - 132 - #define SMB2_LEASE_NONE cpu_to_le32(0x00) 133 - #define SMB2_LEASE_READ_CACHING cpu_to_le32(0x01) 134 - #define SMB2_LEASE_HANDLE_CACHING cpu_to_le32(0x02) 135 - #define SMB2_LEASE_WRITE_CACHING cpu_to_le32(0x04) 136 - 137 - #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS cpu_to_le32(0x00000002) 138 - #define SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET cpu_to_le32(0x00000004) 139 - 140 - #define SMB2_LEASE_KEY_SIZE 16 141 - 142 - struct lease_context { 143 - u8 LeaseKey[SMB2_LEASE_KEY_SIZE]; 144 - __le32 LeaseState; 145 - __le32 LeaseFlags; 146 - __le64 LeaseDuration; 147 - } __packed; 148 - 149 - struct lease_context_v2 { 150 - u8 LeaseKey[SMB2_LEASE_KEY_SIZE]; 151 - __le32 LeaseState; 152 - __le32 LeaseFlags; 153 - __le64 LeaseDuration; 154 - __le64 ParentLeaseKeyLow; 155 - __le64 ParentLeaseKeyHigh; 156 - __le16 Epoch; 157 - __le16 Reserved; 158 - } __packed; 159 - 160 - struct create_lease { 161 - struct create_context ccontext; 162 - __u8 Name[8]; 163 - struct lease_context lcontext; 164 - } __packed; 165 - 166 - struct create_lease_v2 { 167 - struct create_context ccontext; 168 - __u8 Name[8]; 169 - struct lease_context_v2 lcontext; 170 - __u8 Pad[4]; 171 - } __packed; 172 141 173 142 struct create_durable { 174 143 struct create_context ccontext; ··· 546 597 } __packed; 547 598 548 599 struct smb2_query_directory_rsp { 549 - struct smb2_hdr hdr; 550 - __le16 StructureSize; /* Must be 9 */ 551 - __le16 OutputBufferOffset; 552 - __le32 OutputBufferLength; 553 - __u8 Buffer[1]; 554 - } __packed; 555 - 556 - /* Possible InfoType values */ 557 - #define SMB2_O_INFO_FILE 0x01 558 - #define SMB2_O_INFO_FILESYSTEM 0x02 559 - #define SMB2_O_INFO_SECURITY 0x03 560 - #define SMB2_O_INFO_QUOTA 0x04 561 - 562 - /* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */ 563 - #define OWNER_SECINFO 0x00000001 564 - #define GROUP_SECINFO 0x00000002 565 - #define DACL_SECINFO 0x00000004 566 - #define SACL_SECINFO 0x00000008 567 - #define LABEL_SECINFO 0x00000010 568 - #define ATTRIBUTE_SECINFO 0x00000020 569 - #define SCOPE_SECINFO 0x00000040 570 - #define BACKUP_SECINFO 0x00010000 571 - #define UNPROTECTED_SACL_SECINFO 0x10000000 572 - #define UNPROTECTED_DACL_SECINFO 0x20000000 573 - #define PROTECTED_SACL_SECINFO 0x40000000 574 - #define PROTECTED_DACL_SECINFO 0x80000000 575 - 576 - /* Flags used for FileFullEAinfo */ 577 - #define SL_RESTART_SCAN 0x00000001 578 - #define SL_RETURN_SINGLE_ENTRY 0x00000002 579 - #define SL_INDEX_SPECIFIED 0x00000004 580 - 581 - struct smb2_query_info_req { 582 - struct smb2_hdr hdr; 583 - __le16 StructureSize; /* Must be 41 */ 584 - __u8 InfoType; 585 - __u8 FileInfoClass; 586 - __le32 OutputBufferLength; 587 - __le16 InputBufferOffset; 588 - __u16 Reserved; 589 - __le32 InputBufferLength; 590 - __le32 AdditionalInformation; 591 - __le32 Flags; 592 - __u64 PersistentFileId; /* opaque endianness */ 593 - __u64 VolatileFileId; /* opaque endianness */ 594 - __u8 Buffer[1]; 595 - } __packed; 596 - 597 - struct smb2_query_info_rsp { 598 600 struct smb2_hdr hdr; 599 601 __le16 StructureSize; /* Must be 9 */ 600 602 __le16 OutputBufferOffset;
-95
fs/ksmbd/smb2pdu.h
··· 65 65 * 66 66 */ 67 67 68 - #define SMB2_ERROR_STRUCTURE_SIZE2 9 69 - #define SMB2_ERROR_STRUCTURE_SIZE2_LE cpu_to_le16(SMB2_ERROR_STRUCTURE_SIZE2) 70 - 71 - struct smb2_err_rsp { 72 - struct smb2_hdr hdr; 73 - __le16 StructureSize; 74 - __u8 ErrorContextCount; 75 - __u8 Reserved; 76 - __le32 ByteCount; /* even if zero, at least one byte follows */ 77 - __u8 ErrorData[1]; /* variable length */ 78 - } __packed; 79 - 80 68 struct preauth_integrity_info { 81 69 /* PreAuth integrity Hash ID */ 82 70 __le16 Preauth_HashId; ··· 195 207 __le32 reparse_tag; 196 208 __le32 mode; 197 209 u8 SidBuffer[40]; 198 - } __packed; 199 - 200 - #define SMB2_LEASE_NONE_LE cpu_to_le32(0x00) 201 - #define SMB2_LEASE_READ_CACHING_LE cpu_to_le32(0x01) 202 - #define SMB2_LEASE_HANDLE_CACHING_LE cpu_to_le32(0x02) 203 - #define SMB2_LEASE_WRITE_CACHING_LE cpu_to_le32(0x04) 204 - 205 - #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE cpu_to_le32(0x02) 206 - 207 - #define SMB2_LEASE_KEY_SIZE 16 208 - 209 - struct lease_context { 210 - __u8 LeaseKey[SMB2_LEASE_KEY_SIZE]; 211 - __le32 LeaseState; 212 - __le32 LeaseFlags; 213 - __le64 LeaseDuration; 214 - } __packed; 215 - 216 - struct lease_context_v2 { 217 - __u8 LeaseKey[SMB2_LEASE_KEY_SIZE]; 218 - __le32 LeaseState; 219 - __le32 LeaseFlags; 220 - __le64 LeaseDuration; 221 - __u8 ParentLeaseKey[SMB2_LEASE_KEY_SIZE]; 222 - __le16 Epoch; 223 - __le16 Reserved; 224 - } __packed; 225 - 226 - struct create_lease { 227 - struct create_context ccontext; 228 - __u8 Name[8]; 229 - struct lease_context lcontext; 230 - } __packed; 231 - 232 - struct create_lease_v2 { 233 - struct create_context ccontext; 234 - __u8 Name[8]; 235 - struct lease_context_v2 lcontext; 236 - __u8 Pad[4]; 237 210 } __packed; 238 211 239 212 struct smb2_buffer_desc_v1 { ··· 426 477 } __packed; 427 478 428 479 struct smb2_query_directory_rsp { 429 - struct smb2_hdr hdr; 430 - __le16 StructureSize; /* Must be 9 */ 431 - __le16 OutputBufferOffset; 432 - __le32 OutputBufferLength; 433 - __u8 Buffer[1]; 434 - } __packed; 435 - 436 - /* Possible InfoType values */ 437 - #define SMB2_O_INFO_FILE 0x01 438 - #define SMB2_O_INFO_FILESYSTEM 0x02 439 - #define SMB2_O_INFO_SECURITY 0x03 440 - #define SMB2_O_INFO_QUOTA 0x04 441 - 442 - /* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */ 443 - #define OWNER_SECINFO 0x00000001 444 - #define GROUP_SECINFO 0x00000002 445 - #define DACL_SECINFO 0x00000004 446 - #define SACL_SECINFO 0x00000008 447 - #define LABEL_SECINFO 0x00000010 448 - #define ATTRIBUTE_SECINFO 0x00000020 449 - #define SCOPE_SECINFO 0x00000040 450 - #define BACKUP_SECINFO 0x00010000 451 - #define UNPROTECTED_SACL_SECINFO 0x10000000 452 - #define UNPROTECTED_DACL_SECINFO 0x20000000 453 - #define PROTECTED_SACL_SECINFO 0x40000000 454 - #define PROTECTED_DACL_SECINFO 0x80000000 455 - 456 - struct smb2_query_info_req { 457 - struct smb2_hdr hdr; 458 - __le16 StructureSize; /* Must be 41 */ 459 - __u8 InfoType; 460 - __u8 FileInfoClass; 461 - __le32 OutputBufferLength; 462 - __le16 InputBufferOffset; 463 - __u16 Reserved; 464 - __le32 InputBufferLength; 465 - __le32 AdditionalInformation; 466 - __le32 Flags; 467 - __u64 PersistentFileId; 468 - __u64 VolatileFileId; 469 - __u8 Buffer[1]; 470 - } __packed; 471 - 472 - struct smb2_query_info_rsp { 473 480 struct smb2_hdr hdr; 474 481 __le16 StructureSize; /* Must be 9 */ 475 482 __le16 OutputBufferOffset;
+101
fs/smbfs_common/smb2pdu.h
··· 115 115 __le16 StructureSize2; /* size of wct area (varies, request specific) */ 116 116 } __packed; 117 117 118 + #define SMB2_ERROR_STRUCTURE_SIZE2 9 119 + #define SMB2_ERROR_STRUCTURE_SIZE2_LE cpu_to_le16(SMB2_ERROR_STRUCTURE_SIZE2) 120 + 121 + struct smb2_err_rsp { 122 + struct smb2_hdr hdr; 123 + __le16 StructureSize; 124 + __u8 ErrorContextCount; 125 + __u8 Reserved; 126 + __le32 ByteCount; /* even if zero, at least one byte follows */ 127 + __u8 ErrorData[1]; /* variable length */ 128 + } __packed; 129 + 118 130 #define SMB3_AES_CCM_NONCE 11 119 131 #define SMB3_AES_GCM_NONCE 12 120 132 ··· 997 985 __u8 Buffer[1]; 998 986 } __packed; 999 987 988 + #define SMB2_LEASE_NONE_LE cpu_to_le32(0x00) 989 + #define SMB2_LEASE_READ_CACHING_LE cpu_to_le32(0x01) 990 + #define SMB2_LEASE_HANDLE_CACHING_LE cpu_to_le32(0x02) 991 + #define SMB2_LEASE_WRITE_CACHING_LE cpu_to_le32(0x04) 992 + 993 + #define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE cpu_to_le32(0x02) 994 + 995 + #define SMB2_LEASE_KEY_SIZE 16 996 + 997 + struct lease_context { 998 + __u8 LeaseKey[SMB2_LEASE_KEY_SIZE]; 999 + __le32 LeaseState; 1000 + __le32 LeaseFlags; 1001 + __le64 LeaseDuration; 1002 + } __packed; 1003 + 1004 + struct lease_context_v2 { 1005 + __u8 LeaseKey[SMB2_LEASE_KEY_SIZE]; 1006 + __le32 LeaseState; 1007 + __le32 LeaseFlags; 1008 + __le64 LeaseDuration; 1009 + __u8 ParentLeaseKey[SMB2_LEASE_KEY_SIZE]; 1010 + __le16 Epoch; 1011 + __le16 Reserved; 1012 + } __packed; 1013 + 1014 + struct create_lease { 1015 + struct create_context ccontext; 1016 + __u8 Name[8]; 1017 + struct lease_context lcontext; 1018 + } __packed; 1019 + 1020 + struct create_lease_v2 { 1021 + struct create_context ccontext; 1022 + __u8 Name[8]; 1023 + struct lease_context_v2 lcontext; 1024 + __u8 Pad[4]; 1025 + } __packed; 1026 + 1027 + /* Possible InfoType values */ 1028 + #define SMB2_O_INFO_FILE 0x01 1029 + #define SMB2_O_INFO_FILESYSTEM 0x02 1030 + #define SMB2_O_INFO_SECURITY 0x03 1031 + #define SMB2_O_INFO_QUOTA 0x04 1032 + 1033 + /* SMB2 Query Info see MS-SMB2 (2.2.37) or MS-DTYP */ 1034 + 1035 + /* Security info type additionalinfo flags. */ 1036 + #define OWNER_SECINFO 0x00000001 1037 + #define GROUP_SECINFO 0x00000002 1038 + #define DACL_SECINFO 0x00000004 1039 + #define SACL_SECINFO 0x00000008 1040 + #define LABEL_SECINFO 0x00000010 1041 + #define ATTRIBUTE_SECINFO 0x00000020 1042 + #define SCOPE_SECINFO 0x00000040 1043 + #define BACKUP_SECINFO 0x00010000 1044 + #define UNPROTECTED_SACL_SECINFO 0x10000000 1045 + #define UNPROTECTED_DACL_SECINFO 0x20000000 1046 + #define PROTECTED_SACL_SECINFO 0x40000000 1047 + #define PROTECTED_DACL_SECINFO 0x80000000 1048 + 1049 + /* Flags used for FileFullEAinfo */ 1050 + #define SL_RESTART_SCAN 0x00000001 1051 + #define SL_RETURN_SINGLE_ENTRY 0x00000002 1052 + #define SL_INDEX_SPECIFIED 0x00000004 1053 + 1054 + struct smb2_query_info_req { 1055 + struct smb2_hdr hdr; 1056 + __le16 StructureSize; /* Must be 41 */ 1057 + __u8 InfoType; 1058 + __u8 FileInfoClass; 1059 + __le32 OutputBufferLength; 1060 + __le16 InputBufferOffset; 1061 + __u16 Reserved; 1062 + __le32 InputBufferLength; 1063 + __le32 AdditionalInformation; 1064 + __le32 Flags; 1065 + __u64 PersistentFileId; 1066 + __u64 VolatileFileId; 1067 + __u8 Buffer[1]; 1068 + } __packed; 1069 + 1070 + struct smb2_query_info_rsp { 1071 + struct smb2_hdr hdr; 1072 + __le16 StructureSize; /* Must be 9 */ 1073 + __le16 OutputBufferOffset; 1074 + __le32 OutputBufferLength; 1075 + __u8 Buffer[1]; 1076 + } __packed; 1000 1077 1001 1078 #endif /* _COMMON_SMB2PDU_H */