Skip to contentSkip to conversation

smb: move duplicate definitions to common header file

PATCH Applied [email protected] 2 participants 3 messages Nov 17, 2025 – Nov 18, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v9 cover smb: move duplicate definitions to common header file

From: ChenXiaoSong <[email protected]>

I have tested the relevant code related to FILE_SYSTEM_ATTRIBUTE_INFO: https://chenxiaosong.com/en/FILE_SYSTEM_ATTRIBUTE_INFO.html

I have tested all patches using xfstests and smbtorture, and no additional test failures were observed in the results. The detailed test results can be found in https://chenxiaosong.com/en/smb-test-20251117.html

v3: https://lore.kernel.org/all/[email protected]/
The following patches from v3 have already been merged into the mainline:
- d877470b5991 smb: move some duplicate definitions to common/cifsglob.h
- 379510a815cb smb/server: fix possible refcount leak in smb2_sess_setup()
- 6fced056d2cc smb/server: fix possible memory leak in smb2_read()

v4: https://lore.kernel.org/all/[email protected]/
v5: https://lore.kernel.org/all/[email protected]/
v7: https://lore.kernel.org/all/[email protected]/
The following patches from v4 v5 v7 have been applied to the ksmbd-for-next-next branch: https://git.samba.org/?p=ksmbd.git;a=shortlog;h=refs/heads/ksmbd-for-next-next
- smb: move create_durable_reconn to common/smb2pdu.h
- smb: fix some warnings reported by scripts/checkpatch.pl
- smb: do some cleanups
- smb: move FILE_SYSTEM_SIZE_INFO to common/fscc.h
- smb: move some duplicate struct definitions to common/fscc.h
- smb: move list of FileSystemAttributes to common/fscc.h
- smb: move SMB_NEGOTIATE_REQ to common/smb2pdu.h
- smb: move some duplicate definitions to common/smb2pdu.h
- smb: move create_durable_rsp_v2 to common/smb2pdu.h
- smb: move create_durable_handle_reconnect_v2 to common/smb2pdu.h
- smb: move create_durable_req_v2 to common/smb2pdu.h
- smb: move MAX_CIFS_SMALL_BUFFER_SIZE to common/smbglob.h
- smb/client: fix CAP_BULK_TRANSFER value
- smb: move resume_key_ioctl_rsp to common/smb2pdu.h
- smb: move copychunk definitions to common/smb2pdu.h
- smb: move smb_sockaddr_in and smb_sockaddr_in6 to common/smb2pdu.h
- smb: move SMB1_PROTO_NUMBER to common/smbglob.h
- smb: move get_rfc1002_len() to common/smbglob.h
- smb: move smb_version_values to common/smbglob.h
- smb: rename common/cifsglob.h to common/smbglob.h

v8: https://lore.kernel.org/all/[email protected]/
v8->v9:
- SMB2_QFS_attr(): memcpy(..., min_len)
- Fix typo: FS-FSCC -> MS-FSCC

ChenXiaoSong (1):
smb: move FILE_SYSTEM_ATTRIBUTE_INFO to common/fscc.h

 fs/smb/client/cifspdu.h    | 10 ----------
 fs/smb/client/smb2pdu.c    |  6 +++---
 fs/smb/common/fscc.h       |  9 +++++++++
 fs/smb/server/smb2pdu.c    |  6 +++---
 fs/smb/server/smb_common.h |  7 -------
 5 files changed, 15 insertions(+), 23 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v9 1/1 smb: move FILE_SYSTEM_ATTRIBUTE_INFO to common/fscc.h

From: ChenXiaoSong <[email protected]>

Modify the following places:

- struct filesystem_attribute_info -> FILE_SYSTEM_ATTRIBUTE_INFO
- Remove MIN_FS_ATTR_INFO_SIZE definition
- Introduce MAX_FS_NAME_LEN
- max_len of FileFsAttributeInformation -> sizeof(FILE_SYSTEM_ATTRIBUTE_INFO) + MAX_FS_NAME_LEN
- min_len of FileFsAttributeInformation -> sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)
- SMB2_QFS_attr(): memcpy(..., min_len)

