Skip to contentSkip to conversation

smb: move duplicate definitions to common header file

PATCH Superseded [email protected] 3 participants 7 messages Nov 16, 2025 – Nov 17, 2025

Subsystems (2)

v8 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v8 cover smb: move duplicate definitions to common header file

From: ChenXiaoSong <[email protected]>

In order to maintain the code more easily, move some duplicate definitions to common header file. Add some MS documentation references for macro and struct definitions.

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-20251116.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

v7 -> v8:
- 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)

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

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

PATCH v8 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)

Then move FILE_SYSTEM_ATTRIBUTE_INFO to common header file.

---
 fs/smb/client/cifspdu.h    | 10 ----------
 fs/smb/client/smb2pdu.c    |  4 ++--
 fs/smb/common/fscc.h       |  9 +++++++++
 fs/smb/server/smb2pdu.c    |  6 +++---
 fs/smb/server/smb_common.h |  7 -------
 5 files changed, 14 insertions(+), 22 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 +2 -2
index 032b4b037f07..1f40458e2156 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);
fs/smb/common/fscc.h +9 -0
index a0580a772a41..226dcdba0a09 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 FS-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
#2 lore raw

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

Quoted 11 lines · On Sun, Nov 16, 2025 at 3:53 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)

Quoted 4 lines

Then move FILE_SYSTEM_ATTRIBUTE_INFO to common header file.

Did you check if it is being used here too?
cifssmb.c:4866: sizeof(FILE_SYSTEM_ATTRIBUTE_INFO));

#3 lore raw

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

Yes, we should also add MAX_FS_NAME_LEN here. This was my mistake.

Thanks,
ChenXiaoSong.

Quoted 19 lines · Namjae Jeon
Quoted 11 lines · On Sun, Nov 16, 2025 at 3:53 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)

Quoted 4 lines

Then move FILE_SYSTEM_ATTRIBUTE_INFO to common header file.

Did you check if it is being used here too?
cifssmb.c:4866: sizeof(FILE_SYSTEM_ATTRIBUTE_INFO));

#4 lore raw

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

And in the following part of the SMB2_QFS_attr() function, it also seems that we should change it to memcpy(..., min_t(..., min_len)).

```c
SMB2_QFS_attr()
{
...
	if (level == FS_ATTRIBUTE_INFORMATION)
	        memcpy(&tcon->fsAttrInfo, offset
	                + (char *)rsp, min_t(unsigned int,
	                rsp_len, max_len));
...
}
```

Thanks,
ChenXiaoSong.

Quoted 26 lines · ChenXiaoSong

Yes, we should also add MAX_FS_NAME_LEN here. This was my mistake.

Thanks,
ChenXiaoSong.

Quoted 19 lines · Namjae Jeon
Quoted 11 lines · On Sun, Nov 16, 2025 at 3:53 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)

Quoted 4 lines

Then move FILE_SYSTEM_ATTRIBUTE_INFO to common header file.

Did you check if it is being used here too? cifssmb.c:4866:        sizeof(FILE_SYSTEM_ATTRIBUTE_INFO));

reviewer
#5 lore raw

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

In reply to Namjae Jeon

Hi Namjae,

I have confirmed that when FileSystemName uses flexible array member, fsAttrInfo in struct cifs_tcon does not include FileSystemName.

The following part in the CIFSSMBQFSAttributeInfo() function is correct, we cannot add MAX_FS_NAME_LEN to sizeof(FILE_SYSTEM_ATTRIBUTE_INFO).

```c
CIFSSMBQFSAttributeInfo()
{
...
	memcpy(&tcon->fsAttrInfo, response_data,
		sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); // it's correct here
...
}
```

And in the following part of the SMB2_QFS_attr() function, we should change it to memcpy(..., min_t(..., min_len)).

```c
SMB2_QFS_attr()
{
...
    if (level == FS_ATTRIBUTE_INFORMATION)
            memcpy(&tcon->fsAttrInfo, offset
                    + (char *)rsp, min_t(unsigned int,
                    rsp_len, max_len)); // should use `min_len` here
...
}
```

Thanks,
ChenXiaoSong.

Quoted 19 lines · Namjae Jeon
Quoted 11 lines · On Sun, Nov 16, 2025 at 3:53 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)

Quoted 4 lines

Then move FILE_SYSTEM_ATTRIBUTE_INFO to common header file.

Did you check if it is being used here too?
cifssmb.c:4866: sizeof(FILE_SYSTEM_ATTRIBUTE_INFO));

#6 lore raw

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

In reply to Namjae Jeon

Hi Namjae,

I have confirmed that when FileSystemName uses flexible array member, fsAttrInfo in struct cifs_tcon does not include FileSystemName.

The following part in the CIFSSMBQFSAttributeInfo() function is correct, we cannot add MAX_FS_NAME_LEN to sizeof(FILE_SYSTEM_ATTRIBUTE_INFO).

```c
CIFSSMBQFSAttributeInfo()
{
...
    memcpy(&tcon->fsAttrInfo, response_data,
        sizeof(FILE_SYSTEM_ATTRIBUTE_INFO)); // it's correct here
...
}
```

And in the following part of the SMB2_QFS_attr() function, we should change it to memcpy(..., min_t(..., min_len)).

```c
SMB2_QFS_attr()
{
...
    if (level == FS_ATTRIBUTE_INFORMATION)
            memcpy(&tcon->fsAttrInfo, offset
                    + (char *)rsp, min_t(unsigned int,
                    rsp_len, max_len)); // should use `min_len` here
...
}
```

Thanks,
ChenXiaoSong.

Quoted 2 lines · Namjae Jeon

Did you check if it is being used here too?
cifssmb.c:4866: sizeof(FILE_SYSTEM_ATTRIBUTE_INFO));