[RFC PATCH v3 4/5] exfat: make crtime user-settable using ptime
From: koraynilay
Date: Sat Oct 31 2026 - 21:58:30 EST
Since exFAT supports user-settable file creation timestamps, map
provenance time (ptime) to exFAT file creation time (crtime) using the
newly introduced ptime API (in commit "vfs: add provenance time
(ptime)").
To do this, implement exfat_fileattr_set(), set .fileattr_set to it for
both file_inode and dir_inode operations and update exfat_fileattr_get()
and exfat_getattr().
The timestamp is now retrievable by using file_getattr() or statx(), and
is settable by using file_setattr() with the FS_XFLAG_PTIME flag.
Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.4.7
Signed-off-by: koraynilay <koray.fra@xxxxxxxxx>
---
fs/exfat/exfat_fs.h | 2 ++
fs/exfat/file.c | 36 +++++++++++++++++++++++++++++++++++-
fs/exfat/namei.c | 1 +
3 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h
index eee573d1697c..aff96afa258a 100644
--- a/fs/exfat/exfat_fs.h
+++ b/fs/exfat/exfat_fs.h
@@ -619,6 +619,8 @@ int exfat_getattr(const struct mnt_idmap *idmap, const struct path *path,
unsigned int query_flags);
struct file_kattr;
int exfat_fileattr_get(struct dentry *dentry, struct file_kattr *fa);
+int exfat_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
+ struct file_kattr *fa);
int exfat_file_fsync(struct file *file, loff_t start, loff_t end, int datasync);
long exfat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
long exfat_compat_ioctl(struct file *filp, unsigned int cmd,
diff --git a/fs/exfat/file.c b/fs/exfat/file.c
index 1386149916bb..70e226cb4ab7 100644
--- a/fs/exfat/file.c
+++ b/fs/exfat/file.c
@@ -384,15 +384,20 @@ int exfat_getattr(const struct mnt_idmap *idmap, const struct path *path,
generic_fillattr(idmap, request_mask, inode, stat);
exfat_truncate_atime(&stat->atime);
- stat->result_mask |= STATX_BTIME;
+ stat->result_mask |= (STATX_BTIME | STATX_PTIME);
stat->btime.tv_sec = ei->i_crtime.tv_sec;
stat->btime.tv_nsec = ei->i_crtime.tv_nsec;
+ stat->ptime.tv_sec = ei->i_crtime.tv_sec;
+ stat->ptime.tv_nsec = ei->i_crtime.tv_nsec;
stat->blksize = EXFAT_SB(inode->i_sb)->cluster_size;
return 0;
}
int exfat_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
{
+ struct inode *inode = d_backing_inode(dentry);
+ struct exfat_inode_info *ei = EXFAT_I(inode);
+
/*
* exFAT compares filenames through an upcase table, so lookup
* is always case-insensitive. Long names are stored in UTF-16
@@ -400,6 +405,11 @@ int exfat_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
*/
fa->fsx_xflags |= FS_XFLAG_CASEFOLD;
fa->flags |= FS_CASEFOLD_FL;
+
+ fa->fsx_ptime.tv_sec = ei->i_crtime.tv_sec;
+ fa->fsx_ptime.tv_nsec = ei->i_crtime.tv_nsec;
+ fa->fsx_xflags |= FS_XFLAG_PTIME;
+
return 0;
}
@@ -485,6 +495,29 @@ int exfat_setattr(const struct mnt_idmap *idmap, struct dentry *dentry,
return error;
}
+int exfat_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
+ struct file_kattr *fa)
+{
+ struct inode *inode = d_backing_inode(dentry);
+ struct exfat_inode_info *ei = EXFAT_I(inode);
+
+ if (fileattr_has_fsx_mask(fa, FS_XFLAG_PTIME))
+ return -EOPNOTSUPP;
+
+ if (fa->flags & ~FS_CASEFOLD_FL)
+ return -EOPNOTSUPP;
+
+ if (fa->fsx_xflags & FS_XFLAG_PTIME) {
+ ei->i_crtime.tv_sec = fa->fsx_ptime.tv_sec;
+ ei->i_crtime.tv_nsec = fa->fsx_ptime.tv_nsec;
+ }
+
+ inode_set_ctime_current(inode);
+ mark_inode_dirty(inode);
+
+ return 0;
+}
+
/*
* modified ioctls from fat/file.c by Welmer Almesberger
*/
@@ -1110,4 +1143,5 @@ const struct inode_operations exfat_file_inode_operations = {
.setattr = exfat_setattr,
.getattr = exfat_getattr,
.fileattr_get = exfat_fileattr_get,
+ .fileattr_set = exfat_fileattr_set,
};
diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c
index 68ddb9c5504f..15ec7f1942c8 100644
--- a/fs/exfat/namei.c
+++ b/fs/exfat/namei.c
@@ -1349,4 +1349,5 @@ const struct inode_operations exfat_dir_inode_operations = {
.setattr = exfat_setattr,
.getattr = exfat_getattr,
.fileattr_get = exfat_fileattr_get,
+ .fileattr_set = exfat_fileattr_set,
};
--
2.56.0