From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12E0B481FBC for ; Tue, 3 Mar 2026 15:14:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772550875; cv=none; b=YrF9I9x6dD9gkmfGxZL6T99iAK8a34WAp5yHiHlnAav3sitjQ2ECl5toQQ2wsmWsOke1JQMpJhOwGdqkUIjrDXi9ml/EJBUjVEPkUiwkjwX/iX22aRgsSvcFD1K94WEWn15q/Si3r+w7LVqfbLCmiY3cCKLhRSS+zf6bqjKwDkg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772550875; c=relaxed/simple; bh=IKyGziBXPSCgND++3xlUln6VAW0U0+TOhpaylXnZsbI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KOGs30A7oYUM5cP6ZNVCJuaQm0sOjHjOcVRwll9oL1HF4srGz7gPA0CHB3BrWhWaLQdQZIPZwTzw+/zqRcsVyLBNBr866+9adlknR7/2Cb1Sb5VTlFzsPP4wsnqANc9UxAT6tY/6kul9v3gxrJ4X9yRzj5ir1vhTefMfUMjQUeo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=a0Zq+fSS; arc=none smtp.client-ip=91.218.175.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="a0Zq+fSS" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1772550869; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NIupcZAVcTeUMQarbrkHhUdcRGWLXJYmP4Pk8fehCCY=; b=a0Zq+fSSSDrrCclY1CLKHyzKKpqUwfwulKbnI7S8dJIj1vO2z995TmzKPCqSbPhd4NFZEH YdKGB/slPgDkHIEbTfSuVY5cvisZZdYsfQzTtj1xpBL5m266p16G4sh7RoOCQRf/wTXKPL qLTcRB2e6r7NlZev1q5XMKAr1GJR4GE= From: zhang.guodong@linux.dev To: smfrench@gmail.com, linkinjeon@kernel.org, pc@manguebit.org, ronniesahlberg@gmail.com, sprasad@microsoft.com, tom@talpey.com, bharathsm@microsoft.com, senozhatsky@chromium.org, dhowells@redhat.com, chenxiaosong@kylinos.cn, chenxiaosong@chenxiaosong.com Cc: linux-cifs@vger.kernel.org Subject: [PATCH v5 7/7] smb: introduce struct file_posix_info Date: Tue, 3 Mar 2026 15:13:17 +0000 Message-ID: <20260303151317.136332-8-zhang.guodong@linux.dev> In-Reply-To: <20260303151317.136332-1-zhang.guodong@linux.dev> References: <20260303151317.136332-1-zhang.guodong@linux.dev> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT From: ZhangGuoDong Extract the common part of struct smb311_posix_qinfo/file_posix_info into a new struct. Modify the following places: - introduce new struct file_posix_info - smb311_posix_qinfo -> file_posix_info - remove struct smb311_posix_qinfo - some fields in "struct smb2_posix_info" -> "struct file_posix_info" Signed-off-by: ZhangGuoDong Reviewed-by: ChenXiaoSong --- fs/smb/client/cifsglob.h | 2 +- fs/smb/client/inode.c | 2 +- fs/smb/client/readdir.c | 28 ++++++++++++------------ fs/smb/client/reparse.h | 2 +- fs/smb/client/smb2inode.c | 4 ++-- fs/smb/client/smb2pdu.h | 21 +----------------- fs/smb/common/fscc.h | 35 ++++++++++++++++++++++++++++- fs/smb/common/smb2pdu.h | 25 --------------------- fs/smb/server/smb2pdu.c | 46 +++++++++++++++++++-------------------- fs/smb/server/smb2pdu.h | 21 +----------------- 10 files changed, 78 insertions(+), 108 deletions(-) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index 6f9b6c72962b..f49e76feb527 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -270,7 +270,7 @@ struct cifs_open_info_data { struct smb_sid posix_group; union { struct smb2_file_all_info fi; - struct smb311_posix_qinfo posix_fi; + struct file_posix_info posix_fi; }; }; diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c index 3e844c55ab8a..11c5eeaa64fd 100644 --- a/fs/smb/client/inode.c +++ b/fs/smb/client/inode.c @@ -835,7 +835,7 @@ static void smb311_posix_info_to_fattr(struct cifs_fattr *fattr, struct cifs_open_info_data *data, struct super_block *sb) { - struct smb311_posix_qinfo *info = &data->posix_fi; + struct file_posix_info *info = &data->posix_fi; struct cifs_sb_info *cifs_sb = CIFS_SB(sb); struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb); diff --git a/fs/smb/client/readdir.c b/fs/smb/client/readdir.c index be22bbc4a65a..6239d70e7984 100644 --- a/fs/smb/client/readdir.c +++ b/fs/smb/client/readdir.c @@ -247,22 +247,22 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info, posix_info_parse(info, NULL, &parsed); memset(fattr, 0, sizeof(*fattr)); - fattr->cf_uniqueid = le64_to_cpu(info->Inode); - fattr->cf_bytes = le64_to_cpu(info->AllocationSize); - fattr->cf_eof = le64_to_cpu(info->EndOfFile); + fattr->cf_uniqueid = le64_to_cpu(info->fpinfo.Inode); + fattr->cf_bytes = le64_to_cpu(info->fpinfo.AllocationSize); + fattr->cf_eof = le64_to_cpu(info->fpinfo.EndOfFile); - fattr->cf_atime = cifs_NTtimeToUnix(info->LastAccessTime); - fattr->cf_mtime = cifs_NTtimeToUnix(info->LastWriteTime); - fattr->cf_ctime = cifs_NTtimeToUnix(info->CreationTime); + fattr->cf_atime = cifs_NTtimeToUnix(info->fpinfo.LastAccessTime); + fattr->cf_mtime = cifs_NTtimeToUnix(info->fpinfo.LastWriteTime); + fattr->cf_ctime = cifs_NTtimeToUnix(info->fpinfo.CreationTime); - fattr->cf_nlink = le32_to_cpu(info->HardLinks); - fattr->cf_cifsattrs = le32_to_cpu(info->DosAttributes); + fattr->cf_nlink = le32_to_cpu(info->fpinfo.HardLinks); + fattr->cf_cifsattrs = le32_to_cpu(info->fpinfo.DosAttributes); if (fattr->cf_cifsattrs & ATTR_REPARSE_POINT) - fattr->cf_cifstag = le32_to_cpu(info->ReparseTag); + fattr->cf_cifstag = le32_to_cpu(info->fpinfo.ReparseTag); /* The Mode field in the response can now include the file type as well */ - fattr->cf_mode = wire_mode_to_posix(le32_to_cpu(info->Mode), + fattr->cf_mode = wire_mode_to_posix(le32_to_cpu(info->fpinfo.Mode), fattr->cf_cifsattrs & ATTR_DIRECTORY); fattr->cf_dtype = S_DT(fattr->cf_mode); @@ -277,9 +277,9 @@ cifs_posix_to_fattr(struct cifs_fattr *fattr, struct smb2_posix_info *info, } cifs_dbg(FYI, "posix fattr: dev %d, reparse %d, mode %o\n", - le32_to_cpu(info->DeviceId), - le32_to_cpu(info->ReparseTag), - le32_to_cpu(info->Mode)); + le32_to_cpu(info->fpinfo.DeviceId), + le32_to_cpu(info->fpinfo.ReparseTag), + le32_to_cpu(info->fpinfo.Mode)); sid_to_id(cifs_sb, &parsed.owner, fattr, SIDOWNER); sid_to_id(cifs_sb, &parsed.group, fattr, SIDGROUP); @@ -517,7 +517,7 @@ static void cifs_fill_dirent_posix(struct cifs_dirent *de, de->name = parsed.name; de->namelen = parsed.name_len; de->resume_key = info->Ignored; - de->ino = le64_to_cpu(info->Inode); + de->ino = le64_to_cpu(info->fpinfo.Inode); } static void cifs_fill_dirent_unix(struct cifs_dirent *de, diff --git a/fs/smb/client/reparse.h b/fs/smb/client/reparse.h index 0164dc47bdfd..674a4686c035 100644 --- a/fs/smb/client/reparse.h +++ b/fs/smb/client/reparse.h @@ -104,7 +104,7 @@ static inline bool cifs_open_data_reparse(struct cifs_open_info_data *data) bool ret; if (data->contains_posix_file_info) { - struct smb311_posix_qinfo *fi = &data->posix_fi; + struct file_posix_info *fi = &data->posix_fi; attrs = le32_to_cpu(fi->DosAttributes); if (data->reparse_point) { diff --git a/fs/smb/client/smb2inode.c b/fs/smb/client/smb2inode.c index 1c4663ed7e69..119a9ac2e6eb 100644 --- a/fs/smb/client/smb2inode.c +++ b/fs/smb/client/smb2inode.c @@ -325,7 +325,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, cfile->fid.volatile_fid, SMB_FIND_FILE_POSIX_INFO, SMB2_O_INFO_FILE, 0, - sizeof(struct smb311_posix_qinfo) + + sizeof(struct file_posix_info) + (PATH_MAX * 2) + (sizeof(struct smb_sid) * 2), 0, NULL); } else { @@ -335,7 +335,7 @@ static int smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, COMPOUND_FID, SMB_FIND_FILE_POSIX_INFO, SMB2_O_INFO_FILE, 0, - sizeof(struct smb311_posix_qinfo) + + sizeof(struct file_posix_info) + (PATH_MAX * 2) + (sizeof(struct smb_sid) * 2), 0, NULL); } diff --git a/fs/smb/client/smb2pdu.h b/fs/smb/client/smb2pdu.h index 30d70097fe2f..912017461f5f 100644 --- a/fs/smb/client/smb2pdu.h +++ b/fs/smb/client/smb2pdu.h @@ -274,26 +274,7 @@ struct create_posix_rsp { struct smb2_posix_info { __le32 NextEntryOffset; __u32 Ignored; - __le64 CreationTime; - __le64 LastAccessTime; - __le64 LastWriteTime; - __le64 ChangeTime; - __le64 EndOfFile; - __le64 AllocationSize; - __le32 DosAttributes; - __le64 Inode; - __le32 DeviceId; - __le32 Zero; - /* beginning of POSIX Create Context Response */ - __le32 HardLinks; - __le32 ReparseTag; - __le32 Mode; - /* - * var sized owner SID - * var sized group SID - * le32 filenamelength - * u8 filename[] - */ + struct file_posix_info fpinfo; } __packed; /* diff --git a/fs/smb/common/fscc.h b/fs/smb/common/fscc.h index b4ccddca9256..da8f2ba0996c 100644 --- a/fs/smb/common/fscc.h +++ b/fs/smb/common/fscc.h @@ -537,9 +537,42 @@ struct file_notify_information { } __packed; /* - * See POSIX Extensions to MS-FSCC 2.3.2.1 + * [POSIX-FSCC] POSIX Extensions to MS-FSCC * Link: https://gitlab.com/samba-team/smb3-posix-spec/-/blob/master/fscc_posix_extensions.md */ + +/* + * This information class is used to query file posix information. + * Level 100 query info + * See POSIX-FSCC 2.3.1.1 + */ +struct file_posix_info { + __le64 CreationTime; + __le64 LastAccessTime; + __le64 LastWriteTime; + __le64 ChangeTime; + __le64 EndOfFile; + __le64 AllocationSize; + __le32 DosAttributes; + __le64 Inode; + __le32 DeviceId; + __le32 Zero; + /* + * Beginning of POSIX Create Context Response + * See POSIX-SMB2 2.2.14.2.16 + */ + __le32 HardLinks; + __le32 ReparseTag; + __le32 Mode; + // var sized owner SID + // var sized group SID + /* End of POSIX Create Context Response */ + // le32 filenamelength + // u8 filename[] + u8 sids_and_name[]; +} __packed; + +/* See POSIX-FSCC 2.3.2.1 */ typedef struct { /* For undefined recommended transfer size return -1 in that field */ __le32 OptimalTransferSize; /* bsize on some os, iosize on other os */ diff --git a/fs/smb/common/smb2pdu.h b/fs/smb/common/smb2pdu.h index 85a4248d4f29..9abfabb79dad 100644 --- a/fs/smb/common/smb2pdu.h +++ b/fs/smb/common/smb2pdu.h @@ -1610,31 +1610,6 @@ struct smb2_query_info_rsp { __u8 Buffer[]; } __packed; -/* Level 100 query info */ -struct smb311_posix_qinfo { - __le64 CreationTime; - __le64 LastAccessTime; - __le64 LastWriteTime; - __le64 ChangeTime; - __le64 EndOfFile; - __le64 AllocationSize; - __le32 DosAttributes; - __le64 Inode; - __le32 DeviceId; - __le32 Zero; - /* beginning of POSIX Create Context Response */ - __le32 HardLinks; - __le32 ReparseTag; - __le32 Mode; - u8 Sids[]; - /* - * var sized owner SID - * var sized group SID - * le32 filenamelength - * u8 filename[] - */ -} __packed; - /* See MS-SMB2 2.2.23 through 2.2.25 */ struct smb2_oplock_break { struct smb2_hdr hdr; diff --git a/fs/smb/server/smb2pdu.c b/fs/smb/server/smb2pdu.c index f73ea4d1db8f..cf1475fae918 100644 --- a/fs/smb/server/smb2pdu.c +++ b/fs/smb/server/smb2pdu.c @@ -4052,44 +4052,44 @@ static int smb2_populate_readdir_entry(struct ksmbd_conn *conn, int info_level, posix_info = (struct smb2_posix_info *)kstat; posix_info->Ignored = 0; - posix_info->CreationTime = cpu_to_le64(ksmbd_kstat->create_time); + posix_info->fpinfo.CreationTime = cpu_to_le64(ksmbd_kstat->create_time); time = ksmbd_UnixTimeToNT(ksmbd_kstat->kstat->ctime); - posix_info->ChangeTime = cpu_to_le64(time); + posix_info->fpinfo.ChangeTime = cpu_to_le64(time); time = ksmbd_UnixTimeToNT(ksmbd_kstat->kstat->atime); - posix_info->LastAccessTime = cpu_to_le64(time); + posix_info->fpinfo.LastAccessTime = cpu_to_le64(time); time = ksmbd_UnixTimeToNT(ksmbd_kstat->kstat->mtime); - posix_info->LastWriteTime = cpu_to_le64(time); - posix_info->EndOfFile = cpu_to_le64(ksmbd_kstat->kstat->size); - posix_info->AllocationSize = cpu_to_le64(ksmbd_kstat->kstat->blocks << 9); - posix_info->DeviceId = cpu_to_le32(ksmbd_kstat->kstat->rdev); - posix_info->HardLinks = cpu_to_le32(ksmbd_kstat->kstat->nlink); - posix_info->Mode = cpu_to_le32(ksmbd_kstat->kstat->mode & 0777); + posix_info->fpinfo.LastWriteTime = cpu_to_le64(time); + posix_info->fpinfo.EndOfFile = cpu_to_le64(ksmbd_kstat->kstat->size); + posix_info->fpinfo.AllocationSize = cpu_to_le64(ksmbd_kstat->kstat->blocks << 9); + posix_info->fpinfo.DeviceId = cpu_to_le32(ksmbd_kstat->kstat->rdev); + posix_info->fpinfo.HardLinks = cpu_to_le32(ksmbd_kstat->kstat->nlink); + posix_info->fpinfo.Mode = cpu_to_le32(ksmbd_kstat->kstat->mode & 0777); switch (ksmbd_kstat->kstat->mode & S_IFMT) { case S_IFDIR: - posix_info->Mode |= cpu_to_le32(POSIX_TYPE_DIR << POSIX_FILETYPE_SHIFT); + posix_info->fpinfo.Mode |= cpu_to_le32(POSIX_TYPE_DIR << POSIX_FILETYPE_SHIFT); break; case S_IFLNK: - posix_info->Mode |= cpu_to_le32(POSIX_TYPE_SYMLINK << POSIX_FILETYPE_SHIFT); + posix_info->fpinfo.Mode |= cpu_to_le32(POSIX_TYPE_SYMLINK << POSIX_FILETYPE_SHIFT); break; case S_IFCHR: - posix_info->Mode |= cpu_to_le32(POSIX_TYPE_CHARDEV << POSIX_FILETYPE_SHIFT); + posix_info->fpinfo.Mode |= cpu_to_le32(POSIX_TYPE_CHARDEV << POSIX_FILETYPE_SHIFT); break; case S_IFBLK: - posix_info->Mode |= cpu_to_le32(POSIX_TYPE_BLKDEV << POSIX_FILETYPE_SHIFT); + posix_info->fpinfo.Mode |= cpu_to_le32(POSIX_TYPE_BLKDEV << POSIX_FILETYPE_SHIFT); break; case S_IFIFO: - posix_info->Mode |= cpu_to_le32(POSIX_TYPE_FIFO << POSIX_FILETYPE_SHIFT); + posix_info->fpinfo.Mode |= cpu_to_le32(POSIX_TYPE_FIFO << POSIX_FILETYPE_SHIFT); break; case S_IFSOCK: - posix_info->Mode |= cpu_to_le32(POSIX_TYPE_SOCKET << POSIX_FILETYPE_SHIFT); + posix_info->fpinfo.Mode |= cpu_to_le32(POSIX_TYPE_SOCKET << POSIX_FILETYPE_SHIFT); } - posix_info->Inode = cpu_to_le64(ksmbd_kstat->kstat->ino); - posix_info->DosAttributes = + posix_info->fpinfo.Inode = cpu_to_le64(ksmbd_kstat->kstat->ino); + posix_info->fpinfo.DosAttributes = S_ISDIR(ksmbd_kstat->kstat->mode) ? FILE_ATTRIBUTE_DIRECTORY_LE : FILE_ATTRIBUTE_ARCHIVE_LE; if (d_info->hide_dot_file && d_info->name[0] == '.') - posix_info->DosAttributes |= FILE_ATTRIBUTE_HIDDEN_LE; + posix_info->fpinfo.DosAttributes |= FILE_ATTRIBUTE_HIDDEN_LE; /* * SidBuffer(32) contain two sids(Domain sid(16), UNIX group sid(16)). * UNIX sid(16) = revision(1) + num_subauth(1) + authority(6) + @@ -5261,14 +5261,14 @@ static int get_file_attribute_tag_info(struct smb2_query_info_rsp *rsp, static int find_file_posix_info(struct smb2_query_info_rsp *rsp, struct ksmbd_file *fp, void *rsp_org) { - struct smb311_posix_qinfo *file_info; + struct file_posix_info *file_info; struct inode *inode = file_inode(fp->filp); struct mnt_idmap *idmap = file_mnt_idmap(fp->filp); vfsuid_t vfsuid = i_uid_into_vfsuid(idmap, inode); vfsgid_t vfsgid = i_gid_into_vfsgid(idmap, inode); struct kstat stat; u64 time; - int out_buf_len = sizeof(struct smb311_posix_qinfo) + 32; + int out_buf_len = sizeof(struct file_posix_info) + 32; int ret; ret = vfs_getattr(&fp->filp->f_path, &stat, STATX_BASIC_STATS, @@ -5276,7 +5276,7 @@ static int find_file_posix_info(struct smb2_query_info_rsp *rsp, if (ret) return ret; - file_info = (struct smb311_posix_qinfo *)rsp->Buffer; + file_info = (struct file_posix_info *)rsp->Buffer; file_info->CreationTime = cpu_to_le64(fp->create_time); time = ksmbd_UnixTimeToNT(stat.atime); file_info->LastAccessTime = cpu_to_le64(time); @@ -5323,9 +5323,9 @@ static int find_file_posix_info(struct smb2_query_info_rsp *rsp, * sub_auth(4 * 1(num_subauth)) + RID(4). */ id_to_sid(from_kuid_munged(&init_user_ns, vfsuid_into_kuid(vfsuid)), - SIDUNIX_USER, (struct smb_sid *)&file_info->Sids[0]); + SIDUNIX_USER, (struct smb_sid *)&file_info->sids_and_name[0]); id_to_sid(from_kgid_munged(&init_user_ns, vfsgid_into_kgid(vfsgid)), - SIDUNIX_GROUP, (struct smb_sid *)&file_info->Sids[16]); + SIDUNIX_GROUP, (struct smb_sid *)&file_info->sids_and_name[16]); rsp->OutputBufferLength = cpu_to_le32(out_buf_len); diff --git a/fs/smb/server/smb2pdu.h b/fs/smb/server/smb2pdu.h index e7cf573e59f0..f05273f48bd0 100644 --- a/fs/smb/server/smb2pdu.h +++ b/fs/smb/server/smb2pdu.h @@ -281,30 +281,11 @@ struct create_sd_buf_req { struct smb2_posix_info { __le32 NextEntryOffset; __u32 Ignored; - __le64 CreationTime; - __le64 LastAccessTime; - __le64 LastWriteTime; - __le64 ChangeTime; - __le64 EndOfFile; - __le64 AllocationSize; - __le32 DosAttributes; - __le64 Inode; - __le32 DeviceId; - __le32 Zero; - /* beginning of POSIX Create Context Response */ - __le32 HardLinks; - __le32 ReparseTag; - __le32 Mode; + struct file_posix_info fpinfo; /* SidBuffer contain two sids (UNIX user sid(16), UNIX group sid(16)) */ u8 SidBuffer[32]; __le32 name_len; u8 name[]; - /* - * var sized owner SID - * var sized group SID - * le32 filenamelength - * u8 filename[] - */ } __packed; /* functions */ -- 2.52.0