Skip to content

Commit 113be37

Browse files
committed
[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>
1 parent a96c944 commit 113be37

5 files changed

Lines changed: 112 additions & 206 deletions

File tree

fs/cifs/smb2misc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ smb2_check_message(char *buf, unsigned int len, struct TCP_Server_Info *srvr)
203203

204204
if (smb2_rsp_struct_sizes[command] != pdu->StructureSize2) {
205205
if (command != SMB2_OPLOCK_BREAK_HE && (shdr->Status == 0 ||
206-
pdu->StructureSize2 != SMB2_ERROR_STRUCTURE_SIZE2)) {
206+
pdu->StructureSize2 != SMB2_ERROR_STRUCTURE_SIZE2_LE)) {
207207
/* error packets have 9 byte structure size */
208208
cifs_dbg(VFS, "Invalid response size %u for command %d\n",
209209
le16_to_cpu(pdu->StructureSize2), command);
@@ -303,7 +303,7 @@ smb2_get_data_area_len(int *off, int *len, struct smb2_hdr *shdr)
303303
/* error responses do not have data area */
304304
if (shdr->Status && shdr->Status != STATUS_MORE_PROCESSING_REQUIRED &&
305305
(((struct smb2_err_rsp *)shdr)->StructureSize) ==
306-
SMB2_ERROR_STRUCTURE_SIZE2)
306+
SMB2_ERROR_STRUCTURE_SIZE2_LE)
307307
return NULL;
308308

309309
/*
@@ -478,11 +478,11 @@ smb2_get_lease_state(struct cifsInodeInfo *cinode)
478478
__le32 lease = 0;
479479

480480
if (CIFS_CACHE_WRITE(cinode))
481-
lease |= SMB2_LEASE_WRITE_CACHING;
481+
lease |= SMB2_LEASE_WRITE_CACHING_LE;
482482
if (CIFS_CACHE_HANDLE(cinode))
483-
lease |= SMB2_LEASE_HANDLE_CACHING;
483+
lease |= SMB2_LEASE_HANDLE_CACHING_LE;
484484
if (CIFS_CACHE_READ(cinode))
485-
lease |= SMB2_LEASE_READ_CACHING;
485+
lease |= SMB2_LEASE_READ_CACHING_LE;
486486
return lease;
487487
}
488488

fs/cifs/smb2ops.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4319,12 +4319,12 @@ static __le32
43194319
map_oplock_to_lease(u8 oplock)
43204320
{
43214321
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;
43234323
else if (oplock == SMB2_OPLOCK_LEVEL_II)
4324-
return SMB2_LEASE_READ_CACHING;
4324+
return SMB2_LEASE_READ_CACHING_LE;
43254325
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;
43284328
return 0;
43294329
}
43304330

@@ -4386,7 +4386,7 @@ smb2_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
43864386
struct create_lease *lc = (struct create_lease *)buf;
43874387

43884388
*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)
43904390
return SMB2_OPLOCK_LEVEL_NOCHANGE;
43914391
return le32_to_cpu(lc->lcontext.LeaseState);
43924392
}
@@ -4397,7 +4397,7 @@ smb3_parse_lease_buf(void *buf, unsigned int *epoch, char *lease_key)
43974397
struct create_lease_v2 *lc = (struct create_lease_v2 *)buf;
43984398

43994399
*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)
44014401
return SMB2_OPLOCK_LEVEL_NOCHANGE;
44024402
if (lease_key)
44034403
memcpy(lease_key, &lc->lcontext.LeaseKey, SMB2_LEASE_KEY_SIZE);

fs/cifs/smb2pdu.h

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,6 @@ struct smb2_rdma_crypto_transform {
5656

5757
#define COMPOUND_FID 0xFFFFFFFFFFFFFFFFULL
5858

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-
6959
#define SYMLINK_ERROR_TAG 0x4c4d5953
7060

7161
struct smb2_symlink_err_rsp {
@@ -139,47 +129,6 @@ struct share_redirect_error_context_rsp {
139129
#define SMB2_LEASE_HANDLE_CACHING_HE 0x02
140130
#define SMB2_LEASE_WRITE_CACHING_HE 0x04
141131

142-
#define SMB2_LEASE_NONE cpu_to_le32(0x00)
143-
#define SMB2_LEASE_READ_CACHING cpu_to_le32(0x01)
144-
#define SMB2_LEASE_HANDLE_CACHING cpu_to_le32(0x02)
145-
#define SMB2_LEASE_WRITE_CACHING cpu_to_le32(0x04)
146-
147-
#define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS cpu_to_le32(0x00000002)
148-
#define SMB2_LEASE_FLAG_PARENT_LEASE_KEY_SET cpu_to_le32(0x00000004)
149-
150-
#define SMB2_LEASE_KEY_SIZE 16
151-
152-
struct lease_context {
153-
u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
154-
__le32 LeaseState;
155-
__le32 LeaseFlags;
156-
__le64 LeaseDuration;
157-
} __packed;
158-
159-
struct lease_context_v2 {
160-
u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
161-
__le32 LeaseState;
162-
__le32 LeaseFlags;
163-
__le64 LeaseDuration;
164-
__le64 ParentLeaseKeyLow;
165-
__le64 ParentLeaseKeyHigh;
166-
__le16 Epoch;
167-
__le16 Reserved;
168-
} __packed;
169-
170-
struct create_lease {
171-
struct create_context ccontext;
172-
__u8 Name[8];
173-
struct lease_context lcontext;
174-
} __packed;
175-
176-
struct create_lease_v2 {
177-
struct create_context ccontext;
178-
__u8 Name[8];
179-
struct lease_context_v2 lcontext;
180-
__u8 Pad[4];
181-
} __packed;
182-
183132
struct create_durable {
184133
struct create_context ccontext;
185134
__u8 Name[8];
@@ -604,55 +553,6 @@ struct smb2_query_directory_rsp {
604553
__u8 Buffer[1];
605554
} __packed;
606555

607-
/* Possible InfoType values */
608-
#define SMB2_O_INFO_FILE 0x01
609-
#define SMB2_O_INFO_FILESYSTEM 0x02
610-
#define SMB2_O_INFO_SECURITY 0x03
611-
#define SMB2_O_INFO_QUOTA 0x04
612-
613-
/* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */
614-
#define OWNER_SECINFO 0x00000001
615-
#define GROUP_SECINFO 0x00000002
616-
#define DACL_SECINFO 0x00000004
617-
#define SACL_SECINFO 0x00000008
618-
#define LABEL_SECINFO 0x00000010
619-
#define ATTRIBUTE_SECINFO 0x00000020
620-
#define SCOPE_SECINFO 0x00000040
621-
#define BACKUP_SECINFO 0x00010000
622-
#define UNPROTECTED_SACL_SECINFO 0x10000000
623-
#define UNPROTECTED_DACL_SECINFO 0x20000000
624-
#define PROTECTED_SACL_SECINFO 0x40000000
625-
#define PROTECTED_DACL_SECINFO 0x80000000
626-
627-
/* Flags used for FileFullEAinfo */
628-
#define SL_RESTART_SCAN 0x00000001
629-
#define SL_RETURN_SINGLE_ENTRY 0x00000002
630-
#define SL_INDEX_SPECIFIED 0x00000004
631-
632-
struct smb2_query_info_req {
633-
struct smb2_hdr hdr;
634-
__le16 StructureSize; /* Must be 41 */
635-
__u8 InfoType;
636-
__u8 FileInfoClass;
637-
__le32 OutputBufferLength;
638-
__le16 InputBufferOffset;
639-
__u16 Reserved;
640-
__le32 InputBufferLength;
641-
__le32 AdditionalInformation;
642-
__le32 Flags;
643-
__u64 PersistentFileId; /* opaque endianness */
644-
__u64 VolatileFileId; /* opaque endianness */
645-
__u8 Buffer[1];
646-
} __packed;
647-
648-
struct smb2_query_info_rsp {
649-
struct smb2_hdr hdr;
650-
__le16 StructureSize; /* Must be 9 */
651-
__le16 OutputBufferOffset;
652-
__le32 OutputBufferLength;
653-
__u8 Buffer[1];
654-
} __packed;
655-
656556
/*
657557
* Maximum number of iovs we need for a set-info request.
658558
* The largest one is rename/hardlink

fs/ksmbd/smb2pdu.h

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,6 @@
6565
*
6666
*/
6767

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-
8068
struct preauth_integrity_info {
8169
/* PreAuth integrity Hash ID */
8270
__le16 Preauth_HashId;
@@ -209,45 +197,6 @@ struct create_posix_rsp {
209197
u8 SidBuffer[40];
210198
} __packed;
211199

212-
#define SMB2_LEASE_NONE_LE cpu_to_le32(0x00)
213-
#define SMB2_LEASE_READ_CACHING_LE cpu_to_le32(0x01)
214-
#define SMB2_LEASE_HANDLE_CACHING_LE cpu_to_le32(0x02)
215-
#define SMB2_LEASE_WRITE_CACHING_LE cpu_to_le32(0x04)
216-
217-
#define SMB2_LEASE_FLAG_BREAK_IN_PROGRESS_LE cpu_to_le32(0x02)
218-
219-
#define SMB2_LEASE_KEY_SIZE 16
220-
221-
struct lease_context {
222-
__u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
223-
__le32 LeaseState;
224-
__le32 LeaseFlags;
225-
__le64 LeaseDuration;
226-
} __packed;
227-
228-
struct lease_context_v2 {
229-
__u8 LeaseKey[SMB2_LEASE_KEY_SIZE];
230-
__le32 LeaseState;
231-
__le32 LeaseFlags;
232-
__le64 LeaseDuration;
233-
__u8 ParentLeaseKey[SMB2_LEASE_KEY_SIZE];
234-
__le16 Epoch;
235-
__le16 Reserved;
236-
} __packed;
237-
238-
struct create_lease {
239-
struct create_context ccontext;
240-
__u8 Name[8];
241-
struct lease_context lcontext;
242-
} __packed;
243-
244-
struct create_lease_v2 {
245-
struct create_context ccontext;
246-
__u8 Name[8];
247-
struct lease_context_v2 lcontext;
248-
__u8 Pad[4];
249-
} __packed;
250-
251200
struct smb2_buffer_desc_v1 {
252201
__le64 offset;
253202
__le32 token;
@@ -484,50 +433,6 @@ struct smb2_query_directory_rsp {
484433
__u8 Buffer[1];
485434
} __packed;
486435

487-
/* Possible InfoType values */
488-
#define SMB2_O_INFO_FILE 0x01
489-
#define SMB2_O_INFO_FILESYSTEM 0x02
490-
#define SMB2_O_INFO_SECURITY 0x03
491-
#define SMB2_O_INFO_QUOTA 0x04
492-
493-
/* Security info type additionalinfo flags. See MS-SMB2 (2.2.37) or MS-DTYP */
494-
#define OWNER_SECINFO 0x00000001
495-
#define GROUP_SECINFO 0x00000002
496-
#define DACL_SECINFO 0x00000004
497-
#define SACL_SECINFO 0x00000008
498-
#define LABEL_SECINFO 0x00000010
499-
#define ATTRIBUTE_SECINFO 0x00000020
500-
#define SCOPE_SECINFO 0x00000040
501-
#define BACKUP_SECINFO 0x00010000
502-
#define UNPROTECTED_SACL_SECINFO 0x10000000
503-
#define UNPROTECTED_DACL_SECINFO 0x20000000
504-
#define PROTECTED_SACL_SECINFO 0x40000000
505-
#define PROTECTED_DACL_SECINFO 0x80000000
506-
507-
struct smb2_query_info_req {
508-
struct smb2_hdr hdr;
509-
__le16 StructureSize; /* Must be 41 */
510-
__u8 InfoType;
511-
__u8 FileInfoClass;
512-
__le32 OutputBufferLength;
513-
__le16 InputBufferOffset;
514-
__u16 Reserved;
515-
__le32 InputBufferLength;
516-
__le32 AdditionalInformation;
517-
__le32 Flags;
518-
__u64 PersistentFileId;
519-
__u64 VolatileFileId;
520-
__u8 Buffer[1];
521-
} __packed;
522-
523-
struct smb2_query_info_rsp {
524-
struct smb2_hdr hdr;
525-
__le16 StructureSize; /* Must be 9 */
526-
__le16 OutputBufferOffset;
527-
__le32 OutputBufferLength;
528-
__u8 Buffer[1];
529-
} __packed;
530-
531436
struct smb2_set_info_req {
532437
struct smb2_hdr hdr;
533438
__le16 StructureSize; /* Must be 33 */

0 commit comments

Comments
 (0)