* [PATCH 0/3] Add f*_xflags_{rw,ro}_mask flags to the fileattr API
@ 2026-11-22 0:08 koraynilay
2026-11-22 0:08 ` [PATCH 1/3] vfs: use goto out on error in vfs_fileattr_set() koraynilay
` (3 more replies)
0 siblings, 4 replies; 28+ messages in thread
From: koraynilay @ 2026-11-22 0:08 UTC (permalink / raw)
To: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner
Cc: Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong,
Andrey Albershteyn, Amir Goldstein, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
koraynilay
This is a follow up patch series stemmed from [1] and [2], splitting the
_mask change for the fileattr API into its own separate patch.
The first patch is a preparatory patch so that the code in the patch
after can be formatted better.
The second patch is the actual implementation, which introduces:
- fa_xflags_{rw,ro}_mask fields to struct file_attr
- fsx_xflags_{rw,ro}_mask fields and has_masks selector to struct file_kattr
These masks have the following semantics:
- rw_mask:
* for filesystems: advertise which xflags they support changing
* for userspace: specify which xflags it wants to modify
- ro_mask:
* for filesystems: advertise which xflags they support only reading
* for userspace: ignored
(ro_mask for userspace was also proposed as a "verification mask"[3] but
I left out that semantic to keep this patch series more contained, and
can be added later if needed.)
This allows userspace to not have to do a RMW cycle when using the
file_[gs]etattr() syscalls, avoiding possible race conditions and
simplifying their usage.
Patch 2/3 also introduces the missing FS_XFLAG_PROJID flag so that
programs like chattr can leverage the new mask API.
FS_XFLAG_PROJID is kept out of the legacy FS_XFLAG_MASK and so it's
defined as part of a new FS_FILE_ATTR_XFLAGS_MASK group of xflags that
will be used moving forward for any new xflag (like the one proposed in [2]).
Patch 3/3 converts fs/ntfs to this new API, to show how it can benefit
filesystem drivers too.
The series has been tested across NTFS, ext4 (with project quotas), XFS
(project quotas and extent size hints), and Btrfs.
Thanks,
koraynilay
[1]: https://lore.kernel.org/CAOQ4uxg8aVcWyNiFDk8djdn-M3xJcu_7-kRxVq9jjFsbcGp1ew@mail.gmail.com/
[2]: https://lore.kernel.org/CAOQ4uxjVQ9cjV=_jBjQtNg9zCuWUEJT9KNYMKV+1jwBkHen5OA@mail.gmail.com/
[3]: https://lore.kernel.org/CAOQ4uxjCN-ekd18R-soD8tkGFnXjK0S1VdSNhq9b3Ev6y8K9jQ@mail.gmail.com/
koraynilay (3):
vfs: use goto out on error in vfs_fileattr_set()
vfs: add xflags mask to fileattr API
ntfs: switch to the new xflags fileattr API
fs/file_attr.c | 179 ++++++++++++++++++++++++++++++++-------
fs/ntfs/file.c | 63 +++++++-------
include/linux/fileattr.h | 13 ++-
include/uapi/linux/fs.h | 9 +-
4 files changed, 197 insertions(+), 67 deletions(-)
base-commit: 3857587d9d6fa44d40d1c73bde6a39f6f7a5216c
prerequisite-patch-id: 7af19117a27af492e3e525774310fb3a76700ffa
--
2.56.0
^ permalink raw reply [flat|nested] 28+ messages in thread* [PATCH 1/3] vfs: use goto out on error in vfs_fileattr_set() 2026-11-22 0:08 [PATCH 0/3] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay @ 2026-11-22 0:08 ` koraynilay 2026-11-23 8:42 ` Andrey Albershteyn 2026-11-22 0:08 ` [PATCH 2/3] vfs: add xflags mask to fileattr API koraynilay ` (2 subsequent siblings) 3 siblings, 1 reply; 28+ messages in thread From: koraynilay @ 2026-11-22 0:08 UTC (permalink / raw) To: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner Cc: Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Amir Goldstein, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api, koraynilay Switch from using if (!err) { ... } to the cleaner if (err) goto out; in the main body of vfs_fileattr_set(). Signed-off-by: koraynilay <koray.fra@gmail.com> --- fs/file_attr.c | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/fs/file_attr.c b/fs/file_attr.c index 833e03810b24..40d6518f1d8e 100644 --- a/fs/file_attr.c +++ b/fs/file_attr.c @@ -285,30 +285,31 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, inode_lock(inode); err = vfs_fileattr_get(dentry, &old_ma); - if (!err) { - /* initialize missing bits from old_ma */ - if (fa->flags_valid) { - fa->fsx_xflags |= old_ma.fsx_xflags & ~FS_XFLAG_COMMON; - fa->fsx_extsize = old_ma.fsx_extsize; - fa->fsx_nextents = old_ma.fsx_nextents; - fa->fsx_projid = old_ma.fsx_projid; - fa->fsx_cowextsize = old_ma.fsx_cowextsize; - } else { - fa->flags |= old_ma.flags & ~FS_COMMON_FL; - } - - err = fileattr_set_prepare(inode, &old_ma, fa); - if (err) - goto out; - err = security_inode_file_setattr(dentry, fa); - if (err) - goto out; - err = inode->i_op->fileattr_set(idmap, dentry, fa); - if (err) - goto out; - fsnotify_xattr(dentry); + if (err) + goto out; + + /* initialize missing bits from old_ma */ + if (fa->flags_valid) { + fa->fsx_xflags |= old_ma.fsx_xflags & ~FS_XFLAG_COMMON; + fa->fsx_extsize = old_ma.fsx_extsize; + fa->fsx_nextents = old_ma.fsx_nextents; + fa->fsx_projid = old_ma.fsx_projid; + fa->fsx_cowextsize = old_ma.fsx_cowextsize; + } else { + fa->flags |= old_ma.flags & ~FS_COMMON_FL; } + err = fileattr_set_prepare(inode, &old_ma, fa); + if (err) + goto out; + err = security_inode_file_setattr(dentry, fa); + if (err) + goto out; + err = inode->i_op->fileattr_set(idmap, dentry, fa); + if (err) + goto out; + fsnotify_xattr(dentry); + out: inode_unlock(inode); return err; -- 2.56.0 ^ permalink raw reply related [flat|nested] 28+ messages in thread
* Re: [PATCH 1/3] vfs: use goto out on error in vfs_fileattr_set() 2026-11-22 0:08 ` [PATCH 1/3] vfs: use goto out on error in vfs_fileattr_set() koraynilay @ 2026-11-23 8:42 ` Andrey Albershteyn 2026-11-23 14:15 ` koraynilay 0 siblings, 1 reply; 28+ messages in thread From: Andrey Albershteyn @ 2026-11-23 8:42 UTC (permalink / raw) To: koraynilay Cc: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Amir Goldstein, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api On 2026-11-22 01:08:54, koraynilay wrote: > Switch from using if (!err) { ... } to the cleaner if (err) goto out; > in the main body of vfs_fileattr_set(). > > Signed-off-by: koraynilay <koray.fra@gmail.com> Looks good to me Reviewed-by: Andrey Albershteyn <aalbersh@kernel.org> -- - Andrey ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/3] vfs: use goto out on error in vfs_fileattr_set() 2026-11-23 8:42 ` Andrey Albershteyn @ 2026-11-23 14:15 ` koraynilay 2026-11-23 14:18 ` Amir Goldstein 0 siblings, 1 reply; 28+ messages in thread From: koraynilay @ 2026-11-23 14:15 UTC (permalink / raw) To: Andrey Albershteyn, koraynilay Cc: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Amir Goldstein, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api [-- Attachment #1: Type: text/plain, Size: 543 bytes --] On Mon Nov 23, 2026 at 9:42 AM CET, Andrey Albershteyn wrote: > On 2026-11-22 01:08:54, koraynilay wrote: >> Switch from using if (!err) { ... } to the cleaner if (err) goto out; >> in the main body of vfs_fileattr_set(). >> >> Signed-off-by: koraynilay <koray.fra@gmail.com> > > Looks good to me > Reviewed-by: Andrey Albershteyn <aalbersh@kernel.org> Thank you, can I add this tag to the v2 version of this patch (since it won't be changed, and link to this thread in the comment section of the patch)? Thanks, koraynilay [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/3] vfs: use goto out on error in vfs_fileattr_set() 2026-11-23 14:15 ` koraynilay @ 2026-11-23 14:18 ` Amir Goldstein 2026-11-23 14:22 ` koraynilay 0 siblings, 1 reply; 28+ messages in thread From: Amir Goldstein @ 2026-11-23 14:18 UTC (permalink / raw) To: koraynilay Cc: Andrey Albershteyn, Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api On Mon, Nov 23, 2026 at 3:15 PM koraynilay <koray.fra@gmail.com> wrote: > > On Mon Nov 23, 2026 at 9:42 AM CET, Andrey Albershteyn wrote: > > On 2026-11-22 01:08:54, koraynilay wrote: > >> Switch from using if (!err) { ... } to the cleaner if (err) goto out; > >> in the main body of vfs_fileattr_set(). > >> > >> Signed-off-by: koraynilay <koray.fra@gmail.com> > > > > Looks good to me > > Reviewed-by: Andrey Albershteyn <aalbersh@kernel.org> > > Thank you, can I add this tag to the v2 version of this patch (since it > won't be changed, and link to this thread in the comment section of the > patch)? You should always keep RVB when re-posting without meaningful changes to a patch. That's how reviewing works. Thanks, Amir. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 1/3] vfs: use goto out on error in vfs_fileattr_set() 2026-11-23 14:18 ` Amir Goldstein @ 2026-11-23 14:22 ` koraynilay 0 siblings, 0 replies; 28+ messages in thread From: koraynilay @ 2026-11-23 14:22 UTC (permalink / raw) To: Amir Goldstein, koraynilay Cc: Andrey Albershteyn, Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api [-- Attachment #1: Type: text/plain, Size: 917 bytes --] On Mon Nov 23, 2026 at 3:18 PM CET, Amir Goldstein wrote: > On Mon, Nov 23, 2026 at 3:15 PM koraynilay <koray.fra@gmail.com> wrote: >> >> On Mon Nov 23, 2026 at 9:42 AM CET, Andrey Albershteyn wrote: >> > On 2026-11-22 01:08:54, koraynilay wrote: >> >> Switch from using if (!err) { ... } to the cleaner if (err) goto out; >> >> in the main body of vfs_fileattr_set(). >> >> >> >> Signed-off-by: koraynilay <koray.fra@gmail.com> >> > >> > Looks good to me >> > Reviewed-by: Andrey Albershteyn <aalbersh@kernel.org> >> >> Thank you, can I add this tag to the v2 version of this patch (since it >> won't be changed, and link to this thread in the comment section of the >> patch)? > > You should always keep RVB when re-posting without meaningful (RVB = Reviewed-by, right?) > changes to a patch. > > That's how reviewing works. Ok perfect, thanks. Best, koraynilay > Thanks, > Amir. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 2/3] vfs: add xflags mask to fileattr API 2026-11-22 0:08 [PATCH 0/3] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay 2026-11-22 0:08 ` [PATCH 1/3] vfs: use goto out on error in vfs_fileattr_set() koraynilay @ 2026-11-22 0:08 ` koraynilay 2026-11-23 13:24 ` Amir Goldstein 2026-11-22 0:08 ` [PATCH 3/3] ntfs: switch to the new xflags " koraynilay 2026-11-23 13:35 ` [PATCH 0/3] Add f*_xflags_{rw,ro}_mask flags to the " Amir Goldstein 3 siblings, 1 reply; 28+ messages in thread From: koraynilay @ 2026-11-22 0:08 UTC (permalink / raw) To: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner Cc: Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Amir Goldstein, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api, koraynilay Add fa_xflags_rw_mask and fa_xflags_ro_mask to struct file_attr and equivalent masks to struct file_kattr. Also add has_masks selector to struct file_kattr so we can know when a user of this API (userspace or filesystem) supports them. This lets filesystems advertise their support for specific xflags, like statx.stx_attributes_mask does, and userspace can specify only which xflags it wants to change without needing a RMW cycle: - on GET: each filesystem that wants to support this new API fills the masks according to its supported and read-only xflags, then: * for boolean xflags: it fills fsx_xflags with the current on-disk value * for value xflags: it sets the xflag bit to 1 in fsx_xflags and the xflag value in the struct field; - on SET: userspace fills the rw_mask with the bits of the xflags it wants to change, then: * for boolean xflags: it provides the xflag value as a bit in fa_xflags * for value xflags: it sets the xflag bit to 1 in fa_xflags and then provides the value in the struct field; if the xflag bit is set to 0 instead, this informs the kernel to unset/clear that value. Since fa_xflags_rw_mask means "I want to change the xflags specified in here", if userspace specifies fa_xflags_rw_mask = 0, only check for permissions and fileattr support without checking any xflags. Behaviour of older programs that already use file_[gs]etattr() is preserved by checking against FILE_ATTR_SIZE_VER*. Also add the missing FS_XFLAG_PROJID xflag, to allow userspace to set the projid using file_[gs]etattr() by leveraging the new masks. Finally, in order to prevent the legacy FS_IOC_FSSETXATTR from accepting FS_XFLAG_PROJID, add a FS_FILE_ATTR_XFLAGS_MASK to support new xflags and use it to validate/clamp both the _xflags fields and the masks. Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.11 Signed-off-by: koraynilay <koray.fra@gmail.com> --- fs/file_attr.c | 128 ++++++++++++++++++++++++++++++++++++--- include/linux/fileattr.h | 7 +++ include/uapi/linux/fs.h | 7 ++- 3 files changed, 131 insertions(+), 11 deletions(-) diff --git a/fs/file_attr.c b/fs/file_attr.c index 40d6518f1d8e..0e16c23368b2 100644 --- a/fs/file_attr.c +++ b/fs/file_attr.c @@ -102,13 +102,20 @@ EXPORT_SYMBOL(vfs_fileattr_get); static void fileattr_to_file_attr(const struct file_kattr *fa, struct file_attr *fattr) { - __u32 mask = FS_XFLAGS_MASK; - memset(fattr, 0, sizeof(struct file_attr)); - fattr->fa_xflags = fa->fsx_xflags & mask; + /* Pass the masks to userspace if underlying fs uses them. */ + if (fa->has_masks) { + fattr->fa_xflags_rw_mask = fa->fsx_xflags_rw_mask & + FS_FILE_ATTR_XFLAGS_MASK; + fattr->fa_xflags_ro_mask = fa->fsx_xflags_ro_mask & + FS_FILE_ATTR_XFLAGS_MASK; + } + fattr->fa_xflags = fa->fsx_xflags & FS_FILE_ATTR_XFLAGS_MASK; fattr->fa_extsize = fa->fsx_extsize; fattr->fa_nextents = fa->fsx_nextents; fattr->fa_projid = fa->fsx_projid; + if (fa->fsx_projid) + fattr->fa_xflags |= FS_XFLAG_PROJID; fattr->fa_cowextsize = fa->fsx_cowextsize; } @@ -141,12 +148,30 @@ EXPORT_SYMBOL(copy_fsxattr_to_user); static int file_attr_to_fileattr(const struct file_attr *fattr, struct file_kattr *fa) { - __u64 mask = FS_XFLAGS_MASK; + u64 rw_mask = fa->has_masks ? fattr->fa_xflags_rw_mask : FS_XFLAGS_MASK; - if (fattr->fa_xflags & ~mask) + /* + * No need to check for has_masks here, as fa_xflags_rw_mask is 0 in + * VER0 mode. + */ + if (fattr->fa_xflags_rw_mask & ~FS_FILE_ATTR_XFLAGS_MASK) return -EINVAL; - fileattr_fill_xflags(fa, fattr->fa_xflags & ~FS_XFLAG_RDONLY_MASK); + if (fattr->fa_xflags & ~rw_mask) + return -EINVAL; + + /* + * Filter with ~FS_XFLAG_RDONLY_MASK only when in VER0 mode, so + * filtering with the actual filesystem read-only xflags can be done in + * vfs_fileattr_set() once we have the fsx_xflags_ro_mask from the fs. + */ + if (fa->has_masks) { + fileattr_fill_xflags(fa, fattr->fa_xflags); + fa->fsx_xflags_rw_mask = fattr->fa_xflags_rw_mask; + } else { + fileattr_fill_xflags(fa, + fattr->fa_xflags & ~FS_XFLAG_RDONLY_MASK); + } fa->fsx_extsize = fattr->fa_extsize; fa->fsx_projid = fattr->fa_projid; fa->fsx_cowextsize = fattr->fa_cowextsize; @@ -187,6 +212,14 @@ static int fileattr_set_prepare(struct inode *inode, { int err; + /* + * If the fs supports the fsx_xflags_{rw,ro}_mask API, fail when the + * requested rw flags are not in the supported ones for that fs + */ + if (old_ma->has_masks && + (fa->fsx_xflags_rw_mask & ~old_ma->fsx_xflags_rw_mask)) + return -EOPNOTSUPP; + /* * The IMMUTABLE and APPEND_ONLY flags can only be changed by * the relevant capability. @@ -211,6 +244,11 @@ static int fileattr_set_prepare(struct inode *inode, FS_XFLAG_PROJINHERIT) return -EINVAL; } else { + /* If user wants to unset projid, set it to 0 */ + if ((fa->fsx_xflags_rw_mask & FS_XFLAG_PROJID) && + ((fa->fsx_xflags & FS_XFLAG_PROJID) == 0)) + fa->fsx_projid = 0; + /* * Caller is allowed to change the project ID. If it is being * changed, make sure that the new value is valid. @@ -250,6 +288,8 @@ static int fileattr_set_prepare(struct inode *inode, fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT); if (fa->fsx_cowextsize == 0) fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE; + if (fa->fsx_projid == 0) + fa->fsx_xflags &= ~FS_XFLAG_PROJID; return 0; } @@ -275,6 +315,8 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, { struct inode *inode = d_inode(dentry); struct file_kattr old_ma = {}; + u32 rw_user_mask = fa->fsx_xflags_rw_mask; + u32 rw_fs_mask = 0, ro_fs_mask = 0; int err; if (!inode->i_op->fileattr_set) @@ -288,15 +330,53 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, if (err) goto out; + if (old_ma.has_masks) { + old_ma.fsx_xflags_rw_mask &= FS_FILE_ATTR_XFLAGS_MASK; + old_ma.fsx_xflags_ro_mask &= FS_FILE_ATTR_XFLAGS_MASK; + rw_fs_mask = old_ma.fsx_xflags_rw_mask; + ro_fs_mask = old_ma.fsx_xflags_ro_mask; + } + old_ma.fsx_xflags &= FS_FILE_ATTR_XFLAGS_MASK; + /* initialize missing bits from old_ma */ if (fa->flags_valid) { + /* FS_IOC_SETFLAGS */ + fa->fsx_xflags_rw_mask = 0; fa->fsx_xflags |= old_ma.fsx_xflags & ~FS_XFLAG_COMMON; fa->fsx_extsize = old_ma.fsx_extsize; fa->fsx_nextents = old_ma.fsx_nextents; fa->fsx_projid = old_ma.fsx_projid; fa->fsx_cowextsize = old_ma.fsx_cowextsize; } else { + /* + * Preserve flags not being set when using FS_IOC_FSSETXATTR or + * file_setattr VER0+. + */ fa->flags |= old_ma.flags & ~FS_COMMON_FL; + + /* file_setattr VER1+ */ + if (fa->has_masks) { + /* Preserve old xflags that aren't being set. */ + fa->fsx_xflags |= old_ma.fsx_xflags & ~rw_user_mask; + + /* + * Filter fsx_xflags by removing xflags that are: + * - filesystem-reported read only + * - globally read only + * but keeping xflags that are: + * - filesystem-reported rw, globally ro + */ + ro_fs_mask |= FS_XFLAG_RDONLY_MASK & ~rw_fs_mask; + fileattr_fill_xflags(fa, fa->fsx_xflags & ~ro_fs_mask); + + if (!(rw_user_mask & + (FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT))) + fa->fsx_extsize = old_ma.fsx_extsize; + if (!(rw_user_mask & FS_XFLAG_PROJID)) + fa->fsx_projid = old_ma.fsx_projid; + if (!(rw_user_mask & FS_XFLAG_COWEXTSIZE)) + fa->fsx_cowextsize = old_ma.fsx_cowextsize; + } } err = fileattr_set_prepare(inode, &old_ma, fa); @@ -424,6 +504,14 @@ SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename, return error; fileattr_to_file_attr(&fa, &fattr); + /* + * Remove xflags added in or after VER1 so userspace programs compiled + * against VER0 don't try to write xflags they don't know about (since + * they do RMW). + */ + if (usize < FILE_ATTR_SIZE_VER1) + fattr.fa_xflags &= FS_XFLAGS_MASK; + error = copy_struct_to_user(ufattr, usize, &fattr, sizeof(struct file_attr), NULL); @@ -460,10 +548,6 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename, if (error) return error; - error = file_attr_to_fileattr(&fattr, &fa); - if (error) - return error; - CLASS(filename_maybe_null, name)(filename, at_flags); if (!name && dfd >= 0) { CLASS(fd, f)(dfd); @@ -479,6 +563,30 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename, return error; } + /* + * Userspace said "I don't want to change any flag", so be it I guess. + * Still check for fileattr support and permissions, also in case this + * is just a probe. + */ + if (usize >= FILE_ATTR_SIZE_VER1 && fattr.fa_xflags_rw_mask == 0) { + struct inode *inode = d_inode(filepath.dentry); + + if (!inode->i_op->fileattr_set) + return -EOPNOTSUPP; + + if (!inode_owner_or_capable(mnt_idmap(filepath.mnt), inode)) + return -EPERM; + + return error; + } + + if (usize >= FILE_ATTR_SIZE_VER1) + fa.has_masks = true; + + error = file_attr_to_fileattr(&fattr, &fa); + if (error) + return error; + error = mnt_want_write(filepath.mnt); if (!error) { error = vfs_fileattr_set(mnt_idmap(filepath.mnt), diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h index c8f69dde5dd3..4faa40febf11 100644 --- a/include/linux/fileattr.h +++ b/include/linux/fileattr.h @@ -35,6 +35,10 @@ (FS_XFLAG_COMMON | FS_XFLAG_RDONLY_MASK | FS_XFLAG_VALUES_MASK | \ FS_XFLAG_DIRONLY_MASK | FS_XFLAG_MISC_MASK) +/* Flags only for fa_ fields */ +#define FS_FILE_ATTR_XFLAGS_MASK \ + (FS_XFLAGS_MASK | FS_XFLAG_PROJID) + /* * Merged interface for miscellaneous file attributes. 'flags' originates from * ext* and 'fsx_flags' from xfs. There's some overlap between the two, which @@ -45,6 +49,8 @@ struct file_kattr { u32 flags; /* flags (FS_IOC_GETFLAGS/FS_IOC_SETFLAGS) */ /* struct fsxattr: */ u32 fsx_xflags; /* xflags field value (get/set) */ + u32 fsx_xflags_rw_mask; /* supported writeable xflags (get) / flags to set (set) */ + u32 fsx_xflags_ro_mask; /* supported read-only xflags (get) */ u32 fsx_extsize; /* extsize field value (get/set)*/ u32 fsx_nextents; /* nextents field value (get) */ u32 fsx_projid; /* project identifier (get/set) */ @@ -52,6 +58,7 @@ struct file_kattr { /* selectors: */ bool flags_valid:1; bool fsx_valid:1; + bool has_masks:1; }; int copy_fsxattr_to_user(const struct file_kattr *fa, struct fsxattr __user *ufa); diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index a13c7b32a1bd..e40806b3a69c 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -238,10 +238,13 @@ struct file_attr { __u32 fa_nextents; /* nextents field value (get) */ __u32 fa_projid; /* project identifier (get/set) */ __u32 fa_cowextsize; /* CoW extsize field value (get/set) */ + __u32 fa_xflags_rw_mask;/* supported writeable xflags (get) / flags to set (set) */ + __u32 fa_xflags_ro_mask;/* supported read-only xflags (get) */ }; #define FILE_ATTR_SIZE_VER0 24 -#define FILE_ATTR_SIZE_LATEST FILE_ATTR_SIZE_VER0 +#define FILE_ATTR_SIZE_VER1 32 +#define FILE_ATTR_SIZE_LATEST FILE_ATTR_SIZE_VER1 /* * Flags for the fsx_xflags field @@ -270,6 +273,8 @@ struct file_attr { */ #define FS_XFLAG_CASEFOLD 0x00040000 /* case-insensitive lookups */ #define FS_XFLAG_CASENONPRESERVING 0x00080000 /* case not preserved */ + +#define FS_XFLAG_PROJID 0x00100000 /* project ID */ #define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */ /* the read-only stuff doesn't really belong here, but any other place is -- 2.56.0 ^ permalink raw reply related [flat|nested] 28+ messages in thread
* Re: [PATCH 2/3] vfs: add xflags mask to fileattr API 2026-11-22 0:08 ` [PATCH 2/3] vfs: add xflags mask to fileattr API koraynilay @ 2026-11-23 13:24 ` Amir Goldstein 2026-11-23 13:58 ` koraynilay 0 siblings, 1 reply; 28+ messages in thread From: Amir Goldstein @ 2026-11-23 13:24 UTC (permalink / raw) To: koraynilay Cc: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api On Sun, Nov 22, 2026 at 1:09 AM koraynilay <koray.fra@gmail.com> wrote: > > Add fa_xflags_rw_mask and fa_xflags_ro_mask to struct file_attr and > equivalent masks to struct file_kattr. > > Also add has_masks selector to struct file_kattr so we can know when a > user of this API (userspace or filesystem) supports them. > > This lets filesystems advertise their support for specific xflags, like > statx.stx_attributes_mask does, and userspace can specify only which > xflags it wants to change without needing a RMW cycle: > - on GET: each filesystem that wants to support this new API fills the > masks according to its supported and read-only xflags, then: > * for boolean xflags: it fills fsx_xflags with the current on-disk value > * for value xflags: it sets the xflag bit to 1 in fsx_xflags and the > xflag value in the struct field; > - on SET: userspace fills the rw_mask with the bits of the xflags it > wants to change, then: > * for boolean xflags: it provides the xflag value as a bit in fa_xflags > * for value xflags: it sets the xflag bit to 1 in fa_xflags and then > provides the value in the struct field; if the xflag bit is set to 0 > instead, this informs the kernel to unset/clear that value. > > Since fa_xflags_rw_mask means "I want to change the xflags specified in > here", if userspace specifies fa_xflags_rw_mask = 0, only check for > permissions and fileattr support without checking any xflags. > > Behaviour of older programs that already use file_[gs]etattr() is > preserved by checking against FILE_ATTR_SIZE_VER*. > > Also add the missing FS_XFLAG_PROJID xflag, to allow userspace to set > the projid using file_[gs]etattr() by leveraging the new masks. > > Finally, in order to prevent the legacy FS_IOC_FSSETXATTR from accepting > FS_XFLAG_PROJID, add a FS_FILE_ATTR_XFLAGS_MASK to support new xflags > and use it to validate/clamp both the _xflags fields and the masks. > > Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.11 > Signed-off-by: koraynilay <koray.fra@gmail.com> > --- > fs/file_attr.c | 128 ++++++++++++++++++++++++++++++++++++--- > include/linux/fileattr.h | 7 +++ > include/uapi/linux/fs.h | 7 ++- > 3 files changed, 131 insertions(+), 11 deletions(-) > > diff --git a/fs/file_attr.c b/fs/file_attr.c > index 40d6518f1d8e..0e16c23368b2 100644 > --- a/fs/file_attr.c > +++ b/fs/file_attr.c > @@ -102,13 +102,20 @@ EXPORT_SYMBOL(vfs_fileattr_get); > static void fileattr_to_file_attr(const struct file_kattr *fa, > struct file_attr *fattr) > { > - __u32 mask = FS_XFLAGS_MASK; > - > memset(fattr, 0, sizeof(struct file_attr)); > - fattr->fa_xflags = fa->fsx_xflags & mask; > + /* Pass the masks to userspace if underlying fs uses them. */ > + if (fa->has_masks) { > + fattr->fa_xflags_rw_mask = fa->fsx_xflags_rw_mask & > + FS_FILE_ATTR_XFLAGS_MASK; > + fattr->fa_xflags_ro_mask = fa->fsx_xflags_ro_mask & > + FS_FILE_ATTR_XFLAGS_MASK; > + } > + fattr->fa_xflags = fa->fsx_xflags & FS_FILE_ATTR_XFLAGS_MASK; > fattr->fa_extsize = fa->fsx_extsize; > fattr->fa_nextents = fa->fsx_nextents; > fattr->fa_projid = fa->fsx_projid; > + if (fa->fsx_projid) > + fattr->fa_xflags |= FS_XFLAG_PROJID; > fattr->fa_cowextsize = fa->fsx_cowextsize; > } > > @@ -141,12 +148,30 @@ EXPORT_SYMBOL(copy_fsxattr_to_user); > static int file_attr_to_fileattr(const struct file_attr *fattr, > struct file_kattr *fa) > { > - __u64 mask = FS_XFLAGS_MASK; > + u64 rw_mask = fa->has_masks ? fattr->fa_xflags_rw_mask : FS_XFLAGS_MASK; > > - if (fattr->fa_xflags & ~mask) > + /* > + * No need to check for has_masks here, as fa_xflags_rw_mask is 0 in > + * VER0 mode. > + */ > + if (fattr->fa_xflags_rw_mask & ~FS_FILE_ATTR_XFLAGS_MASK) > return -EINVAL; > > - fileattr_fill_xflags(fa, fattr->fa_xflags & ~FS_XFLAG_RDONLY_MASK); > + if (fattr->fa_xflags & ~rw_mask) > + return -EINVAL; > + > + /* > + * Filter with ~FS_XFLAG_RDONLY_MASK only when in VER0 mode, so > + * filtering with the actual filesystem read-only xflags can be done in > + * vfs_fileattr_set() once we have the fsx_xflags_ro_mask from the fs. > + */ > + if (fa->has_masks) { > + fileattr_fill_xflags(fa, fattr->fa_xflags); > + fa->fsx_xflags_rw_mask = fattr->fa_xflags_rw_mask; > + } else { > + fileattr_fill_xflags(fa, > + fattr->fa_xflags & ~FS_XFLAG_RDONLY_MASK); > + } > fa->fsx_extsize = fattr->fa_extsize; > fa->fsx_projid = fattr->fa_projid; > fa->fsx_cowextsize = fattr->fa_cowextsize; > @@ -187,6 +212,14 @@ static int fileattr_set_prepare(struct inode *inode, > { > int err; > > + /* > + * If the fs supports the fsx_xflags_{rw,ro}_mask API, fail when the > + * requested rw flags are not in the supported ones for that fs > + */ > + if (old_ma->has_masks && > + (fa->fsx_xflags_rw_mask & ~old_ma->fsx_xflags_rw_mask)) > + return -EOPNOTSUPP; > + > /* > * The IMMUTABLE and APPEND_ONLY flags can only be changed by > * the relevant capability. > @@ -211,6 +244,11 @@ static int fileattr_set_prepare(struct inode *inode, > FS_XFLAG_PROJINHERIT) > return -EINVAL; > } else { > + /* If user wants to unset projid, set it to 0 */ > + if ((fa->fsx_xflags_rw_mask & FS_XFLAG_PROJID) && > + ((fa->fsx_xflags & FS_XFLAG_PROJID) == 0)) > + fa->fsx_projid = 0; > + > /* > * Caller is allowed to change the project ID. If it is being > * changed, make sure that the new value is valid. > @@ -250,6 +288,8 @@ static int fileattr_set_prepare(struct inode *inode, > fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT); > if (fa->fsx_cowextsize == 0) > fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE; > + if (fa->fsx_projid == 0) > + fa->fsx_xflags &= ~FS_XFLAG_PROJID; > > return 0; > } > @@ -275,6 +315,8 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, > { > struct inode *inode = d_inode(dentry); > struct file_kattr old_ma = {}; > + u32 rw_user_mask = fa->fsx_xflags_rw_mask; > + u32 rw_fs_mask = 0, ro_fs_mask = 0; > int err; > > if (!inode->i_op->fileattr_set) > @@ -288,15 +330,53 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, > if (err) > goto out; > > + if (old_ma.has_masks) { > + old_ma.fsx_xflags_rw_mask &= FS_FILE_ATTR_XFLAGS_MASK; > + old_ma.fsx_xflags_ro_mask &= FS_FILE_ATTR_XFLAGS_MASK; > + rw_fs_mask = old_ma.fsx_xflags_rw_mask; > + ro_fs_mask = old_ma.fsx_xflags_ro_mask; > + } > + old_ma.fsx_xflags &= FS_FILE_ATTR_XFLAGS_MASK; > + > /* initialize missing bits from old_ma */ > if (fa->flags_valid) { > + /* FS_IOC_SETFLAGS */ > + fa->fsx_xflags_rw_mask = 0; > fa->fsx_xflags |= old_ma.fsx_xflags & ~FS_XFLAG_COMMON; > fa->fsx_extsize = old_ma.fsx_extsize; > fa->fsx_nextents = old_ma.fsx_nextents; > fa->fsx_projid = old_ma.fsx_projid; > fa->fsx_cowextsize = old_ma.fsx_cowextsize; > } else { > + /* > + * Preserve flags not being set when using FS_IOC_FSSETXATTR or > + * file_setattr VER0+. > + */ > fa->flags |= old_ma.flags & ~FS_COMMON_FL; > + > + /* file_setattr VER1+ */ > + if (fa->has_masks) { > + /* Preserve old xflags that aren't being set. */ > + fa->fsx_xflags |= old_ma.fsx_xflags & ~rw_user_mask; > + > + /* > + * Filter fsx_xflags by removing xflags that are: > + * - filesystem-reported read only > + * - globally read only > + * but keeping xflags that are: > + * - filesystem-reported rw, globally ro > + */ > + ro_fs_mask |= FS_XFLAG_RDONLY_MASK & ~rw_fs_mask; > + fileattr_fill_xflags(fa, fa->fsx_xflags & ~ro_fs_mask); > + > + if (!(rw_user_mask & > + (FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT))) > + fa->fsx_extsize = old_ma.fsx_extsize; > + if (!(rw_user_mask & FS_XFLAG_PROJID)) > + fa->fsx_projid = old_ma.fsx_projid; > + if (!(rw_user_mask & FS_XFLAG_COWEXTSIZE)) > + fa->fsx_cowextsize = old_ma.fsx_cowextsize; > + } > } > > err = fileattr_set_prepare(inode, &old_ma, fa); > @@ -424,6 +504,14 @@ SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename, > return error; > > fileattr_to_file_attr(&fa, &fattr); > + /* > + * Remove xflags added in or after VER1 so userspace programs compiled > + * against VER0 don't try to write xflags they don't know about (since > + * they do RMW). > + */ > + if (usize < FILE_ATTR_SIZE_VER1) > + fattr.fa_xflags &= FS_XFLAGS_MASK; > + This looks odd. old struct size with new flags should be -EINVAL not silently drop them > error = copy_struct_to_user(ufattr, usize, &fattr, > sizeof(struct file_attr), NULL); > > @@ -460,10 +548,6 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename, > if (error) > return error; > > - error = file_attr_to_fileattr(&fattr, &fa); > - if (error) > - return error; > - > CLASS(filename_maybe_null, name)(filename, at_flags); > if (!name && dfd >= 0) { > CLASS(fd, f)(dfd); > @@ -479,6 +563,30 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename, > return error; > } > > + /* > + * Userspace said "I don't want to change any flag", so be it I guess. > + * Still check for fileattr support and permissions, also in case this > + * is just a probe. > + */ > + if (usize >= FILE_ATTR_SIZE_VER1 && fattr.fa_xflags_rw_mask == 0) { > + struct inode *inode = d_inode(filepath.dentry); No No this is not what this userspace said! This user space is the same old chattr programs recompiled with a new fs.h header file installed. When userspace does not set anything is masks it means "old API" > + > + if (!inode->i_op->fileattr_set) > + return -EOPNOTSUPP; > + > + if (!inode_owner_or_capable(mnt_idmap(filepath.mnt), inode)) > + return -EPERM; > + > + return error; > + } > + > + if (usize >= FILE_ATTR_SIZE_VER1) > + fa.has_masks = true; And a non-zero ro or rw mask > + > + error = file_attr_to_fileattr(&fattr, &fa); > + if (error) > + return error; > + > error = mnt_want_write(filepath.mnt); > if (!error) { > error = vfs_fileattr_set(mnt_idmap(filepath.mnt), > diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h > index c8f69dde5dd3..4faa40febf11 100644 > --- a/include/linux/fileattr.h > +++ b/include/linux/fileattr.h > @@ -35,6 +35,10 @@ > (FS_XFLAG_COMMON | FS_XFLAG_RDONLY_MASK | FS_XFLAG_VALUES_MASK | \ > FS_XFLAG_DIRONLY_MASK | FS_XFLAG_MISC_MASK) > > +/* Flags only for fa_ fields */ > +#define FS_FILE_ATTR_XFLAGS_MASK \ > + (FS_XFLAGS_MASK | FS_XFLAG_PROJID) > + > /* > * Merged interface for miscellaneous file attributes. 'flags' originates from > * ext* and 'fsx_flags' from xfs. There's some overlap between the two, which > @@ -45,6 +49,8 @@ struct file_kattr { > u32 flags; /* flags (FS_IOC_GETFLAGS/FS_IOC_SETFLAGS) */ > /* struct fsxattr: */ > u32 fsx_xflags; /* xflags field value (get/set) */ > + u32 fsx_xflags_rw_mask; /* supported writeable xflags (get) / flags to set (set) */ > + u32 fsx_xflags_ro_mask; /* supported read-only xflags (get) */ > u32 fsx_extsize; /* extsize field value (get/set)*/ > u32 fsx_nextents; /* nextents field value (get) */ > u32 fsx_projid; /* project identifier (get/set) */ > @@ -52,6 +58,7 @@ struct file_kattr { > /* selectors: */ > bool flags_valid:1; > bool fsx_valid:1; > + bool has_masks:1; > }; > > int copy_fsxattr_to_user(const struct file_kattr *fa, struct fsxattr __user *ufa); > diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h > index a13c7b32a1bd..e40806b3a69c 100644 > --- a/include/uapi/linux/fs.h > +++ b/include/uapi/linux/fs.h > @@ -238,10 +238,13 @@ struct file_attr { > __u32 fa_nextents; /* nextents field value (get) */ > __u32 fa_projid; /* project identifier (get/set) */ > __u32 fa_cowextsize; /* CoW extsize field value (get/set) */ > + __u32 fa_xflags_rw_mask;/* supported writeable xflags (get) / flags to set (set) */ > + __u32 fa_xflags_ro_mask;/* supported read-only xflags (get) */ > }; > fa_xflags is __u64 It is short sighted to use __u32 masks for the syscall API > #define FILE_ATTR_SIZE_VER0 24 > -#define FILE_ATTR_SIZE_LATEST FILE_ATTR_SIZE_VER0 > +#define FILE_ATTR_SIZE_VER1 32 > +#define FILE_ATTR_SIZE_LATEST FILE_ATTR_SIZE_VER1 > > /* > * Flags for the fsx_xflags field > @@ -270,6 +273,8 @@ struct file_attr { > */ > #define FS_XFLAG_CASEFOLD 0x00040000 /* case-insensitive lookups */ > #define FS_XFLAG_CASENONPRESERVING 0x00080000 /* case not preserved */ > + > +#define FS_XFLAG_PROJID 0x00100000 /* project ID */ > #define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */ > If anything the newline should be before the gap to HASATTR Thanks, Amir. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 2/3] vfs: add xflags mask to fileattr API 2026-11-23 13:24 ` Amir Goldstein @ 2026-11-23 13:58 ` koraynilay 2026-11-23 15:29 ` Amir Goldstein 0 siblings, 1 reply; 28+ messages in thread From: koraynilay @ 2026-11-23 13:58 UTC (permalink / raw) To: Amir Goldstein, koraynilay Cc: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api [-- Attachment #1: Type: text/plain, Size: 16208 bytes --] On Mon Nov 23, 2026 at 2:24 PM CET, Amir Goldstein wrote: > On Sun, Nov 22, 2026 at 1:09 AM koraynilay <koray.fra@gmail.com> wrote: >> >> Add fa_xflags_rw_mask and fa_xflags_ro_mask to struct file_attr and >> equivalent masks to struct file_kattr. >> >> Also add has_masks selector to struct file_kattr so we can know when a >> user of this API (userspace or filesystem) supports them. >> >> This lets filesystems advertise their support for specific xflags, like >> statx.stx_attributes_mask does, and userspace can specify only which >> xflags it wants to change without needing a RMW cycle: >> - on GET: each filesystem that wants to support this new API fills the >> masks according to its supported and read-only xflags, then: >> * for boolean xflags: it fills fsx_xflags with the current on-disk value >> * for value xflags: it sets the xflag bit to 1 in fsx_xflags and the >> xflag value in the struct field; >> - on SET: userspace fills the rw_mask with the bits of the xflags it >> wants to change, then: >> * for boolean xflags: it provides the xflag value as a bit in fa_xflags >> * for value xflags: it sets the xflag bit to 1 in fa_xflags and then >> provides the value in the struct field; if the xflag bit is set to 0 >> instead, this informs the kernel to unset/clear that value. >> >> Since fa_xflags_rw_mask means "I want to change the xflags specified in >> here", if userspace specifies fa_xflags_rw_mask = 0, only check for >> permissions and fileattr support without checking any xflags. >> >> Behaviour of older programs that already use file_[gs]etattr() is >> preserved by checking against FILE_ATTR_SIZE_VER*. >> >> Also add the missing FS_XFLAG_PROJID xflag, to allow userspace to set >> the projid using file_[gs]etattr() by leveraging the new masks. >> >> Finally, in order to prevent the legacy FS_IOC_FSSETXATTR from accepting >> FS_XFLAG_PROJID, add a FS_FILE_ATTR_XFLAGS_MASK to support new xflags >> and use it to validate/clamp both the _xflags fields and the masks. >> >> Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.11 >> Signed-off-by: koraynilay <koray.fra@gmail.com> >> --- >> fs/file_attr.c | 128 ++++++++++++++++++++++++++++++++++++--- >> include/linux/fileattr.h | 7 +++ >> include/uapi/linux/fs.h | 7 ++- >> 3 files changed, 131 insertions(+), 11 deletions(-) >> >> diff --git a/fs/file_attr.c b/fs/file_attr.c >> index 40d6518f1d8e..0e16c23368b2 100644 >> --- a/fs/file_attr.c >> +++ b/fs/file_attr.c >> @@ -102,13 +102,20 @@ EXPORT_SYMBOL(vfs_fileattr_get); >> static void fileattr_to_file_attr(const struct file_kattr *fa, >> struct file_attr *fattr) >> { >> - __u32 mask = FS_XFLAGS_MASK; >> - >> memset(fattr, 0, sizeof(struct file_attr)); >> - fattr->fa_xflags = fa->fsx_xflags & mask; >> + /* Pass the masks to userspace if underlying fs uses them. */ >> + if (fa->has_masks) { >> + fattr->fa_xflags_rw_mask = fa->fsx_xflags_rw_mask & >> + FS_FILE_ATTR_XFLAGS_MASK; >> + fattr->fa_xflags_ro_mask = fa->fsx_xflags_ro_mask & >> + FS_FILE_ATTR_XFLAGS_MASK; >> + } >> + fattr->fa_xflags = fa->fsx_xflags & FS_FILE_ATTR_XFLAGS_MASK; >> fattr->fa_extsize = fa->fsx_extsize; >> fattr->fa_nextents = fa->fsx_nextents; >> fattr->fa_projid = fa->fsx_projid; >> + if (fa->fsx_projid) >> + fattr->fa_xflags |= FS_XFLAG_PROJID; >> fattr->fa_cowextsize = fa->fsx_cowextsize; >> } >> >> @@ -141,12 +148,30 @@ EXPORT_SYMBOL(copy_fsxattr_to_user); >> static int file_attr_to_fileattr(const struct file_attr *fattr, >> struct file_kattr *fa) >> { >> - __u64 mask = FS_XFLAGS_MASK; >> + u64 rw_mask = fa->has_masks ? fattr->fa_xflags_rw_mask : FS_XFLAGS_MASK; >> >> - if (fattr->fa_xflags & ~mask) >> + /* >> + * No need to check for has_masks here, as fa_xflags_rw_mask is 0 in >> + * VER0 mode. >> + */ >> + if (fattr->fa_xflags_rw_mask & ~FS_FILE_ATTR_XFLAGS_MASK) >> return -EINVAL; >> >> - fileattr_fill_xflags(fa, fattr->fa_xflags & ~FS_XFLAG_RDONLY_MASK); >> + if (fattr->fa_xflags & ~rw_mask) >> + return -EINVAL; >> + >> + /* >> + * Filter with ~FS_XFLAG_RDONLY_MASK only when in VER0 mode, so >> + * filtering with the actual filesystem read-only xflags can be done in >> + * vfs_fileattr_set() once we have the fsx_xflags_ro_mask from the fs. >> + */ >> + if (fa->has_masks) { >> + fileattr_fill_xflags(fa, fattr->fa_xflags); >> + fa->fsx_xflags_rw_mask = fattr->fa_xflags_rw_mask; >> + } else { >> + fileattr_fill_xflags(fa, >> + fattr->fa_xflags & ~FS_XFLAG_RDONLY_MASK); >> + } >> fa->fsx_extsize = fattr->fa_extsize; >> fa->fsx_projid = fattr->fa_projid; >> fa->fsx_cowextsize = fattr->fa_cowextsize; >> @@ -187,6 +212,14 @@ static int fileattr_set_prepare(struct inode *inode, >> { >> int err; >> >> + /* >> + * If the fs supports the fsx_xflags_{rw,ro}_mask API, fail when the >> + * requested rw flags are not in the supported ones for that fs >> + */ >> + if (old_ma->has_masks && >> + (fa->fsx_xflags_rw_mask & ~old_ma->fsx_xflags_rw_mask)) >> + return -EOPNOTSUPP; >> + >> /* >> * The IMMUTABLE and APPEND_ONLY flags can only be changed by >> * the relevant capability. >> @@ -211,6 +244,11 @@ static int fileattr_set_prepare(struct inode *inode, >> FS_XFLAG_PROJINHERIT) >> return -EINVAL; >> } else { >> + /* If user wants to unset projid, set it to 0 */ >> + if ((fa->fsx_xflags_rw_mask & FS_XFLAG_PROJID) && >> + ((fa->fsx_xflags & FS_XFLAG_PROJID) == 0)) >> + fa->fsx_projid = 0; >> + >> /* >> * Caller is allowed to change the project ID. If it is being >> * changed, make sure that the new value is valid. >> @@ -250,6 +288,8 @@ static int fileattr_set_prepare(struct inode *inode, >> fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT); >> if (fa->fsx_cowextsize == 0) >> fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE; >> + if (fa->fsx_projid == 0) >> + fa->fsx_xflags &= ~FS_XFLAG_PROJID; >> >> return 0; >> } >> @@ -275,6 +315,8 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, >> { >> struct inode *inode = d_inode(dentry); >> struct file_kattr old_ma = {}; >> + u32 rw_user_mask = fa->fsx_xflags_rw_mask; >> + u32 rw_fs_mask = 0, ro_fs_mask = 0; >> int err; >> >> if (!inode->i_op->fileattr_set) >> @@ -288,15 +330,53 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, >> if (err) >> goto out; >> >> + if (old_ma.has_masks) { >> + old_ma.fsx_xflags_rw_mask &= FS_FILE_ATTR_XFLAGS_MASK; >> + old_ma.fsx_xflags_ro_mask &= FS_FILE_ATTR_XFLAGS_MASK; >> + rw_fs_mask = old_ma.fsx_xflags_rw_mask; >> + ro_fs_mask = old_ma.fsx_xflags_ro_mask; >> + } >> + old_ma.fsx_xflags &= FS_FILE_ATTR_XFLAGS_MASK; >> + >> /* initialize missing bits from old_ma */ >> if (fa->flags_valid) { >> + /* FS_IOC_SETFLAGS */ >> + fa->fsx_xflags_rw_mask = 0; >> fa->fsx_xflags |= old_ma.fsx_xflags & ~FS_XFLAG_COMMON; >> fa->fsx_extsize = old_ma.fsx_extsize; >> fa->fsx_nextents = old_ma.fsx_nextents; >> fa->fsx_projid = old_ma.fsx_projid; >> fa->fsx_cowextsize = old_ma.fsx_cowextsize; >> } else { >> + /* >> + * Preserve flags not being set when using FS_IOC_FSSETXATTR or >> + * file_setattr VER0+. >> + */ >> fa->flags |= old_ma.flags & ~FS_COMMON_FL; >> + >> + /* file_setattr VER1+ */ >> + if (fa->has_masks) { >> + /* Preserve old xflags that aren't being set. */ >> + fa->fsx_xflags |= old_ma.fsx_xflags & ~rw_user_mask; >> + >> + /* >> + * Filter fsx_xflags by removing xflags that are: >> + * - filesystem-reported read only >> + * - globally read only >> + * but keeping xflags that are: >> + * - filesystem-reported rw, globally ro >> + */ >> + ro_fs_mask |= FS_XFLAG_RDONLY_MASK & ~rw_fs_mask; >> + fileattr_fill_xflags(fa, fa->fsx_xflags & ~ro_fs_mask); >> + >> + if (!(rw_user_mask & >> + (FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT))) >> + fa->fsx_extsize = old_ma.fsx_extsize; >> + if (!(rw_user_mask & FS_XFLAG_PROJID)) >> + fa->fsx_projid = old_ma.fsx_projid; >> + if (!(rw_user_mask & FS_XFLAG_COWEXTSIZE)) >> + fa->fsx_cowextsize = old_ma.fsx_cowextsize; >> + } >> } >> >> err = fileattr_set_prepare(inode, &old_ma, fa); >> @@ -424,6 +504,14 @@ SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename, >> return error; >> >> fileattr_to_file_attr(&fa, &fattr); >> + /* >> + * Remove xflags added in or after VER1 so userspace programs compiled >> + * against VER0 don't try to write xflags they don't know about (since >> + * they do RMW). >> + */ >> + if (usize < FILE_ATTR_SIZE_VER1) >> + fattr.fa_xflags &= FS_XFLAGS_MASK; >> + > > This looks odd. > old struct size with new flags should be -EINVAL not silently drop them Right, and the GET path should strip any new flags, so old programs doing RMW will never see them, correct? > >> error = copy_struct_to_user(ufattr, usize, &fattr, >> sizeof(struct file_attr), NULL); >> >> @@ -460,10 +548,6 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename, >> if (error) >> return error; >> >> - error = file_attr_to_fileattr(&fattr, &fa); >> - if (error) >> - return error; >> - >> CLASS(filename_maybe_null, name)(filename, at_flags); >> if (!name && dfd >= 0) { >> CLASS(fd, f)(dfd); >> @@ -479,6 +563,30 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename, >> return error; >> } >> >> + /* >> + * Userspace said "I don't want to change any flag", so be it I guess. >> + * Still check for fileattr support and permissions, also in case this >> + * is just a probe. >> + */ >> + if (usize >= FILE_ATTR_SIZE_VER1 && fattr.fa_xflags_rw_mask == 0) { >> + struct inode *inode = d_inode(filepath.dentry); > > > No No this is not what this userspace said! > > This user space is the same old chattr programs recompiled with a new > fs.h header file > installed. Oh, right, I did not think about this case, I hope it doesn't break too much of the new code I changed already for v2 :( > When userspace does not set anything is masks it means "old API" And so a modern program using masks that passes rw_mask as 0 should be also interpreted as "old API", even if it kinda goes against the definition of rw_mask right? And other than VER there is no way to know if it's a SETFLAGS compiled against modern fs.h or fileattr VER1 explicitly setting rw_mask to 0, right? > >> + >> + if (!inode->i_op->fileattr_set) >> + return -EOPNOTSUPP; >> + >> + if (!inode_owner_or_capable(mnt_idmap(filepath.mnt), inode)) >> + return -EPERM; >> + >> + return error; >> + } >> + >> + if (usize >= FILE_ATTR_SIZE_VER1) >> + fa.has_masks = true; > > And a non-zero ro or rw mask Right, for the same case as above. > >> + >> + error = file_attr_to_fileattr(&fattr, &fa); >> + if (error) >> + return error; >> + >> error = mnt_want_write(filepath.mnt); >> if (!error) { >> error = vfs_fileattr_set(mnt_idmap(filepath.mnt), >> diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h >> index c8f69dde5dd3..4faa40febf11 100644 >> --- a/include/linux/fileattr.h >> +++ b/include/linux/fileattr.h >> @@ -35,6 +35,10 @@ >> (FS_XFLAG_COMMON | FS_XFLAG_RDONLY_MASK | FS_XFLAG_VALUES_MASK | \ >> FS_XFLAG_DIRONLY_MASK | FS_XFLAG_MISC_MASK) >> >> +/* Flags only for fa_ fields */ >> +#define FS_FILE_ATTR_XFLAGS_MASK \ >> + (FS_XFLAGS_MASK | FS_XFLAG_PROJID) >> + >> /* >> * Merged interface for miscellaneous file attributes. 'flags' originates from >> * ext* and 'fsx_flags' from xfs. There's some overlap between the two, which >> @@ -45,6 +49,8 @@ struct file_kattr { >> u32 flags; /* flags (FS_IOC_GETFLAGS/FS_IOC_SETFLAGS) */ >> /* struct fsxattr: */ >> u32 fsx_xflags; /* xflags field value (get/set) */ >> + u32 fsx_xflags_rw_mask; /* supported writeable xflags (get) / flags to set (set) */ >> + u32 fsx_xflags_ro_mask; /* supported read-only xflags (get) */ >> u32 fsx_extsize; /* extsize field value (get/set)*/ >> u32 fsx_nextents; /* nextents field value (get) */ >> u32 fsx_projid; /* project identifier (get/set) */ >> @@ -52,6 +58,7 @@ struct file_kattr { >> /* selectors: */ >> bool flags_valid:1; >> bool fsx_valid:1; >> + bool has_masks:1; >> }; >> >> int copy_fsxattr_to_user(const struct file_kattr *fa, struct fsxattr __user *ufa); >> diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h >> index a13c7b32a1bd..e40806b3a69c 100644 >> --- a/include/uapi/linux/fs.h >> +++ b/include/uapi/linux/fs.h >> @@ -238,10 +238,13 @@ struct file_attr { >> __u32 fa_nextents; /* nextents field value (get) */ >> __u32 fa_projid; /* project identifier (get/set) */ >> __u32 fa_cowextsize; /* CoW extsize field value (get/set) */ >> + __u32 fa_xflags_rw_mask;/* supported writeable xflags (get) / flags to set (set) */ >> + __u32 fa_xflags_ro_mask;/* supported read-only xflags (get) */ >> }; >> > > fa_xflags is __u64 > It is short sighted to use __u32 masks for the syscall API Ah yes thanks, gemini neon pointed this out to me just yesterday ahah. Thanks, koraynilay > >> #define FILE_ATTR_SIZE_VER0 24 >> -#define FILE_ATTR_SIZE_LATEST FILE_ATTR_SIZE_VER0 >> +#define FILE_ATTR_SIZE_VER1 32 >> +#define FILE_ATTR_SIZE_LATEST FILE_ATTR_SIZE_VER1 >> >> /* >> * Flags for the fsx_xflags field >> @@ -270,6 +273,8 @@ struct file_attr { >> */ >> #define FS_XFLAG_CASEFOLD 0x00040000 /* case-insensitive lookups */ >> #define FS_XFLAG_CASENONPRESERVING 0x00080000 /* case not preserved */ >> + >> +#define FS_XFLAG_PROJID 0x00100000 /* project ID */ >> #define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */ >> > > > If anything the newline should be before the gap to HASATTR > > Thanks, > Amir. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 2/3] vfs: add xflags mask to fileattr API 2026-11-23 13:58 ` koraynilay @ 2026-11-23 15:29 ` Amir Goldstein 0 siblings, 0 replies; 28+ messages in thread From: Amir Goldstein @ 2026-11-23 15:29 UTC (permalink / raw) To: koraynilay Cc: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api On Mon, Nov 23, 2026 at 2:58 PM koraynilay <koray.fra@gmail.com> wrote: > > On Mon Nov 23, 2026 at 2:24 PM CET, Amir Goldstein wrote: > > On Sun, Nov 22, 2026 at 1:09 AM koraynilay <koray.fra@gmail.com> wrote: > >> > >> Add fa_xflags_rw_mask and fa_xflags_ro_mask to struct file_attr and > >> equivalent masks to struct file_kattr. > >> > >> Also add has_masks selector to struct file_kattr so we can know when a > >> user of this API (userspace or filesystem) supports them. > >> > >> This lets filesystems advertise their support for specific xflags, like > >> statx.stx_attributes_mask does, and userspace can specify only which > >> xflags it wants to change without needing a RMW cycle: > >> - on GET: each filesystem that wants to support this new API fills the > >> masks according to its supported and read-only xflags, then: > >> * for boolean xflags: it fills fsx_xflags with the current on-disk value > >> * for value xflags: it sets the xflag bit to 1 in fsx_xflags and the > >> xflag value in the struct field; > >> - on SET: userspace fills the rw_mask with the bits of the xflags it > >> wants to change, then: > >> * for boolean xflags: it provides the xflag value as a bit in fa_xflags > >> * for value xflags: it sets the xflag bit to 1 in fa_xflags and then > >> provides the value in the struct field; if the xflag bit is set to 0 > >> instead, this informs the kernel to unset/clear that value. > >> > >> Since fa_xflags_rw_mask means "I want to change the xflags specified in > >> here", if userspace specifies fa_xflags_rw_mask = 0, only check for > >> permissions and fileattr support without checking any xflags. > >> > >> Behaviour of older programs that already use file_[gs]etattr() is > >> preserved by checking against FILE_ATTR_SIZE_VER*. > >> > >> Also add the missing FS_XFLAG_PROJID xflag, to allow userspace to set > >> the projid using file_[gs]etattr() by leveraging the new masks. > >> > >> Finally, in order to prevent the legacy FS_IOC_FSSETXATTR from accepting > >> FS_XFLAG_PROJID, add a FS_FILE_ATTR_XFLAGS_MASK to support new xflags > >> and use it to validate/clamp both the _xflags fields and the masks. > >> > >> Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.11 > >> Signed-off-by: koraynilay <koray.fra@gmail.com> > >> --- ... > >> err = fileattr_set_prepare(inode, &old_ma, fa); > >> @@ -424,6 +504,14 @@ SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename, > >> return error; > >> > >> fileattr_to_file_attr(&fa, &fattr); > >> + /* > >> + * Remove xflags added in or after VER1 so userspace programs compiled > >> + * against VER0 don't try to write xflags they don't know about (since > >> + * they do RMW). > >> + */ > >> + if (usize < FILE_ATTR_SIZE_VER1) > >> + fattr.fa_xflags &= FS_XFLAGS_MASK; > >> + > > > > This looks odd. > > old struct size with new flags should be -EINVAL not silently drop them > > Right, and the GET path should strip any new flags, so old programs > doing RMW will never see them, correct? > Yes, I think so. > > > >> error = copy_struct_to_user(ufattr, usize, &fattr, > >> sizeof(struct file_attr), NULL); > >> > >> @@ -460,10 +548,6 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename, > >> if (error) > >> return error; > >> > >> - error = file_attr_to_fileattr(&fattr, &fa); > >> - if (error) > >> - return error; > >> - > >> CLASS(filename_maybe_null, name)(filename, at_flags); > >> if (!name && dfd >= 0) { > >> CLASS(fd, f)(dfd); > >> @@ -479,6 +563,30 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename, > >> return error; > >> } > >> > >> + /* > >> + * Userspace said "I don't want to change any flag", so be it I guess. > >> + * Still check for fileattr support and permissions, also in case this > >> + * is just a probe. > >> + */ > >> + if (usize >= FILE_ATTR_SIZE_VER1 && fattr.fa_xflags_rw_mask == 0) { > >> + struct inode *inode = d_inode(filepath.dentry); > > > > > > No No this is not what this userspace said! > > > > This user space is the same old chattr programs recompiled with a new > > fs.h header file > > installed. > > Oh, right, I did not think about this case, I hope it doesn't break too > much of the new code I changed already for v2 :( > > > When userspace does not set anything is masks it means "old API" > > And so a modern program using masks that passes rw_mask as 0 should be > also interpreted as "old API", even if it kinda goes against the > definition of rw_mask right? Yes, but it is not a problem to describe this backward compat exception: When (rw_mask | ro_mask) == 0, it means "no mask" "set everything" but then vfs will not accept new xflags that were not supported in v0 syscall. > And other than VER there is no way to know if it's a SETFLAGS compiled > against modern fs.h or fileattr VER1 explicitly setting rw_mask to 0, > right? > SETFLAGS with explicit 0 rw_mask is not useful and does not make sense, so there is no reason to support this in any other meaning than legacy programs. Thanks, Amir. ^ permalink raw reply [flat|nested] 28+ messages in thread
* [PATCH 3/3] ntfs: switch to the new xflags fileattr API 2026-11-22 0:08 [PATCH 0/3] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay 2026-11-22 0:08 ` [PATCH 1/3] vfs: use goto out on error in vfs_fileattr_set() koraynilay 2026-11-22 0:08 ` [PATCH 2/3] vfs: add xflags mask to fileattr API koraynilay @ 2026-11-22 0:08 ` koraynilay 2026-11-22 12:49 ` liubaolin 2026-11-23 13:00 ` Amir Goldstein 2026-11-23 13:35 ` [PATCH 0/3] Add f*_xflags_{rw,ro}_mask flags to the " Amir Goldstein 3 siblings, 2 replies; 28+ messages in thread From: koraynilay @ 2026-11-22 0:08 UTC (permalink / raw) To: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner Cc: Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Amir Goldstein, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api, koraynilay Switch ntfs_fileattr_[gs]et() from the legacy FS_*_FL flags to the modern xflags (FS_XFLAG_*) fileattr API with masks. Introduce FS_XFLAG_COMPR and FS_XFLAG_ENCRYPT and add them to FS_XFLAG_COMMON (and add FS_COMPR_FL and FS_ENCRYPT_FL to FS_COMMON_FL) to be used in this API switch. Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.11 Signed-off-by: koraynilay <koray.fra@gmail.com> --- fs/file_attr.c | 8 +++++ fs/ntfs/file.c | 63 +++++++++++++++++++--------------------- include/linux/fileattr.h | 6 ++-- include/uapi/linux/fs.h | 2 ++ 4 files changed, 44 insertions(+), 35 deletions(-) diff --git a/fs/file_attr.c b/fs/file_attr.c index 0e16c23368b2..815b8ba50e1f 100644 --- a/fs/file_attr.c +++ b/fs/file_attr.c @@ -39,6 +39,10 @@ void fileattr_fill_xflags(struct file_kattr *fa, u32 xflags) fa->flags |= FS_VERITY_FL; if (fa->fsx_xflags & FS_XFLAG_CASEFOLD) fa->flags |= FS_CASEFOLD_FL; + if (fa->fsx_xflags & FS_XFLAG_COMPR) + fa->flags |= FS_COMPR_FL; + if (fa->fsx_xflags & FS_XFLAG_ENCRYPT) + fa->flags |= FS_ENCRYPT_FL; } EXPORT_SYMBOL(fileattr_fill_xflags); @@ -71,6 +75,10 @@ void fileattr_fill_flags(struct file_kattr *fa, u32 flags) fa->fsx_xflags |= FS_XFLAG_VERITY; if (fa->flags & FS_CASEFOLD_FL) fa->fsx_xflags |= FS_XFLAG_CASEFOLD; + if (fa->flags & FS_COMPR_FL) + fa->fsx_xflags |= FS_XFLAG_COMPR; + if (fa->flags & FS_ENCRYPT_FL) + fa->fsx_xflags |= FS_XFLAG_ENCRYPT; } EXPORT_SYMBOL(fileattr_fill_flags); diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c index 50be49f4c913..fde6fb2fe39c 100644 --- a/fs/ntfs/file.c +++ b/fs/ntfs/file.c @@ -155,31 +155,37 @@ int ntfs_file_release(struct inode *vi, struct file *filp) * @dentry: dentry to report the flags of * @fa: filled in with the flags of @dentry */ +#define NTFS_RO_XFLAGS (FS_XFLAG_COMPR | FS_XFLAG_ENCRYPT | FS_XFLAG_CASEFOLD) +#define NTFS_RW_XFLAGS (FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND | \ + FS_XFLAG_NOATIME | FS_XFLAG_NODUMP) int ntfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa) { struct inode *vi = d_inode(dentry); struct ntfs_inode *ni = NTFS_I(vi); - u32 flags = 0; + u32 xflags = 0; if (NVolShutdown(ni->vol)) return -EIO; if (NInoCompressed(ni) || NInoWofCompressed(ni)) - flags |= FS_COMPR_FL; + xflags |= FS_XFLAG_COMPR; if (NInoEncrypted(ni)) - flags |= FS_ENCRYPT_FL; + xflags |= FS_XFLAG_ENCRYPT; if (vi->i_flags & S_IMMUTABLE) - flags |= FS_IMMUTABLE_FL; + xflags |= FS_XFLAG_IMMUTABLE; if (vi->i_flags & S_APPEND) - flags |= FS_APPEND_FL; + xflags |= FS_XFLAG_APPEND; if (vi->i_flags & S_NOATIME) - flags |= FS_NOATIME_FL; + xflags |= FS_XFLAG_NOATIME; if (ni->linuxflags & NTFS_LINUXFLAGS_NODUMP) - flags |= FS_NODUMP_FL; + xflags |= FS_XFLAG_NODUMP; if (!NVolCaseSensitive(ni->vol)) - flags |= FS_CASEFOLD_FL; + xflags |= FS_XFLAG_CASEFOLD; - fileattr_fill_flags(fa, flags); + fileattr_fill_xflags(fa, xflags); + fa->fsx_xflags_ro_mask = NTFS_RO_XFLAGS; + fa->fsx_xflags_rw_mask = NTFS_RW_XFLAGS; + fa->has_masks = true; return 0; } @@ -207,9 +213,6 @@ int ntfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, { struct inode *vi = d_inode(dentry); struct ntfs_inode *ni = NTFS_I(vi); - u32 allowed = FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | - FS_NOATIME_FL; - u32 readonly = 0; u32 linuxflags = ni->linuxflags & ~NTFS_LINUXFLAGS_MASK; unsigned int new_fl = 0; bool forced_immutable; @@ -219,42 +222,36 @@ int ntfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, if (err) return err; - if (fileattr_has_fsx(fa)) - return -EOPNOTSUPP; - - /* chattr passes the unchanged read-only flags back to us too. */ - if (NInoCompressed(ni) || NInoWofCompressed(ni)) - readonly |= FS_COMPR_FL; - if (NInoEncrypted(ni)) - readonly |= FS_ENCRYPT_FL; - if ((fa->flags ^ readonly) & (FS_COMPR_FL | FS_ENCRYPT_FL)) - return -EOPNOTSUPP; - allowed |= readonly; - - /* Case folding is a read-only, mount-wide property. */ - if (!NVolCaseSensitive(ni->vol)) - allowed |= FS_CASEFOLD_FL; - if (fa->flags & ~allowed) + /* + * When userspace uses file_[gs]etattr(), VFS already checks and fails + * with -EOPNOTSUPP if rw_mask & ro_mask != 0 and rw_mask & ~allowed, + * but for FS_IOC_SETFLAGS and FS_IOC_FSSETXATTR VFS can't check for + * allowed flags as these ioctls don't support fsx_xflags_{rw,ro}_mask, + * so we need to check for unsupported flags anyway. + */ + if (!fa->has_masks && + ((fa->fsx_xflags & ~NTFS_RW_XFLAGS) || + fa->fsx_extsize || fa->fsx_projid || fa->fsx_cowextsize)) return -EOPNOTSUPP; forced_immutable = ntfs_is_forced_immutable(vi); - if (!(fa->flags & FS_IMMUTABLE_FL) && forced_immutable) + if (!(fa->fsx_xflags & FS_XFLAG_IMMUTABLE) && forced_immutable) return -EPERM; - if (fa->flags & FS_IMMUTABLE_FL) { + if (fa->fsx_xflags & FS_XFLAG_IMMUTABLE) { new_fl |= S_IMMUTABLE; /* Do not persist an immutable bit derived from the mount. */ if (!forced_immutable || (ni->linuxflags & NTFS_LINUXFLAGS_IMMUTABLE)) linuxflags |= NTFS_LINUXFLAGS_IMMUTABLE; } - if (fa->flags & FS_APPEND_FL) { + if (fa->fsx_xflags & FS_XFLAG_APPEND) { new_fl |= S_APPEND; linuxflags |= NTFS_LINUXFLAGS_APPEND; } - if (fa->flags & FS_NODUMP_FL) + if (fa->fsx_xflags & FS_XFLAG_NODUMP) linuxflags |= NTFS_LINUXFLAGS_NODUMP; - if (fa->flags & FS_NOATIME_FL) { + if (fa->fsx_xflags & FS_XFLAG_NOATIME) { new_fl |= S_NOATIME; linuxflags |= NTFS_LINUXFLAGS_NOATIME; } diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h index 4faa40febf11..219e7c8eb601 100644 --- a/include/linux/fileattr.h +++ b/include/linux/fileattr.h @@ -7,12 +7,14 @@ #define FS_COMMON_FL \ (FS_SYNC_FL | FS_IMMUTABLE_FL | FS_APPEND_FL | \ FS_NODUMP_FL | FS_NOATIME_FL | FS_DAX_FL | \ - FS_PROJINHERIT_FL | FS_VERITY_FL) + FS_PROJINHERIT_FL | FS_VERITY_FL | FS_COMPR_FL | \ + FS_ENCRYPT_FL) #define FS_XFLAG_COMMON \ (FS_XFLAG_SYNC | FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND | \ FS_XFLAG_NODUMP | FS_XFLAG_NOATIME | FS_XFLAG_DAX | \ - FS_XFLAG_PROJINHERIT | FS_XFLAG_VERITY) + FS_XFLAG_PROJINHERIT | FS_XFLAG_VERITY | FS_XFLAG_COMPR | \ + FS_XFLAG_ENCRYPT) /* Read-only inode flags */ #define FS_XFLAG_RDONLY_MASK \ diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index e40806b3a69c..09fc7e066485 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -275,6 +275,8 @@ struct file_attr { #define FS_XFLAG_CASENONPRESERVING 0x00080000 /* case not preserved */ #define FS_XFLAG_PROJID 0x00100000 /* project ID */ +#define FS_XFLAG_COMPR 0x00200000 /* Compress file */ +#define FS_XFLAG_ENCRYPT 0x00400000 /* Encrypted file */ #define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */ /* the read-only stuff doesn't really belong here, but any other place is -- 2.56.0 ^ permalink raw reply related [flat|nested] 28+ messages in thread
* Re: [PATCH 3/3] ntfs: switch to the new xflags fileattr API 2026-11-22 0:08 ` [PATCH 3/3] ntfs: switch to the new xflags " koraynilay @ 2026-11-22 12:49 ` liubaolin 2026-11-23 0:38 ` koraynilay 2026-11-23 13:00 ` Amir Goldstein 1 sibling, 1 reply; 28+ messages in thread From: liubaolin @ 2026-11-22 12:49 UTC (permalink / raw) To: koraynilay, Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner Cc: Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Amir Goldstein, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api 在 2026/11/22 08:08, koraynilay 写道: > Switch ntfs_fileattr_[gs]et() from the legacy FS_*_FL flags to the > modern xflags (FS_XFLAG_*) fileattr API with masks. > > Introduce FS_XFLAG_COMPR and FS_XFLAG_ENCRYPT and add them to > FS_XFLAG_COMMON (and add FS_COMPR_FL and FS_ENCRYPT_FL to FS_COMMON_FL) > to be used in this API switch. > > Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.11 > Signed-off-by: koraynilay <koray.fra@gmail.com> > --- > fs/file_attr.c | 8 +++++ > fs/ntfs/file.c | 63 +++++++++++++++++++--------------------- > include/linux/fileattr.h | 6 ++-- > include/uapi/linux/fs.h | 2 ++ Hi koraynilay, One suggestion on the patch split: would it make sense to put the new COMPR/ENCRYPT xflags and their VFS handling in a separate patch before the NTFS conversion? The changes to include/uapi/linux/fs.h, include/linux/fileattr.h and fs/file_attr.c introduce generic fileattr support, and the COMMON mask changes also affect other filesystems. Keeping those changes together in a VFS patch would make the API and compatibility aspects easier to review. The following NTFS patch could then focus on using the new flags while preserving the existing NTFS behaviour. Thanks, Baolin. > 4 files changed, 44 insertions(+), 35 deletions(-) > > diff --git a/fs/file_attr.c b/fs/file_attr.c > index 0e16c23368b2..815b8ba50e1f 100644 > --- a/fs/file_attr.c > +++ b/fs/file_attr.c > @@ -39,6 +39,10 @@ void fileattr_fill_xflags(struct file_kattr *fa, u32 xflags) > fa->flags |= FS_VERITY_FL; > if (fa->fsx_xflags & FS_XFLAG_CASEFOLD) > fa->flags |= FS_CASEFOLD_FL; > + if (fa->fsx_xflags & FS_XFLAG_COMPR) > + fa->flags |= FS_COMPR_FL; > + if (fa->fsx_xflags & FS_XFLAG_ENCRYPT) > + fa->flags |= FS_ENCRYPT_FL; > } > EXPORT_SYMBOL(fileattr_fill_xflags); > > @@ -71,6 +75,10 @@ void fileattr_fill_flags(struct file_kattr *fa, u32 flags) > fa->fsx_xflags |= FS_XFLAG_VERITY; > if (fa->flags & FS_CASEFOLD_FL) > fa->fsx_xflags |= FS_XFLAG_CASEFOLD; > + if (fa->flags & FS_COMPR_FL) > + fa->fsx_xflags |= FS_XFLAG_COMPR; > + if (fa->flags & FS_ENCRYPT_FL) > + fa->fsx_xflags |= FS_XFLAG_ENCRYPT; > } > EXPORT_SYMBOL(fileattr_fill_flags); > > diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c > index 50be49f4c913..fde6fb2fe39c 100644 > --- a/fs/ntfs/file.c > +++ b/fs/ntfs/file.c > @@ -155,31 +155,37 @@ int ntfs_file_release(struct inode *vi, struct file *filp) > * @dentry: dentry to report the flags of > * @fa: filled in with the flags of @dentry > */ > +#define NTFS_RO_XFLAGS (FS_XFLAG_COMPR | FS_XFLAG_ENCRYPT | FS_XFLAG_CASEFOLD) > +#define NTFS_RW_XFLAGS (FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND | \ > + FS_XFLAG_NOATIME | FS_XFLAG_NODUMP) > int ntfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa) > { > struct inode *vi = d_inode(dentry); > struct ntfs_inode *ni = NTFS_I(vi); > - u32 flags = 0; > + u32 xflags = 0; > > if (NVolShutdown(ni->vol)) > return -EIO; > > if (NInoCompressed(ni) || NInoWofCompressed(ni)) > - flags |= FS_COMPR_FL; > + xflags |= FS_XFLAG_COMPR; > if (NInoEncrypted(ni)) > - flags |= FS_ENCRYPT_FL; > + xflags |= FS_XFLAG_ENCRYPT; > if (vi->i_flags & S_IMMUTABLE) > - flags |= FS_IMMUTABLE_FL; > + xflags |= FS_XFLAG_IMMUTABLE; > if (vi->i_flags & S_APPEND) > - flags |= FS_APPEND_FL; > + xflags |= FS_XFLAG_APPEND; > if (vi->i_flags & S_NOATIME) > - flags |= FS_NOATIME_FL; > + xflags |= FS_XFLAG_NOATIME; > if (ni->linuxflags & NTFS_LINUXFLAGS_NODUMP) > - flags |= FS_NODUMP_FL; > + xflags |= FS_XFLAG_NODUMP; > if (!NVolCaseSensitive(ni->vol)) > - flags |= FS_CASEFOLD_FL; > + xflags |= FS_XFLAG_CASEFOLD; > > - fileattr_fill_flags(fa, flags); > + fileattr_fill_xflags(fa, xflags); > + fa->fsx_xflags_ro_mask = NTFS_RO_XFLAGS; > + fa->fsx_xflags_rw_mask = NTFS_RW_XFLAGS; > + fa->has_masks = true; > return 0; > } > > @@ -207,9 +213,6 @@ int ntfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, > { > struct inode *vi = d_inode(dentry); > struct ntfs_inode *ni = NTFS_I(vi); > - u32 allowed = FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | > - FS_NOATIME_FL; > - u32 readonly = 0; > u32 linuxflags = ni->linuxflags & ~NTFS_LINUXFLAGS_MASK; > unsigned int new_fl = 0; > bool forced_immutable; > @@ -219,42 +222,36 @@ int ntfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry, > if (err) > return err; > > - if (fileattr_has_fsx(fa)) > - return -EOPNOTSUPP; > - > - /* chattr passes the unchanged read-only flags back to us too. */ > - if (NInoCompressed(ni) || NInoWofCompressed(ni)) > - readonly |= FS_COMPR_FL; > - if (NInoEncrypted(ni)) > - readonly |= FS_ENCRYPT_FL; > - if ((fa->flags ^ readonly) & (FS_COMPR_FL | FS_ENCRYPT_FL)) > - return -EOPNOTSUPP; > - allowed |= readonly; > - > - /* Case folding is a read-only, mount-wide property. */ > - if (!NVolCaseSensitive(ni->vol)) > - allowed |= FS_CASEFOLD_FL; > - if (fa->flags & ~allowed) Hi koraynilay, There is another case worth keeping in mind when replacing this check: fileattr_fill_flags() only translates a subset of FS_*_FL bits, so some unsupported flags will not appear in fsx_xflags. For example, a direct SETFLAGS request containing only FS_NOCOW_FL produces fsx_xflags == 0. On a normal file on a case-sensitive mount, the new check would accept that request. If the file already has persistent NODUMP set, the request would also clear it, since the setter rebuilds linuxflags without NODUMP and writes it back to the EA. The current code rejects the request and leaves the existing attributes unchanged. Would it be possible to keep validating fa->flags when flags_valid is set, in addition to the xflags check? Thanks, Baolin. > + /* > + * When userspace uses file_[gs]etattr(), VFS already checks and fails > + * with -EOPNOTSUPP if rw_mask & ro_mask != 0 and rw_mask & ~allowed, > + * but for FS_IOC_SETFLAGS and FS_IOC_FSSETXATTR VFS can't check for > + * allowed flags as these ioctls don't support fsx_xflags_{rw,ro}_mask, > + * so we need to check for unsupported flags anyway. > + */ > + if (!fa->has_masks && > + ((fa->fsx_xflags & ~NTFS_RW_XFLAGS) || > + fa->fsx_extsize || fa->fsx_projid || fa->fsx_cowextsize)) > return -EOPNOTSUPP; Hi koraynilay, Could we keep the existing handling of read-only attributes for legacy SETFLAGS callers here? On a case-insensitive NTFS mount, the VFS carries over FS_XFLAG_CASEFOLD from the current attributes, since it is not in FS_XFLAG_COMMON. This check would then reject it because CASEFOLD is not in NTFS_RW_XFLAGS, so even chattr +d would fail with EOPNOTSUPP. The unchanged COMPR/ENCRYPT bits that chattr reads with GETFLAGS and passes back with SETFLAGS would also be rejected on compressed/encrypted files. Allowing those existing read-only attributes to be passed back unchanged would let users continue setting and clearing the persistent flags through chattr,as they can today. Thanks, Baolin. > > forced_immutable = ntfs_is_forced_immutable(vi); > - if (!(fa->flags & FS_IMMUTABLE_FL) && forced_immutable) > + if (!(fa->fsx_xflags & FS_XFLAG_IMMUTABLE) && forced_immutable) > return -EPERM; > > - if (fa->flags & FS_IMMUTABLE_FL) { > + if (fa->fsx_xflags & FS_XFLAG_IMMUTABLE) { > new_fl |= S_IMMUTABLE; > /* Do not persist an immutable bit derived from the mount. */ > if (!forced_immutable || > (ni->linuxflags & NTFS_LINUXFLAGS_IMMUTABLE)) > linuxflags |= NTFS_LINUXFLAGS_IMMUTABLE; > } > - if (fa->flags & FS_APPEND_FL) { > + if (fa->fsx_xflags & FS_XFLAG_APPEND) { > new_fl |= S_APPEND; > linuxflags |= NTFS_LINUXFLAGS_APPEND; > } > - if (fa->flags & FS_NODUMP_FL) > + if (fa->fsx_xflags & FS_XFLAG_NODUMP) > linuxflags |= NTFS_LINUXFLAGS_NODUMP; > - if (fa->flags & FS_NOATIME_FL) { > + if (fa->fsx_xflags & FS_XFLAG_NOATIME) { > new_fl |= S_NOATIME; > linuxflags |= NTFS_LINUXFLAGS_NOATIME; > } > diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h > index 4faa40febf11..219e7c8eb601 100644 > --- a/include/linux/fileattr.h > +++ b/include/linux/fileattr.h > @@ -7,12 +7,14 @@ > #define FS_COMMON_FL \ > (FS_SYNC_FL | FS_IMMUTABLE_FL | FS_APPEND_FL | \ > FS_NODUMP_FL | FS_NOATIME_FL | FS_DAX_FL | \ > - FS_PROJINHERIT_FL | FS_VERITY_FL) > + FS_PROJINHERIT_FL | FS_VERITY_FL | FS_COMPR_FL | \ > + FS_ENCRYPT_FL) > > #define FS_XFLAG_COMMON \ > (FS_XFLAG_SYNC | FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND | \ > FS_XFLAG_NODUMP | FS_XFLAG_NOATIME | FS_XFLAG_DAX | \ > - FS_XFLAG_PROJINHERIT | FS_XFLAG_VERITY) > + FS_XFLAG_PROJINHERIT | FS_XFLAG_VERITY | FS_XFLAG_COMPR | \ > + FS_XFLAG_ENCRYPT) > > /* Read-only inode flags */ > #define FS_XFLAG_RDONLY_MASK \ > diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h > index e40806b3a69c..09fc7e066485 100644 > --- a/include/uapi/linux/fs.h > +++ b/include/uapi/linux/fs.h > @@ -275,6 +275,8 @@ struct file_attr { > #define FS_XFLAG_CASENONPRESERVING 0x00080000 /* case not preserved */ > > #define FS_XFLAG_PROJID 0x00100000 /* project ID */ > +#define FS_XFLAG_COMPR 0x00200000 /* Compress file */ > +#define FS_XFLAG_ENCRYPT 0x00400000 /* Encrypted file */ > #define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */ > > /* the read-only stuff doesn't really belong here, but any other place is ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/3] ntfs: switch to the new xflags fileattr API 2026-11-22 12:49 ` liubaolin @ 2026-11-23 0:38 ` koraynilay 2026-11-23 3:06 ` liubaolin 0 siblings, 1 reply; 28+ messages in thread From: koraynilay @ 2026-11-23 0:38 UTC (permalink / raw) To: liubaolin, koraynilay, Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner Cc: Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Amir Goldstein, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api [-- Attachment #1: Type: text/plain, Size: 7280 bytes --] On Sun Nov 22, 2026 at 1:49 PM CET, liubaolin wrote: > > > 在 2026/11/22 08:08, koraynilay 写道: >> Switch ntfs_fileattr_[gs]et() from the legacy FS_*_FL flags to the >> modern xflags (FS_XFLAG_*) fileattr API with masks. >> >> Introduce FS_XFLAG_COMPR and FS_XFLAG_ENCRYPT and add them to >> FS_XFLAG_COMMON (and add FS_COMPR_FL and FS_ENCRYPT_FL to FS_COMMON_FL) >> to be used in this API switch. >> >> Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.11 >> Signed-off-by: koraynilay <koray.fra@gmail.com> >> --- >> fs/file_attr.c | 8 +++++ >> fs/ntfs/file.c | 63 +++++++++++++++++++--------------------- >> include/linux/fileattr.h | 6 ++-- >> include/uapi/linux/fs.h | 2 ++ > > Hi koraynilay, > One suggestion on the patch split: would it make sense to put the > new COMPR/ENCRYPT xflags and their VFS handling in a separate patch > before the NTFS conversion? > The changes to include/uapi/linux/fs.h, include/linux/fileattr.h > and fs/file_attr.c introduce generic fileattr support, and the > COMMON mask changes also affect other filesystems. > Keeping those changes together in a VFS patch would make the API > and compatibility aspects easier to review. > The following NTFS patch could then focus on using the new flags > while preserving the existing NTFS behaviour. Hi Baolin and thanks for the feedback, for now I put them in the same patch since they're not many lines of code changes, but I now also had to add NOCOMP, maybe I'll split it in the next version. > Thanks, > Baolin. > >> 4 files changed, 44 insertions(+), 35 deletions(-) >> [...] >> if (err) >> return err; >> >> - if (fileattr_has_fsx(fa)) >> - return -EOPNOTSUPP; >> - >> - /* chattr passes the unchanged read-only flags back to us too. */ >> - if (NInoCompressed(ni) || NInoWofCompressed(ni)) >> - readonly |= FS_COMPR_FL; >> - if (NInoEncrypted(ni)) >> - readonly |= FS_ENCRYPT_FL; >> - if ((fa->flags ^ readonly) & (FS_COMPR_FL | FS_ENCRYPT_FL)) >> - return -EOPNOTSUPP; >> - allowed |= readonly; >> - >> - /* Case folding is a read-only, mount-wide property. */ >> - if (!NVolCaseSensitive(ni->vol)) >> - allowed |= FS_CASEFOLD_FL; >> - if (fa->flags & ~allowed) > Hi koraynilay, > There is another case worth keeping in mind when replacing this check: > fileattr_fill_flags() only translates a subset of FS_*_FL bits, > so some unsupported flags will not appear in fsx_xflags. > For example, a direct SETFLAGS request containing only FS_NOCOW_FL > produces fsx_xflags == 0. On a normal file on a case-sensitive mount, > the new check would accept that request. > If the file already has persistent NODUMP set, the request would also > clear it, since the setter rebuilds linuxflags without NODUMP and writes > it back to the EA. The current code rejects the request and leaves the > existing attributes unchanged. > > Would it be possible to keep validating fa->flags when flags_valid is > set, in addition to the xflags check? We could, but the objective is to have filesystems that implement the new _masks API use only xflags. > Thanks, > Baolin. > > >> + /* >> + * When userspace uses file_[gs]etattr(), VFS already checks and fails >> + * with -EOPNOTSUPP if rw_mask & ro_mask != 0 and rw_mask & ~allowed, >> + * but for FS_IOC_SETFLAGS and FS_IOC_FSSETXATTR VFS can't check for >> + * allowed flags as these ioctls don't support fsx_xflags_{rw,ro}_mask, >> + * so we need to check for unsupported flags anyway. >> + */ >> + if (!fa->has_masks && >> + ((fa->fsx_xflags & ~NTFS_RW_XFLAGS) || >> + fa->fsx_extsize || fa->fsx_projid || fa->fsx_cowextsize)) >> return -EOPNOTSUPP; > > Hi koraynilay, > Could we keep the existing handling of read-only attributes > for legacy SETFLAGS callers here? > On a case-insensitive NTFS mount, the VFS carries over > FS_XFLAG_CASEFOLD from the current attributes, since it is not in > FS_XFLAG_COMMON. > This check would then reject it because CASEFOLD is not in > NTFS_RW_XFLAGS, so even chattr +d would fail with EOPNOTSUPP. > The unchanged COMPR/ENCRYPT bits that chattr reads with GETFLAGS and > passes back with SETFLAGS would also be rejected on compressed/encrypted > files. > Allowing those existing read-only attributes to be passed back > unchanged would let users continue setting and clearing the persistent > flags through chattr,as they can today. > > Thanks, > Baolin. Since I wasn't quite satisfied with this version, I'm working on a revisited v2, that is hopefully cleaner and fixes these bugs and the ones reported by sashiko. Thanks, koraynilay >> >> forced_immutable = ntfs_is_forced_immutable(vi); >> - if (!(fa->flags & FS_IMMUTABLE_FL) && forced_immutable) >> + if (!(fa->fsx_xflags & FS_XFLAG_IMMUTABLE) && forced_immutable) >> return -EPERM; >> >> - if (fa->flags & FS_IMMUTABLE_FL) { >> + if (fa->fsx_xflags & FS_XFLAG_IMMUTABLE) { >> new_fl |= S_IMMUTABLE; >> /* Do not persist an immutable bit derived from the mount. */ >> if (!forced_immutable || >> (ni->linuxflags & NTFS_LINUXFLAGS_IMMUTABLE)) >> linuxflags |= NTFS_LINUXFLAGS_IMMUTABLE; >> } >> - if (fa->flags & FS_APPEND_FL) { >> + if (fa->fsx_xflags & FS_XFLAG_APPEND) { >> new_fl |= S_APPEND; >> linuxflags |= NTFS_LINUXFLAGS_APPEND; >> } >> - if (fa->flags & FS_NODUMP_FL) >> + if (fa->fsx_xflags & FS_XFLAG_NODUMP) >> linuxflags |= NTFS_LINUXFLAGS_NODUMP; >> - if (fa->flags & FS_NOATIME_FL) { >> + if (fa->fsx_xflags & FS_XFLAG_NOATIME) { >> new_fl |= S_NOATIME; >> linuxflags |= NTFS_LINUXFLAGS_NOATIME; >> } >> diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h >> index 4faa40febf11..219e7c8eb601 100644 >> --- a/include/linux/fileattr.h >> +++ b/include/linux/fileattr.h >> @@ -7,12 +7,14 @@ >> #define FS_COMMON_FL \ >> (FS_SYNC_FL | FS_IMMUTABLE_FL | FS_APPEND_FL | \ >> FS_NODUMP_FL | FS_NOATIME_FL | FS_DAX_FL | \ >> - FS_PROJINHERIT_FL | FS_VERITY_FL) >> + FS_PROJINHERIT_FL | FS_VERITY_FL | FS_COMPR_FL | \ >> + FS_ENCRYPT_FL) >> >> #define FS_XFLAG_COMMON \ >> (FS_XFLAG_SYNC | FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND | \ >> FS_XFLAG_NODUMP | FS_XFLAG_NOATIME | FS_XFLAG_DAX | \ >> - FS_XFLAG_PROJINHERIT | FS_XFLAG_VERITY) >> + FS_XFLAG_PROJINHERIT | FS_XFLAG_VERITY | FS_XFLAG_COMPR | \ >> + FS_XFLAG_ENCRYPT) >> >> /* Read-only inode flags */ >> #define FS_XFLAG_RDONLY_MASK \ >> diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h >> index e40806b3a69c..09fc7e066485 100644 >> --- a/include/uapi/linux/fs.h >> +++ b/include/uapi/linux/fs.h >> @@ -275,6 +275,8 @@ struct file_attr { >> #define FS_XFLAG_CASENONPRESERVING 0x00080000 /* case not preserved */ >> >> #define FS_XFLAG_PROJID 0x00100000 /* project ID */ >> +#define FS_XFLAG_COMPR 0x00200000 /* Compress file */ >> +#define FS_XFLAG_ENCRYPT 0x00400000 /* Encrypted file */ >> #define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */ >> >> /* the read-only stuff doesn't really belong here, but any other place is [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/3] ntfs: switch to the new xflags fileattr API 2026-11-23 0:38 ` koraynilay @ 2026-11-23 3:06 ` liubaolin 2026-11-23 14:13 ` koraynilay 0 siblings, 1 reply; 28+ messages in thread From: liubaolin @ 2026-11-23 3:06 UTC (permalink / raw) To: koraynilay, Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner Cc: Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Amir Goldstein, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api 在 2026/11/23 08:38, koraynilay 写道: > On Sun Nov 22, 2026 at 1:49 PM CET, liubaolin wrote: >> >> >> 在 2026/11/22 08:08, koraynilay 写道: >>> Switch ntfs_fileattr_[gs]et() from the legacy FS_*_FL flags to the >>> modern xflags (FS_XFLAG_*) fileattr API with masks. >>> >>> Introduce FS_XFLAG_COMPR and FS_XFLAG_ENCRYPT and add them to >>> FS_XFLAG_COMMON (and add FS_COMPR_FL and FS_ENCRYPT_FL to FS_COMMON_FL) >>> to be used in this API switch. >>> >>> Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.11 >>> Signed-off-by: koraynilay <koray.fra@gmail.com> >>> --- >>> fs/file_attr.c | 8 +++++ >>> fs/ntfs/file.c | 63 +++++++++++++++++++--------------------- >>> include/linux/fileattr.h | 6 ++-- >>> include/uapi/linux/fs.h | 2 ++ >> >> Hi koraynilay, >> One suggestion on the patch split: would it make sense to put the >> new COMPR/ENCRYPT xflags and their VFS handling in a separate patch >> before the NTFS conversion? >> The changes to include/uapi/linux/fs.h, include/linux/fileattr.h >> and fs/file_attr.c introduce generic fileattr support, and the >> COMMON mask changes also affect other filesystems. >> Keeping those changes together in a VFS patch would make the API >> and compatibility aspects easier to review. >> The following NTFS patch could then focus on using the new flags >> while preserving the existing NTFS behaviour. > > Hi Baolin and thanks for the feedback, > for now I put them in the same patch since they're not many lines of > code changes, but I now also had to add NOCOMP, maybe I'll split it in > the next version. > >> Thanks, >> Baolin. >> >>> 4 files changed, 44 insertions(+), 35 deletions(-) >>> [...] >>> if (err) >>> return err; >>> >>> - if (fileattr_has_fsx(fa)) >>> - return -EOPNOTSUPP; >>> - >>> - /* chattr passes the unchanged read-only flags back to us too. */ >>> - if (NInoCompressed(ni) || NInoWofCompressed(ni)) >>> - readonly |= FS_COMPR_FL; >>> - if (NInoEncrypted(ni)) >>> - readonly |= FS_ENCRYPT_FL; >>> - if ((fa->flags ^ readonly) & (FS_COMPR_FL | FS_ENCRYPT_FL)) >>> - return -EOPNOTSUPP; >>> - allowed |= readonly; >>> - >>> - /* Case folding is a read-only, mount-wide property. */ >>> - if (!NVolCaseSensitive(ni->vol)) >>> - allowed |= FS_CASEFOLD_FL; >>> - if (fa->flags & ~allowed) >> Hi koraynilay, >> There is another case worth keeping in mind when replacing this check: >> fileattr_fill_flags() only translates a subset of FS_*_FL bits, >> so some unsupported flags will not appear in fsx_xflags. >> For example, a direct SETFLAGS request containing only FS_NOCOW_FL >> produces fsx_xflags == 0. On a normal file on a case-sensitive mount, >> the new check would accept that request. >> If the file already has persistent NODUMP set, the request would also >> clear it, since the setter rebuilds linuxflags without NODUMP and writes >> it back to the EA. The current code rejects the request and leaves the >> existing attributes unchanged. >> >> Would it be possible to keep validating fa->flags when flags_valid is >> set, in addition to the xflags check? > > We could, but the objective is to have filesystems that implement the > new _masks API use only xflags. Hi koraynilay, That makes sense, and I'm fine with NTFS using only xflags. Could we still make sure that legacy SETFLAGS requests with flags unsupported by NTFS are rejected rather than silently accepted after conversion? Thanks, Baolin. > >> Thanks, >> Baolin. >> >> >>> + /* >>> + * When userspace uses file_[gs]etattr(), VFS already checks and fails >>> + * with -EOPNOTSUPP if rw_mask & ro_mask != 0 and rw_mask & ~allowed, >>> + * but for FS_IOC_SETFLAGS and FS_IOC_FSSETXATTR VFS can't check for >>> + * allowed flags as these ioctls don't support fsx_xflags_{rw,ro}_mask, >>> + * so we need to check for unsupported flags anyway. >>> + */ >>> + if (!fa->has_masks && >>> + ((fa->fsx_xflags & ~NTFS_RW_XFLAGS) || >>> + fa->fsx_extsize || fa->fsx_projid || fa->fsx_cowextsize)) >>> return -EOPNOTSUPP; >> >> Hi koraynilay, >> Could we keep the existing handling of read-only attributes >> for legacy SETFLAGS callers here? >> On a case-insensitive NTFS mount, the VFS carries over >> FS_XFLAG_CASEFOLD from the current attributes, since it is not in >> FS_XFLAG_COMMON. >> This check would then reject it because CASEFOLD is not in >> NTFS_RW_XFLAGS, so even chattr +d would fail with EOPNOTSUPP. >> The unchanged COMPR/ENCRYPT bits that chattr reads with GETFLAGS and >> passes back with SETFLAGS would also be rejected on compressed/encrypted >> files. >> Allowing those existing read-only attributes to be passed back >> unchanged would let users continue setting and clearing the persistent >> flags through chattr,as they can today. >> >> Thanks, >> Baolin. > > Since I wasn't quite satisfied with this version, I'm working on a > revisited v2, that is hopefully cleaner and fixes these bugs and the > ones reported by sashiko. > > Thanks, > koraynilay > > >>> >>> forced_immutable = ntfs_is_forced_immutable(vi); >>> - if (!(fa->flags & FS_IMMUTABLE_FL) && forced_immutable) >>> + if (!(fa->fsx_xflags & FS_XFLAG_IMMUTABLE) && forced_immutable) >>> return -EPERM; >>> >>> - if (fa->flags & FS_IMMUTABLE_FL) { >>> + if (fa->fsx_xflags & FS_XFLAG_IMMUTABLE) { >>> new_fl |= S_IMMUTABLE; >>> /* Do not persist an immutable bit derived from the mount. */ >>> if (!forced_immutable || >>> (ni->linuxflags & NTFS_LINUXFLAGS_IMMUTABLE)) >>> linuxflags |= NTFS_LINUXFLAGS_IMMUTABLE; >>> } >>> - if (fa->flags & FS_APPEND_FL) { >>> + if (fa->fsx_xflags & FS_XFLAG_APPEND) { >>> new_fl |= S_APPEND; >>> linuxflags |= NTFS_LINUXFLAGS_APPEND; >>> } >>> - if (fa->flags & FS_NODUMP_FL) >>> + if (fa->fsx_xflags & FS_XFLAG_NODUMP) >>> linuxflags |= NTFS_LINUXFLAGS_NODUMP; >>> - if (fa->flags & FS_NOATIME_FL) { >>> + if (fa->fsx_xflags & FS_XFLAG_NOATIME) { >>> new_fl |= S_NOATIME; >>> linuxflags |= NTFS_LINUXFLAGS_NOATIME; >>> } >>> diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h >>> index 4faa40febf11..219e7c8eb601 100644 >>> --- a/include/linux/fileattr.h >>> +++ b/include/linux/fileattr.h >>> @@ -7,12 +7,14 @@ >>> #define FS_COMMON_FL \ >>> (FS_SYNC_FL | FS_IMMUTABLE_FL | FS_APPEND_FL | \ >>> FS_NODUMP_FL | FS_NOATIME_FL | FS_DAX_FL | \ >>> - FS_PROJINHERIT_FL | FS_VERITY_FL) >>> + FS_PROJINHERIT_FL | FS_VERITY_FL | FS_COMPR_FL | \ >>> + FS_ENCRYPT_FL) >>> >>> #define FS_XFLAG_COMMON \ >>> (FS_XFLAG_SYNC | FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND | \ >>> FS_XFLAG_NODUMP | FS_XFLAG_NOATIME | FS_XFLAG_DAX | \ >>> - FS_XFLAG_PROJINHERIT | FS_XFLAG_VERITY) >>> + FS_XFLAG_PROJINHERIT | FS_XFLAG_VERITY | FS_XFLAG_COMPR | \ >>> + FS_XFLAG_ENCRYPT) >>> >>> /* Read-only inode flags */ >>> #define FS_XFLAG_RDONLY_MASK \ >>> diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h >>> index e40806b3a69c..09fc7e066485 100644 >>> --- a/include/uapi/linux/fs.h >>> +++ b/include/uapi/linux/fs.h >>> @@ -275,6 +275,8 @@ struct file_attr { >>> #define FS_XFLAG_CASENONPRESERVING 0x00080000 /* case not preserved */ >>> >>> #define FS_XFLAG_PROJID 0x00100000 /* project ID */ >>> +#define FS_XFLAG_COMPR 0x00200000 /* Compress file */ >>> +#define FS_XFLAG_ENCRYPT 0x00400000 /* Encrypted file */ >>> #define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */ >>> >>> /* the read-only stuff doesn't really belong here, but any other place is > ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/3] ntfs: switch to the new xflags fileattr API 2026-11-23 3:06 ` liubaolin @ 2026-11-23 14:13 ` koraynilay 0 siblings, 0 replies; 28+ messages in thread From: koraynilay @ 2026-11-23 14:13 UTC (permalink / raw) To: liubaolin, koraynilay, Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner Cc: Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Amir Goldstein, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api [-- Attachment #1: Type: text/plain, Size: 8559 bytes --] On Mon Nov 23, 2026 at 4:06 AM CET, liubaolin wrote: > > > 在 2026/11/23 08:38, koraynilay 写道: >> On Sun Nov 22, 2026 at 1:49 PM CET, liubaolin wrote: >>> >>> >>> 在 2026/11/22 08:08, koraynilay 写道: >>>> Switch ntfs_fileattr_[gs]et() from the legacy FS_*_FL flags to the >>>> modern xflags (FS_XFLAG_*) fileattr API with masks. >>>> >>>> Introduce FS_XFLAG_COMPR and FS_XFLAG_ENCRYPT and add them to >>>> FS_XFLAG_COMMON (and add FS_COMPR_FL and FS_ENCRYPT_FL to FS_COMMON_FL) >>>> to be used in this API switch. >>>> >>>> Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.11 >>>> Signed-off-by: koraynilay <koray.fra@gmail.com> >>>> --- >>>> fs/file_attr.c | 8 +++++ >>>> fs/ntfs/file.c | 63 +++++++++++++++++++--------------------- >>>> include/linux/fileattr.h | 6 ++-- >>>> include/uapi/linux/fs.h | 2 ++ >>> >>> Hi koraynilay, >>> One suggestion on the patch split: would it make sense to put the >>> new COMPR/ENCRYPT xflags and their VFS handling in a separate patch >>> before the NTFS conversion? >>> The changes to include/uapi/linux/fs.h, include/linux/fileattr.h >>> and fs/file_attr.c introduce generic fileattr support, and the >>> COMMON mask changes also affect other filesystems. >>> Keeping those changes together in a VFS patch would make the API >>> and compatibility aspects easier to review. >>> The following NTFS patch could then focus on using the new flags >>> while preserving the existing NTFS behaviour. >> >> Hi Baolin and thanks for the feedback, >> for now I put them in the same patch since they're not many lines of >> code changes, but I now also had to add NOCOMP, maybe I'll split it in >> the next version. >> >>> Thanks, >>> Baolin. >>> >>>> 4 files changed, 44 insertions(+), 35 deletions(-) >>>> [...] >>>> if (err) >>>> return err; >>>> >>>> - if (fileattr_has_fsx(fa)) >>>> - return -EOPNOTSUPP; >>>> - >>>> - /* chattr passes the unchanged read-only flags back to us too. */ >>>> - if (NInoCompressed(ni) || NInoWofCompressed(ni)) >>>> - readonly |= FS_COMPR_FL; >>>> - if (NInoEncrypted(ni)) >>>> - readonly |= FS_ENCRYPT_FL; >>>> - if ((fa->flags ^ readonly) & (FS_COMPR_FL | FS_ENCRYPT_FL)) >>>> - return -EOPNOTSUPP; >>>> - allowed |= readonly; >>>> - >>>> - /* Case folding is a read-only, mount-wide property. */ >>>> - if (!NVolCaseSensitive(ni->vol)) >>>> - allowed |= FS_CASEFOLD_FL; >>>> - if (fa->flags & ~allowed) >>> Hi koraynilay, >>> There is another case worth keeping in mind when replacing this check: >>> fileattr_fill_flags() only translates a subset of FS_*_FL bits, >>> so some unsupported flags will not appear in fsx_xflags. >>> For example, a direct SETFLAGS request containing only FS_NOCOW_FL >>> produces fsx_xflags == 0. On a normal file on a case-sensitive mount, >>> the new check would accept that request. >>> If the file already has persistent NODUMP set, the request would also >>> clear it, since the setter rebuilds linuxflags without NODUMP and writes >>> it back to the EA. The current code rejects the request and leaves the >>> existing attributes unchanged. >>> >>> Would it be possible to keep validating fa->flags when flags_valid is >>> set, in addition to the xflags check? >> >> We could, but the objective is to have filesystems that implement the >> new _masks API use only xflags. > > Hi koraynilay, > That makes sense, and I'm fine with NTFS using only xflags. > Could we still make sure that legacy SETFLAGS requests with flags > unsupported by NTFS are rejected rather than silently accepted after > conversion? Hi, yes, my current (v2) code, in the new fileattr_legacy_to_mask() helper, does this: if (fa->flags_valid) { /* * Assume that if the filesystem supports masks it also added * its supported FS_*_FL flags to FS_XFLAG_* and to the COMMON * masks. */ changed = fa->flags ^ old_ma->flags; if (changed & ~FS_COMMON_FL) return -EOPNOTSUPP; changed = flags_to_xflags(changed); } so they should be correctly rejected. Thanks, koraynilay > Thanks, > Baolin. > >> >>> Thanks, >>> Baolin. >>> >>> >>>> + /* >>>> + * When userspace uses file_[gs]etattr(), VFS already checks and fails >>>> + * with -EOPNOTSUPP if rw_mask & ro_mask != 0 and rw_mask & ~allowed, >>>> + * but for FS_IOC_SETFLAGS and FS_IOC_FSSETXATTR VFS can't check for >>>> + * allowed flags as these ioctls don't support fsx_xflags_{rw,ro}_mask, >>>> + * so we need to check for unsupported flags anyway. >>>> + */ >>>> + if (!fa->has_masks && >>>> + ((fa->fsx_xflags & ~NTFS_RW_XFLAGS) || >>>> + fa->fsx_extsize || fa->fsx_projid || fa->fsx_cowextsize)) >>>> return -EOPNOTSUPP; >>> >>> Hi koraynilay, >>> Could we keep the existing handling of read-only attributes >>> for legacy SETFLAGS callers here? >>> On a case-insensitive NTFS mount, the VFS carries over >>> FS_XFLAG_CASEFOLD from the current attributes, since it is not in >>> FS_XFLAG_COMMON. >>> This check would then reject it because CASEFOLD is not in >>> NTFS_RW_XFLAGS, so even chattr +d would fail with EOPNOTSUPP. >>> The unchanged COMPR/ENCRYPT bits that chattr reads with GETFLAGS and >>> passes back with SETFLAGS would also be rejected on compressed/encrypted >>> files. >>> Allowing those existing read-only attributes to be passed back >>> unchanged would let users continue setting and clearing the persistent >>> flags through chattr,as they can today. >>> >>> Thanks, >>> Baolin. >> >> Since I wasn't quite satisfied with this version, I'm working on a >> revisited v2, that is hopefully cleaner and fixes these bugs and the >> ones reported by sashiko. >> >> Thanks, >> koraynilay >> >> >>>> >>>> forced_immutable = ntfs_is_forced_immutable(vi); >>>> - if (!(fa->flags & FS_IMMUTABLE_FL) && forced_immutable) >>>> + if (!(fa->fsx_xflags & FS_XFLAG_IMMUTABLE) && forced_immutable) >>>> return -EPERM; >>>> >>>> - if (fa->flags & FS_IMMUTABLE_FL) { >>>> + if (fa->fsx_xflags & FS_XFLAG_IMMUTABLE) { >>>> new_fl |= S_IMMUTABLE; >>>> /* Do not persist an immutable bit derived from the mount. */ >>>> if (!forced_immutable || >>>> (ni->linuxflags & NTFS_LINUXFLAGS_IMMUTABLE)) >>>> linuxflags |= NTFS_LINUXFLAGS_IMMUTABLE; >>>> } >>>> - if (fa->flags & FS_APPEND_FL) { >>>> + if (fa->fsx_xflags & FS_XFLAG_APPEND) { >>>> new_fl |= S_APPEND; >>>> linuxflags |= NTFS_LINUXFLAGS_APPEND; >>>> } >>>> - if (fa->flags & FS_NODUMP_FL) >>>> + if (fa->fsx_xflags & FS_XFLAG_NODUMP) >>>> linuxflags |= NTFS_LINUXFLAGS_NODUMP; >>>> - if (fa->flags & FS_NOATIME_FL) { >>>> + if (fa->fsx_xflags & FS_XFLAG_NOATIME) { >>>> new_fl |= S_NOATIME; >>>> linuxflags |= NTFS_LINUXFLAGS_NOATIME; >>>> } >>>> diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h >>>> index 4faa40febf11..219e7c8eb601 100644 >>>> --- a/include/linux/fileattr.h >>>> +++ b/include/linux/fileattr.h >>>> @@ -7,12 +7,14 @@ >>>> #define FS_COMMON_FL \ >>>> (FS_SYNC_FL | FS_IMMUTABLE_FL | FS_APPEND_FL | \ >>>> FS_NODUMP_FL | FS_NOATIME_FL | FS_DAX_FL | \ >>>> - FS_PROJINHERIT_FL | FS_VERITY_FL) >>>> + FS_PROJINHERIT_FL | FS_VERITY_FL | FS_COMPR_FL | \ >>>> + FS_ENCRYPT_FL) >>>> >>>> #define FS_XFLAG_COMMON \ >>>> (FS_XFLAG_SYNC | FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND | \ >>>> FS_XFLAG_NODUMP | FS_XFLAG_NOATIME | FS_XFLAG_DAX | \ >>>> - FS_XFLAG_PROJINHERIT | FS_XFLAG_VERITY) >>>> + FS_XFLAG_PROJINHERIT | FS_XFLAG_VERITY | FS_XFLAG_COMPR | \ >>>> + FS_XFLAG_ENCRYPT) >>>> >>>> /* Read-only inode flags */ >>>> #define FS_XFLAG_RDONLY_MASK \ >>>> diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h >>>> index e40806b3a69c..09fc7e066485 100644 >>>> --- a/include/uapi/linux/fs.h >>>> +++ b/include/uapi/linux/fs.h >>>> @@ -275,6 +275,8 @@ struct file_attr { >>>> #define FS_XFLAG_CASENONPRESERVING 0x00080000 /* case not preserved */ >>>> >>>> #define FS_XFLAG_PROJID 0x00100000 /* project ID */ >>>> +#define FS_XFLAG_COMPR 0x00200000 /* Compress file */ >>>> +#define FS_XFLAG_ENCRYPT 0x00400000 /* Encrypted file */ >>>> #define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */ >>>> >>>> /* the read-only stuff doesn't really belong here, but any other place is >> [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/3] ntfs: switch to the new xflags fileattr API 2026-11-22 0:08 ` [PATCH 3/3] ntfs: switch to the new xflags " koraynilay 2026-11-22 12:49 ` liubaolin @ 2026-11-23 13:00 ` Amir Goldstein 2026-11-23 13:50 ` koraynilay 1 sibling, 1 reply; 28+ messages in thread From: Amir Goldstein @ 2026-11-23 13:00 UTC (permalink / raw) To: koraynilay Cc: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api On Sun, Nov 22, 2026 at 1:09 AM koraynilay <koray.fra@gmail.com> wrote: > > Switch ntfs_fileattr_[gs]et() from the legacy FS_*_FL flags to the > modern xflags (FS_XFLAG_*) fileattr API with masks. > > Introduce FS_XFLAG_COMPR and FS_XFLAG_ENCRYPT and add them to > FS_XFLAG_COMMON (and add FS_COMPR_FL and FS_ENCRYPT_FL to FS_COMMON_FL) > to be used in this API switch. > > Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.11 > Signed-off-by: koraynilay <koray.fra@gmail.com> > --- > fs/file_attr.c | 8 +++++ > fs/ntfs/file.c | 63 +++++++++++++++++++--------------------- > include/linux/fileattr.h | 6 ++-- > include/uapi/linux/fs.h | 2 ++ > 4 files changed, 44 insertions(+), 35 deletions(-) > ... > diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c > index 50be49f4c913..fde6fb2fe39c 100644 > --- a/fs/ntfs/file.c > +++ b/fs/ntfs/file.c > @@ -155,31 +155,37 @@ int ntfs_file_release(struct inode *vi, struct file *filp) > * @dentry: dentry to report the flags of > * @fa: filled in with the flags of @dentry > */ > +#define NTFS_RO_XFLAGS (FS_XFLAG_COMPR | FS_XFLAG_ENCRYPT | FS_XFLAG_CASEFOLD) > +#define NTFS_RW_XFLAGS (FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND | \ > + FS_XFLAG_NOATIME | FS_XFLAG_NODUMP) Nit: checkpatch may allow 100 chars, but this due formatting is not easy on the eyes pls break to RO line and indent the broken lines below ( > diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h > index 4faa40febf11..219e7c8eb601 100644 > --- a/include/linux/fileattr.h > +++ b/include/linux/fileattr.h > @@ -7,12 +7,14 @@ > #define FS_COMMON_FL \ > (FS_SYNC_FL | FS_IMMUTABLE_FL | FS_APPEND_FL | \ > FS_NODUMP_FL | FS_NOATIME_FL | FS_DAX_FL | \ > - FS_PROJINHERIT_FL | FS_VERITY_FL) > + FS_PROJINHERIT_FL | FS_VERITY_FL | FS_COMPR_FL | \ > + FS_ENCRYPT_FL) > > #define FS_XFLAG_COMMON \ > (FS_XFLAG_SYNC | FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND | \ > FS_XFLAG_NODUMP | FS_XFLAG_NOATIME | FS_XFLAG_DAX | \ > - FS_XFLAG_PROJINHERIT | FS_XFLAG_VERITY) > + FS_XFLAG_PROJINHERIT | FS_XFLAG_VERITY | FS_XFLAG_COMPR | \ > + FS_XFLAG_ENCRYPT) Rule: You cannot add a flag to common without carefully auditing all filesystems that support the legacy flag. FS_XFLAG_ENCRYPT can go into common but must also go to FS_XFLAG_RDONLY_MASK because it's read-only for all existing fs. COMPR is rw for some fs and ro for others. As with CASEFOLD, you cannot make it COMMON before converting all casefold fs to new API so that each can say whether it wants RO or RW. I think there may be a way to deal with this easily since ntfs doesn't need to set either but not sure. > > /* Read-only inode flags */ > #define FS_XFLAG_RDONLY_MASK \ > diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h > index e40806b3a69c..09fc7e066485 100644 > --- a/include/uapi/linux/fs.h > +++ b/include/uapi/linux/fs.h > @@ -275,6 +275,8 @@ struct file_attr { > #define FS_XFLAG_CASENONPRESERVING 0x00080000 /* case not preserved */ > > #define FS_XFLAG_PROJID 0x00100000 /* project ID */ > +#define FS_XFLAG_COMPR 0x00200000 /* Compress file */ > +#define FS_XFLAG_ENCRYPT 0x00400000 /* Encrypted file */ This is a mistake of patch 1. the newline should remain above HASATTR which is allocated from the end. > #define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */ > > /* the read-only stuff doesn't really belong here, but any other place is Thanks, Amir. > ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/3] ntfs: switch to the new xflags fileattr API 2026-11-23 13:00 ` Amir Goldstein @ 2026-11-23 13:50 ` koraynilay 2026-11-23 14:14 ` Amir Goldstein 0 siblings, 1 reply; 28+ messages in thread From: koraynilay @ 2026-11-23 13:50 UTC (permalink / raw) To: Amir Goldstein, koraynilay Cc: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api [-- Attachment #1: Type: text/plain, Size: 4978 bytes --] On Mon Nov 23, 2026 at 2:00 PM CET, Amir Goldstein wrote: > On Sun, Nov 22, 2026 at 1:09 AM koraynilay <koray.fra@gmail.com> wrote: >> >> Switch ntfs_fileattr_[gs]et() from the legacy FS_*_FL flags to the >> modern xflags (FS_XFLAG_*) fileattr API with masks. >> >> Introduce FS_XFLAG_COMPR and FS_XFLAG_ENCRYPT and add them to >> FS_XFLAG_COMMON (and add FS_COMPR_FL and FS_ENCRYPT_FL to FS_COMMON_FL) >> to be used in this API switch. >> >> Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.11 >> Signed-off-by: koraynilay <koray.fra@gmail.com> >> --- >> fs/file_attr.c | 8 +++++ >> fs/ntfs/file.c | 63 +++++++++++++++++++--------------------- >> include/linux/fileattr.h | 6 ++-- >> include/uapi/linux/fs.h | 2 ++ >> 4 files changed, 44 insertions(+), 35 deletions(-) >> > ... > >> diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c >> index 50be49f4c913..fde6fb2fe39c 100644 >> --- a/fs/ntfs/file.c >> +++ b/fs/ntfs/file.c >> @@ -155,31 +155,37 @@ int ntfs_file_release(struct inode *vi, struct file *filp) >> * @dentry: dentry to report the flags of >> * @fa: filled in with the flags of @dentry >> */ >> +#define NTFS_RO_XFLAGS (FS_XFLAG_COMPR | FS_XFLAG_ENCRYPT | FS_XFLAG_CASEFOLD) >> +#define NTFS_RW_XFLAGS (FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND | \ >> + FS_XFLAG_NOATIME | FS_XFLAG_NODUMP) > > Nit: checkpatch may allow 100 chars, but this due formatting is not > easy on the eyes > pls break to RO line It should be 78 and imo it looks fine, but yes, I'll split it in next patch. > and indent the broken lines below ( This should be a diff-only problem, in my working tree the file has them correctly indented using 3 tabs (wide 8) and 0 space, probably same problem as the PROJID line being unaligned here: >> #define FS_XFLAG_PROJID 0x00100000 /* project ID */ >> +#define FS_XFLAG_COMPR 0x00200000 /* Compress file */ > >> diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h >> index 4faa40febf11..219e7c8eb601 100644 >> --- a/include/linux/fileattr.h >> +++ b/include/linux/fileattr.h >> @@ -7,12 +7,14 @@ >> #define FS_COMMON_FL \ >> (FS_SYNC_FL | FS_IMMUTABLE_FL | FS_APPEND_FL | \ >> FS_NODUMP_FL | FS_NOATIME_FL | FS_DAX_FL | \ >> - FS_PROJINHERIT_FL | FS_VERITY_FL) >> + FS_PROJINHERIT_FL | FS_VERITY_FL | FS_COMPR_FL | \ >> + FS_ENCRYPT_FL) >> >> #define FS_XFLAG_COMMON \ >> (FS_XFLAG_SYNC | FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND | \ >> FS_XFLAG_NODUMP | FS_XFLAG_NOATIME | FS_XFLAG_DAX | \ >> - FS_XFLAG_PROJINHERIT | FS_XFLAG_VERITY) >> + FS_XFLAG_PROJINHERIT | FS_XFLAG_VERITY | FS_XFLAG_COMPR | \ >> + FS_XFLAG_ENCRYPT) > > > Rule: > > You cannot add a flag to common without carefully auditing all > filesystems that support the legacy flag. Yeah, sashiko pointed out a problem in f2fs, and I could reproduce it in testing, where adding COMPR to COMMON makes f2fs crash, it also needs NOCOMP in COMMON. > FS_XFLAG_ENCRYPT can go into common but must also > go to FS_XFLAG_RDONLY_MASK because it's read-only for > all existing fs. > > COMPR is rw for some fs and ro for others. > As with CASEFOLD, you cannot make it COMMON before > converting all casefold fs to new API so that each can say > whether it wants RO or RW. How's CASEFOLD currently handled? in the v2 I'm drafting, I added fileattr_mask_to_legacy() and fileattr_legacy_to_mask(), which convert between the old format (filtering by FS_XFLAGS_MASK) and the new mask format. > I think there may be a way to deal with this easily since > ntfs doesn't need to set either but not sure. We could export the 2 other helpers I added for v2 (xflags_to_flags and flags_to_xflags) and make NTFS use them? Though adding the fileattr_ prefix will make the current (v2) vfs code maybe too verbose. >> >> /* Read-only inode flags */ >> #define FS_XFLAG_RDONLY_MASK \ >> diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h >> index e40806b3a69c..09fc7e066485 100644 >> --- a/include/uapi/linux/fs.h >> +++ b/include/uapi/linux/fs.h >> @@ -275,6 +275,8 @@ struct file_attr { >> #define FS_XFLAG_CASENONPRESERVING 0x00080000 /* case not preserved */ >> >> #define FS_XFLAG_PROJID 0x00100000 /* project ID */ >> +#define FS_XFLAG_COMPR 0x00200000 /* Compress file */ >> +#define FS_XFLAG_ENCRYPT 0x00400000 /* Encrypted file */ > > This is a mistake of patch 1. the newline should remain above HASATTR > which is allocated from the end. Right, fixed (and removed the blank line between CASENONPRESERVING and PROJID). Thanks, koraynilay > >> #define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */ >> >> /* the read-only stuff doesn't really belong here, but any other place is > > Thanks, > Amir. >> [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/3] ntfs: switch to the new xflags fileattr API 2026-11-23 13:50 ` koraynilay @ 2026-11-23 14:14 ` Amir Goldstein 2026-11-23 14:31 ` koraynilay 0 siblings, 1 reply; 28+ messages in thread From: Amir Goldstein @ 2026-11-23 14:14 UTC (permalink / raw) To: koraynilay Cc: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api On Mon, Nov 23, 2026 at 2:50 PM koraynilay <koray.fra@gmail.com> wrote: > > On Mon Nov 23, 2026 at 2:00 PM CET, Amir Goldstein wrote: > > On Sun, Nov 22, 2026 at 1:09 AM koraynilay <koray.fra@gmail.com> wrote: > >> > >> Switch ntfs_fileattr_[gs]et() from the legacy FS_*_FL flags to the > >> modern xflags (FS_XFLAG_*) fileattr API with masks. > >> > >> Introduce FS_XFLAG_COMPR and FS_XFLAG_ENCRYPT and add them to > >> FS_XFLAG_COMMON (and add FS_COMPR_FL and FS_ENCRYPT_FL to FS_COMMON_FL) > >> to be used in this API switch. > >> > >> Assisted-by: Gemini:3.8-flash-high antigravity-cli-1.5.11 > >> Signed-off-by: koraynilay <koray.fra@gmail.com> > >> --- > >> fs/file_attr.c | 8 +++++ > >> fs/ntfs/file.c | 63 +++++++++++++++++++--------------------- > >> include/linux/fileattr.h | 6 ++-- > >> include/uapi/linux/fs.h | 2 ++ > >> 4 files changed, 44 insertions(+), 35 deletions(-) > >> > > ... > > > >> diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c > >> index 50be49f4c913..fde6fb2fe39c 100644 > >> --- a/fs/ntfs/file.c > >> +++ b/fs/ntfs/file.c > >> @@ -155,31 +155,37 @@ int ntfs_file_release(struct inode *vi, struct file *filp) > >> * @dentry: dentry to report the flags of > >> * @fa: filled in with the flags of @dentry > >> */ > >> +#define NTFS_RO_XFLAGS (FS_XFLAG_COMPR | FS_XFLAG_ENCRYPT | FS_XFLAG_CASEFOLD) > >> +#define NTFS_RW_XFLAGS (FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND | \ > >> + FS_XFLAG_NOATIME | FS_XFLAG_NODUMP) > > > > Nit: checkpatch may allow 100 chars, but this due formatting is not > > easy on the eyes > > pls break to RO line > It should be 78 and imo it looks fine, but yes, I'll split it in next > patch. > > > and indent the broken lines below ( > > This should be a diff-only problem, in my working tree the file has them > correctly indented using 3 tabs (wide 8) and 0 space, probably same > problem as the PROJID line being unaligned here: Sorry, pls ignore. > >> #define FS_XFLAG_PROJID 0x00100000 /* project ID */ > >> +#define FS_XFLAG_COMPR 0x00200000 /* Compress file */ > > > > >> diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h > >> index 4faa40febf11..219e7c8eb601 100644 > >> --- a/include/linux/fileattr.h > >> +++ b/include/linux/fileattr.h > >> @@ -7,12 +7,14 @@ > >> #define FS_COMMON_FL \ > >> (FS_SYNC_FL | FS_IMMUTABLE_FL | FS_APPEND_FL | \ > >> FS_NODUMP_FL | FS_NOATIME_FL | FS_DAX_FL | \ > >> - FS_PROJINHERIT_FL | FS_VERITY_FL) > >> + FS_PROJINHERIT_FL | FS_VERITY_FL | FS_COMPR_FL | \ > >> + FS_ENCRYPT_FL) > >> > >> #define FS_XFLAG_COMMON \ > >> (FS_XFLAG_SYNC | FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND | \ > >> FS_XFLAG_NODUMP | FS_XFLAG_NOATIME | FS_XFLAG_DAX | \ > >> - FS_XFLAG_PROJINHERIT | FS_XFLAG_VERITY) > >> + FS_XFLAG_PROJINHERIT | FS_XFLAG_VERITY | FS_XFLAG_COMPR | \ > >> + FS_XFLAG_ENCRYPT) > > > > > > Rule: > > > > You cannot add a flag to common without carefully auditing all > > filesystems that support the legacy flag. > > Yeah, sashiko pointed out a problem in f2fs, and I could reproduce it in > testing, where adding COMPR to COMMON makes f2fs crash, it also needs > NOCOMP in COMMON. > I don't think this is correct, or at least not enough. My agent said that this breaks or changes things on f2fs/ext4/ubifs I didn't bother to check if all of them are true - I doubt it bottom line - need careful audit and good testing. > > FS_XFLAG_ENCRYPT can go into common but must also > > go to FS_XFLAG_RDONLY_MASK because it's read-only for > > all existing fs. > > > > COMPR is rw for some fs and ro for others. > > As with CASEFOLD, you cannot make it COMMON before > > converting all casefold fs to new API so that each can say > > whether it wants RO or RW. > > How's CASEFOLD currently handled? in the v2 I'm drafting, I added > fileattr_mask_to_legacy() and fileattr_legacy_to_mask(), which convert > between the old format (filtering by FS_XFLAGS_MASK) and the new mask > format. > Good question. Need to check this. > > I think there may be a way to deal with this easily since > > ntfs doesn't need to set either but not sure. > > We could export the 2 other helpers I added for v2 (xflags_to_flags and > flags_to_xflags) and make NTFS use them? > Though adding the fileattr_ prefix will make the current (v2) vfs code > maybe too verbose. > Honestly, I can't say for sure - you can try I think you may need a different set of helpers fileattr_prep_ used by the filesystsems that are converted to xflags_mask, which may be different from the set of helpers used by the user facing ioctls but I'm not sure. The thing is - this is all hard to wrap our heads around You and I have parts of the design in our heads w.r.t backward compat with legacy API, both UAPI and vfs internal api. I think you should put it in writing to see that you and I have not left anything out because this v1 surely does get it wrong in several places both wrt legacy UAPI breakage and internal API correctness. Thanks, Amir. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/3] ntfs: switch to the new xflags fileattr API 2026-11-23 14:14 ` Amir Goldstein @ 2026-11-23 14:31 ` koraynilay 2026-11-23 14:55 ` Amir Goldstein 0 siblings, 1 reply; 28+ messages in thread From: koraynilay @ 2026-11-23 14:31 UTC (permalink / raw) To: Amir Goldstein, koraynilay Cc: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api [-- Attachment #1: Type: text/plain, Size: 3198 bytes --] On Mon Nov 23, 2026 at 3:14 PM CET, Amir Goldstein wrote: > On Mon, Nov 23, 2026 at 2:50 PM koraynilay <koray.fra@gmail.com> wrote: >> >> On Mon Nov 23, 2026 at 2:00 PM CET, Amir Goldstein wrote: >> > On Sun, Nov 22, 2026 at 1:09 AM koraynilay <koray.fra@gmail.com> wrote: >> >> [...] >> > Rule: >> > >> > You cannot add a flag to common without carefully auditing all >> > filesystems that support the legacy flag. >> >> Yeah, sashiko pointed out a problem in f2fs, and I could reproduce it in >> testing, where adding COMPR to COMMON makes f2fs crash, it also needs >> NOCOMP in COMMON. >> > > I don't think this is correct, or at least not enough. > My agent said that this breaks or changes things on f2fs/ext4/ubifs > I didn't bother to check if all of them are true - I doubt it > bottom line - need careful audit and good testing. Yes, definitely. > >> > FS_XFLAG_ENCRYPT can go into common but must also >> > go to FS_XFLAG_RDONLY_MASK because it's read-only for >> > all existing fs. >> > >> > COMPR is rw for some fs and ro for others. >> > As with CASEFOLD, you cannot make it COMMON before >> > converting all casefold fs to new API so that each can say >> > whether it wants RO or RW. >> >> How's CASEFOLD currently handled? in the v2 I'm drafting, I added >> fileattr_mask_to_legacy() and fileattr_legacy_to_mask(), which convert >> between the old format (filtering by FS_XFLAGS_MASK) and the new mask >> format. >> > > Good question. > Need to check this. Can you do that? If not, I'll check tonight, no problem. >> > I think there may be a way to deal with this easily since >> > ntfs doesn't need to set either but not sure. >> >> We could export the 2 other helpers I added for v2 (xflags_to_flags and >> flags_to_xflags) and make NTFS use them? >> Though adding the fileattr_ prefix will make the current (v2) vfs code >> maybe too verbose. >> > > Honestly, I can't say for sure - you can try > > I think you may need a different set of helpers fileattr_prep_ used by the > filesystsems that are converted to xflags_mask, which may be different from > the set of helpers used by the user facing ioctls but I'm not sure. > I guess I'll think about it when I move NTFS's impl to the updated vfs code. > The thing is - this is all hard to wrap our heads around Yes. > You and I have parts of the design in our heads w.r.t backward > compat with legacy API, both UAPI and vfs internal api. > > I think you should put it in writing to see that you and I have > not left anything out because this v1 surely does get it wrong > in several places both wrt legacy UAPI breakage and internal > API correctness. I agree, now the version in my head is not finalized yet, so I'll do that in the v2 patch/cover letter. TLDR is "use the legacy to/from mask converters whenever needed, so: - user legacy -> fs legacy: keep as the old code did - user legacy -> fs mask: fileattr_legacy_to_mask() - user mask -> fs legacy: fileattr_mask_to_legacy() - user mask -> fs mask: pass it through (before finalizing the GET path I want to finish the SET path). Thanks, koraynilay > Thanks, > Amir. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/3] ntfs: switch to the new xflags fileattr API 2026-11-23 14:31 ` koraynilay @ 2026-11-23 14:55 ` Amir Goldstein 2026-11-23 15:18 ` Amir Goldstein 0 siblings, 1 reply; 28+ messages in thread From: Amir Goldstein @ 2026-11-23 14:55 UTC (permalink / raw) To: koraynilay Cc: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api On Mon, Nov 23, 2026 at 3:31 PM koraynilay <koray.fra@gmail.com> wrote: > > On Mon Nov 23, 2026 at 3:14 PM CET, Amir Goldstein wrote: > > On Mon, Nov 23, 2026 at 2:50 PM koraynilay <koray.fra@gmail.com> wrote: > >> > >> On Mon Nov 23, 2026 at 2:00 PM CET, Amir Goldstein wrote: > >> > On Sun, Nov 22, 2026 at 1:09 AM koraynilay <koray.fra@gmail.com> wrote: > >> >> > [...] > >> > Rule: > >> > > >> > You cannot add a flag to common without carefully auditing all > >> > filesystems that support the legacy flag. > >> > >> Yeah, sashiko pointed out a problem in f2fs, and I could reproduce it in > >> testing, where adding COMPR to COMMON makes f2fs crash, it also needs > >> NOCOMP in COMMON. > >> > > > > I don't think this is correct, or at least not enough. > > My agent said that this breaks or changes things on f2fs/ext4/ubifs > > I didn't bother to check if all of them are true - I doubt it > > bottom line - need careful audit and good testing. > > Yes, definitely. > > > > >> > FS_XFLAG_ENCRYPT can go into common but must also > >> > go to FS_XFLAG_RDONLY_MASK because it's read-only for > >> > all existing fs. > >> > > >> > COMPR is rw for some fs and ro for others. > >> > As with CASEFOLD, you cannot make it COMMON before > >> > converting all casefold fs to new API so that each can say > >> > whether it wants RO or RW. > >> > >> How's CASEFOLD currently handled? in the v2 I'm drafting, I added > >> fileattr_mask_to_legacy() and fileattr_legacy_to_mask(), which convert > >> between the old format (filtering by FS_XFLAGS_MASK) and the new mask > >> format. > >> > > > > Good question. > > Need to check this. > > Can you do that? If not, I'll check tonight, no problem. > CASEFOLD is set in FS_XFLAG_RDONLY_MASK and NOT set in COMMON Therefore, doing set with the old xflags API for the common flags always preserves the old CASEFOLD. This is kind of ugly and works but its hard to see the design there so hopefully all the new helpers and masks will sort this and make it more explicit. IOW, ENCRYPT can use the VERITY RDONLY and COMMON precedent because it is read-only across all fs (via this API). COMPR (for the purpose of ntfs patch) can follow the precedent of CASEFOLD of RDONLY and ~COMMON, which somehow works. Note that for fs that were converted to the xflags_mask API, COMMON should be irrelevant. COMMON is only used in SET to do GET and preserve the ~COMMON bits of the "other" API flavor. With the xflags_mask API, unless we adopt the "verify" feature there needs to be no internal GET with user SET and then COMMON is not used at all relevant at all for those fs (e.g. ntfs) only the _fill_ converters are important. > >> > I think there may be a way to deal with this easily since > >> > ntfs doesn't need to set either but not sure. > >> > >> We could export the 2 other helpers I added for v2 (xflags_to_flags and > >> flags_to_xflags) and make NTFS use them? > >> Though adding the fileattr_ prefix will make the current (v2) vfs code > >> maybe too verbose. > >> > > > > Honestly, I can't say for sure - you can try > > > > I think you may need a different set of helpers fileattr_prep_ used by the > > filesystsems that are converted to xflags_mask, which may be different from > > the set of helpers used by the user facing ioctls but I'm not sure. > > > > I guess I'll think about it when I move NTFS's impl to the updated vfs > code. > > > The thing is - this is all hard to wrap our heads around > Yes. > > You and I have parts of the design in our heads w.r.t backward > > compat with legacy API, both UAPI and vfs internal api. > > > > I think you should put it in writing to see that you and I have > > not left anything out because this v1 surely does get it wrong > > in several places both wrt legacy UAPI breakage and internal > > API correctness. > > I agree, now the version in my head is not finalized yet, so I'll do > that in the v2 patch/cover letter. > > TLDR is "use the legacy to/from mask converters whenever needed, so: > - user legacy -> fs legacy: keep as the old code did > - user legacy -> fs mask: fileattr_legacy_to_mask() > - user mask -> fs legacy: fileattr_mask_to_legacy() > - user mask -> fs mask: pass it through > > (before finalizing the GET path I want to finish the SET path). > Maybe for me if I don't see the full picture, full get-set cycle it's hard for me to judge. Thanks, Amir. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 3/3] ntfs: switch to the new xflags fileattr API 2026-11-23 14:55 ` Amir Goldstein @ 2026-11-23 15:18 ` Amir Goldstein 0 siblings, 0 replies; 28+ messages in thread From: Amir Goldstein @ 2026-11-23 15:18 UTC (permalink / raw) To: koraynilay Cc: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api On Mon, Nov 23, 2026 at 3:55 PM Amir Goldstein <amir73il@gmail.com> wrote: > > On Mon, Nov 23, 2026 at 3:31 PM koraynilay <koray.fra@gmail.com> wrote: > > > > On Mon Nov 23, 2026 at 3:14 PM CET, Amir Goldstein wrote: > > > On Mon, Nov 23, 2026 at 2:50 PM koraynilay <koray.fra@gmail.com> wrote: > > >> > > >> On Mon Nov 23, 2026 at 2:00 PM CET, Amir Goldstein wrote: > > >> > On Sun, Nov 22, 2026 at 1:09 AM koraynilay <koray.fra@gmail.com> wrote: > > >> >> > > [...] > > >> > Rule: > > >> > > > >> > You cannot add a flag to common without carefully auditing all > > >> > filesystems that support the legacy flag. > > >> > > >> Yeah, sashiko pointed out a problem in f2fs, and I could reproduce it in > > >> testing, where adding COMPR to COMMON makes f2fs crash, it also needs > > >> NOCOMP in COMMON. > > >> > > > > > > I don't think this is correct, or at least not enough. > > > My agent said that this breaks or changes things on f2fs/ext4/ubifs > > > I didn't bother to check if all of them are true - I doubt it > > > bottom line - need careful audit and good testing. > > > > Yes, definitely. > > > > > > > >> > FS_XFLAG_ENCRYPT can go into common but must also > > >> > go to FS_XFLAG_RDONLY_MASK because it's read-only for > > >> > all existing fs. > > >> > > > >> > COMPR is rw for some fs and ro for others. > > >> > As with CASEFOLD, you cannot make it COMMON before > > >> > converting all casefold fs to new API so that each can say > > >> > whether it wants RO or RW. > > >> > > >> How's CASEFOLD currently handled? in the v2 I'm drafting, I added > > >> fileattr_mask_to_legacy() and fileattr_legacy_to_mask(), which convert > > >> between the old format (filtering by FS_XFLAGS_MASK) and the new mask > > >> format. > > >> > > > > > > Good question. > > > Need to check this. > > > > Can you do that? If not, I'll check tonight, no problem. > > > > CASEFOLD is set in FS_XFLAG_RDONLY_MASK and NOT set > in COMMON > > Therefore, doing set with the old xflags API for the common flags always > preserves the old CASEFOLD. > > This is kind of ugly and works but its hard to see the design there > so hopefully all the new helpers and masks will sort this and make it > more explicit. > > IOW, ENCRYPT can use the VERITY RDONLY and COMMON > precedent because it is read-only across all fs (via this API). > > COMPR (for the purpose of ntfs patch) can follow the precedent > of CASEFOLD of RDONLY and ~COMMON, which somehow works. > > Note that for fs that were converted to the xflags_mask API, > COMMON should be irrelevant. > > COMMON is only used in SET to do GET and preserve the ~COMMON > bits of the "other" API flavor. > > With the xflags_mask API, unless we adopt the "verify" feature > there needs to be no internal GET with user SET and then COMMON > is not used at all relevant at all for those fs (e.g. ntfs) only the > _fill_ converters are important. > The statement above came out too strong The internal GET is still needed for the permission checks (immutable, etc), and for converted fs COMMON still matters for the legacy ioctls, but it is not used when the new xflags_masks API is used. I would love it if we could get rid of the internal GET, by moving the IMMUTABLE|APPEND checks to the fs fileattr_prep_ helpers. But this can wait, you should not be distracted by this now. Thanks, Amir. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 0/3] Add f*_xflags_{rw,ro}_mask flags to the fileattr API 2026-11-22 0:08 [PATCH 0/3] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay ` (2 preceding siblings ...) 2026-11-22 0:08 ` [PATCH 3/3] ntfs: switch to the new xflags " koraynilay @ 2026-11-23 13:35 ` Amir Goldstein 2026-11-23 14:10 ` koraynilay 2026-11-23 21:45 ` koraynilay 3 siblings, 2 replies; 28+ messages in thread From: Amir Goldstein @ 2026-11-23 13:35 UTC (permalink / raw) To: koraynilay Cc: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api On Sun, Nov 22, 2026 at 1:09 AM koraynilay <koray.fra@gmail.com> wrote: > > This is a follow up patch series stemmed from [1] and [2], splitting the > _mask change for the fileattr API into its own separate patch. > > The first patch is a preparatory patch so that the code in the patch > after can be formatted better. > > The second patch is the actual implementation, which introduces: > - fa_xflags_{rw,ro}_mask fields to struct file_attr > - fsx_xflags_{rw,ro}_mask fields and has_masks selector to struct file_kattr > > These masks have the following semantics: > - rw_mask: > * for filesystems: advertise which xflags they support changing > * for userspace: specify which xflags it wants to modify > - ro_mask: > * for filesystems: advertise which xflags they support only reading > * for userspace: ignored Nice! I think this API description is very clear and coherent > > (ro_mask for userspace was also proposed as a "verification mask"[3] but > I left out that semantic to keep this patch series more contained, and > can be added later if needed.) Not so easily added later. We cannot change the meaning from ignore to verify without any opt-in later, but we could use the combination of rw_mask |= X ro_mask |= X to "verify" (set it as long as it is already set) all we need to do now is make sure that the API returns -EINVAL for rw_mask & ro_mask on set. > > This allows userspace to not have to do a RMW cycle when using the > file_[gs]etattr() syscalls, avoiding possible race conditions and > simplifying their usage. > > Patch 2/3 also introduces the missing FS_XFLAG_PROJID flag so that > programs like chattr can leverage the new mask API. > FS_XFLAG_PROJID is kept out of the legacy FS_XFLAG_MASK and so it's > defined as part of a new FS_FILE_ATTR_XFLAGS_MASK group of xflags that > will be used moving forward for any new xflag (like the one proposed in [2]). > > Patch 3/3 converts fs/ntfs to this new API, to show how it can benefit > filesystem drivers too. > > The series has been tested across NTFS, ext4 (with project quotas), XFS > (project quotas and extent size hints), and Btrfs. > Judging from the number of bugs reported by Sashiko and by my agent on the COMMON flags change, I think this needs test coverage for the old APIs, especially with old binaries chattt/xfs_io that do the get/set cycle and re-built binaries with new headers both tested against old and new kernel. Sorry, but the UAPI issues are fragile... This is one of the changes that would have been very hard to audit without the LLM agents. Hopefully with the agents it is doable, but need to guide them how to review/test for regressions. Thanks, Amir. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 0/3] Add f*_xflags_{rw,ro}_mask flags to the fileattr API 2026-11-23 13:35 ` [PATCH 0/3] Add f*_xflags_{rw,ro}_mask flags to the " Amir Goldstein @ 2026-11-23 14:10 ` koraynilay 2026-11-23 15:42 ` Amir Goldstein 2026-11-23 21:45 ` koraynilay 1 sibling, 1 reply; 28+ messages in thread From: koraynilay @ 2026-11-23 14:10 UTC (permalink / raw) To: Amir Goldstein, koraynilay Cc: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api [-- Attachment #1: Type: text/plain, Size: 3868 bytes --] On Mon Nov 23, 2026 at 2:35 PM CET, Amir Goldstein wrote: > On Sun, Nov 22, 2026 at 1:09 AM koraynilay <koray.fra@gmail.com> wrote: >> >> This is a follow up patch series stemmed from [1] and [2], splitting the >> _mask change for the fileattr API into its own separate patch. >> >> The first patch is a preparatory patch so that the code in the patch >> after can be formatted better. >> >> The second patch is the actual implementation, which introduces: >> - fa_xflags_{rw,ro}_mask fields to struct file_attr >> - fsx_xflags_{rw,ro}_mask fields and has_masks selector to struct file_kattr >> >> These masks have the following semantics: >> - rw_mask: >> * for filesystems: advertise which xflags they support changing >> * for userspace: specify which xflags it wants to modify >> - ro_mask: >> * for filesystems: advertise which xflags they support only reading >> * for userspace: ignored > > Nice! > I think this API description is very clear and coherent Nice. > >> >> (ro_mask for userspace was also proposed as a "verification mask"[3] but >> I left out that semantic to keep this patch series more contained, and >> can be added later if needed.) > > Not so easily added later. > We cannot change the meaning from ignore to verify without any opt-in > later, but we could use the combination of > rw_mask |= X > ro_mask |= X > > to "verify" (set it as long as it is already set) Isn't this just "preserving"? > all we need to do now is make sure that the API returns -EINVAL > for rw_mask & ro_mask on set. Yes, the current (v2) code does if (fa->has_masks && (rw_user_mask & ~old_ma->fsx_xflags_rw_mask)) return -EOPNOTSUPP; at the start of set_prepare(), I think that is enough, since we assume the filesystems return the masks such that rw_mask & ro_mask == 0. >> >> This allows userspace to not have to do a RMW cycle when using the >> file_[gs]etattr() syscalls, avoiding possible race conditions and >> simplifying their usage. >> >> Patch 2/3 also introduces the missing FS_XFLAG_PROJID flag so that >> programs like chattr can leverage the new mask API. >> FS_XFLAG_PROJID is kept out of the legacy FS_XFLAG_MASK and so it's >> defined as part of a new FS_FILE_ATTR_XFLAGS_MASK group of xflags that >> will be used moving forward for any new xflag (like the one proposed in [2]). >> >> Patch 3/3 converts fs/ntfs to this new API, to show how it can benefit >> filesystem drivers too. >> >> The series has been tested across NTFS, ext4 (with project quotas), XFS >> (project quotas and extent size hints), and Btrfs. >> > > Judging from the number of bugs reported by Sashiko and by my agent > on the COMMON flags change, > I think this needs test coverage for the old APIs, especially with old binaries > chattt/xfs_io that do the get/set cycle and re-built binaries with new headers > both tested against old and new kernel. > Sorry, but the UAPI issues are fragile... Yeah, I thought about adding some tests to xfstests yesteday after I made my agent test the sashiko issues in my test vm, but I don't want to make it generate them and submit them with minimal oversight. It could still be worth to make it generate them to just test locally, then clean them up and submit them after the vfs design/code is finalized. > This is one of the changes that would have been very hard to audit without > the LLM agents. Hopefully with the agents it is doable, but need to guide > them how to review/test for regressions. Yeah, the amount of edge cases it catches in my code is very high, I manually wrote the main vfs code in this patch series, but I took at least the same amount of time to fix *some* (considering the amount sashiko still reported anyway) of the bugs the robot pointed out. Thanks, koraynilay > Thanks, > Amir. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 0/3] Add f*_xflags_{rw,ro}_mask flags to the fileattr API 2026-11-23 14:10 ` koraynilay @ 2026-11-23 15:42 ` Amir Goldstein 2026-11-23 17:58 ` koraynilay 0 siblings, 1 reply; 28+ messages in thread From: Amir Goldstein @ 2026-11-23 15:42 UTC (permalink / raw) To: koraynilay Cc: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api On Mon, Nov 23, 2026 at 3:10 PM koraynilay <koray.fra@gmail.com> wrote: > > On Mon Nov 23, 2026 at 2:35 PM CET, Amir Goldstein wrote: > > On Sun, Nov 22, 2026 at 1:09 AM koraynilay <koray.fra@gmail.com> wrote: > >> > >> This is a follow up patch series stemmed from [1] and [2], splitting the > >> _mask change for the fileattr API into its own separate patch. > >> > >> The first patch is a preparatory patch so that the code in the patch > >> after can be formatted better. > >> > >> The second patch is the actual implementation, which introduces: > >> - fa_xflags_{rw,ro}_mask fields to struct file_attr > >> - fsx_xflags_{rw,ro}_mask fields and has_masks selector to struct file_kattr > >> > >> These masks have the following semantics: > >> - rw_mask: > >> * for filesystems: advertise which xflags they support changing > >> * for userspace: specify which xflags it wants to modify > >> - ro_mask: > >> * for filesystems: advertise which xflags they support only reading > >> * for userspace: ignored > > > > Nice! > > I think this API description is very clear and coherent > > Nice. > > > > >> > >> (ro_mask for userspace was also proposed as a "verification mask"[3] but > >> I left out that semantic to keep this patch series more contained, and > >> can be added later if needed.) > > > > Not so easily added later. > > We cannot change the meaning from ignore to verify without any opt-in > > later, but we could use the combination of > > rw_mask |= X > > ro_mask |= X > > > > to "verify" (set it as long as it is already set) > > Isn't this just "preserving"? > I donno I am confused let's keep this side discussion for another time. > > all we need to do now is make sure that the API returns -EINVAL > > for rw_mask & ro_mask on set. > > Yes, the current (v2) code does > > if (fa->has_masks && (rw_user_mask & ~old_ma->fsx_xflags_rw_mask)) > return -EOPNOTSUPP; > This is not the check I was talking about Use should not pass via the new API a flag on both ro_mask and rw_mask This one is definitely EINVAL and not EOPNOTSUPP. It is a basic contradiction of the API definition it is not a specific flag that can be supported on this fs and not on the other. > at the start of set_prepare(), I think that is enough, since we assume > the filesystems return the masks such that rw_mask & ro_mask == 0. > It needs to be in the vfs before calling the filesystem at all. It is a UAPI definition. > >> > >> This allows userspace to not have to do a RMW cycle when using the > >> file_[gs]etattr() syscalls, avoiding possible race conditions and > >> simplifying their usage. > >> > >> Patch 2/3 also introduces the missing FS_XFLAG_PROJID flag so that > >> programs like chattr can leverage the new mask API. > >> FS_XFLAG_PROJID is kept out of the legacy FS_XFLAG_MASK and so it's > >> defined as part of a new FS_FILE_ATTR_XFLAGS_MASK group of xflags that > >> will be used moving forward for any new xflag (like the one proposed in [2]). > >> > >> Patch 3/3 converts fs/ntfs to this new API, to show how it can benefit > >> filesystem drivers too. > >> > >> The series has been tested across NTFS, ext4 (with project quotas), XFS > >> (project quotas and extent size hints), and Btrfs. > >> > > > > Judging from the number of bugs reported by Sashiko and by my agent > > on the COMMON flags change, > > I think this needs test coverage for the old APIs, especially with old binaries > > chattt/xfs_io that do the get/set cycle and re-built binaries with new headers > > both tested against old and new kernel. > > Sorry, but the UAPI issues are fragile... > > Yeah, I thought about adding some tests to xfstests yesteday after I > made my agent test the sashiko issues in my test vm, but I don't want to > make it generate them and submit them with minimal oversight. > > It could still be worth to make it generate them to just test locally, > then clean them up and submit them after the vfs design/code is > finalized. > I think that selftest will be easier to check these backward compact issues with a C program that can use its own re-definitions of the struct. Then you can post it as part of the series which is much preferred for visibility of the test coverage in the context of review. > > This is one of the changes that would have been very hard to audit without > > the LLM agents. Hopefully with the agents it is doable, but need to guide > > them how to review/test for regressions. > > Yeah, the amount of edge cases it catches in my code is very high, I > manually wrote the main vfs code in this patch series, but I took at > least the same amount of time to fix *some* (considering the amount > sashiko still reported anyway) of the bugs the robot pointed out. > My 2c: prompt the robot how can I make this easier for human reviewers to verify - keeps it away from being too creative. Thanks, Amir. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 0/3] Add f*_xflags_{rw,ro}_mask flags to the fileattr API 2026-11-23 15:42 ` Amir Goldstein @ 2026-11-23 17:58 ` koraynilay 0 siblings, 0 replies; 28+ messages in thread From: koraynilay @ 2026-11-23 17:58 UTC (permalink / raw) To: Amir Goldstein, koraynilay Cc: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api [-- Attachment #1: Type: text/plain, Size: 5654 bytes --] On Mon Nov 23, 2026 at 4:42 PM CET, Amir Goldstein wrote: > On Mon, Nov 23, 2026 at 3:10 PM koraynilay <koray.fra@gmail.com> wrote: >> >> On Mon Nov 23, 2026 at 2:35 PM CET, Amir Goldstein wrote: >> > On Sun, Nov 22, 2026 at 1:09 AM koraynilay <koray.fra@gmail.com> wrote: >> >> >> >> This is a follow up patch series stemmed from [1] and [2], splitting the >> >> _mask change for the fileattr API into its own separate patch. >> >> >> >> The first patch is a preparatory patch so that the code in the patch >> >> after can be formatted better. >> >> >> >> The second patch is the actual implementation, which introduces: >> >> - fa_xflags_{rw,ro}_mask fields to struct file_attr >> >> - fsx_xflags_{rw,ro}_mask fields and has_masks selector to struct file_kattr >> >> >> >> These masks have the following semantics: >> >> - rw_mask: >> >> * for filesystems: advertise which xflags they support changing >> >> * for userspace: specify which xflags it wants to modify >> >> - ro_mask: >> >> * for filesystems: advertise which xflags they support only reading >> >> * for userspace: ignored >> > >> > Nice! >> > I think this API description is very clear and coherent >> >> Nice. >> >> > >> >> >> >> (ro_mask for userspace was also proposed as a "verification mask"[3] but >> >> I left out that semantic to keep this patch series more contained, and >> >> can be added later if needed.) >> > >> > Not so easily added later. >> > We cannot change the meaning from ignore to verify without any opt-in >> > later, but we could use the combination of >> > rw_mask |= X >> > ro_mask |= X >> > >> > to "verify" (set it as long as it is already set) >> >> Isn't this just "preserving"? >> > > I donno I am confused let's keep this side discussion for another time. I agree lmao. >> > all we need to do now is make sure that the API returns -EINVAL >> > for rw_mask & ro_mask on set. >> >> Yes, the current (v2) code does >> >> if (fa->has_masks && (rw_user_mask & ~old_ma->fsx_xflags_rw_mask)) >> return -EOPNOTSUPP; >> > > This is not the check I was talking about > Use should not pass via the new API a flag on both ro_mask and rw_mask > This one is definitely EINVAL and not EOPNOTSUPP. > It is a basic contradiction of the API definition Hmm, IMO ro_mask on set should just be ignored, so userspace can do a get, change rw_mask and then do a set without having to zero out ro_mask. > it is not a specific flag that can be supported on this fs and not on the other. > >> at the start of set_prepare(), I think that is enough, since we assume >> the filesystems return the masks such that rw_mask & ro_mask == 0. >> > > It needs to be in the vfs before calling the filesystem at all. > It is a UAPI definition. > >> >> >> >> This allows userspace to not have to do a RMW cycle when using the >> >> file_[gs]etattr() syscalls, avoiding possible race conditions and >> >> simplifying their usage. >> >> >> >> Patch 2/3 also introduces the missing FS_XFLAG_PROJID flag so that >> >> programs like chattr can leverage the new mask API. >> >> FS_XFLAG_PROJID is kept out of the legacy FS_XFLAG_MASK and so it's >> >> defined as part of a new FS_FILE_ATTR_XFLAGS_MASK group of xflags that >> >> will be used moving forward for any new xflag (like the one proposed in [2]). >> >> >> >> Patch 3/3 converts fs/ntfs to this new API, to show how it can benefit >> >> filesystem drivers too. >> >> >> >> The series has been tested across NTFS, ext4 (with project quotas), XFS >> >> (project quotas and extent size hints), and Btrfs. >> >> >> > >> > Judging from the number of bugs reported by Sashiko and by my agent >> > on the COMMON flags change, >> > I think this needs test coverage for the old APIs, especially with old binaries >> > chattt/xfs_io that do the get/set cycle and re-built binaries with new headers >> > both tested against old and new kernel. >> > Sorry, but the UAPI issues are fragile... >> >> Yeah, I thought about adding some tests to xfstests yesteday after I >> made my agent test the sashiko issues in my test vm, but I don't want to >> make it generate them and submit them with minimal oversight. >> >> It could still be worth to make it generate them to just test locally, >> then clean them up and submit them after the vfs design/code is >> finalized. >> > > I think that selftest will be easier to check these backward compact > issues with a C program that can use its own re-definitions of the struct. > Then you can post it as part of the series which is much preferred for > visibility of the test coverage in the context of review. Ah right, I could copy src/file_attr.c from xfstests and modify that, since it defines the structs and XFLAGS in the .c itself. >> > This is one of the changes that would have been very hard to audit without >> > the LLM agents. Hopefully with the agents it is doable, but need to guide >> > them how to review/test for regressions. >> >> Yeah, the amount of edge cases it catches in my code is very high, I >> manually wrote the main vfs code in this patch series, but I took at >> least the same amount of time to fix *some* (considering the amount >> sashiko still reported anyway) of the bugs the robot pointed out. >> > > My 2c: prompt the robot how can I make this easier for human reviewers > to verify - keeps it away from being too creative. I usually just ask it why it changed "all that code" and it's usually enough, if I can't review it manually it's probably not that correct. Thanks, koraynilay > Thanks, > Amir. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 0/3] Add f*_xflags_{rw,ro}_mask flags to the fileattr API 2026-11-23 13:35 ` [PATCH 0/3] Add f*_xflags_{rw,ro}_mask flags to the " Amir Goldstein 2026-11-23 14:10 ` koraynilay @ 2026-11-23 21:45 ` koraynilay 2026-11-23 22:47 ` Amir Goldstein 1 sibling, 1 reply; 28+ messages in thread From: koraynilay @ 2026-11-23 21:45 UTC (permalink / raw) To: Amir Goldstein, koraynilay Cc: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api [-- Attachment #1: Type: text/plain, Size: 2146 bytes --] On Mon Nov 23, 2026 at 2:35 PM CET, Amir Goldstein wrote: > On Sun, Nov 22, 2026 at 1:09 AM koraynilay <koray.fra@gmail.com> wrote: >> >> This is a follow up patch series stemmed from [1] and [2], splitting the >> _mask change for the fileattr API into its own separate patch. >> >> The first patch is a preparatory patch so that the code in the patch >> after can be formatted better. >> >> The second patch is the actual implementation, which introduces: >> - fa_xflags_{rw,ro}_mask fields to struct file_attr >> - fsx_xflags_{rw,ro}_mask fields and has_masks selector to struct file_kattr >> >> These masks have the following semantics: >> - rw_mask: >> * for filesystems: advertise which xflags they support changing >> * for userspace: specify which xflags it wants to modify >> - ro_mask: >> * for filesystems: advertise which xflags they support only reading >> * for userspace: ignored > > Nice! > I think this API description is very clear and coherent By the way, should I use this description in the commit message (and integrate it with missing information before/after the bullet points), or should I keep the current one? (current one:) > This lets filesystems advertise their support for specific xflags, like > statx.stx_attributes_mask does, and userspace can specify only which > xflags it wants to change without needing a RMW cycle: > - on GET: each filesystem that wants to support this new API fills the > masks according to its supported and read-only xflags, then: > * for boolean xflags: it fills fsx_xflags with the current on-disk value > * for value xflags: it sets the xflag bit to 1 in fsx_xflags and the > xflag value in the struct field; > - on SET: userspace fills the rw_mask with the bits of the xflags it > wants to change, then: > * for boolean xflags: it provides the xflag value as a bit in fa_xflags > * for value xflags: it sets the xflag bit to 1 in fa_xflags and then > provides the value in the struct field; if the xflag bit is set to 0 > instead, this informs the kernel to unset/clear that value. Thanks, koraynilay [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 0/3] Add f*_xflags_{rw,ro}_mask flags to the fileattr API 2026-11-23 21:45 ` koraynilay @ 2026-11-23 22:47 ` Amir Goldstein 2026-11-23 22:56 ` koraynilay 0 siblings, 1 reply; 28+ messages in thread From: Amir Goldstein @ 2026-11-23 22:47 UTC (permalink / raw) To: koraynilay Cc: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api On Mon, Nov 23, 2026 at 10:45 PM koraynilay <koray.fra@gmail.com> wrote: > > On Mon Nov 23, 2026 at 2:35 PM CET, Amir Goldstein wrote: > > On Sun, Nov 22, 2026 at 1:09 AM koraynilay <koray.fra@gmail.com> wrote: > >> > >> This is a follow up patch series stemmed from [1] and [2], splitting the > >> _mask change for the fileattr API into its own separate patch. > >> > >> The first patch is a preparatory patch so that the code in the patch > >> after can be formatted better. > >> > >> The second patch is the actual implementation, which introduces: > >> - fa_xflags_{rw,ro}_mask fields to struct file_attr > >> - fsx_xflags_{rw,ro}_mask fields and has_masks selector to struct file_kattr > >> > >> These masks have the following semantics: > >> - rw_mask: > >> * for filesystems: advertise which xflags they support changing > >> * for userspace: specify which xflags it wants to modify > >> - ro_mask: > >> * for filesystems: advertise which xflags they support only reading > >> * for userspace: ignored > > > > Nice! > > I think this API description is very clear and coherent > > By the way, should I use this description in the commit message (and You could use that as a short TLDR intro > integrate it with missing information before/after the bullet points), > or should I keep the current one? > > (current one:) > > This lets filesystems advertise their support for specific xflags, like > > statx.stx_attributes_mask does, and userspace can specify only which > > xflags it wants to change without needing a RMW cycle: > > - on GET: each filesystem that wants to support this new API fills the > > masks according to its supported and read-only xflags, then: > > * for boolean xflags: it fills fsx_xflags with the current on-disk value > > * for value xflags: it sets the xflag bit to 1 in fsx_xflags and the > > xflag value in the struct field; > > - on SET: userspace fills the rw_mask with the bits of the xflags it > > wants to change, then: > > * for boolean xflags: it provides the xflag value as a bit in fa_xflags > > * for value xflags: it sets the xflag bit to 1 in fa_xflags and then > > provides the value in the struct field; if the xflag bit is set to 0 > > instead, this informs the kernel to unset/clear that value. You can keep it also but tbh UAPI documentation is more useful in comments and in Documentation than in commit messages. Thanks, Amir. ^ permalink raw reply [flat|nested] 28+ messages in thread
* Re: [PATCH 0/3] Add f*_xflags_{rw,ro}_mask flags to the fileattr API 2026-11-23 22:47 ` Amir Goldstein @ 2026-11-23 22:56 ` koraynilay 0 siblings, 0 replies; 28+ messages in thread From: koraynilay @ 2026-11-23 22:56 UTC (permalink / raw) To: Amir Goldstein, koraynilay Cc: Namjae Jeon, Hyunchul Lee, Alexander Viro, Christian Brauner, Chuck Lever, Jeff Layton, Jan Kara, Darrick J . Wong, Andrey Albershteyn, Pali Rohár, Lauri Gates, Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs, linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api [-- Attachment #1: Type: text/plain, Size: 3266 bytes --] On Mon Nov 23, 2026 at 11:47 PM CET, Amir Goldstein wrote: > On Mon, Nov 23, 2026 at 10:45 PM koraynilay <koray.fra@gmail.com> wrote: >> >> On Mon Nov 23, 2026 at 2:35 PM CET, Amir Goldstein wrote: >> > On Sun, Nov 22, 2026 at 1:09 AM koraynilay <koray.fra@gmail.com> wrote: >> >> >> >> This is a follow up patch series stemmed from [1] and [2], splitting the >> >> _mask change for the fileattr API into its own separate patch. >> >> >> >> The first patch is a preparatory patch so that the code in the patch >> >> after can be formatted better. >> >> >> >> The second patch is the actual implementation, which introduces: >> >> - fa_xflags_{rw,ro}_mask fields to struct file_attr >> >> - fsx_xflags_{rw,ro}_mask fields and has_masks selector to struct file_kattr >> >> >> >> These masks have the following semantics: >> >> - rw_mask: >> >> * for filesystems: advertise which xflags they support changing >> >> * for userspace: specify which xflags it wants to modify >> >> - ro_mask: >> >> * for filesystems: advertise which xflags they support only reading >> >> * for userspace: ignored >> > >> > Nice! >> > I think this API description is very clear and coherent >> >> By the way, should I use this description in the commit message (and > > You could use that as a short TLDR intro Hmm, then would it be better keep only this for the commit message >> integrate it with missing information before/after the bullet points), >> or should I keep the current one? >> >> (current one:) >> > This lets filesystems advertise their support for specific xflags, like >> > statx.stx_attributes_mask does, and userspace can specify only which >> > xflags it wants to change without needing a RMW cycle: >> > - on GET: each filesystem that wants to support this new API fills the >> > masks according to its supported and read-only xflags, then: >> > * for boolean xflags: it fills fsx_xflags with the current on-disk value >> > * for value xflags: it sets the xflag bit to 1 in fsx_xflags and the >> > xflag value in the struct field; >> > - on SET: userspace fills the rw_mask with the bits of the xflags it >> > wants to change, then: >> > * for boolean xflags: it provides the xflag value as a bit in fa_xflags >> > * for value xflags: it sets the xflag bit to 1 in fa_xflags and then >> > provides the value in the struct field; if the xflag bit is set to 0 >> > instead, this informs the kernel to unset/clear that value. > > You can keep it also but tbh UAPI documentation is more useful in > comments and in Documentation than in commit messages. and add a documentation patch that uses this (maybe expanded/clearer since it would be user-facing docs)? > You and I have parts of the design in our heads w.r.t backward > compat with legacy API, both UAPI and vfs internal api. > > I think you should put it in writing to see that you and I have > not left anything out because this v1 surely does get it wrong > in several places both wrt legacy UAPI breakage and internal > API correctness. It would also be useful for this actually, so I'll draft it tomorrow and then send it as part of the patch series. Thanks, koraynilay > Thanks, > Amir. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 228 bytes --] ^ permalink raw reply [flat|nested] 28+ messages in thread
end of thread, other threads:[~2026-11-23 22:57 UTC | newest]
Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 0:08 [PATCH 0/3] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay
2026-11-22 0:08 ` [PATCH 1/3] vfs: use goto out on error in vfs_fileattr_set() koraynilay
2026-11-23 8:42 ` Andrey Albershteyn
2026-11-23 14:15 ` koraynilay
2026-11-23 14:18 ` Amir Goldstein
2026-11-23 14:22 ` koraynilay
2026-11-22 0:08 ` [PATCH 2/3] vfs: add xflags mask to fileattr API koraynilay
2026-11-23 13:24 ` Amir Goldstein
2026-11-23 13:58 ` koraynilay
2026-11-23 15:29 ` Amir Goldstein
2026-11-22 0:08 ` [PATCH 3/3] ntfs: switch to the new xflags " koraynilay
2026-11-22 12:49 ` liubaolin
2026-11-23 0:38 ` koraynilay
2026-11-23 3:06 ` liubaolin
2026-11-23 14:13 ` koraynilay
2026-11-23 13:00 ` Amir Goldstein
2026-11-23 13:50 ` koraynilay
2026-11-23 14:14 ` Amir Goldstein
2026-11-23 14:31 ` koraynilay
2026-11-23 14:55 ` Amir Goldstein
2026-11-23 15:18 ` Amir Goldstein
2026-11-23 13:35 ` [PATCH 0/3] Add f*_xflags_{rw,ro}_mask flags to the " Amir Goldstein
2026-11-23 14:10 ` koraynilay
2026-11-23 15:42 ` Amir Goldstein
2026-11-23 17:58 ` koraynilay
2026-11-23 21:45 ` koraynilay
2026-11-23 22:47 ` Amir Goldstein
2026-11-23 22:56 ` koraynilay
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox