[RFC PATCH v4 10/10] cifs: add provenance time (ptime) and map it to SMB's CreationTime
From: koraynilay
Date: Sun Nov 15 2026 - 13:05:22 EST
Implement provenance time (ptime) in cifs, as introduced in a
previous commit ("vfs: add provenance time (ptime)").
Map it to SMB's CreationTime, making it settable from userspace and
propagating it to the SMB server via FILE_BASIC_INFO.
Support reading ptime via statx(2) and fileattr_get() from the cached
CreationTime.
Update cifs_fileattr_set() to check xflags instead of only legacy flags
and add the cifs_set_file_crtime() helper to wrap the RPC call to the
SMB server.
Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.7
Signed-off-by: koraynilay <koray.fra@xxxxxxxxx>
---
fs/smb/client/cifsfs.c | 8 +++
fs/smb/client/inode.c | 7 ++-
fs/smb/client/ioctl.c | 109 ++++++++++++++++++++++++++++++-----------
3 files changed, 94 insertions(+), 30 deletions(-)
diff --git a/fs/smb/client/cifsfs.c b/fs/smb/client/cifsfs.c
index 8cff7857b450..c2f557e406d3 100644
--- a/fs/smb/client/cifsfs.c
+++ b/fs/smb/client/cifsfs.c
@@ -1307,6 +1307,14 @@ int cifs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
if (READ_ONCE(CIFS_I(inode)->cifsAttrs) & ATTR_COMPRESSED)
fa->flags |= FS_COMPR_FL;
+ /* Report provenance time (ptime) to userspace */
+ if (CIFS_I(inode)->createtime) {
+ fa->fsx_xflags |= FS_XFLAG_PTIME;
+ fa->fsx_xflags_mask |= FS_XFLAG_PTIME;
+ fa->fsx_ptime =
+ cifs_NTtimeToUnix(cpu_to_le64(CIFS_I(inode)->createtime));
+ }
+
/*
* FS_CASEFOLD_FL is defined by UAPI as a folder attribute,
* and userspace tools (e.g., lsattr) display it only on
diff --git a/fs/smb/client/inode.c b/fs/smb/client/inode.c
index 2647785ec1e4..f0b20a72b9c2 100644
--- a/fs/smb/client/inode.c
+++ b/fs/smb/client/inode.c
@@ -222,6 +222,7 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr,
cifs_i->cifsAttrs = fattr->cf_cifsattrs;
cifs_i->reparse_tag = fattr->cf_cifstag;
+ cifs_i->createtime = fattr->cf_createtime;
if (fattr->cf_flags & CIFS_FATTR_NEED_REVAL)
cifs_i->time = 0;
@@ -2958,7 +2959,8 @@ int cifs_getattr(const struct mnt_idmap *idmap, const struct path *path,
* We need to be sure that all dirty pages are written and the server
* has actual ctime, mtime and file length.
*/
- if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_SIZE | STATX_BLOCKS)) &&
+ if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_PTIME
+ | STATX_SIZE | STATX_BLOCKS)) &&
!CIFS_CACHE_READ(CIFS_I(inode)) &&
inode->i_mapping && inode->i_mapping->nrpages != 0) {
rc = filemap_fdatawait(inode->i_mapping);
@@ -2992,6 +2994,9 @@ int cifs_getattr(const struct mnt_idmap *idmap, const struct path *path,
stat->result_mask |= STATX_BTIME;
stat->btime =
cifs_NTtimeToUnix(cpu_to_le64(CIFS_I(inode)->createtime));
+ stat->result_mask |= STATX_PTIME;
+ stat->ptime =
+ cifs_NTtimeToUnix(cpu_to_le64(CIFS_I(inode)->createtime));
}
stat->attributes_mask |= (STATX_ATTR_COMPRESSED | STATX_ATTR_ENCRYPTED);
diff --git a/fs/smb/client/ioctl.c b/fs/smb/client/ioctl.c
index bb8808289a46..19a9556d39b4 100644
--- a/fs/smb/client/ioctl.c
+++ b/fs/smb/client/ioctl.c
@@ -181,6 +181,41 @@ static int cifs_set_compression(unsigned int xid, struct dentry *dentry,
compression_state);
}
+static int cifs_set_file_crtime(unsigned int xid, struct dentry *dentry,
+ struct cifs_tcon *tcon, u64 crtime)
+{
+ struct inode *inode = d_inode(dentry);
+ struct TCP_Server_Info *server = tcon->ses->server;
+ FILE_BASIC_INFO info_buf = {};
+ const char *full_path;
+ void *page;
+ int rc;
+
+ if (!server->ops->set_file_info)
+ return -EOPNOTSUPP;
+
+ info_buf.CreationTime = cpu_to_le64(crtime);
+
+ page = alloc_dentry_path();
+ full_path = build_path_from_dentry(dentry, page);
+ if (IS_ERR(full_path)) {
+ rc = PTR_ERR(full_path);
+ goto out;
+ }
+
+ rc = server->ops->set_file_info(inode, full_path, &info_buf, xid);
+ if (rc == 0) {
+ CIFS_I(inode)->createtime = crtime;
+ CIFS_I(inode)->time = 0;
+ inode_set_ctime_current(inode);
+ }
+
+out:
+ free_dentry_path(page);
+ return rc;
+}
+
+#define CIFS_SUPPORTED_XFLAGS (FS_XFLAG_PTIME)
int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
struct file_kattr *fa)
{
@@ -193,49 +228,65 @@ int cifs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
bool enable_compression;
struct cifs_tcon *tcon;
unsigned int xid;
- int rc;
+ int rc = 0;
- if (!fa->flags_valid)
+ if (fileattr_has_fsx_mask(fa, CIFS_SUPPORTED_XFLAGS))
return -EOPNOTSUPP;
- /*
- * chattr writes back all flags returned by fileattr_get(). Accept
- * FS_CASEFOLD_FL only when it reflects the share's casefold state.
- */
- if (fa->flags & FS_CASEFOLD_FL) {
- rc = cifs_fileattr_get(dentry, ¤t_fa);
- if (rc)
- return rc;
- if (current_fa.flags & FS_CASEFOLD_FL)
- allowed |= FS_CASEFOLD_FL;
- }
- if (fa->flags & ~allowed)
+ if (fa->fsx_xflags_mask & ~CIFS_SUPPORTED_XFLAGS)
return -EOPNOTSUPP;
- enable_compression = fa->flags & FS_COMPR_FL;
- compression_state = enable_compression ? COMPRESSION_FORMAT_DEFAULT :
- COMPRESSION_FORMAT_NONE;
+ if (fa->flags_valid) {
+ /*
+ * chattr writes back all flags returned by fileattr_get(). Accept
+ * FS_CASEFOLD_FL only when it reflects the share's casefold state.
+ */
+ if (fa->flags & FS_CASEFOLD_FL) {
+ rc = cifs_fileattr_get(dentry, ¤t_fa);
+ if (rc)
+ return rc;
+ if (current_fa.flags & FS_CASEFOLD_FL)
+ allowed |= FS_CASEFOLD_FL;
+ }
+ if (fa->flags & ~allowed)
+ return -EOPNOTSUPP;
+ }
tlink = cifs_sb_tlink(cifs_sb);
if (IS_ERR(tlink))
return PTR_ERR(tlink);
tcon = tlink_tcon(tlink);
-
xid = get_xid();
- rc = cifs_set_compression(xid, dentry, tcon, NULL, compression_state);
- free_xid(xid);
- cifs_put_tlink(tlink);
- if (!rc) {
- spin_lock(&inode->i_lock);
- if (enable_compression)
- CIFS_I(inode)->cifsAttrs |= FILE_ATTRIBUTE_COMPRESSED;
- else
- CIFS_I(inode)->cifsAttrs &= ~FILE_ATTRIBUTE_COMPRESSED;
- spin_unlock(&inode->i_lock);
+ /* modern xflags */
+ if (fa->fsx_valid) {
+ if (fa->fsx_xflags_mask & FS_XFLAG_PTIME) {
+ rc = cifs_set_file_crtime(xid, dentry, tcon,
+ cifs_UnixTimeToNT(fa->fsx_ptime));
+ if (rc)
+ goto out;
+ }
+ } else if (fa->flags_valid) { /* legacy flags */
+ enable_compression = fa->flags & FS_COMPR_FL;
+ compression_state = enable_compression ? COMPRESSION_FORMAT_DEFAULT :
+ COMPRESSION_FORMAT_NONE;
+
+ rc = cifs_set_compression(xid, dentry, tcon, NULL, compression_state);
+
+ if (!rc) {
+ spin_lock(&inode->i_lock);
+ if (enable_compression)
+ CIFS_I(inode)->cifsAttrs |= FILE_ATTRIBUTE_COMPRESSED;
+ else
+ CIFS_I(inode)->cifsAttrs &= ~FILE_ATTRIBUTE_COMPRESSED;
+ spin_unlock(&inode->i_lock);
+ }
+ cifs_dbg(FYI, "set compress flag rc %d\n", rc);
}
- cifs_dbg(FYI, "set compress flag rc %d\n", rc);
+out:
+ free_xid(xid);
+ cifs_put_tlink(tlink);
return rc;
}
--
2.56.0