Then move FILE_SYSTEM_ATTRIBUTE_INFO to common header file.

I have tested the relevant code related to FILE_SYSTEM_ATTRIBUTE_INFO (Link[1]).

Link[1]: https://chenxiaosong.com/en/FILE_SYSTEM_ATTRIBUTE_INFO.html

---
 fs/smb/client/cifspdu.h    | 10 ----------
 fs/smb/client/smb2pdu.c    |  6 +++---
 fs/smb/common/fscc.h       |  9 +++++++++
 fs/smb/server/smb2pdu.c    |  6 +++---
 fs/smb/server/smb_common.h |  7 -------
 5 files changed, 15 insertions(+), 23 deletions(-)
fs/smb/client/cifspdu.h +0 -10
index d84e10b1477f..49f35cb3cf2e 100644
@@ -2068,16 +2068,6 @@ typedef struct {
 #define FILE_PORTABLE_DEVICE			0x00004000
 #define FILE_DEVICE_ALLOW_APPCONTAINER_TRAVERSAL 0x00020000
 
-/* minimum includes first three fields, and empty FS Name */
-#define MIN_FS_ATTR_INFO_SIZE 12
-
-typedef struct {
-	__le32 Attributes;
-	__le32 MaxPathNameComponentLength;
-	__le32 FileSystemNameLen;
-	char FileSystemName[52]; /* do not have to save this - get subset? */
-} __attribute__((packed)) FILE_SYSTEM_ATTRIBUTE_INFO;
-
 /******************************************************************************/
 /* QueryFileInfo/QueryPathinfo (also for SetPath/SetFile) data buffer formats */
 /******************************************************************************/
fs/smb/client/smb2pdu.c +3 -3
index 032b4b037f07..ef2c6ac500f7 100644
@@ -5981,8 +5981,8 @@ SMB2_QFS_attr(const unsigned int xid, struct cifs_tcon *tcon,
 		max_len = sizeof(FILE_SYSTEM_DEVICE_INFO);
 		min_len = sizeof(FILE_SYSTEM_DEVICE_INFO);
 	} else if (level == FS_ATTRIBUTE_INFORMATION) {
-		max_len = sizeof(FILE_SYSTEM_ATTRIBUTE_INFO);
-		min_len = MIN_FS_ATTR_INFO_SIZE;
+		max_len = sizeof(FILE_SYSTEM_ATTRIBUTE_INFO) + MAX_FS_NAME_LEN;
+		min_len = sizeof(FILE_SYSTEM_ATTRIBUTE_INFO);
 	} else if (level == FS_SECTOR_SIZE_INFORMATION) {
 		max_len = sizeof(struct smb3_fs_ss_info);
 		min_len = sizeof(struct smb3_fs_ss_info);
@@ -6028,7 +6028,7 @@ SMB2_QFS_attr(const unsigned int xid, struct cifs_tcon *tcon,
 	if (level == FS_ATTRIBUTE_INFORMATION)
 		memcpy(&tcon->fsAttrInfo, offset
 			+ (char *)rsp, min_t(unsigned int,
-			rsp_len, max_len));
+			rsp_len, min_len));
 	else if (level == FS_DEVICE_INFORMATION)
 		memcpy(&tcon->fsDevInfo, offset
 			+ (char *)rsp, sizeof(FILE_SYSTEM_DEVICE_INFO));
fs/smb/common/fscc.h +9 -0
index a0580a772a41..35dbacdbb902 100644
@@ -94,6 +94,15 @@ struct smb2_file_network_open_info {
 	__le32 Reserved;
 } __packed; /* level 34 Query also similar returned in close rsp and open rsp */
 
+/* See MS-FSCC 2.5.1 */
+#define MAX_FS_NAME_LEN		52
+typedef struct {
+	__le32 Attributes;
+	__le32 MaxPathNameComponentLength;
+	__le32 FileSystemNameLen;
+	__le16 FileSystemName[]; /* do not have to save this - get subset? */
+} __packed FILE_SYSTEM_ATTRIBUTE_INFO;
+
 /* List of FileSystemAttributes - see MS-FSCC 2.5.1 */
 #define FILE_SUPPORTS_SPARSE_VDL	0x10000000 /* faster nonsparse extend */
 #define FILE_SUPPORTS_BLOCK_REFCOUNTING	0x08000000 /* allow ioctl dup extents */
fs/smb/server/smb2pdu.c +3 -3
index c71f156cc64a..1c8935f61150 100644
@@ -5492,10 +5492,10 @@ static int smb2_get_info_filesystem(struct ksmbd_work *work,
 	}
 	case FS_ATTRIBUTE_INFORMATION:
 	{
-		struct filesystem_attribute_info *info;
+		FILE_SYSTEM_ATTRIBUTE_INFO *info;
 		size_t sz;
 
-		info = (struct filesystem_attribute_info *)rsp->Buffer;
+		info = (FILE_SYSTEM_ATTRIBUTE_INFO *)rsp->Buffer;
 		info->Attributes = cpu_to_le32(FILE_SUPPORTS_OBJECT_IDS |
 					       FILE_PERSISTENT_ACLS |
 					       FILE_UNICODE_ON_DISK |
@@ -5514,7 +5514,7 @@ static int smb2_get_info_filesystem(struct ksmbd_work *work,
 					"NTFS", PATH_MAX, conn->local_nls, 0);
 		len = len * 2;
 		info->FileSystemNameLen = cpu_to_le32(len);
-		sz = sizeof(struct filesystem_attribute_info) + len;
+		sz = sizeof(FILE_SYSTEM_ATTRIBUTE_INFO) + len;
 		rsp->OutputBufferLength = cpu_to_le32(sz);
 		break;
 	}
fs/smb/server/smb_common.h +0 -7
index 4dd573c5f0b2..6c1607b43eb3 100644
@@ -90,13 +90,6 @@ struct smb_negotiate_rsp {
 	__le16 ByteCount;
 } __packed;
 
-struct filesystem_attribute_info {
-	__le32 Attributes;
-	__le32 MaxPathNameComponentLength;
-	__le32 FileSystemNameLen;
-	__le16 FileSystemName[]; /* do not have to save this - get subset? */
-} __packed;
-
 struct filesystem_vol_info {
 	__le64 VolumeCreationTime;
 	__le32 SerialNumber;
Signature · 1 line
2.43.0
maintainer Applied
#2 lore raw

Re: [PATCH v9 1/1] smb: move FILE_SYSTEM_ATTRIBUTE_INFO to common/fscc.h

Quoted 12 lines · On Mon, Nov 17, 2025 at 8:29 PM <[email protected]> wrote:

From: ChenXiaoSong <[email protected]>

Modify the following places:

- struct filesystem_attribute_info -> FILE_SYSTEM_ATTRIBUTE_INFO
- Remove MIN_FS_ATTR_INFO_SIZE definition
- Introduce MAX_FS_NAME_LEN
- max_len of FileFsAttributeInformation -> sizeof(FILE_SYSTEM_ATTRIBUTE_INFO) + MAX_FS_NAME_LEN
- min_len of FileFsAttributeInformation -> sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)
- SMB2_QFS_attr(): memcpy(..., min_len)

Quoted 8 lines

Then move FILE_SYSTEM_ATTRIBUTE_INFO to common header file.

I have tested the relevant code related to FILE_SYSTEM_ATTRIBUTE_INFO (Link[1]).

Link[1]: https://chenxiaosong.com/en/FILE_SYSTEM_ATTRIBUTE_INFO.html

Applied it to #ksmbd-for-next-next.
Thanks!