* [PATCH v5 00/12] Add f*_xflags_{rw,ro}_mask flags to the fileattr API
@ 2026-12-05 14:23 koraynilay
2026-12-05 14:24 ` [PATCH v5 01/12] fs: use goto out on error in vfs_fileattr_set() koraynilay
` (11 more replies)
0 siblings, 12 replies; 25+ messages in thread
From: koraynilay @ 2026-12-05 14:23 UTC (permalink / raw)
To: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner
Cc: Shuah Khan, Randy Dunlap, Chuck Lever, Jeff Layton, Jan Kara,
Alexander Aring, Darrick J . Wong, Andrey Albershteyn,
Amir Goldstein, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs, 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 series.
The series extends the fileattr API with xflags masks by introducing:
- fa_xflags_{rw,ro}_mask fields to struct file_attr
- fsx_xflags_{rw,ro}_mask fields and has_masks / use_masks / get_only_masks
selectors to struct file_kattr
- AT_FILEATTR_MASKS at_flag for file_[gs]etattr()
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
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.
The series 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 FSX_FSXATTR_MASK and defined as part of the new
FSX_FILEATTR_MASK group of xflags that will be used moving forward for
any new xflag (like the one proposed in [2]).
In addition, FS_XFLAG_COMPR and FS_XFLAG_ENCRYPT are added (as
FS_COMPR_FL and FS_ENCRYPT_FL counterparts) for fs/ntfs, which is
converted to the new mask API as an example. Old programs will also get
these new flags, which should be fine since xflags were made to be
expandable.
Documentation/filesystems/fileattr.rst explains how this API can be used
by both userspace and filesystems along with the various semantics (it
doesn't go into *too much* detail though, since that would mean writing
the code itself). The rendered page can be found at [4].
Please also check the specific patch comments.
The series has been tested with custom xfstests [3] (generic/816-835,
xfs/611, xfs/673) across NTFS, ext4 (project quotas), XFS (project
quotas and extent size hints), Btrfs, and F2FS.
Note: these tests were written by gemini and not manually checked,
before sending them upstream (if needed) I'll have to review/rewrite
them manually.
IMPORTANT NOTE: there are quite a few bugs with overlayfs
(generic/832-835 above) when using a masks filesystem, I haven't
investigated them deeply yet since I would first need to understand a
lot more how overlayfs works, but the robot's report is in [5].
To help me develop this patch series I used Gemini 4 Hydrogen/Neon in
antigravity-cli to audit the code, find edge-cases, propose possible
fixes, develop and run the tests above and help with
comments/language/style.
Thanks,
koraynilay
v5 changes:
- split the v4 masks patch (3/7) into smaller patches, and separate
get_only_masks into the overlayfs fix patch;
- move FSX_COMMON / FSX_RDONLY_MASK comments into the rename patch;
- add FSX_EXTSIZE_MASK to the rename patch to avoid having to always OR
the two extsize macros in the later patches;
- simplify file_attr_to_fileattr() with an early return when !use_masks;
- fix mid-series ntfs regression by guarding the COMPR/ENCRYPT check
with fa->flags_valid (kept in xflags conversion patch, removed in the
masks conversion patch);
- move NTFS_{RO,RW}_XFLAGS macros into the xflags conversion patch;
- replace open-coded extsize/projid/cowextsize check with
fileattr_fsx_ok(), rename fileattr_has_invalid_fsx_masks() to
fileattr_fsx_masks_ok(), and build it on top of fileattr_fsx_ok() in the
masks conversion patch;
- docs: merge the two flag tables (ordered BOTH, XFLAGS-only,
FLAGS-only, drop RESERVED/EOFBLOCKS, add single-fs notes and
descriptions);
- docs: clarify {flags,fsx}_valid for get vs set;
- docs: document get_only_masks's writable-counterpart requirement;
- docs: add the Filesystem Contract for Masks section;
- add patch comments for 2/12, 8/12, 9/12 and 10/12.
v4 changes:
- add patch 2/7 to shorten internal xflag macro names (FSX_*) and document
FSX_COMMON / FSX_RDONLY_MASK;
- split ntfs conversion into flags->xflags (5/7) and masks support (6/7);
- add use_masks and get_only_masks selectors to struct file_kattr, and clamp
FS_IOC_SETFLAGS in fileattr_set_convert() (as discussed in [9]);
- rename fileattr_set_{rmw_to_mask,mask_to_rmw}() to
fileattr_set_{to,from}_masks();
- reject rw_mask == 0 and clearing value attributes with non-zero values
with -EINVAL;
- add FSX_FSXATTR_SET_MASK and clamp unmasked new_xflags in
fileattr_set_from_masks();
- add fileattr_has_invalid_fsx_masks() and use it in ntfs_fileattr_set();
- update docs per v3 review (focus on internals, reference man-pages,
VER0/VER1 phrasing);
- dropped all Assisted-by tags and add LLM-usage explanation above.
v3 changes:
- refactor the big if/else in vfs_fileattr_set() to a
fileattr_set_convert() helper and simplify (hopefully?) its code;
- drop fscrypt flags -> xflags patch and just use xflags_to_flags() in
vfs;
- add FS_XFLAG_COMPR/ENCRYPT in a separate patch instead of in the ntfs
one ([6]);
- move FILE_ATTR_SIZE_VER* variables from the uapi header to the
internal header ([7]);
- rename AT_FILE_ATTR_MASKS to AT_FILEATTR_MASKS ([8]);
- change "legacy" references to "rmw" references in both comments and
helper names ([8]);
- add docs.
v2 changes:
- make fa_xflags_{rw,ro}_mask in struct file_attr __u64;
- add AT_FILE_ATTR_MASKS to opt in to mask semantics instead of needing
unreliable heuristics on usize and mask values;
- reject intermediate sizes between VER0 and VER1;
- reject non-zero masks on SET without AT_FILE_ATTR_MASKS;
- add patch 2/4 for fscrypt_prepare_setflags;
- add xflags_to_flags() / flags_to_xflags() and
fileattr_set_{legacy_to_mask,mask_to_legacy}() to translate between
legacy RMW callers/filesystems and _mask callers/filesystems;
- clamp fa->fsx_xflags to rw_user_mask in file_attr_to_fileattr();
- update fileattr_set_prepare() to validate capabilities and projid
changes against rw_user_mask / xflags;
- move the rw_mask == 0 early-return no-op from file_setattr() into
vfs_fileattr_set();
- put FS_XFLAG_COMPR in FS_XFLAG_RDONLY_MASK only (keep FS_XFLAG_ENCRYPT
in both FS_XFLAG_COMMON and FS_XFLAG_RDONLY_MASK);
- update ntfs_fileattr_set() to apply only bits selected in
fsx_xflags_rw_mask;
[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://github.com/koraynilay/xfstests/tree/patches-in-queue
[4]: https://koraynilay.neocities.org/vfs-masks/fileattr
[5]: https://koraynilay.neocities.org/vfs-masks/overlayfs-fileattr-bugs
[6]: https://lore.kernel.org/CAOQ4uxgJjy3TaORBkMOdef-JvzX2uA5K2sbMDEcLqmpkedsESw@mail.gmail.com/
[7]: https://lore.kernel.org/CAOQ4uxi6oyFj_A9nPbgGeSufGo11L2N=QxLi2DW=ZKy25YQ5Tw@mail.gmail.com/
[8]: https://lore.kernel.org/CAOQ4uxhA+93bo5WseLxe7cAvJHJ8eQodoQHLwh=iToyEVkeXEA@mail.gmail.com/
[9]: https://lore.kernel.org/DN8RMUP6F5CI.2KSDF5TMCRO1X@gmail.com/
koraynilay (12):
fs: use goto out on error in vfs_fileattr_set()
fs,overlayfs: rename FS_XFLAGS_MASK and shorten other internal macro
names
fs: move fileattr sizes out of uapi and factor out set_preserve()
fs: switch fileattr_set_prepare() to xflags and refactor projid check
fs: add initial implementation of xflags masks to fileattr API
fs: add UAPI implementation of xflags masks to fileattr API
fs: add missing FS_XFLAG_PROJID xflag
fs,overlayfs: add fileattr masks support on get
fs,ntfs: advertise COMPR/ENCRYPT xflags in file_getattr()
ntfs: switch from flags to xflags in ntfs_fileattr_get/set()
ntfs: support the fileattr API masks in ntfs_fileattr_get/set()
docs: add fileattr API documentation
Documentation/filesystems/fileattr.rst | 463 +++++++++++++++++++++++++
Documentation/filesystems/index.rst | 1 +
Documentation/filesystems/vfs.rst | 19 +-
fs/file_attr.c | 402 ++++++++++++++++++---
fs/ntfs/file.c | 98 +++---
fs/overlayfs/copy_up.c | 2 +-
fs/overlayfs/inode.c | 5 +-
include/linux/fileattr.h | 129 ++++++-
include/uapi/linux/fcntl.h | 6 +
include/uapi/linux/fs.h | 38 +-
10 files changed, 1038 insertions(+), 125 deletions(-)
create mode 100644 Documentation/filesystems/fileattr.rst
base-commit: d8d9179592a52044a52591b31b914cfc0edbf36d
--
2.56.1.dirty
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH v5 01/12] fs: use goto out on error in vfs_fileattr_set()
2026-12-05 14:23 [PATCH v5 00/12] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay
@ 2026-12-05 14:24 ` koraynilay
2026-12-05 14:24 ` [PATCH v5 02/12] fs,overlayfs: rename FS_XFLAGS_MASK and shorten other internal macro names koraynilay
` (10 subsequent siblings)
11 siblings, 0 replies; 25+ messages in thread
From: koraynilay @ 2026-12-05 14:24 UTC (permalink / raw)
To: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner
Cc: Shuah Khan, Randy Dunlap, Chuck Lever, Jeff Layton, Jan Kara,
Alexander Aring, Darrick J . Wong, Andrey Albershteyn,
Amir Goldstein, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs, koraynilay
Switch from using if (!err) { ... } to the cleaner if (err) goto out;
in the main body of vfs_fileattr_set().
Reviewed-by: Andrey Albershteyn <aalbersh@kernel.org>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
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 3b249a0a6b36..0f2975c9b7bc 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.1.dirty
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v5 02/12] fs,overlayfs: rename FS_XFLAGS_MASK and shorten other internal macro names
2026-12-05 14:23 [PATCH v5 00/12] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay
2026-12-05 14:24 ` [PATCH v5 01/12] fs: use goto out on error in vfs_fileattr_set() koraynilay
@ 2026-12-05 14:24 ` koraynilay
2026-12-05 20:09 ` Amir Goldstein
2026-12-05 14:24 ` [PATCH v5 03/12] fs: move fileattr sizes out of uapi and factor out set_preserve() koraynilay
` (9 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: koraynilay @ 2026-12-05 14:24 UTC (permalink / raw)
To: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner
Cc: Shuah Khan, Randy Dunlap, Chuck Lever, Jeff Layton, Jan Kara,
Alexander Aring, Darrick J . Wong, Andrey Albershteyn,
Amir Goldstein, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs, koraynilay
Rename FS_XFLAGS_MASK to FSX_FSXATTR_MASK and make the internal xflags
collection macros' names shorter so the code that uses them can be
cleaner and more readable.
Add an explanatory comment for FS_COMMON_FL/FSX_COMMON, FSX_RDONLY_MASK
and FSX_FSXATTR_MASK, so it's clearer which xflags they include.
Also add FSX_EXTSIZE_MASK to avoid long lines caused only by OR'ing
FS_XFLAG_EXTSIZE and FS_XFLAG_EXTSZINHERIT.
Don't touch the names of the actual xflags macros as those are exposed
to userspace so they can't be easily changed.
Signed-off-by: koraynilay <koray.fra@gmail.com>
---
Sorry, dropped Reviewed-by: Amir Goldstein <amir73il@gmail.com> because
I added FSX_EXTSIZE_MASK.
(Wasn't sure if I could keep it or not)
Thanks.
fs/file_attr.c | 16 ++++++++--------
fs/overlayfs/copy_up.c | 2 +-
fs/overlayfs/inode.c | 2 +-
include/linux/fileattr.h | 34 +++++++++++++++++++++++-----------
4 files changed, 33 insertions(+), 21 deletions(-)
diff --git a/fs/file_attr.c b/fs/file_attr.c
index 0f2975c9b7bc..cc1621d3b710 100644
--- a/fs/file_attr.c
+++ b/fs/file_attr.c
@@ -102,7 +102,7 @@ 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;
+ __u32 mask = FSX_FSXATTR_MASK;
memset(fattr, 0, sizeof(struct file_attr));
fattr->fa_xflags = fa->fsx_xflags & mask;
@@ -122,7 +122,7 @@ static void fileattr_to_file_attr(const struct file_kattr *fa,
int copy_fsxattr_to_user(const struct file_kattr *fa, struct fsxattr __user *ufa)
{
struct fsxattr xfa;
- __u32 mask = FS_XFLAGS_MASK;
+ __u32 mask = FSX_FSXATTR_MASK;
memset(&xfa, 0, sizeof(xfa));
xfa.fsx_xflags = fa->fsx_xflags & mask;
@@ -141,12 +141,12 @@ 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 mask = FSX_FSXATTR_MASK;
if (fattr->fa_xflags & ~mask)
return -EINVAL;
- fileattr_fill_xflags(fa, fattr->fa_xflags & ~FS_XFLAG_RDONLY_MASK);
+ fileattr_fill_xflags(fa, fattr->fa_xflags & ~FSX_RDONLY_MASK);
fa->fsx_extsize = fattr->fa_extsize;
fa->fsx_projid = fattr->fa_projid;
fa->fsx_cowextsize = fattr->fa_cowextsize;
@@ -158,7 +158,7 @@ static int copy_fsxattr_from_user(struct file_kattr *fa,
struct fsxattr __user *ufa)
{
struct fsxattr xfa;
- __u32 mask = FS_XFLAGS_MASK;
+ __u32 mask = FSX_FSXATTR_MASK;
if (copy_from_user(&xfa, ufa, sizeof(xfa)))
return -EFAULT;
@@ -166,7 +166,7 @@ static int copy_fsxattr_from_user(struct file_kattr *fa,
if (xfa.fsx_xflags & ~mask)
return -EOPNOTSUPP;
- fileattr_fill_xflags(fa, xfa.fsx_xflags & ~FS_XFLAG_RDONLY_MASK);
+ fileattr_fill_xflags(fa, xfa.fsx_xflags & ~FSX_RDONLY_MASK);
fa->fsx_extsize = xfa.fsx_extsize;
fa->fsx_nextents = xfa.fsx_nextents;
fa->fsx_projid = xfa.fsx_projid;
@@ -247,7 +247,7 @@ static int fileattr_set_prepare(struct inode *inode,
/* Extent size hints of zero turn off the flags. */
if (fa->fsx_extsize == 0)
- fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT);
+ fa->fsx_xflags &= ~FSX_EXTSIZE_MASK;
if (fa->fsx_cowextsize == 0)
fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE;
@@ -290,7 +290,7 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
/* initialize missing bits from old_ma */
if (fa->flags_valid) {
- fa->fsx_xflags |= old_ma.fsx_xflags & ~FS_XFLAG_COMMON;
+ fa->fsx_xflags |= old_ma.fsx_xflags & ~FSX_COMMON;
fa->fsx_extsize = old_ma.fsx_extsize;
fa->fsx_nextents = old_ma.fsx_nextents;
fa->fsx_projid = old_ma.fsx_projid;
diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
index c147ad155b79..20f369863faf 100644
--- a/fs/overlayfs/copy_up.c
+++ b/fs/overlayfs/copy_up.c
@@ -220,7 +220,7 @@ static int ovl_copy_fileattr(struct inode *inode, const struct path *old,
newfa.flags &= ~OVL_COPY_FS_FLAGS_MASK;
newfa.flags |= (oldfa.flags & OVL_COPY_FS_FLAGS_MASK);
- BUILD_BUG_ON(OVL_COPY_FSX_FLAGS_MASK & ~FS_XFLAG_COMMON);
+ BUILD_BUG_ON(OVL_COPY_FSX_FLAGS_MASK & ~FSX_COMMON);
newfa.fsx_xflags &= ~OVL_COPY_FSX_FLAGS_MASK;
newfa.fsx_xflags |= (oldfa.fsx_xflags & OVL_COPY_FSX_FLAGS_MASK);
diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index f1c6df39d0ae..92df4f5c071e 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -709,7 +709,7 @@ int ovl_fileattr_set(const struct mnt_idmap *idmap,
static void ovl_fileattr_prot_flags(struct inode *inode, struct file_kattr *fa)
{
BUILD_BUG_ON(OVL_PROT_FS_FLAGS_MASK & ~FS_COMMON_FL);
- BUILD_BUG_ON(OVL_PROT_FSX_FLAGS_MASK & ~FS_XFLAG_COMMON);
+ BUILD_BUG_ON(OVL_PROT_FSX_FLAGS_MASK & ~FSX_COMMON);
if (inode->i_flags & S_APPEND) {
fa->flags |= FS_APPEND_FL;
diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
index 09e32b84e02a..79371aa93a61 100644
--- a/include/linux/fileattr.h
+++ b/include/linux/fileattr.h
@@ -3,37 +3,49 @@
#ifndef _LINUX_FILEATTR_H
#define _LINUX_FILEATTR_H
-/* Flags shared betwen flags/xflags */
+/*
+ * FS_COMMON_FL/FSX_COMMON are preserved through an RMW cycle via either UAPI
+ * flavor. They must NOT include flags that are read-write via one API flavor
+ * and read-only in another (e.g. CASEFOLD).
+ */
#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)
-#define FS_XFLAG_COMMON \
+#define FSX_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)
-/* Read-only inode flags */
-#define FS_XFLAG_RDONLY_MASK \
+/*
+ * Read-only xflags via FS_IOC_FS[GS]ETXATTR and file_[gs]etattr().
+ * The respective flags may still be read-write via FS_IOC_SETFLAGS.
+ */
+#define FSX_RDONLY_MASK \
(FS_XFLAG_PREALLOC | FS_XFLAG_HASATTR | FS_XFLAG_VERITY | \
FS_XFLAG_CASEFOLD | FS_XFLAG_CASENONPRESERVING)
/* Flags to indicate valid value of fsx_ fields */
-#define FS_XFLAG_VALUES_MASK \
+#define FSX_VALUES_MASK \
(FS_XFLAG_EXTSIZE | FS_XFLAG_COWEXTSIZE)
/* Flags for directories */
-#define FS_XFLAG_DIRONLY_MASK \
+#define FSX_DIRONLY_MASK \
(FS_XFLAG_RTINHERIT | FS_XFLAG_NOSYMLINKS | FS_XFLAG_EXTSZINHERIT)
/* Misc settable flags */
-#define FS_XFLAG_MISC_MASK \
+#define FSX_MISC_MASK \
(FS_XFLAG_REALTIME | FS_XFLAG_NODEFRAG | FS_XFLAG_FILESTREAM)
-#define FS_XFLAGS_MASK \
- (FS_XFLAG_COMMON | FS_XFLAG_RDONLY_MASK | FS_XFLAG_VALUES_MASK | \
- FS_XFLAG_DIRONLY_MASK | FS_XFLAG_MISC_MASK)
+/* Flags for fa/fsx_extsize value fields */
+#define FSX_EXTSIZE_MASK \
+ (FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT)
+
+/* Flags supported by FS_IOC_FS[GS]ETXATTR and file_[gs]etattr() */
+#define FSX_FSXATTR_MASK \
+ (FSX_COMMON | FSX_RDONLY_MASK | FSX_VALUES_MASK | \
+ FSX_DIRONLY_MASK | FSX_MISC_MASK)
/*
* Merged interface for miscellaneous file attributes. 'flags' originates from
@@ -69,7 +81,7 @@ void fileattr_fill_flags(struct file_kattr *fa, u32 flags);
static inline bool fileattr_has_fsx(const struct file_kattr *fa)
{
return fa->fsx_valid &&
- ((fa->fsx_xflags & ~FS_XFLAG_COMMON) || fa->fsx_extsize != 0 ||
+ ((fa->fsx_xflags & ~FSX_COMMON) || fa->fsx_extsize != 0 ||
fa->fsx_projid != 0 || fa->fsx_cowextsize != 0);
}
--
2.56.1.dirty
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v5 03/12] fs: move fileattr sizes out of uapi and factor out set_preserve()
2026-12-05 14:23 [PATCH v5 00/12] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay
2026-12-05 14:24 ` [PATCH v5 01/12] fs: use goto out on error in vfs_fileattr_set() koraynilay
2026-12-05 14:24 ` [PATCH v5 02/12] fs,overlayfs: rename FS_XFLAGS_MASK and shorten other internal macro names koraynilay
@ 2026-12-05 14:24 ` koraynilay
2026-12-05 22:15 ` Amir Goldstein
2026-12-05 14:24 ` [PATCH v5 04/12] fs: switch fileattr_set_prepare() to xflags and refactor projid check koraynilay
` (8 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: koraynilay @ 2026-12-05 14:24 UTC (permalink / raw)
To: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner
Cc: Shuah Khan, Randy Dunlap, Chuck Lever, Jeff Layton, Jan Kara,
Alexander Aring, Darrick J . Wong, Andrey Albershteyn,
Amir Goldstein, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs, koraynilay
Move FILE_ATTR_SIZE_* constants from the user-facing
include/uapi/linux/fs.h to the internal include/linux/fileattr.h.
Move old flags preservation from vfs_fileattr_set() to a dedicated
helper in preparation for the addition of masks to the fileattr API.
Signed-off-by: koraynilay <koray.fra@gmail.com>
---
fs/file_attr.c | 26 +++++++++++++++++---------
include/linux/fileattr.h | 4 ++++
include/uapi/linux/fs.h | 3 ---
3 files changed, 21 insertions(+), 12 deletions(-)
diff --git a/fs/file_attr.c b/fs/file_attr.c
index cc1621d3b710..77e2f1bc22ad 100644
--- a/fs/file_attr.c
+++ b/fs/file_attr.c
@@ -175,6 +175,22 @@ static int copy_fsxattr_from_user(struct file_kattr *fa,
return 0;
}
+static void fileattr_set_preserve(struct file_kattr *fa,
+ const struct file_kattr *old_ma)
+{
+ if (fa->flags_valid) {
+ /* FS_IOC_SETFLAGS */
+ fa->fsx_xflags |= old_ma->fsx_xflags & ~FSX_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 {
+ /* FS_IOC_FSSETXATTR or file_setattr */
+ fa->flags |= old_ma->flags & ~FS_COMMON_FL;
+ }
+}
+
/*
* Generic function to check FS_IOC_FSSETXATTR/FS_IOC_SETFLAGS values and reject
* any invalid configurations.
@@ -289,15 +305,7 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
goto out;
/* initialize missing bits from old_ma */
- if (fa->flags_valid) {
- fa->fsx_xflags |= old_ma.fsx_xflags & ~FSX_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;
- }
+ fileattr_set_preserve(fa, &old_ma);
err = fileattr_set_prepare(inode, &old_ma, fa);
if (err)
diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
index 79371aa93a61..d9e89e171f3e 100644
--- a/include/linux/fileattr.h
+++ b/include/linux/fileattr.h
@@ -3,6 +3,10 @@
#ifndef _LINUX_FILEATTR_H
#define _LINUX_FILEATTR_H
+/* Version UAPI's struct file_attr based on size */
+#define FILE_ATTR_SIZE_VER0 24
+#define FILE_ATTR_SIZE_LATEST FILE_ATTR_SIZE_VER0
+
/*
* FS_COMMON_FL/FSX_COMMON are preserved through an RMW cycle via either UAPI
* flavor. They must NOT include flags that are read-write via one API flavor
diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
index a13c7b32a1bd..f77e2b929f6d 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -240,9 +240,6 @@ struct file_attr {
__u32 fa_cowextsize; /* CoW extsize field value (get/set) */
};
-#define FILE_ATTR_SIZE_VER0 24
-#define FILE_ATTR_SIZE_LATEST FILE_ATTR_SIZE_VER0
-
/*
* Flags for the fsx_xflags field
*/
--
2.56.1.dirty
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v5 04/12] fs: switch fileattr_set_prepare() to xflags and refactor projid check
2026-12-05 14:23 [PATCH v5 00/12] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay
` (2 preceding siblings ...)
2026-12-05 14:24 ` [PATCH v5 03/12] fs: move fileattr sizes out of uapi and factor out set_preserve() koraynilay
@ 2026-12-05 14:24 ` koraynilay
2026-12-05 14:24 ` [PATCH v5 05/12] fs: add initial implementation of xflags masks to fileattr API koraynilay
` (7 subsequent siblings)
11 siblings, 0 replies; 25+ messages in thread
From: koraynilay @ 2026-12-05 14:24 UTC (permalink / raw)
To: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner
Cc: Shuah Khan, Randy Dunlap, Chuck Lever, Jeff Layton, Jan Kara,
Alexander Aring, Darrick J . Wong, Andrey Albershteyn,
Amir Goldstein, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs, koraynilay
In preparation for the addition of masks to the fileattr API, switch
fileattr_set_prepare() checks from using FS_*_FL flags to FS_XFLAG_*
xflags and refactor project ID value check to be cleaner.
Signed-off-by: koraynilay <koray.fra@gmail.com>
---
fs/file_attr.c | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/fs/file_attr.c b/fs/file_attr.c
index 77e2f1bc22ad..c1a0272f1a83 100644
--- a/fs/file_attr.c
+++ b/fs/file_attr.c
@@ -74,6 +74,14 @@ void fileattr_fill_flags(struct file_kattr *fa, u32 flags)
}
EXPORT_SYMBOL(fileattr_fill_flags);
+static u32 xflags_to_flags(u32 xflags)
+{
+ struct file_kattr tmp = {};
+
+ fileattr_fill_xflags(&tmp, xflags);
+ return tmp.flags;
+}
+
/**
* vfs_fileattr_get - retrieve miscellaneous file attributes
* @dentry: the object to retrieve from
@@ -201,17 +209,20 @@ static int fileattr_set_prepare(struct inode *inode,
const struct file_kattr *old_ma,
struct file_kattr *fa)
{
+ u32 changed = (fa->fsx_xflags ^ old_ma->fsx_xflags) & FSX_FSXATTR_MASK;
int err;
/*
* The IMMUTABLE and APPEND_ONLY flags can only be changed by
* the relevant capability.
*/
- if ((fa->flags ^ old_ma->flags) & (FS_APPEND_FL | FS_IMMUTABLE_FL) &&
+ if (changed & (FS_XFLAG_APPEND | FS_XFLAG_IMMUTABLE) &&
!capable(CAP_LINUX_IMMUTABLE))
return -EPERM;
- err = fscrypt_prepare_setflags(inode, old_ma->flags, fa->flags);
+ err = fscrypt_prepare_setflags(inode,
+ xflags_to_flags(old_ma->fsx_xflags),
+ xflags_to_flags(fa->fsx_xflags));
if (err)
return err;
@@ -220,21 +231,20 @@ static int fileattr_set_prepare(struct inode *inode,
* namespace. Enforce that restriction only if we are trying to change
* the quota ID state. Everything else is allowed in user namespaces.
*/
- if (current_user_ns() != &init_user_ns) {
- if (old_ma->fsx_projid != fa->fsx_projid)
+ if (old_ma->fsx_projid != fa->fsx_projid) {
+ /* Caller is not allowed to change the project ID. */
+ if (current_user_ns() != &init_user_ns)
return -EINVAL;
- if ((old_ma->fsx_xflags ^ fa->fsx_xflags) &
- FS_XFLAG_PROJINHERIT)
- return -EINVAL;
- } else {
/*
* Caller is allowed to change the project ID. If it is being
* changed, make sure that the new value is valid.
*/
- if (old_ma->fsx_projid != fa->fsx_projid &&
- !projid_valid(make_kprojid(&init_user_ns, fa->fsx_projid)))
+ if (!projid_valid(make_kprojid(&init_user_ns, fa->fsx_projid)))
return -EINVAL;
}
+ if ((changed & FS_XFLAG_PROJINHERIT) &&
+ current_user_ns() != &init_user_ns)
+ return -EINVAL;
/* Check extent size hints. */
if ((fa->fsx_xflags & FS_XFLAG_EXTSIZE) && !S_ISREG(inode->i_mode))
--
2.56.1.dirty
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v5 05/12] fs: add initial implementation of xflags masks to fileattr API
2026-12-05 14:23 [PATCH v5 00/12] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay
` (3 preceding siblings ...)
2026-12-05 14:24 ` [PATCH v5 04/12] fs: switch fileattr_set_prepare() to xflags and refactor projid check koraynilay
@ 2026-12-05 14:24 ` koraynilay
2026-12-05 14:24 ` [PATCH v5 06/12] fs: add UAPI " koraynilay
` (6 subsequent siblings)
11 siblings, 0 replies; 25+ messages in thread
From: koraynilay @ 2026-12-05 14:24 UTC (permalink / raw)
To: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner
Cc: Shuah Khan, Randy Dunlap, Chuck Lever, Jeff Layton, Jan Kara,
Alexander Aring, Darrick J . Wong, Andrey Albershteyn,
Amir Goldstein, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs, koraynilay
Add read-write and read-only masks to the fileattr API to let
filesystems advertise their support for specific xflags, like
statx.stx_attributes_mask, and to let userspace specify only which
xflags it wants to change without needing a RMW cycle.
The masks have the following semantics:
- read-write mask:
* for filesystems: advertise which xflags they support changing
* for userspace: specify which xflags it wants to modify
- read-only mask:
* for filesystems: advertise which xflags they support only reading
* for userspace: ignored
And they should be filled according to the following:
- GET:
each filesystem that wants to implement this new API fills the masks
according to its supported read-write 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;
- 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 fsx_xflags;
* for value xflags: it sets the xflag bit to 1 in fsx_xflags and then
provides the value in the struct field; if the xflag bit is set to 0
instead and the value is 0, this informs the kernel to unset/clear
that value (if the value field is non-zero it should get rejected
with -EINVAL).
To achieve this, add fsx_xflags_{rw,ro}_mask fields and {has,use}_masks
selectors to struct file_kattr, so we can know when a user of this API
(userspace or filesystem) supports them.
To eventually make both non-masks and masks programs interact correctly
with both non-masks and masks filesystems, add:
- fileattr_set_{from,to}_masks(): convert between non-masks
read-modify-write API and masks API;
- fileattr_set_convert(): handles calling the above helpers as needed,
then calls fileattr_set_preserve() if neither userspace nor filesystem
has masks.
Note that this is only the initial internal VFS implementation: it
doesn't include any changes to UAPI yet, nor does it include
FS_XFLAG_PROJID, so with only this patch it's not possible to set the
project ID using masks.
Signed-off-by: koraynilay <koray.fra@gmail.com>
---
fs/file_attr.c | 197 +++++++++++++++++++++++++++++++++++++--
include/linux/fileattr.h | 6 ++
2 files changed, 197 insertions(+), 6 deletions(-)
diff --git a/fs/file_attr.c b/fs/file_attr.c
index c1a0272f1a83..2cc06b5117f8 100644
--- a/fs/file_attr.c
+++ b/fs/file_attr.c
@@ -74,6 +74,14 @@ void fileattr_fill_flags(struct file_kattr *fa, u32 flags)
}
EXPORT_SYMBOL(fileattr_fill_flags);
+static u32 flags_to_xflags(u32 flags)
+{
+ struct file_kattr tmp = {};
+
+ fileattr_fill_flags(&tmp, flags);
+ return tmp.fsx_xflags;
+}
+
static u32 xflags_to_flags(u32 xflags)
{
struct file_kattr tmp = {};
@@ -103,7 +111,17 @@ int vfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
if (error)
return error;
- return inode->i_op->fileattr_get(dentry, fa);
+ error = inode->i_op->fileattr_get(dentry, fa);
+ if (error)
+ return error;
+
+ if (fa->has_masks) {
+ fa->fsx_xflags_rw_mask &= FSX_FSXATTR_MASK;
+ fa->fsx_xflags_ro_mask &= FSX_FSXATTR_MASK;
+ }
+ fa->fsx_xflags &= FSX_FSXATTR_MASK;
+
+ return 0;
}
EXPORT_SYMBOL(vfs_fileattr_get);
@@ -189,16 +207,165 @@ static void fileattr_set_preserve(struct file_kattr *fa,
if (fa->flags_valid) {
/* FS_IOC_SETFLAGS */
fa->fsx_xflags |= old_ma->fsx_xflags & ~FSX_COMMON;
+ fa->fsx_xflags &= FSX_FSXATTR_MASK;
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 {
- /* FS_IOC_FSSETXATTR or file_setattr */
+ /* FS_IOC_FSSETXATTR or file_setattr without masks */
fa->flags |= old_ma->flags & ~FS_COMMON_FL;
}
}
+/*
+ * Convert FSSETXATTR input format without masks, coming from userspace, to
+ * input format with masks, for filesystems that already support masks.
+ */
+static int fileattr_set_to_masks(struct file_kattr *fa,
+ const struct file_kattr *old_ma)
+{
+ u32 changed = 0;
+ u32 new_rw_mask = 0;
+ u32 new_xflags = 0;
+
+ if (fa->flags_valid) {
+ /*
+ * Assume that if the filesystem supports masks it supports its
+ * writable FS_*_FL flags via FS_XFLAG_* and fsx_xflags_rw_mask.
+ */
+ changed = fa->flags ^ old_ma->flags;
+ if (changed & ~xflags_to_flags(old_ma->fsx_xflags_rw_mask))
+ return -EOPNOTSUPP;
+
+ changed = flags_to_xflags(changed);
+ } else { /* if (fa->fsx_valid) */
+ changed = fa->fsx_xflags ^ old_ma->fsx_xflags;
+ changed &= FSX_FSXATTR_MASK & ~FSX_RDONLY_MASK;
+ }
+
+ new_xflags = fa->fsx_xflags;
+
+ new_rw_mask = changed;
+
+ if (fa->fsx_valid) {
+ if (fa->fsx_extsize != old_ma->fsx_extsize)
+ new_rw_mask |= new_xflags & FSX_EXTSIZE_MASK;
+
+ if (fa->fsx_projid != old_ma->fsx_projid)
+ return -EOPNOTSUPP;
+
+ if ((new_xflags & FS_XFLAG_COWEXTSIZE) &&
+ fa->fsx_cowextsize != old_ma->fsx_cowextsize)
+ new_rw_mask |= FS_XFLAG_COWEXTSIZE;
+ }
+
+ /* Make sure we're only setting the wanted bits. */
+ new_xflags &= new_rw_mask;
+
+ /* Mask aware filesystems shouldn't use fa->flags, but just to be sure. */
+ fa->flags = xflags_to_flags(new_xflags);
+
+ fa->fsx_xflags = new_xflags;
+ fa->fsx_xflags_rw_mask = new_rw_mask;
+ fa->has_masks = true;
+ fa->use_masks = true;
+
+ fa->fsx_valid = true;
+ fa->flags_valid = false;
+
+ return 0;
+}
+
+/*
+ * Convert input format with masks, coming from userspace, to FSSETXATTR input
+ * format without masks, for filesystems that don't support masks yet.
+ */
+static int fileattr_set_from_masks(struct file_kattr *fa,
+ const struct file_kattr *old_ma)
+{
+ u32 rw_user_mask = fa->fsx_xflags_rw_mask;
+ u32 new_xflags = fa->fsx_xflags;
+ u32 new_flags = 0;
+
+ if (rw_user_mask & ~(FSX_FSXATTR_MASK & ~FSX_RDONLY_MASK))
+ return -EOPNOTSUPP;
+
+ /* Do RMW. */
+ new_xflags |= old_ma->fsx_xflags & ~rw_user_mask;
+
+ /* RMW filesystems only expect writable fsxattr xflags. */
+ new_xflags &= FSX_FSXATTR_MASK & ~FSX_RDONLY_MASK;
+
+ new_flags = xflags_to_flags(new_xflags);
+ new_flags |= old_ma->flags & ~FS_COMMON_FL;
+
+ /* User didn't turn on any flag for extsize. */
+ if (!(fa->fsx_xflags & FSX_EXTSIZE_MASK)) {
+ if ((rw_user_mask & FSX_EXTSIZE_MASK) &&
+ !(new_xflags & FSX_EXTSIZE_MASK)) {
+ /*
+ * If the user wants to clear one of them and neither
+ * is set after the RMW above, clear fsx_extsize.
+ */
+ fa->fsx_extsize = 0;
+ } else {
+ /*
+ * If the user doesn't want to clear either of them OR
+ * the other flag is still set after RMW, preserve the
+ * old value.
+ */
+ fa->fsx_extsize = old_ma->fsx_extsize;
+ }
+ }
+
+ fa->fsx_projid = old_ma->fsx_projid;
+
+ if (!(rw_user_mask & FS_XFLAG_COWEXTSIZE))
+ fa->fsx_cowextsize = old_ma->fsx_cowextsize;
+ else if (!(new_xflags & FS_XFLAG_COWEXTSIZE))
+ fa->fsx_cowextsize = 0;
+
+ fa->flags = new_flags;
+ fa->fsx_xflags = new_xflags;
+ fa->fsx_xflags_rw_mask = 0;
+ fa->has_masks = false;
+ fa->use_masks = false;
+
+ fa->fsx_valid = true;
+ fa->flags_valid = false;
+
+ return 0;
+}
+
+/*
+ * Handle converting between FSSETXATTR and masks formats based on userspace and
+ * filesystem support.
+ * Preserve unchanged bits from old_ma.
+ */
+static int fileattr_set_convert(struct file_kattr *fa,
+ const struct file_kattr *old_ma)
+{
+ bool fs_has_masks = old_ma->has_masks;
+
+ if (fa->has_masks) {
+ if (!fs_has_masks)
+ return fileattr_set_from_masks(fa, old_ma);
+
+ /* Both have masks, pass the request through. */
+ return 0;
+ }
+
+ if (fs_has_masks)
+ return fileattr_set_to_masks(fa, old_ma);
+
+ fa->fsx_xflags_rw_mask = 0;
+
+ /* Initialize missing bits from old_ma. */
+ fileattr_set_preserve(fa, old_ma);
+ return 0;
+}
+
/*
* Generic function to check FS_IOC_FSSETXATTR/FS_IOC_SETFLAGS values and reject
* any invalid configurations.
@@ -209,9 +376,16 @@ static int fileattr_set_prepare(struct inode *inode,
const struct file_kattr *old_ma,
struct file_kattr *fa)
{
- u32 changed = (fa->fsx_xflags ^ old_ma->fsx_xflags) & FSX_FSXATTR_MASK;
+ u32 rw_user_mask = fa->has_masks ?
+ fa->fsx_xflags_rw_mask : FSX_FSXATTR_MASK;
+ u32 changed = 0;
int err;
+ if (fa->has_masks && (rw_user_mask & ~old_ma->fsx_xflags_rw_mask))
+ return -EOPNOTSUPP;
+
+ changed = (fa->fsx_xflags ^ old_ma->fsx_xflags) & rw_user_mask;
+
/*
* The IMMUTABLE and APPEND_ONLY flags can only be changed by
* the relevant capability.
@@ -231,7 +405,7 @@ static int fileattr_set_prepare(struct inode *inode,
* namespace. Enforce that restriction only if we are trying to change
* the quota ID state. Everything else is allowed in user namespaces.
*/
- if (old_ma->fsx_projid != fa->fsx_projid) {
+ if (!fa->has_masks && old_ma->fsx_projid != fa->fsx_projid) {
/* Caller is not allowed to change the project ID. */
if (current_user_ns() != &init_user_ns)
return -EINVAL;
@@ -309,13 +483,24 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
if (!inode_owner_or_capable(idmap, inode))
return -EPERM;
+ if (fa->use_masks && !fa->has_masks)
+ return -EINVAL;
+
+ /* This comes from an older call or caller wanted VER0 semantics */
+ if (!fa->use_masks)
+ fa->has_masks = false;
+
+ if (fa->has_masks && !fa->fsx_xflags_rw_mask)
+ return -EINVAL;
+
inode_lock(inode);
err = vfs_fileattr_get(dentry, &old_ma);
if (err)
goto out;
- /* initialize missing bits from old_ma */
- fileattr_set_preserve(fa, &old_ma);
+ err = fileattr_set_convert(fa, &old_ma);
+ if (err)
+ goto out;
err = fileattr_set_prepare(inode, &old_ma, fa);
if (err)
diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
index d9e89e171f3e..ef835436550d 100644
--- a/include/linux/fileattr.h
+++ b/include/linux/fileattr.h
@@ -61,6 +61,9 @@ 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 writable 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) */
@@ -68,6 +71,9 @@ struct file_kattr {
/* selectors: */
bool flags_valid:1;
bool fsx_valid:1;
+ bool has_masks:1; /* struct has valid masks (get/set) */
+ bool use_masks:1; /* in-kernel callers need to set this to use
+ masks (set) */
};
int copy_fsxattr_to_user(const struct file_kattr *fa, struct fsxattr __user *ufa);
--
2.56.1.dirty
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v5 06/12] fs: add UAPI implementation of xflags masks to fileattr API
2026-12-05 14:23 [PATCH v5 00/12] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay
` (4 preceding siblings ...)
2026-12-05 14:24 ` [PATCH v5 05/12] fs: add initial implementation of xflags masks to fileattr API koraynilay
@ 2026-12-05 14:24 ` koraynilay
2026-12-05 14:24 ` [PATCH v5 07/12] fs: add missing FS_XFLAG_PROJID xflag koraynilay
` (5 subsequent siblings)
11 siblings, 0 replies; 25+ messages in thread
From: koraynilay @ 2026-12-05 14:24 UTC (permalink / raw)
To: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner
Cc: Shuah Khan, Randy Dunlap, Chuck Lever, Jeff Layton, Jan Kara,
Alexander Aring, Darrick J . Wong, Andrey Albershteyn,
Amir Goldstein, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs, koraynilay
Add fa_xflags_rw_mask and fa_xflags_ro_mask to struct file_attr, both
__u64 to match fa_xflags' size, and bump FILE_ATTR_SIZE_LATEST to
FILE_ATTR_SIZE_VER1.
Add FSX_FILEATTR_MASK macro to define VER1+ xflags, even though we have
none yet, since it makes the code clearer.
Add AT_FILEATTR_MASKS at_flags option that userspace needs to pass
(with usize >= FILE_ATTR_SIZE_VER1) in order to be able to use masks,
otherwise normal FS_IOC_FSSETXATTR semantics are used.
Without AT_FILEATTR_MASKS:
- on GET: set fa_xflags_rw_mask and fa_xflags_ro_mask to 0 and strip new
xflags added in or after VER1, so older programs doing RMW don't pass
them back on SET;
- on SET: reject the operation with -EINVAL if fa_xflags_rw_mask or
fa_xflags_ro_mask is non-zero; if they're zero, convert the input as
necessary for masks filesystems or do normal RMW for non-masks
filesystems.
With AT_FILEATTR_MASKS:
- on GET: if the filesystem supports masks, they will be filled,
otherwise they will be zero, either way return the full struct;
- on SET: convert the input as necessary for non-masks filesystems or
pass the input directly to the filesystem if it supports masks; if the
rw_mask is 0, reject it with -EINVAL; also reject with -EINVAL if a
value xflag is in fa_xflags_rw_mask and it's cleared in fa_xflags, but
the value field is non-zero.
Signed-off-by: koraynilay <koray.fra@gmail.com>
---
fs/file_attr.c | 104 ++++++++++++++++++++++++++++++-------
include/linux/fileattr.h | 9 +++-
include/uapi/linux/fcntl.h | 6 +++
include/uapi/linux/fs.h | 31 ++++++++++-
4 files changed, 127 insertions(+), 23 deletions(-)
diff --git a/fs/file_attr.c b/fs/file_attr.c
index 2cc06b5117f8..8b9785447e72 100644
--- a/fs/file_attr.c
+++ b/fs/file_attr.c
@@ -116,10 +116,10 @@ int vfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
return error;
if (fa->has_masks) {
- fa->fsx_xflags_rw_mask &= FSX_FSXATTR_MASK;
- fa->fsx_xflags_ro_mask &= FSX_FSXATTR_MASK;
+ fa->fsx_xflags_rw_mask &= FSX_FILEATTR_MASK;
+ fa->fsx_xflags_ro_mask &= FSX_FILEATTR_MASK;
}
- fa->fsx_xflags &= FSX_FSXATTR_MASK;
+ fa->fsx_xflags &= FSX_FILEATTR_MASK;
return 0;
}
@@ -128,10 +128,13 @@ EXPORT_SYMBOL(vfs_fileattr_get);
static void fileattr_to_file_attr(const struct file_kattr *fa,
struct file_attr *fattr)
{
- __u32 mask = FSX_FSXATTR_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;
+ fattr->fa_xflags_ro_mask = fa->fsx_xflags_ro_mask;
+ }
+ fattr->fa_xflags = fa->fsx_xflags;
fattr->fa_extsize = fa->fsx_extsize;
fattr->fa_nextents = fa->fsx_nextents;
fattr->fa_projid = fa->fsx_projid;
@@ -167,15 +170,50 @@ EXPORT_SYMBOL(copy_fsxattr_to_user);
static int file_attr_to_fileattr(const struct file_attr *fattr,
struct file_kattr *fa)
{
- __u64 mask = FSX_FSXATTR_MASK;
+ bool use_masks = fa->use_masks && fa->has_masks;
+ u64 mask = use_masks ? FSX_FILEATTR_MASK : FSX_FSXATTR_MASK;
+ u64 rw_user_mask = fattr->fa_xflags_rw_mask;
if (fattr->fa_xflags & ~mask)
return -EINVAL;
- fileattr_fill_xflags(fa, fattr->fa_xflags & ~FSX_RDONLY_MASK);
- fa->fsx_extsize = fattr->fa_extsize;
- fa->fsx_projid = fattr->fa_projid;
- fa->fsx_cowextsize = fattr->fa_cowextsize;
+ if (!use_masks) {
+ fileattr_fill_xflags(fa, fattr->fa_xflags & ~FSX_RDONLY_MASK);
+ fa->fsx_extsize = fattr->fa_extsize;
+ fa->fsx_projid = fattr->fa_projid;
+ fa->fsx_cowextsize = fattr->fa_cowextsize;
+ return 0;
+ }
+
+ if (rw_user_mask & ~FSX_FILEATTR_MASK)
+ return -EINVAL;
+
+ /*
+ * Pass xflags clamped to the rw_mask, so the rest of the code can
+ * assume that if a flag is not in fsx_xflags, it isn't being changed.
+ */
+ fileattr_fill_xflags(fa, fattr->fa_xflags & rw_user_mask);
+ fa->fsx_xflags_rw_mask = rw_user_mask;
+
+ /*
+ * For value attributes, clearing the xflag bit in fa_xflags while
+ * selecting it in rw_mask requires the field value to be 0, to prevent
+ * accidental resets.
+ */
+ if (fa->fsx_xflags & FSX_EXTSIZE_MASK)
+ fa->fsx_extsize = fattr->fa_extsize;
+ else if ((rw_user_mask & FSX_EXTSIZE_MASK) &&
+ fattr->fa_extsize)
+ return -EINVAL;
+ else
+ fa->fsx_extsize = 0;
+
+ if (fa->fsx_xflags & FS_XFLAG_COWEXTSIZE)
+ fa->fsx_cowextsize = fattr->fa_cowextsize;
+ else if ((rw_user_mask & FS_XFLAG_COWEXTSIZE) && fattr->fa_cowextsize)
+ return -EINVAL;
+ else
+ fa->fsx_cowextsize = 0;
return 0;
}
@@ -377,7 +415,7 @@ static int fileattr_set_prepare(struct inode *inode,
struct file_kattr *fa)
{
u32 rw_user_mask = fa->has_masks ?
- fa->fsx_xflags_rw_mask : FSX_FSXATTR_MASK;
+ fa->fsx_xflags_rw_mask : FSX_FILEATTR_MASK;
u32 changed = 0;
int err;
@@ -593,7 +631,8 @@ SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename,
BUILD_BUG_ON(sizeof(struct file_attr) < FILE_ATTR_SIZE_VER0);
BUILD_BUG_ON(sizeof(struct file_attr) != FILE_ATTR_SIZE_LATEST);
- if ((at_flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) != 0)
+ if ((at_flags &
+ ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH | AT_FILEATTR_MASKS)) != 0)
return -EINVAL;
if (!(at_flags & AT_SYMLINK_NOFOLLOW))
@@ -602,7 +641,10 @@ SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename,
if (usize > PAGE_SIZE)
return -E2BIG;
- if (usize < FILE_ATTR_SIZE_VER0)
+ if (usize != FILE_ATTR_SIZE_VER0 && usize < FILE_ATTR_SIZE_VER1)
+ return -EINVAL;
+
+ if ((at_flags & AT_FILEATTR_MASKS) && usize < FILE_ATTR_SIZE_VER1)
return -EINVAL;
CLASS(filename_maybe_null, name)(filename, at_flags);
@@ -627,6 +669,17 @@ SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename,
return error;
fileattr_to_file_attr(&fa, &fattr);
+ /*
+ * Caller doesn't know about masks, so it also doesn't know about
+ * xflags added in or after VER1.
+ * Zero out the masks and strip VER1+ xflags.
+ */
+ if (!(at_flags & AT_FILEATTR_MASKS)) {
+ fattr.fa_xflags &= FSX_FSXATTR_MASK;
+ fattr.fa_xflags_rw_mask = 0;
+ fattr.fa_xflags_ro_mask = 0;
+ }
+
error = copy_struct_to_user(ufattr, usize, &fattr,
sizeof(struct file_attr), NULL);
@@ -646,7 +699,8 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename,
BUILD_BUG_ON(sizeof(struct file_attr) < FILE_ATTR_SIZE_VER0);
BUILD_BUG_ON(sizeof(struct file_attr) != FILE_ATTR_SIZE_LATEST);
- if ((at_flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) != 0)
+ if ((at_flags &
+ ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH | AT_FILEATTR_MASKS)) != 0)
return -EINVAL;
if (!(at_flags & AT_SYMLINK_NOFOLLOW))
@@ -655,7 +709,10 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename,
if (usize > PAGE_SIZE)
return -E2BIG;
- if (usize < FILE_ATTR_SIZE_VER0)
+ if (usize != FILE_ATTR_SIZE_VER0 && usize < FILE_ATTR_SIZE_VER1)
+ return -EINVAL;
+
+ if ((at_flags & AT_FILEATTR_MASKS) && usize < FILE_ATTR_SIZE_VER1)
return -EINVAL;
error = copy_struct_from_user(&fattr, sizeof(struct file_attr), ufattr,
@@ -663,9 +720,9 @@ 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;
+ if (!(at_flags & AT_FILEATTR_MASKS) &&
+ (fattr.fa_xflags_rw_mask || fattr.fa_xflags_ro_mask))
+ return -EINVAL;
CLASS(filename_maybe_null, name)(filename, at_flags);
if (!name && dfd >= 0) {
@@ -682,6 +739,15 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename,
return error;
}
+ if (at_flags & AT_FILEATTR_MASKS) {
+ fa.has_masks = true;
+ fa.use_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 ef835436550d..adb586e21fd5 100644
--- a/include/linux/fileattr.h
+++ b/include/linux/fileattr.h
@@ -5,7 +5,8 @@
/* Version UAPI's struct file_attr based on size */
#define FILE_ATTR_SIZE_VER0 24
-#define FILE_ATTR_SIZE_LATEST FILE_ATTR_SIZE_VER0
+#define FILE_ATTR_SIZE_VER1 40
+#define FILE_ATTR_SIZE_LATEST FILE_ATTR_SIZE_VER1
/*
* FS_COMMON_FL/FSX_COMMON are preserved through an RMW cycle via either UAPI
@@ -46,11 +47,15 @@
#define FSX_EXTSIZE_MASK \
(FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT)
-/* Flags supported by FS_IOC_FS[GS]ETXATTR and file_[gs]etattr() */
+/* Flags supported by FS_IOC_FS[GS]ETXATTR and VER0 file_[gs]etattr() */
#define FSX_FSXATTR_MASK \
(FSX_COMMON | FSX_RDONLY_MASK | FSX_VALUES_MASK | \
FSX_DIRONLY_MASK | FSX_MISC_MASK)
+/* All xflags supported by VER1+ file_[gs]etattr() with AT_FILEATTR_MASKS */
+#define FSX_FILEATTR_MASK \
+ (FSX_FSXATTR_MASK)
+
/*
* Merged interface for miscellaneous file attributes. 'flags' originates from
* ext* and 'fsx_flags' from xfs. There's some overlap between the two, which
diff --git a/include/uapi/linux/fcntl.h b/include/uapi/linux/fcntl.h
index faa63d0b60d2..7347efb3df3c 100644
--- a/include/uapi/linux/fcntl.h
+++ b/include/uapi/linux/fcntl.h
@@ -191,4 +191,10 @@ struct delegation {
#define AT_EXECVE_CHECK 0x10000 /* Only perform a check if execution
would be allowed. */
+/* Flags for file_getattr(2) / file_setattr(2). */
+#define AT_FILEATTR_MASKS 0x001 /* Advertise knowing and being able to
+ handle the struct file_attr fields
+ fa_xflags_rw_mask and
+ fa_xflags_ro_mask */
+
#endif /* _UAPI_LINUX_FCNTL_H */
diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
index f77e2b929f6d..d402db1a2254 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -225,9 +225,34 @@ struct fsxattr {
unsigned char fsx_pad[8];
};
-/*
- * Variable size structure for file_[sg]et_attr().
+/**
+ * struct file_attr - Variable size structure for file_getattr() / file_setattr().
+ *
+ * @fa_xflags: Bit mask of zero or more FS_XFLAG_* file attribute flags to be
+ * set/unset (in) or currently enabled (out) on the inode. See
+ * :ref:`Flag Reference <fileattr_flags>` for a list of flags.
+ * @fa_extsize: Extent size allocator hint in bytes, value of the
+ * FS_XFLAG_EXTSIZE/FS_XFLAG_EXTSZINHERIT xflag. This value
+ * suggests a preferred extent size for new allocations. (in/out)
+ * @fa_nextents: Number of data extents in the file, read-only. Filled in by
+ * file_getattr(2) and ignored by file_setattr(2). (out)
+ * @fa_projid: Project identifier. Used by quota systems quotactl(2) to group
+ * related files. (in/out)
+ * @fa_cowextsize: Copy-on-Write (CoW) extent size hint in bytes, value of
+ * FS_XFLAG_COWEXTSIZE. This value suggests a preferred extent
+ * size for CoW operations. (in/out)
+ * @fa_xflags_rw_mask: Bit mask of writable xflags supported by the filesystem
+ * (out). Bit mask of xflags that need to be set to their
+ * corresponding on/off state in @fa_xflags and, if present,
+ * to their @fa_* value (in) ("flags that userspace wants
+ * to change"). See :ref:`Masks <masks>` for details.
+ * @fa_xflags_ro_mask: Bit mask of read-only xflags supported by the filesystem
+ * (out). See :ref:`Masks <masks>` for details.
*
+ * Note: @fa_xflags_rw_mask and @fa_xflags_ro_mask need the
+ * ``AT_FILEATTR_MASKS`` at_flag to be used.
+ */
+/*
* Note. This is alternative to the structure 'struct file_kattr'/'struct fsxattr'.
* As this structure is passed to/from userspace with its size, this can
* be versioned based on the size.
@@ -238,6 +263,8 @@ 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) */
+ __u64 fa_xflags_rw_mask;/* supported writable xflags (get) / flags to set (set) */
+ __u64 fa_xflags_ro_mask;/* supported read-only xflags (get) */
};
/*
--
2.56.1.dirty
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v5 07/12] fs: add missing FS_XFLAG_PROJID xflag
2026-12-05 14:23 [PATCH v5 00/12] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay
` (5 preceding siblings ...)
2026-12-05 14:24 ` [PATCH v5 06/12] fs: add UAPI " koraynilay
@ 2026-12-05 14:24 ` koraynilay
2026-12-05 22:08 ` Amir Goldstein
2026-12-05 14:24 ` [PATCH v5 08/12] fs,overlayfs: add fileattr masks support on get koraynilay
` (4 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: koraynilay @ 2026-12-05 14:24 UTC (permalink / raw)
To: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner
Cc: Shuah Khan, Randy Dunlap, Chuck Lever, Jeff Layton, Jan Kara,
Alexander Aring, Darrick J . Wong, Andrey Albershteyn,
Amir Goldstein, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs, koraynilay
Add FS_XFLAG_PROJID to the UAPI header and include it in
FSX_FILEATTR_MASK so file_[gs]etattr() with AT_FILEATTR_MASKS can
advertise, set and clear the project ID using masks, while keeping it
out of FS_IOC_FS[GS]ETXATTR and non-AT_FILEATTR_MASKS callers.
Add FSX_FSXATTR_SET_MASK to specify xflags that are settable by
file_setattr with masks on non-masks filesystems. This macro is then
used to validate input xflags in fileattr_set_from_masks().
Signed-off-by: koraynilay <koray.fra@gmail.com>
---
fs/file_attr.c | 32 ++++++++++++++++++++++++++------
include/linux/fileattr.h | 12 +++++++++++-
include/uapi/linux/fs.h | 6 ++++--
3 files changed, 41 insertions(+), 9 deletions(-)
diff --git a/fs/file_attr.c b/fs/file_attr.c
index 8b9785447e72..7bfd7651d1d8 100644
--- a/fs/file_attr.c
+++ b/fs/file_attr.c
@@ -138,6 +138,8 @@ static void fileattr_to_file_attr(const struct file_kattr *fa,
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;
}
@@ -208,6 +210,13 @@ static int file_attr_to_fileattr(const struct file_attr *fattr,
else
fa->fsx_extsize = 0;
+ if (fa->fsx_xflags & FS_XFLAG_PROJID)
+ fa->fsx_projid = fattr->fa_projid;
+ else if ((rw_user_mask & FS_XFLAG_PROJID) && fattr->fa_projid)
+ return -EINVAL;
+ else
+ fa->fsx_projid = 0;
+
if (fa->fsx_xflags & FS_XFLAG_COWEXTSIZE)
fa->fsx_cowextsize = fattr->fa_cowextsize;
else if ((rw_user_mask & FS_XFLAG_COWEXTSIZE) && fattr->fa_cowextsize)
@@ -290,8 +299,11 @@ static int fileattr_set_to_masks(struct file_kattr *fa,
if (fa->fsx_extsize != old_ma->fsx_extsize)
new_rw_mask |= new_xflags & FSX_EXTSIZE_MASK;
- if (fa->fsx_projid != old_ma->fsx_projid)
- return -EOPNOTSUPP;
+ if (fa->fsx_projid != old_ma->fsx_projid) {
+ new_rw_mask |= FS_XFLAG_PROJID;
+ if (fa->fsx_projid > 0)
+ new_xflags |= FS_XFLAG_PROJID;
+ }
if ((new_xflags & FS_XFLAG_COWEXTSIZE) &&
fa->fsx_cowextsize != old_ma->fsx_cowextsize)
@@ -326,14 +338,14 @@ static int fileattr_set_from_masks(struct file_kattr *fa,
u32 new_xflags = fa->fsx_xflags;
u32 new_flags = 0;
- if (rw_user_mask & ~(FSX_FSXATTR_MASK & ~FSX_RDONLY_MASK))
+ if (rw_user_mask & ~FSX_FSXATTR_SET_MASK)
return -EOPNOTSUPP;
/* Do RMW. */
new_xflags |= old_ma->fsx_xflags & ~rw_user_mask;
/* RMW filesystems only expect writable fsxattr xflags. */
- new_xflags &= FSX_FSXATTR_MASK & ~FSX_RDONLY_MASK;
+ new_xflags &= FSX_FSXATTR_SET_MASK;
new_flags = xflags_to_flags(new_xflags);
new_flags |= old_ma->flags & ~FS_COMMON_FL;
@@ -357,7 +369,12 @@ static int fileattr_set_from_masks(struct file_kattr *fa,
}
}
- fa->fsx_projid = old_ma->fsx_projid;
+ if (!(rw_user_mask & FS_XFLAG_PROJID))
+ fa->fsx_projid = old_ma->fsx_projid;
+ else if (!(fa->fsx_xflags & FS_XFLAG_PROJID))
+ fa->fsx_projid = 0;
+ /* Strip PROJID now that we've used it, old format doesn't have it. */
+ new_xflags &= ~FS_XFLAG_PROJID;
if (!(rw_user_mask & FS_XFLAG_COWEXTSIZE))
fa->fsx_cowextsize = old_ma->fsx_cowextsize;
@@ -443,7 +460,8 @@ static int fileattr_set_prepare(struct inode *inode,
* namespace. Enforce that restriction only if we are trying to change
* the quota ID state. Everything else is allowed in user namespaces.
*/
- if (!fa->has_masks && old_ma->fsx_projid != fa->fsx_projid) {
+ if ((rw_user_mask & FS_XFLAG_PROJID) &&
+ old_ma->fsx_projid != fa->fsx_projid) {
/* Caller is not allowed to change the project ID. */
if (current_user_ns() != &init_user_ns)
return -EINVAL;
@@ -488,6 +506,8 @@ static int fileattr_set_prepare(struct inode *inode,
fa->fsx_xflags &= ~FSX_EXTSIZE_MASK;
if (fa->fsx_cowextsize == 0)
fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE;
+ if (fa->fsx_projid == 0)
+ fa->fsx_xflags &= ~FS_XFLAG_PROJID;
return 0;
}
diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
index adb586e21fd5..8dcabbb294fa 100644
--- a/include/linux/fileattr.h
+++ b/include/linux/fileattr.h
@@ -52,9 +52,19 @@
(FSX_COMMON | FSX_RDONLY_MASK | FSX_VALUES_MASK | \
FSX_DIRONLY_MASK | FSX_MISC_MASK)
+/*
+ * Writable xflags for filesystems that don't support masks.
+ * The VFS converts masked requests to FS_IOC_FSSETXATTR format, which lacks
+ * FS_XFLAG_PROJID and uses only file_kattr.fsx_projid instead.
+ * Include FS_XFLAG_PROJID here so masked callers can use it to select project
+ * ID changes on unmasked filesystems.
+ */
+#define FSX_FSXATTR_SET_MASK \
+ ((FSX_FSXATTR_MASK & ~FSX_RDONLY_MASK) | FS_XFLAG_PROJID)
+
/* All xflags supported by VER1+ file_[gs]etattr() with AT_FILEATTR_MASKS */
#define FSX_FILEATTR_MASK \
- (FSX_FSXATTR_MASK)
+ (FSX_FSXATTR_MASK | FS_XFLAG_PROJID)
/*
* Merged interface for miscellaneous file attributes. 'flags' originates from
diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
index d402db1a2254..337bb00b0e64 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -236,8 +236,8 @@ struct fsxattr {
* suggests a preferred extent size for new allocations. (in/out)
* @fa_nextents: Number of data extents in the file, read-only. Filled in by
* file_getattr(2) and ignored by file_setattr(2). (out)
- * @fa_projid: Project identifier. Used by quota systems quotactl(2) to group
- * related files. (in/out)
+ * @fa_projid: Project identifier, value of FS_XFLAG_PROJID. Used by quota
+ * systems quotactl(2) to group related files. (in/out)
* @fa_cowextsize: Copy-on-Write (CoW) extent size hint in bytes, value of
* FS_XFLAG_COWEXTSIZE. This value suggests a preferred extent
* size for CoW operations. (in/out)
@@ -294,6 +294,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.1.dirty
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v5 08/12] fs,overlayfs: add fileattr masks support on get
2026-12-05 14:23 [PATCH v5 00/12] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay
` (6 preceding siblings ...)
2026-12-05 14:24 ` [PATCH v5 07/12] fs: add missing FS_XFLAG_PROJID xflag koraynilay
@ 2026-12-05 14:24 ` koraynilay
2026-12-05 21:42 ` Amir Goldstein
2026-12-05 14:24 ` [PATCH v5 09/12] fs,ntfs: advertise COMPR/ENCRYPT xflags in file_getattr() koraynilay
` (3 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: koraynilay @ 2026-12-05 14:24 UTC (permalink / raw)
To: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner
Cc: Shuah Khan, Randy Dunlap, Chuck Lever, Jeff Layton, Jan Kara,
Alexander Aring, Darrick J . Wong, Andrey Albershteyn,
Amir Goldstein, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs, koraynilay
Add transitional get_only_masks selector in file_kattr for filesystems
that want to advertise their read-only mask on GET but don't want to
receive masked requests on SET.
Use it in ovl_fileattr_get() to ask the VFS for unmasked SET if the
underlying filesystem returns masks on GET, otherwise ovl_set_protattr()
treats fa->flags as the full set of flags and clears IMMUTABLE/APPEND.
Signed-off-by: koraynilay <koray.fra@gmail.com>
---
Amir, is this commit message correct?
This is what I understood, but I'm not 100% sure.
I wanted to mention the actual bugs fixed, but since I haven't
understood them that much I didn't want to just leave the robot's
explanation in the commit message :D
Thanks.
fs/file_attr.c | 2 +-
fs/overlayfs/inode.c | 3 +++
include/linux/fileattr.h | 2 ++
3 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/fs/file_attr.c b/fs/file_attr.c
index 7bfd7651d1d8..7ca19364d8c9 100644
--- a/fs/file_attr.c
+++ b/fs/file_attr.c
@@ -401,7 +401,7 @@ static int fileattr_set_from_masks(struct file_kattr *fa,
static int fileattr_set_convert(struct file_kattr *fa,
const struct file_kattr *old_ma)
{
- bool fs_has_masks = old_ma->has_masks;
+ bool fs_has_masks = old_ma->has_masks && !old_ma->get_only_masks;
if (fa->has_masks) {
if (!fs_has_masks)
diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index 92df4f5c071e..8d4753fd2d92 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -747,6 +747,9 @@ int ovl_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
err = ovl_real_fileattr_get(&realpath, fa);
ovl_fileattr_prot_flags(inode, fa);
+ if (!err && fa->has_masks)
+ fa->get_only_masks = true;
+
return err;
}
diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
index 8dcabbb294fa..3a8a00545686 100644
--- a/include/linux/fileattr.h
+++ b/include/linux/fileattr.h
@@ -89,6 +89,8 @@ struct file_kattr {
bool has_masks:1; /* struct has valid masks (get/set) */
bool use_masks:1; /* in-kernel callers need to set this to use
masks (set) */
+ bool get_only_masks:1;/* Transitional: filesystem doesn't support
+ rw_mask for set, but supports ro_mask on get */
};
int copy_fsxattr_to_user(const struct file_kattr *fa, struct fsxattr __user *ufa);
--
2.56.1.dirty
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v5 09/12] fs,ntfs: advertise COMPR/ENCRYPT xflags in file_getattr()
2026-12-05 14:23 [PATCH v5 00/12] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay
` (7 preceding siblings ...)
2026-12-05 14:24 ` [PATCH v5 08/12] fs,overlayfs: add fileattr masks support on get koraynilay
@ 2026-12-05 14:24 ` koraynilay
2026-12-05 20:21 ` Amir Goldstein
2026-12-05 14:24 ` [PATCH v5 10/12] ntfs: switch from flags to xflags in ntfs_fileattr_get/set() koraynilay
` (2 subsequent siblings)
11 siblings, 1 reply; 25+ messages in thread
From: koraynilay @ 2026-12-05 14:24 UTC (permalink / raw)
To: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner
Cc: Shuah Khan, Randy Dunlap, Chuck Lever, Jeff Layton, Jan Kara,
Alexander Aring, Darrick J . Wong, Andrey Albershteyn,
Amir Goldstein, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs, koraynilay
Introduce FS_XFLAG_COMPR and FS_XFLAG_ENCRYPT and update
fileattr_fill_*() helpers so file_getattr() and FS_IOC_FSGETXATTR
advertise them too, in preparation for upgrading ntfs to the masks
API ([1] and newer versions).
Since FS_COMPR_FL is read-write only with FS_IOC_SETFLAGS for some
filesystems, put it in FSX_RDONLY_MASK but not in FSX_COMMON,
following the FS_XFLAG_CASEFOLD example.
Since FS_ENCRYPT_FL is read-only with both FS_IOC_SETFLAGS and
FS_IOC_FSSETXATTR/file_setattr(), put it in both FSX_RDONLY_MASK and
FSX_COMMON, following the FS_XFLAG_VERITY example.
Since during FS_IOC_FSSETXATTR and file_setattr() (without masks) the
VFS strips these new xflags (because they're both in FSX_RDONLY_MASK),
ntfs sees this as a change on already compressed or encrypted files and
rejects the operation. Fix this by checking for fa->flags_valid.
Link: https://lore.kernel.org/20261122000856.536902-1-koray.fra@gmail.com/ [1]
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: koraynilay <koray.fra@gmail.com>
---
Amir, I kept your RVB since I just copy pasted your change, but tell me
if I should've dropped it.
Thanks.
fs/file_attr.c | 8 ++++++++
fs/ntfs/file.c | 3 ++-
include/linux/fileattr.h | 9 +++++----
include/uapi/linux/fs.h | 2 ++
4 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/fs/file_attr.c b/fs/file_attr.c
index 7ca19364d8c9..fe420e350bc7 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..7882e256133e 100644
--- a/fs/ntfs/file.c
+++ b/fs/ntfs/file.c
@@ -227,7 +227,8 @@ int ntfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
readonly |= FS_COMPR_FL;
if (NInoEncrypted(ni))
readonly |= FS_ENCRYPT_FL;
- if ((fa->flags ^ readonly) & (FS_COMPR_FL | FS_ENCRYPT_FL))
+ if (fa->flags_valid &&
+ ((fa->flags ^ readonly) & (FS_COMPR_FL | FS_ENCRYPT_FL)))
return -EOPNOTSUPP;
allowed |= readonly;
diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
index 3a8a00545686..4779aaf81b9f 100644
--- a/include/linux/fileattr.h
+++ b/include/linux/fileattr.h
@@ -11,17 +11,17 @@
/*
* FS_COMMON_FL/FSX_COMMON are preserved through an RMW cycle via either UAPI
* flavor. They must NOT include flags that are read-write via one API flavor
- * and read-only in another (e.g. CASEFOLD).
+ * and read-only in another (e.g. CASEFOLD, COMPR).
*/
#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_ENCRYPT_FL)
#define FSX_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_ENCRYPT)
/*
* Read-only xflags via FS_IOC_FS[GS]ETXATTR and file_[gs]etattr().
@@ -29,7 +29,8 @@
*/
#define FSX_RDONLY_MASK \
(FS_XFLAG_PREALLOC | FS_XFLAG_HASATTR | FS_XFLAG_VERITY | \
- FS_XFLAG_CASEFOLD | FS_XFLAG_CASENONPRESERVING)
+ FS_XFLAG_CASEFOLD | FS_XFLAG_CASENONPRESERVING | FS_XFLAG_ENCRYPT | \
+ FS_XFLAG_COMPR)
/* Flags to indicate valid value of fsx_ fields */
#define FSX_VALUES_MASK \
diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
index 337bb00b0e64..54d970dd30dc 100644
--- a/include/uapi/linux/fs.h
+++ b/include/uapi/linux/fs.h
@@ -295,6 +295,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_COMPR 0x00200000 /* Compress file */
+#define FS_XFLAG_ENCRYPT 0x00400000 /* Encrypted file */
#define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */
--
2.56.1.dirty
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v5 10/12] ntfs: switch from flags to xflags in ntfs_fileattr_get/set()
2026-12-05 14:23 [PATCH v5 00/12] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay
` (8 preceding siblings ...)
2026-12-05 14:24 ` [PATCH v5 09/12] fs,ntfs: advertise COMPR/ENCRYPT xflags in file_getattr() koraynilay
@ 2026-12-05 14:24 ` koraynilay
2026-12-05 20:25 ` Amir Goldstein
2026-12-05 14:24 ` [PATCH v5 11/12] ntfs: support the fileattr API masks " koraynilay
2026-12-05 14:24 ` [PATCH v5 12/12] docs: add fileattr API documentation koraynilay
11 siblings, 1 reply; 25+ messages in thread
From: koraynilay @ 2026-12-05 14:24 UTC (permalink / raw)
To: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner
Cc: Shuah Khan, Randy Dunlap, Chuck Lever, Jeff Layton, Jan Kara,
Alexander Aring, Darrick J . Wong, Andrey Albershteyn,
Amir Goldstein, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs, koraynilay
Switch ntfs_fileattr_get() and ntfs_fileattr_set() to use FS_XFLAG_*
xflags instead of FS_*_FL flags.
Add macros for NTFS specific RW and RO xflags.
Add fileattr_fsx_ok() helper to let filesystems that support xflags
check for unsupported xflags and value fields being passed.
Signed-off-by: koraynilay <koray.fra@gmail.com>
---
The robot suggested the _ok suffix and it works very well IMO.
fs/ntfs/file.c | 48 ++++++++++++++++++++++------------------
include/linux/fileattr.h | 30 +++++++++++++++++++++++++
2 files changed, 56 insertions(+), 22 deletions(-)
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index 7882e256133e..68e66e7912ca 100644
--- a/fs/ntfs/file.c
+++ b/fs/ntfs/file.c
@@ -150,6 +150,11 @@ int ntfs_file_release(struct inode *vi, struct file *filp)
return 0;
}
+#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)
+
/*
* ntfs_fileattr_get - inode_operations::fileattr_get
* @dentry: dentry to report the flags of
@@ -159,27 +164,27 @@ 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);
return 0;
}
@@ -207,8 +212,7 @@ 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 allowed = NTFS_RW_XFLAGS;
u32 readonly = 0;
u32 linuxflags = ni->linuxflags & ~NTFS_LINUXFLAGS_MASK;
unsigned int new_fl = 0;
@@ -219,43 +223,43 @@ int ntfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
if (err)
return err;
- if (fileattr_has_fsx(fa))
+ if (!fileattr_fsx_ok(fa, NTFS_RW_XFLAGS | NTFS_RO_XFLAGS))
return -EOPNOTSUPP;
/* chattr passes the unchanged read-only flags back to us too. */
if (NInoCompressed(ni) || NInoWofCompressed(ni))
- readonly |= FS_COMPR_FL;
+ readonly |= FS_XFLAG_COMPR;
if (NInoEncrypted(ni))
- readonly |= FS_ENCRYPT_FL;
+ readonly |= FS_XFLAG_ENCRYPT;
if (fa->flags_valid &&
- ((fa->flags ^ readonly) & (FS_COMPR_FL | FS_ENCRYPT_FL)))
+ ((fa->fsx_xflags ^ readonly) & (FS_XFLAG_COMPR | FS_XFLAG_ENCRYPT)))
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)
+ allowed |= FS_XFLAG_CASEFOLD;
+ if (fa->fsx_xflags & ~allowed)
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 4779aaf81b9f..d62b1cafea84 100644
--- a/include/linux/fileattr.h
+++ b/include/linux/fileattr.h
@@ -99,6 +99,36 @@ int copy_fsxattr_to_user(const struct file_kattr *fa, struct fsxattr __user *ufa
void fileattr_fill_xflags(struct file_kattr *fa, u32 xflags);
void fileattr_fill_flags(struct file_kattr *fa, u32 flags);
+/**
+ * fileattr_fsx_ok - check if fileattr flags and values are supported
+ * @fa: pointer to the input request
+ * @supported: bitmask of supported FS_XFLAG_* xflags
+ *
+ * Used in ->fileattr_set() by filesystems that support setting xflags but do
+ * not support masks.
+ *
+ * Return: false if @fa contains xflags not present in @supported or if any
+ * value field is non-zero while its xflag is not in @supported, true
+ * otherwise.
+ */
+static inline bool fileattr_fsx_ok(const struct file_kattr *fa,
+ const u32 supported)
+{
+ if (fa->fsx_xflags & ~supported)
+ return false;
+
+ if (fa->fsx_extsize && !(supported & FSX_EXTSIZE_MASK))
+ return false;
+
+ if (fa->fsx_projid && !(supported & FS_XFLAG_PROJID))
+ return false;
+
+ if (fa->fsx_cowextsize && !(supported & FS_XFLAG_COWEXTSIZE))
+ return false;
+
+ return true;
+}
+
/**
* fileattr_has_fsx - check for extended flags/attributes
* @fa: fileattr pointer
--
2.56.1.dirty
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v5 11/12] ntfs: support the fileattr API masks in ntfs_fileattr_get/set()
2026-12-05 14:23 [PATCH v5 00/12] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay
` (9 preceding siblings ...)
2026-12-05 14:24 ` [PATCH v5 10/12] ntfs: switch from flags to xflags in ntfs_fileattr_get/set() koraynilay
@ 2026-12-05 14:24 ` koraynilay
2026-12-05 21:15 ` Amir Goldstein
2026-12-05 14:24 ` [PATCH v5 12/12] docs: add fileattr API documentation koraynilay
11 siblings, 1 reply; 25+ messages in thread
From: koraynilay @ 2026-12-05 14:24 UTC (permalink / raw)
To: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner
Cc: Shuah Khan, Randy Dunlap, Chuck Lever, Jeff Layton, Jan Kara,
Alexander Aring, Darrick J . Wong, Andrey Albershteyn,
Amir Goldstein, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs, koraynilay
Add support for the new fileattr API with masks in ntfs_fileattr_get()
and ntfs_fileattr_set().
To check for unsupported xflags in the masks, add fileattr_fsx_masks_ok()
helper and use it in place of the previous checks in ntfs_fileattr_set().
Signed-off-by: koraynilay <koray.fra@gmail.com>
---
fs/ntfs/file.c | 67 +++++++++++++++++++++-------------------
include/linux/fileattr.h | 31 +++++++++++++++++++
2 files changed, 67 insertions(+), 31 deletions(-)
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index 68e66e7912ca..f20fa46c0d61 100644
--- a/fs/ntfs/file.c
+++ b/fs/ntfs/file.c
@@ -185,6 +185,9 @@ int ntfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
xflags |= FS_XFLAG_CASEFOLD;
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;
}
@@ -212,65 +215,67 @@ 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 = NTFS_RW_XFLAGS;
- u32 readonly = 0;
- u32 linuxflags = ni->linuxflags & ~NTFS_LINUXFLAGS_MASK;
- unsigned int new_fl = 0;
- bool forced_immutable;
+ u32 linuxflags = ni->linuxflags;
+ u32 rw_user_mask = fa->fsx_xflags_rw_mask;
+ unsigned int new_fl = 0, mask_fl = 0;
+ unsigned int new_linuxflags = 0, mask_linuxflags = 0;
+ bool forced_immutable = false;
int err;
err = ntfs_emergency_state(ni->vol);
if (err)
return err;
- if (!fileattr_fsx_ok(fa, NTFS_RW_XFLAGS | NTFS_RO_XFLAGS))
+ if (!fileattr_fsx_masks_ok(fa, NTFS_RW_XFLAGS, NTFS_RO_XFLAGS))
return -EOPNOTSUPP;
- /* chattr passes the unchanged read-only flags back to us too. */
- if (NInoCompressed(ni) || NInoWofCompressed(ni))
- readonly |= FS_XFLAG_COMPR;
- if (NInoEncrypted(ni))
- readonly |= FS_XFLAG_ENCRYPT;
- if (fa->flags_valid &&
- ((fa->fsx_xflags ^ readonly) & (FS_XFLAG_COMPR | FS_XFLAG_ENCRYPT)))
- return -EOPNOTSUPP;
- allowed |= readonly;
-
- /* Case folding is a read-only, mount-wide property. */
- if (!NVolCaseSensitive(ni->vol))
- allowed |= FS_XFLAG_CASEFOLD;
- if (fa->fsx_xflags & ~allowed)
- return -EOPNOTSUPP;
-
- forced_immutable = ntfs_is_forced_immutable(vi);
- if (!(fa->fsx_xflags & FS_XFLAG_IMMUTABLE) && forced_immutable)
- return -EPERM;
+ if (rw_user_mask & FS_XFLAG_IMMUTABLE) {
+ forced_immutable = ntfs_is_forced_immutable(vi);
+ if (!(fa->fsx_xflags & FS_XFLAG_IMMUTABLE) && forced_immutable)
+ return -EPERM;
+ mask_fl |= S_IMMUTABLE;
+ mask_linuxflags |= NTFS_LINUXFLAGS_IMMUTABLE;
+ }
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;
+ new_linuxflags |= NTFS_LINUXFLAGS_IMMUTABLE;
+ }
+
+ if (rw_user_mask & FS_XFLAG_APPEND) {
+ mask_fl |= S_APPEND;
+ mask_linuxflags |= NTFS_LINUXFLAGS_APPEND;
}
if (fa->fsx_xflags & FS_XFLAG_APPEND) {
new_fl |= S_APPEND;
- linuxflags |= NTFS_LINUXFLAGS_APPEND;
+ new_linuxflags |= NTFS_LINUXFLAGS_APPEND;
}
+
+ if (rw_user_mask & FS_XFLAG_NODUMP)
+ mask_linuxflags |= NTFS_LINUXFLAGS_NODUMP;
if (fa->fsx_xflags & FS_XFLAG_NODUMP)
- linuxflags |= NTFS_LINUXFLAGS_NODUMP;
+ new_linuxflags |= NTFS_LINUXFLAGS_NODUMP;
+
+ if (rw_user_mask & FS_XFLAG_NOATIME) {
+ mask_fl |= S_NOATIME;
+ mask_linuxflags |= NTFS_LINUXFLAGS_NOATIME;
+ }
if (fa->fsx_xflags & FS_XFLAG_NOATIME) {
new_fl |= S_NOATIME;
- linuxflags |= NTFS_LINUXFLAGS_NOATIME;
+ new_linuxflags |= NTFS_LINUXFLAGS_NOATIME;
}
mutex_lock(&ni->mrec_lock);
- err = ntfs_ea_set_linuxflags(vi, linuxflags);
+ new_linuxflags |= linuxflags & ~mask_linuxflags;
+ err = ntfs_ea_set_linuxflags(vi, new_linuxflags);
mutex_unlock(&ni->mrec_lock);
if (err)
return err;
- inode_set_flags(vi, new_fl, S_IMMUTABLE | S_APPEND | S_NOATIME);
+ inode_set_flags(vi, new_fl, mask_fl);
inode_set_ctime_current(vi);
mark_inode_dirty(vi);
return 0;
diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
index d62b1cafea84..d237465153ac 100644
--- a/include/linux/fileattr.h
+++ b/include/linux/fileattr.h
@@ -129,6 +129,37 @@ static inline bool fileattr_fsx_ok(const struct file_kattr *fa,
return true;
}
+/**
+ * fileattr_fsx_masks_ok - check if fileattr masks and values are valid and
+ * supported
+ * @fa: pointer to the input request
+ * @allowed_rw: bitmask of supported writable FS_XFLAG_* flags
+ * @allowed_ro: bitmask of supported read-only FS_XFLAG_* flags
+ *
+ * Used in ->fileattr_set() by filesystems that support masks on set, instead
+ * of fileattr_fsx_ok().
+ * See Documentation/filesystems/fileattr.rst for the full filesystem contract.
+ *
+ * Return: true if @fa satisfies mask invariants, only requests modifying flags
+ * in @allowed_rw and only contains supported xflags/values, false otherwise.
+ */
+static inline bool fileattr_fsx_masks_ok(const struct file_kattr *fa,
+ const u32 allowed_rw,
+ const u32 allowed_ro)
+{
+ if (WARN_ON_ONCE(!fa->fsx_valid || !fa->has_masks))
+ return false;
+
+ if (WARN_ON_ONCE((fa->fsx_xflags & allowed_rw) &
+ ~fa->fsx_xflags_rw_mask))
+ return false;
+
+ if (fa->fsx_xflags_rw_mask & ~allowed_rw)
+ return false;
+
+ return fileattr_fsx_ok(fa, allowed_rw | allowed_ro);
+}
+
/**
* fileattr_has_fsx - check for extended flags/attributes
* @fa: fileattr pointer
--
2.56.1.dirty
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v5 12/12] docs: add fileattr API documentation
2026-12-05 14:23 [PATCH v5 00/12] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay
` (10 preceding siblings ...)
2026-12-05 14:24 ` [PATCH v5 11/12] ntfs: support the fileattr API masks " koraynilay
@ 2026-12-05 14:24 ` koraynilay
2026-12-05 21:14 ` Amir Goldstein
11 siblings, 1 reply; 25+ messages in thread
From: koraynilay @ 2026-12-05 14:24 UTC (permalink / raw)
To: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner
Cc: Shuah Khan, Randy Dunlap, Chuck Lever, Jeff Layton, Jan Kara,
Alexander Aring, Darrick J . Wong, Andrey Albershteyn,
Amir Goldstein, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs, koraynilay
Add documentation for the fileattr API.
Signed-off-by: koraynilay <koray.fra@gmail.com>
---
Documentation/filesystems/fileattr.rst | 465 +++++++++++++++++++++++++
Documentation/filesystems/index.rst | 1 +
Documentation/filesystems/vfs.rst | 19 +-
3 files changed, 477 insertions(+), 8 deletions(-)
create mode 100644 Documentation/filesystems/fileattr.rst
diff --git a/Documentation/filesystems/fileattr.rst b/Documentation/filesystems/fileattr.rst
new file mode 100644
index 000000000000..dc52edee0ecf
--- /dev/null
+++ b/Documentation/filesystems/fileattr.rst
@@ -0,0 +1,465 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+============
+Fileattr API
+============
+
+Overview
+========
+
+The fileattr API provides a modern way to query and modify file attributes and
+it should be used instead of the older ``FS_IOC_[GS]ETFLAGS``
+(:manpage:`fs_ioc_getflags(2const)` / :manpage:`fs_ioc_setflags(2const)`) and
+``FS_IOC_FS[GS]ETXATTR`` (:manpage:`ioctl_xfs_fsgetxattr(2)` /
+:manpage:`ioctl_xfs_fssetxattr(2)`) ioctls.
+
+The "file attributes" that this document refers to are an overlap of the ones
+reported by :manpage:`statx(2)` in its ``stx_attributes`` field (e.g. immutable
+or append-only). Not to be confused with "Extended attributes", which are
+the ones managed by :manpage:`getxattr(2)` and :manpage:`setxattr(2)`.
+
+.. note::
+ For usage by userspace, see :manpage:`file_getattr(2)`,
+ :manpage:`file_setattr(2)` and :manpage:`file_attr(2type)`.
+
+Userspace API Summary
+=====================
+
+struct file_attr is versioned by size:
+
+- ``VER0``: The base structure, equivalent to struct fsxattr.
+- ``VER1``: Adds the ``fa_xflags_rw_mask`` and ``fa_xflags_ro_mask`` fields,
+ see :ref:`Masks <masks>` for more details.
+
+.. kernel-doc:: include/uapi/linux/fs.h
+ :identifiers: file_attr
+
+.. _fileattr_flags:
+
+Flag Reference
+==============
+
+This is the full list of currently implemented ``FS_XFLAG_*`` and ``FS_*_FL``
+flags.
+
+.. note::
+ Each ``FLAG`` name in the Flag column corresponds to a ``FS_XFLAG_FLAG``
+ and/or ``FS_FLAG_FL`` macro in ``include/uapi/linux/fs.h``.
+
+ The ``Flag`` and ``XFlag`` columns show how each flag can be handled,
+ respectively, through ``FS_IOC_[GS]ETFLAGS`` and
+ ``FS_IOC_FS[GS]ETXATTR``/``file_[gs]etattr()``:
+
+ - ``RW``: Read-write.
+ - ``RW/M``: Read-write only with :ref:`masks <masks>`.
+ - ``RO``: Read-only.
+ - ``-``: Not supported by that API.
+
+ Filesystem support may still vary.
+
++-----------------------+-----------+------+--------------------------------------------------+
+| Flag | XFlag | Flag | Description and Constraints |
++=======================+===========+======+==================================================+
+| ``IMMUTABLE`` | RW | RW | Inode cannot be modified. Requires |
+| | | | ``CAP_LINUX_IMMUTABLE``. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``APPEND`` | RW | RW | All writes append only. Requires |
+| | | | ``CAP_LINUX_IMMUTABLE``. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``SYNC`` | RW | RW | File writes are synchronous. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``NOATIME`` | RW | RW | Do not update inode access time (atime). |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``NODUMP`` | RW | RW | Exclude file from dump/backup utilities. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``DAX`` | RW | RW | Direct Access (DAX) I/O (regular files and |
+| | | | directories only); mutually exclusive with |
+| | | | ``FS_XFLAG_VERITY``. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``VERITY`` | RO | RO | fs-verity enabled, read-only (set via verity |
+| | | | ioctl). |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``CASEFOLD`` | RO | RW | Case-insensitive lookups. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``COMPR`` | RO | RW | Compressed file flag. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``ENCRYPT`` | RO | RO | Encrypted file flag (fscrypt). Read-only. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``PROJINHERIT`` | RW | RW | Inherit project ID on newly created files |
+| | | | (directories only). |
+| | | | Updates require ``init_user_ns``. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``PROJID`` | RW/M [#r]_| \- | Project ID value flag (``VER1``). |
+| | | | Updates require ``init_user_ns``. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``REALTIME`` | RW | \- | Realtime volume storage (XFS). |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``PREALLOC`` | RO | \- | File has preallocated extents (XFS). |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``RTINHERIT`` | RW | \- | Inherit realtime bit on newly created files |
+| | | | (directories only; XFS). |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``NOSYMLINKS`` | RW | \- | Disallow creation of symlinks (directories |
+| | | | only; XFS). |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``EXTSIZE`` | RW | \- | Extent size allocator hint (regular files only; |
+| | | | XFS). |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``EXTSZINHERIT`` | RW | \- | Inherit extent size allocator hint |
+| | | | (directories only; XFS). |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``NODEFRAG`` | RW | \- | Disable filesystem defragmentation for file |
+| | | | (XFS). |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``FILESTREAM`` | RW | \- | Enable filestream allocator (directories only; |
+| | | | XFS). |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``COWEXTSIZE`` | RW | \- | Copy-on-Write extent size allocator hint |
+| | | | (regular files and directories only; XFS). |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``CASENONPRESERVING`` | RO | \- | Case not preserved in directory lookups. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``HASATTR`` | RO | \- | Inode has extended attributes (XFS). |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``SECRM`` | \- | RW | Secure deletion. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``UNRM`` | \- | RW | Undelete. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``DIRTY`` | \- | RO | Dirty (reserved for compression). |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``COMPRBLK`` | \- | RO | One or more compressed clusters. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``NOCOMP`` | \- | RW | Don't compress. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``BTREE`` / | \- | RO | Btree format / hash-indexed directory. |
+| ``INDEX`` | | | |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``IMAGIC`` | \- | RO | AFS directory. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``JOURNAL_DATA`` | \- | RW | Journaled file data. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``NOTAIL`` | \- | RW | File tail should not be merged. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``DIRSYNC`` | \- | RW | Dirsync behaviour (directories only). |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``TOPDIR`` | \- | RW | Top of directory hierarchies. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``HUGE_FILE`` | \- | RO | File size/blocks use huge-file accounting |
+| | | | (ext4). |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``EXTENT`` | \- | RO | Inode uses extents (ext4). |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``EA_INODE`` | \- | RO | Inode used for large EA (ext4). |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``NOCOW`` | \- | RW | Do not CoW file. |
++-----------------------+-----------+------+--------------------------------------------------+
+| ``INLINE_DATA`` | \- | RO | File data is stored inline in the inode. |
++-----------------------+-----------+------+--------------------------------------------------+
+
+.. [#r] The project ID can also be changed with ``FS_IOC_FS[GS]ETXATTR`` (or
+ ``file_[gs]etattr()`` without masks), by passing a modified ``fsx_projid``
+ directly, because ``FS_XFLAG_PROJID`` was added in ``VER1``, while the
+ ``fsx_projid`` field was available before that.
+
+.. _masks:
+
+Masks
+=====
+
+In ``VER1``, the fileattr API introduced the ``fa_xflags_rw_mask`` and
+``fa_xflags_ro_mask`` fields, to enable its usage without needing a
+Read-Modify-Write cycle like ``FS_IOC_SETFLAGS`` and ``FS_IOC_FSSETXATTR``
+require.
+
+To use this feature ``AT_FILEATTR_MASKS`` needs to be set in the ``at_flags``
+argument of file_getattr() / file_setattr(), otherwise the normal behaviour is kept.
+
+.. note::
+ For filesystems that don't support masks (and for userspace without
+ ``AT_FILEATTR_MASKS``), conversion between the two formats on set is handled
+ by the VFS as described :ref:`below <conversion>`.
+
+On file_getattr()
+-----------------
+
+- If the filesystem supports mask reporting, file_getattr() populates
+ ``fa_xflags_rw_mask`` with all xflags it supports modifying on this inode,
+ and ``fa_xflags_ro_mask`` with all read-only xflags it supports reporting.
+- If the filesystem does not support masks, file_getattr() sets to ``0``
+ both ``fa_xflags_rw_mask`` and ``fa_xflags_ro_mask``.
+
+.. caution::
+
+ Passing the result of file_getattr() directly into file_setattr()
+ like this (e.g. in backup/sync workloads)::
+
+ file_getattr(file1, &fa, ..., AT_FILEATTR_MASKS);
+ file_setattr(file2, &fa, ..., AT_FILEATTR_MASKS);
+
+ is a change of behaviour compared to the unmasked APIs, where unsupported
+ flags were often silently dropped:
+
+ - on filesystems without mask support, file_getattr() returns
+ ``fa_xflags_rw_mask = 0``, causing file_setattr() to fail with
+ ``-EINVAL``;
+ - on filesystems with mask support, file_getattr() returns all supported
+ writable xflags in ``fa_xflags_rw_mask``, so file_setattr() tries to set
+ all of them on ``file2`` and fails with ``-EOPNOTSUPP`` if ``file2``
+ doesn't support all of them, instead of silently dropping them.
+
+ With masks, the program can inspect ``file2``'s masks first and decide how
+ to handle unsupported flags.
+
+On file_setattr()
+-----------------
+
+- Userspace populates ``fa_xflags_rw_mask`` with the xflags it wishes to
+ change. If ``fa_xflags_rw_mask`` is ``0``, the request fails with
+ ``-EINVAL``.
+- Any valid flag outside ``fa_xflags_rw_mask`` is ignored and left unmodified.
+- For boolean attributes:
+
+ - Setting the xflag bit in both ``fa_xflags_rw_mask`` and ``fa_xflags``
+ enables the feature.
+ - Setting the xflag bit in ``fa_xflags_rw_mask`` and clearing the bit in
+ ``fa_xflags`` disables the feature.
+
+- For value attributes (like ``FS_XFLAG_PROJID`` and ``FS_XFLAG_COWEXTSIZE``):
+
+ - Setting the flag bit in both ``fa_xflags_rw_mask`` and ``fa_xflags`` sets
+ the attribute, taking the value from the corresponding field in the struct.
+ - Setting the flag bit in ``fa_xflags_rw_mask``, clearing the bit in
+ ``fa_xflags`` and setting the field value to ``0`` unsets/clears the
+ attribute. If instead the field value is left non-zero, the request fails
+ with ``-EINVAL``.
+
+- Validation:
+
+ - If the filesystem supports masks, requesting modification of any flag not
+ advertised in the filesystem's writable mask fails with ``-EOPNOTSUPP``.
+ - If the filesystem does not support masks, requesting modification of any
+ flag outside ``FSX_FSXATTR_SET_MASK`` fails with ``-EOPNOTSUPP``.
+
+Usage Examples
+--------------
+
+See :manpage:`file_setattr(2)` for examples.
+
+Behaviour without ``AT_FILEATTR_MASKS``
+=======================================
+
+When not using ``AT_FILEATTR_MASKS``, file_getattr() and file_setattr() behave
+in the same way as ``FS_IOC_FSGETXATTR`` and ``FS_IOC_FSSETXATTR``
+respectively.
+
+In-Kernel Filesystem Interface
+==============================
+
+Filesystem Operations
+---------------------
+
+Filesystems wanting to implement this API, need to set the ``fileattr_get`` and
+``fileattr_set`` functions in ``struct inode_operations``:
+
+.. code-block:: c
+
+ struct inode_operations {
+ ...
+ int (*fileattr_get)(struct dentry *dentry, struct file_kattr *fa);
+ int (*fileattr_set)(const struct mnt_idmap *idmap, struct dentry *dentry,
+ struct file_kattr *fa);
+ ...
+ };
+
+Internal Structure: struct file_kattr
+-------------------------------------
+
+Defined in ``<linux/fileattr.h>``:
+
+.. code-block:: c
+
+ struct file_kattr {
+ u32 flags; /* FS_*_FL legacy flags */
+ u32 fsx_xflags; /* FS_XFLAG_* modern flags */
+ u32 fsx_xflags_rw_mask; /* Supported writable flags (get) / flags to set (set) */
+ u32 fsx_xflags_ro_mask; /* Supported read-only flags (get) */
+ u32 fsx_extsize; /* Extent size hint */
+ u32 fsx_nextents; /* Extent count */
+ u32 fsx_projid; /* Project ID */
+ u32 fsx_cowextsize; /* CoW extent size hint */
+ bool flags_valid:1; /* Legacy flags valid */
+ bool fsx_valid:1; /* Modern xflags valid */
+ bool has_masks:1; /* Struct has valid masks */
+ bool use_masks:1; /* In-kernel callers need to set this to use masks (set) */
+ bool get_only_masks:1; /* Transitional: fs supports ro_mask on get, but wants an unmasked request on set */
+ };
+
+Fields of struct file_kattr have the same semantics as their user-facing
+counterparts in struct file_attr above.
+In addition, struct file_kattr has:
+
+``flags``
+ Bit mask of the ``FS_*_FL`` flags, used by ``FS_IOC_GETFLAGS`` and ``FS_IOC_SETFLAGS``.
+
+``flags_valid`` / ``fsx_valid``
+ - get: hints from the caller indicating which attributes it intends
+ to read, both may be ``true``.
+ - set: indicates which attributes were filled by the caller (``flags`` vs.
+ ``fsx_xflags``/``fsx_*``). Syscalls/ioctls only set one, in-kernel
+ callers reusing the result of a ``->fileattr_get()`` may pass both.
+ Masked requests always have ``fsx_valid = true`` and
+ ``flags_valid = false``.
+
+``has_masks``
+ Indicates whether ``fsx_xflags_rw_mask`` and ``fsx_xflags_ro_mask`` contain
+ valid masks.
+
+``use_masks``
+ Indicates whether the set request uses mask semantics (the in-kernel
+ equivalent of ``AT_FILEATTR_MASKS``).
+
+``get_only_masks``
+ Transitional flag indicating that the filesystem supports
+ ``fsx_xflags_ro_mask`` on get, but still expects unmasked input in
+ ``->fileattr_set()``. If a filesystem wants to accept masks on set it
+ **must** make sure all of its writable ``FS_*_FL`` flags have
+ ``FS_XFLAG_*`` counterparts, otherwise ``FS_IOC_SETFLAGS`` will fail when
+ setting a flag without an xflag counterpart.
+
+Filesystem Contract for Masks
+-----------------------------
+
+When a filesystem accepts masks on ``->fileattr_set()``:
+
+- ``fsx_xflags_rw_mask`` is validated by the VFS against the ``rw_mask``
+ returned by ``->fileattr_get()``, and ``fsx_xflags`` is clamped to only
+ contain bits within ``fsx_xflags_rw_mask``.
+- For ``AT_FILEATTR_MASKS`` calls, ``fsx_*`` value fields are ``0`` unless
+ enabled in ``fsx_xflags``; for unmasked calls converted by
+ fileattr_set_to_masks(), unchanged ``fsx_*`` fields are preserved (except for
+ ``FS_IOC_SETFLAGS``, where they remain ``0``, but in that case they also
+ won't be in ``fsx_xflags_rw_mask``).
+- After validation and (if necessary) conversion, the VFS passes the resulting
+ struct file_kattr to ``->fileattr_set()`` with ``has_masks = true``,
+ ``fsx_valid = true``, and ``flags_valid = false``.
+- The filesystem should validate the request with fileattr_fsx_masks_ok()
+ and must modify **only** the attributes selected in ``fsx_xflags_rw_mask``.
+
+VFS Helpers
+-----------
+
+When implementing ``->fileattr_get()``, filesystems can populate struct
+file_kattr using either fileattr_fill_xflags() or fileattr_fill_flags()::
+
+ void fileattr_fill_xflags(struct file_kattr *fa, u32 xflags);
+
+ void fileattr_fill_flags(struct file_kattr *fa, u32 flags);
+
+This way filesystems can handle flags internally either as ``FS_*_FL`` flags or
+``FS_XFLAG_*`` xflags and let VFS translate the common ones (defined in
+``FS_COMMON_FL`` / ``FSX_COMMON``).
+
+New and mask-aware drivers should use fileattr_fill_xflags() and set
+``fa->has_masks = true`` along with their supported masks, while
+``FS_*_FL``-only drivers use fileattr_fill_flags().
+
+Drivers that only support ``FS_*_FL`` flags can check for unsupported
+xflags in ``->fileattr_set()`` using fileattr_has_fsx(). Drivers using
+``FS_XFLAG_*`` can validate supported xflags and values with
+fileattr_fsx_ok() or against allowed masks with fileattr_fsx_masks_ok()::
+
+ bool fileattr_has_fsx(const struct file_kattr *fa);
+
+ bool fileattr_fsx_ok(const struct file_kattr *fa, const u32 supported);
+
+ bool fileattr_fsx_masks_ok(const struct file_kattr *fa,
+ const u32 allowed_rw,
+ const u32 allowed_ro);
+
+See :ref:`Flag Reference <fileattr_flags>` for the ``FS_*_FL`` to
+``FS_XFLAG_*`` translation mapping.
+
+.. _conversion:
+
+VFS Conversion Helpers
+----------------------
+
+With fileattr_set_convert(), the VFS bridges differing caller and driver
+capabilities automatically using the inode's current attributes retrieved via
+vfs_fileattr_get():
+
+- fileattr_set_to_masks(): Converts non-masked requests (``FS_IOC_SETFLAGS``,
+ ``FS_IOC_FSSETXATTR``, file_setattr() without ``AT_FILEATTR_MASKS``, or
+ in-kernel callers with ``use_masks = false``) to a masked request when
+ targeting a filesystem that accepts masks on set.
+- fileattr_set_from_masks(): Converts masked requests (file_setattr() with
+ ``AT_FILEATTR_MASKS``) to unmasked format when targeting a
+ filesystem that doesn't accept masks on set.
+- flags_to_xflags() / xflags_to_flags(): Convert between ``FS_XFLAG_*`` xflags
+ and ``FS_*_FL`` flags.
+
+Adding New Flags
+----------------
+
+When adding new xflags or value attributes:
+
+- New flags should target the ``VER1+`` syscall API (``FSX_FILEATTR_MASK``)
+ only, keeping ``FSX_FSXATTR_MASK`` and ``FSX_RDONLY_MASK`` frozen except
+ when exposing xflag counterparts for existing ``FS_*_FL`` flags.
+- When adding a ``FS_XFLAG_*`` counterpart to a ``FS_*_FL`` flag, add it to
+ ``FSX_COMMON`` / ``FS_COMMON_FL`` only if it has the same read-only /
+ read-write behaviour across both ``FS_IOC_SETFLAGS`` and the xflags APIs
+ [#excomm]_, add the counterpart to the :ref:`table above <fileattr_flags>`
+ and move the line up so it's grouped with the other flags with counterparts.
+- Filesystems that only want to report new read-only flags on get without
+ converting ``->fileattr_set()`` to masks have to change their
+ ``->fileattr_get()`` so that it:
+
+ - sets ``has_masks = true``,
+ - sets ``get_only_masks = true``,
+ - sets the xflag bit(s) they want to report as read-only in
+ ``fsx_xflags_ro_mask``.
+
+.. [#excomm] For example ``FS_XFLAG_CASEFOLD`` and ``FS_XFLAG_COMPR``, which
+ are writable via ``FS_IOC_SETFLAGS`` but read-only in xflags, must not be
+ added to ``FSX_COMMON``.
+
+Mask-Aware Driver Example
+-------------------------
+
+An example of a filesystem that supports masks can be found in ``fs/ntfs/file.c``.
+
+Locking
+-------
+
+- vfs_fileattr_set() takes inode_lock(), so no external locking is required.
+
+Permissions
+-----------
+
+- Inode ownership or ``CAP_FOWNER`` in the owning user namespace is required.
+- Modifying ``FS_XFLAG_IMMUTABLE`` or ``FS_XFLAG_APPEND`` requires
+ ``CAP_LINUX_IMMUTABLE`` in the initial user namespace.
+- Modifying ``FS_XFLAG_PROJID`` (when ``fsx_projid`` changes) or
+ ``FS_XFLAG_PROJINHERIT`` requires the caller to reside in the initial user
+ namespace.
+
+Error Codes
+===========
+
+``-EINVAL``
+ Invalid structure size, ``AT_FILEATTR_MASKS`` passed with non-mask struct,
+ ``AT_FILEATTR_MASKS`` passed to file_setattr() with ``fa_xflags_rw_mask = 0``,
+ non-zero masks passed to file_setattr() without ``AT_FILEATTR_MASKS``,
+ unknown flags in ``at_flags``, unknown bits in ``fa_xflags`` or
+ ``fa_xflags_rw_mask``, invalid inode type for the specified xflags,
+ incompatible attribute combinations (e.g. DAX on fs-verity), invalid
+ project ID or changing ``FS_XFLAG_PROJID`` / ``FS_XFLAG_PROJINHERIT``
+ outside the host namespace, specifying xflags added in or after ``VER1``
+ without ``AT_FILEATTR_MASKS``, or clearing a value attribute with a
+ non-zero field value.
+
+``-EOPNOTSUPP``
+ The filesystem does not implement ``fileattr`` operations for this inode,
+ or userspace requested modification of an attribute not writable by the
+ filesystem.
diff --git a/Documentation/filesystems/index.rst b/Documentation/filesystems/index.rst
index a556084c8858..71a1ae852e5b 100644
--- a/Documentation/filesystems/index.rst
+++ b/Documentation/filesystems/index.rst
@@ -28,6 +28,7 @@ algorithms work.
dnotify
fiemap
files
+ fileattr
locks
mmap_prepare
multigrain-ts
diff --git a/Documentation/filesystems/vfs.rst b/Documentation/filesystems/vfs.rst
index 9ab182dbbd73..01fddb2dacf3 100644
--- a/Documentation/filesystems/vfs.rst
+++ b/Documentation/filesystems/vfs.rst
@@ -621,16 +621,19 @@ otherwise noted.
the end.
``fileattr_get``
- called on ioctl(FS_IOC_GETFLAGS) and ioctl(FS_IOC_FSGETXATTR) to
- retrieve miscellaneous file flags and attributes. Also called
- before the relevant SET operation to check what is being changed
- (in this case with i_rwsem locked exclusive). If unset, then
- fall back to f_op->ioctl().
+ called on ioctl(FS_IOC_GETFLAGS), ioctl(FS_IOC_FSGETXATTR) and
+ file_getattr(2) to retrieve miscellaneous file flags and attributes
+ (see Documentation/filesystems/fileattr.rst). Also called before the
+ relevant SET operation to check what is being changed (in this case
+ with i_rwsem locked exclusive). If unset, then fall back to
+ f_op->ioctl().
``fileattr_set``
- called on ioctl(FS_IOC_SETFLAGS) and ioctl(FS_IOC_FSSETXATTR) to
- change miscellaneous file flags and attributes. Callers hold
- i_rwsem exclusive. If unset, then fall back to f_op->ioctl().
+ called on ioctl(FS_IOC_SETFLAGS), ioctl(FS_IOC_FSSETXATTR) and
+ file_setattr(2) to change miscellaneous file flags and attributes (see
+ Documentation/filesystems/fileattr.rst). Callers hold i_rwsem
+ exclusive. If unset, then fall back to f_op->ioctl().
+
``get_offset_ctx``
called to get the offset context for a directory inode. A
filesystem must define this operation to use
--
2.56.1.dirty
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH v5 02/12] fs,overlayfs: rename FS_XFLAGS_MASK and shorten other internal macro names
2026-12-05 14:24 ` [PATCH v5 02/12] fs,overlayfs: rename FS_XFLAGS_MASK and shorten other internal macro names koraynilay
@ 2026-12-05 20:09 ` Amir Goldstein
2026-12-05 22:42 ` koraynilay
0 siblings, 1 reply; 25+ messages in thread
From: Amir Goldstein @ 2026-12-05 20:09 UTC (permalink / raw)
To: koraynilay
Cc: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner, Shuah Khan, Randy Dunlap, Chuck Lever,
Jeff Layton, Jan Kara, Alexander Aring, Darrick J . Wong,
Andrey Albershteyn, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs
On Sat, Dec 5, 2026 at 3:24 PM koraynilay <koray.fra@gmail.com> wrote:
>
> Rename FS_XFLAGS_MASK to FSX_FSXATTR_MASK and make the internal xflags
> collection macros' names shorter so the code that uses them can be
> cleaner and more readable.
>
> Add an explanatory comment for FS_COMMON_FL/FSX_COMMON, FSX_RDONLY_MASK
> and FSX_FSXATTR_MASK, so it's clearer which xflags they include.
>
> Also add FSX_EXTSIZE_MASK to avoid long lines caused only by OR'ing
> FS_XFLAG_EXTSIZE and FS_XFLAG_EXTSZINHERIT.
>
> Don't touch the names of the actual xflags macros as those are exposed
> to userspace so they can't be easily changed.
>
> Signed-off-by: koraynilay <koray.fra@gmail.com>
> ---
>
> Sorry, dropped Reviewed-by: Amir Goldstein <amir73il@gmail.com> because
> I added FSX_EXTSIZE_MASK.
> (Wasn't sure if I could keep it or not)
As long as you say what you change the re-review is easy so now
may restore my RVB thanks.
One comment though
fs,overlayfs: rename FS_XFLAGS_MASK...
lose the ",overlayfs" prefix please - it's out of context and
a very robotic thing to do.
The commit message is NOT a list of changed subsystem
THIS is an fs: change. As such it can affect several filesystems
it happens to affect only one (overlayfs)
Thanks,
Amir.
>
> Thanks.
>
> fs/file_attr.c | 16 ++++++++--------
> fs/overlayfs/copy_up.c | 2 +-
> fs/overlayfs/inode.c | 2 +-
> include/linux/fileattr.h | 34 +++++++++++++++++++++++-----------
> 4 files changed, 33 insertions(+), 21 deletions(-)
>
> diff --git a/fs/file_attr.c b/fs/file_attr.c
> index 0f2975c9b7bc..cc1621d3b710 100644
> --- a/fs/file_attr.c
> +++ b/fs/file_attr.c
> @@ -102,7 +102,7 @@ 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;
> + __u32 mask = FSX_FSXATTR_MASK;
>
> memset(fattr, 0, sizeof(struct file_attr));
> fattr->fa_xflags = fa->fsx_xflags & mask;
> @@ -122,7 +122,7 @@ static void fileattr_to_file_attr(const struct file_kattr *fa,
> int copy_fsxattr_to_user(const struct file_kattr *fa, struct fsxattr __user *ufa)
> {
> struct fsxattr xfa;
> - __u32 mask = FS_XFLAGS_MASK;
> + __u32 mask = FSX_FSXATTR_MASK;
>
> memset(&xfa, 0, sizeof(xfa));
> xfa.fsx_xflags = fa->fsx_xflags & mask;
> @@ -141,12 +141,12 @@ 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 mask = FSX_FSXATTR_MASK;
>
> if (fattr->fa_xflags & ~mask)
> return -EINVAL;
>
> - fileattr_fill_xflags(fa, fattr->fa_xflags & ~FS_XFLAG_RDONLY_MASK);
> + fileattr_fill_xflags(fa, fattr->fa_xflags & ~FSX_RDONLY_MASK);
> fa->fsx_extsize = fattr->fa_extsize;
> fa->fsx_projid = fattr->fa_projid;
> fa->fsx_cowextsize = fattr->fa_cowextsize;
> @@ -158,7 +158,7 @@ static int copy_fsxattr_from_user(struct file_kattr *fa,
> struct fsxattr __user *ufa)
> {
> struct fsxattr xfa;
> - __u32 mask = FS_XFLAGS_MASK;
> + __u32 mask = FSX_FSXATTR_MASK;
>
> if (copy_from_user(&xfa, ufa, sizeof(xfa)))
> return -EFAULT;
> @@ -166,7 +166,7 @@ static int copy_fsxattr_from_user(struct file_kattr *fa,
> if (xfa.fsx_xflags & ~mask)
> return -EOPNOTSUPP;
>
> - fileattr_fill_xflags(fa, xfa.fsx_xflags & ~FS_XFLAG_RDONLY_MASK);
> + fileattr_fill_xflags(fa, xfa.fsx_xflags & ~FSX_RDONLY_MASK);
> fa->fsx_extsize = xfa.fsx_extsize;
> fa->fsx_nextents = xfa.fsx_nextents;
> fa->fsx_projid = xfa.fsx_projid;
> @@ -247,7 +247,7 @@ static int fileattr_set_prepare(struct inode *inode,
>
> /* Extent size hints of zero turn off the flags. */
> if (fa->fsx_extsize == 0)
> - fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT);
> + fa->fsx_xflags &= ~FSX_EXTSIZE_MASK;
> if (fa->fsx_cowextsize == 0)
> fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE;
>
> @@ -290,7 +290,7 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
>
> /* initialize missing bits from old_ma */
> if (fa->flags_valid) {
> - fa->fsx_xflags |= old_ma.fsx_xflags & ~FS_XFLAG_COMMON;
> + fa->fsx_xflags |= old_ma.fsx_xflags & ~FSX_COMMON;
> fa->fsx_extsize = old_ma.fsx_extsize;
> fa->fsx_nextents = old_ma.fsx_nextents;
> fa->fsx_projid = old_ma.fsx_projid;
> diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
> index c147ad155b79..20f369863faf 100644
> --- a/fs/overlayfs/copy_up.c
> +++ b/fs/overlayfs/copy_up.c
> @@ -220,7 +220,7 @@ static int ovl_copy_fileattr(struct inode *inode, const struct path *old,
> newfa.flags &= ~OVL_COPY_FS_FLAGS_MASK;
> newfa.flags |= (oldfa.flags & OVL_COPY_FS_FLAGS_MASK);
>
> - BUILD_BUG_ON(OVL_COPY_FSX_FLAGS_MASK & ~FS_XFLAG_COMMON);
> + BUILD_BUG_ON(OVL_COPY_FSX_FLAGS_MASK & ~FSX_COMMON);
> newfa.fsx_xflags &= ~OVL_COPY_FSX_FLAGS_MASK;
> newfa.fsx_xflags |= (oldfa.fsx_xflags & OVL_COPY_FSX_FLAGS_MASK);
>
> diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
> index f1c6df39d0ae..92df4f5c071e 100644
> --- a/fs/overlayfs/inode.c
> +++ b/fs/overlayfs/inode.c
> @@ -709,7 +709,7 @@ int ovl_fileattr_set(const struct mnt_idmap *idmap,
> static void ovl_fileattr_prot_flags(struct inode *inode, struct file_kattr *fa)
> {
> BUILD_BUG_ON(OVL_PROT_FS_FLAGS_MASK & ~FS_COMMON_FL);
> - BUILD_BUG_ON(OVL_PROT_FSX_FLAGS_MASK & ~FS_XFLAG_COMMON);
> + BUILD_BUG_ON(OVL_PROT_FSX_FLAGS_MASK & ~FSX_COMMON);
>
> if (inode->i_flags & S_APPEND) {
> fa->flags |= FS_APPEND_FL;
> diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
> index 09e32b84e02a..79371aa93a61 100644
> --- a/include/linux/fileattr.h
> +++ b/include/linux/fileattr.h
> @@ -3,37 +3,49 @@
> #ifndef _LINUX_FILEATTR_H
> #define _LINUX_FILEATTR_H
>
> -/* Flags shared betwen flags/xflags */
> +/*
> + * FS_COMMON_FL/FSX_COMMON are preserved through an RMW cycle via either UAPI
> + * flavor. They must NOT include flags that are read-write via one API flavor
> + * and read-only in another (e.g. CASEFOLD).
> + */
> #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)
>
> -#define FS_XFLAG_COMMON \
> +#define FSX_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)
>
> -/* Read-only inode flags */
> -#define FS_XFLAG_RDONLY_MASK \
> +/*
> + * Read-only xflags via FS_IOC_FS[GS]ETXATTR and file_[gs]etattr().
> + * The respective flags may still be read-write via FS_IOC_SETFLAGS.
> + */
> +#define FSX_RDONLY_MASK \
> (FS_XFLAG_PREALLOC | FS_XFLAG_HASATTR | FS_XFLAG_VERITY | \
> FS_XFLAG_CASEFOLD | FS_XFLAG_CASENONPRESERVING)
>
> /* Flags to indicate valid value of fsx_ fields */
> -#define FS_XFLAG_VALUES_MASK \
> +#define FSX_VALUES_MASK \
> (FS_XFLAG_EXTSIZE | FS_XFLAG_COWEXTSIZE)
>
> /* Flags for directories */
> -#define FS_XFLAG_DIRONLY_MASK \
> +#define FSX_DIRONLY_MASK \
> (FS_XFLAG_RTINHERIT | FS_XFLAG_NOSYMLINKS | FS_XFLAG_EXTSZINHERIT)
>
> /* Misc settable flags */
> -#define FS_XFLAG_MISC_MASK \
> +#define FSX_MISC_MASK \
> (FS_XFLAG_REALTIME | FS_XFLAG_NODEFRAG | FS_XFLAG_FILESTREAM)
>
> -#define FS_XFLAGS_MASK \
> - (FS_XFLAG_COMMON | FS_XFLAG_RDONLY_MASK | FS_XFLAG_VALUES_MASK | \
> - FS_XFLAG_DIRONLY_MASK | FS_XFLAG_MISC_MASK)
> +/* Flags for fa/fsx_extsize value fields */
> +#define FSX_EXTSIZE_MASK \
> + (FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT)
> +
> +/* Flags supported by FS_IOC_FS[GS]ETXATTR and file_[gs]etattr() */
> +#define FSX_FSXATTR_MASK \
> + (FSX_COMMON | FSX_RDONLY_MASK | FSX_VALUES_MASK | \
> + FSX_DIRONLY_MASK | FSX_MISC_MASK)
>
> /*
> * Merged interface for miscellaneous file attributes. 'flags' originates from
> @@ -69,7 +81,7 @@ void fileattr_fill_flags(struct file_kattr *fa, u32 flags);
> static inline bool fileattr_has_fsx(const struct file_kattr *fa)
> {
> return fa->fsx_valid &&
> - ((fa->fsx_xflags & ~FS_XFLAG_COMMON) || fa->fsx_extsize != 0 ||
> + ((fa->fsx_xflags & ~FSX_COMMON) || fa->fsx_extsize != 0 ||
> fa->fsx_projid != 0 || fa->fsx_cowextsize != 0);
> }
>
> --
> 2.56.1.dirty
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v5 09/12] fs,ntfs: advertise COMPR/ENCRYPT xflags in file_getattr()
2026-12-05 14:24 ` [PATCH v5 09/12] fs,ntfs: advertise COMPR/ENCRYPT xflags in file_getattr() koraynilay
@ 2026-12-05 20:21 ` Amir Goldstein
2026-12-05 20:41 ` Amir Goldstein
0 siblings, 1 reply; 25+ messages in thread
From: Amir Goldstein @ 2026-12-05 20:21 UTC (permalink / raw)
To: koraynilay
Cc: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner, Shuah Khan, Randy Dunlap, Chuck Lever,
Jeff Layton, Jan Kara, Alexander Aring, Darrick J . Wong,
Andrey Albershteyn, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs
On Sat, Dec 5, 2026 at 3:25 PM koraynilay <koray.fra@gmail.com> wrote:
>
> Introduce FS_XFLAG_COMPR and FS_XFLAG_ENCRYPT and update
> fileattr_fill_*() helpers so file_getattr() and FS_IOC_FSGETXATTR
> advertise them too, in preparation for upgrading ntfs to the masks
> API ([1] and newer versions).
>
> Since FS_COMPR_FL is read-write only with FS_IOC_SETFLAGS for some
> filesystems, put it in FSX_RDONLY_MASK but not in FSX_COMMON,
> following the FS_XFLAG_CASEFOLD example.
>
> Since FS_ENCRYPT_FL is read-only with both FS_IOC_SETFLAGS and
> FS_IOC_FSSETXATTR/file_setattr(), put it in both FSX_RDONLY_MASK and
> FSX_COMMON, following the FS_XFLAG_VERITY example.
>
> Since during FS_IOC_FSSETXATTR and file_setattr() (without masks) the
> VFS strips these new xflags (because they're both in FSX_RDONLY_MASK),
> ntfs sees this as a change on already compressed or encrypted files and
> rejects the operation. Fix this by checking for fa->flags_valid.
>
> Link: https://lore.kernel.org/20261122000856.536902-1-koray.fra@gmail.com/ [1]
> Reviewed-by: Amir Goldstein <amir73il@gmail.com>
> Signed-off-by: koraynilay <koray.fra@gmail.com>
> ---
>
> Amir, I kept your RVB since I just copy pasted your change, but tell me
> if I should've dropped it.
It's fine
thanks,
Amir.
>
> Thanks.
>
> fs/file_attr.c | 8 ++++++++
> fs/ntfs/file.c | 3 ++-
> include/linux/fileattr.h | 9 +++++----
> include/uapi/linux/fs.h | 2 ++
> 4 files changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/fs/file_attr.c b/fs/file_attr.c
> index 7ca19364d8c9..fe420e350bc7 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..7882e256133e 100644
> --- a/fs/ntfs/file.c
> +++ b/fs/ntfs/file.c
> @@ -227,7 +227,8 @@ int ntfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
> readonly |= FS_COMPR_FL;
> if (NInoEncrypted(ni))
> readonly |= FS_ENCRYPT_FL;
> - if ((fa->flags ^ readonly) & (FS_COMPR_FL | FS_ENCRYPT_FL))
> + if (fa->flags_valid &&
> + ((fa->flags ^ readonly) & (FS_COMPR_FL | FS_ENCRYPT_FL)))
> return -EOPNOTSUPP;
> allowed |= readonly;
>
> diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
> index 3a8a00545686..4779aaf81b9f 100644
> --- a/include/linux/fileattr.h
> +++ b/include/linux/fileattr.h
> @@ -11,17 +11,17 @@
> /*
> * FS_COMMON_FL/FSX_COMMON are preserved through an RMW cycle via either UAPI
> * flavor. They must NOT include flags that are read-write via one API flavor
> - * and read-only in another (e.g. CASEFOLD).
> + * and read-only in another (e.g. CASEFOLD, COMPR).
> */
> #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_ENCRYPT_FL)
>
> #define FSX_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_ENCRYPT)
>
> /*
> * Read-only xflags via FS_IOC_FS[GS]ETXATTR and file_[gs]etattr().
> @@ -29,7 +29,8 @@
> */
> #define FSX_RDONLY_MASK \
> (FS_XFLAG_PREALLOC | FS_XFLAG_HASATTR | FS_XFLAG_VERITY | \
> - FS_XFLAG_CASEFOLD | FS_XFLAG_CASENONPRESERVING)
> + FS_XFLAG_CASEFOLD | FS_XFLAG_CASENONPRESERVING | FS_XFLAG_ENCRYPT | \
> + FS_XFLAG_COMPR)
>
> /* Flags to indicate valid value of fsx_ fields */
> #define FSX_VALUES_MASK \
> diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
> index 337bb00b0e64..54d970dd30dc 100644
> --- a/include/uapi/linux/fs.h
> +++ b/include/uapi/linux/fs.h
> @@ -295,6 +295,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_COMPR 0x00200000 /* Compress file */
> +#define FS_XFLAG_ENCRYPT 0x00400000 /* Encrypted file */
>
> #define FS_XFLAG_HASATTR 0x80000000 /* no DIFLAG for this */
>
> --
> 2.56.1.dirty
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v5 10/12] ntfs: switch from flags to xflags in ntfs_fileattr_get/set()
2026-12-05 14:24 ` [PATCH v5 10/12] ntfs: switch from flags to xflags in ntfs_fileattr_get/set() koraynilay
@ 2026-12-05 20:25 ` Amir Goldstein
2026-12-05 21:31 ` Amir Goldstein
0 siblings, 1 reply; 25+ messages in thread
From: Amir Goldstein @ 2026-12-05 20:25 UTC (permalink / raw)
To: koraynilay
Cc: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner, Shuah Khan, Randy Dunlap, Chuck Lever,
Jeff Layton, Jan Kara, Alexander Aring, Darrick J . Wong,
Andrey Albershteyn, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs
On Sat, Dec 5, 2026 at 3:25 PM koraynilay <koray.fra@gmail.com> wrote:
>
> Switch ntfs_fileattr_get() and ntfs_fileattr_set() to use FS_XFLAG_*
> xflags instead of FS_*_FL flags.
>
> Add macros for NTFS specific RW and RO xflags.
>
> Add fileattr_fsx_ok() helper to let filesystems that support xflags
> check for unsupported xflags and value fields being passed.
>
> Signed-off-by: koraynilay <koray.fra@gmail.com>
This is nice :)
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
> ---
>
> The robot suggested the _ok suffix and it works very well IMO.
>
>
> fs/ntfs/file.c | 48 ++++++++++++++++++++++------------------
> include/linux/fileattr.h | 30 +++++++++++++++++++++++++
> 2 files changed, 56 insertions(+), 22 deletions(-)
>
> diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
> index 7882e256133e..68e66e7912ca 100644
> --- a/fs/ntfs/file.c
> +++ b/fs/ntfs/file.c
> @@ -150,6 +150,11 @@ int ntfs_file_release(struct inode *vi, struct file *filp)
> return 0;
> }
>
> +#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)
> +
> /*
> * ntfs_fileattr_get - inode_operations::fileattr_get
> * @dentry: dentry to report the flags of
> @@ -159,27 +164,27 @@ 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);
> return 0;
> }
>
> @@ -207,8 +212,7 @@ 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 allowed = NTFS_RW_XFLAGS;
> u32 readonly = 0;
> u32 linuxflags = ni->linuxflags & ~NTFS_LINUXFLAGS_MASK;
> unsigned int new_fl = 0;
> @@ -219,43 +223,43 @@ int ntfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
> if (err)
> return err;
>
> - if (fileattr_has_fsx(fa))
> + if (!fileattr_fsx_ok(fa, NTFS_RW_XFLAGS | NTFS_RO_XFLAGS))
> return -EOPNOTSUPP;
>
> /* chattr passes the unchanged read-only flags back to us too. */
> if (NInoCompressed(ni) || NInoWofCompressed(ni))
> - readonly |= FS_COMPR_FL;
> + readonly |= FS_XFLAG_COMPR;
> if (NInoEncrypted(ni))
> - readonly |= FS_ENCRYPT_FL;
> + readonly |= FS_XFLAG_ENCRYPT;
> if (fa->flags_valid &&
> - ((fa->flags ^ readonly) & (FS_COMPR_FL | FS_ENCRYPT_FL)))
> + ((fa->fsx_xflags ^ readonly) & (FS_XFLAG_COMPR | FS_XFLAG_ENCRYPT)))
> 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)
> + allowed |= FS_XFLAG_CASEFOLD;
> + if (fa->fsx_xflags & ~allowed)
> 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 4779aaf81b9f..d62b1cafea84 100644
> --- a/include/linux/fileattr.h
> +++ b/include/linux/fileattr.h
> @@ -99,6 +99,36 @@ int copy_fsxattr_to_user(const struct file_kattr *fa, struct fsxattr __user *ufa
> void fileattr_fill_xflags(struct file_kattr *fa, u32 xflags);
> void fileattr_fill_flags(struct file_kattr *fa, u32 flags);
>
> +/**
> + * fileattr_fsx_ok - check if fileattr flags and values are supported
> + * @fa: pointer to the input request
> + * @supported: bitmask of supported FS_XFLAG_* xflags
> + *
> + * Used in ->fileattr_set() by filesystems that support setting xflags but do
> + * not support masks.
> + *
> + * Return: false if @fa contains xflags not present in @supported or if any
> + * value field is non-zero while its xflag is not in @supported, true
> + * otherwise.
> + */
> +static inline bool fileattr_fsx_ok(const struct file_kattr *fa,
> + const u32 supported)
> +{
> + if (fa->fsx_xflags & ~supported)
> + return false;
> +
> + if (fa->fsx_extsize && !(supported & FSX_EXTSIZE_MASK))
> + return false;
> +
> + if (fa->fsx_projid && !(supported & FS_XFLAG_PROJID))
> + return false;
> +
> + if (fa->fsx_cowextsize && !(supported & FS_XFLAG_COWEXTSIZE))
> + return false;
> +
> + return true;
> +}
> +
> /**
> * fileattr_has_fsx - check for extended flags/attributes
> * @fa: fileattr pointer
> --
> 2.56.1.dirty
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v5 09/12] fs,ntfs: advertise COMPR/ENCRYPT xflags in file_getattr()
2026-12-05 20:21 ` Amir Goldstein
@ 2026-12-05 20:41 ` Amir Goldstein
0 siblings, 0 replies; 25+ messages in thread
From: Amir Goldstein @ 2026-12-05 20:41 UTC (permalink / raw)
To: koraynilay
Cc: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner, Shuah Khan, Randy Dunlap, Chuck Lever,
Jeff Layton, Jan Kara, Alexander Aring, Darrick J . Wong,
Andrey Albershteyn, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs
On Sat, Dec 5, 2026 at 9:21 PM Amir Goldstein <amir73il@gmail.com> wrote:
>
> On Sat, Dec 5, 2026 at 3:25 PM koraynilay <koray.fra@gmail.com> wrote:
> >
> > Introduce FS_XFLAG_COMPR and FS_XFLAG_ENCRYPT and update
> > fileattr_fill_*() helpers so file_getattr() and FS_IOC_FSGETXATTR
> > advertise them too, in preparation for upgrading ntfs to the masks
> > API ([1] and newer versions).
> >
> > Since FS_COMPR_FL is read-write only with FS_IOC_SETFLAGS for some
> > filesystems, put it in FSX_RDONLY_MASK but not in FSX_COMMON,
> > following the FS_XFLAG_CASEFOLD example.
> >
> > Since FS_ENCRYPT_FL is read-only with both FS_IOC_SETFLAGS and
> > FS_IOC_FSSETXATTR/file_setattr(), put it in both FSX_RDONLY_MASK and
> > FSX_COMMON, following the FS_XFLAG_VERITY example.
> >
> > Since during FS_IOC_FSSETXATTR and file_setattr() (without masks) the
> > VFS strips these new xflags (because they're both in FSX_RDONLY_MASK),
> > ntfs sees this as a change on already compressed or encrypted files and
> > rejects the operation. Fix this by checking for fa->flags_valid.
> >
> > Link: https://lore.kernel.org/20261122000856.536902-1-koray.fra@gmail.com/ [1]
> > Reviewed-by: Amir Goldstein <amir73il@gmail.com>
> > Signed-off-by: koraynilay <koray.fra@gmail.com>
> > ---
> >
> > Amir, I kept your RVB since I just copy pasted your change, but tell me
> > if I should've dropped it.
>
> It's fine
Only the fs,ntfs: change it to fs: please
Thanks,
Amir.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v5 12/12] docs: add fileattr API documentation
2026-12-05 14:24 ` [PATCH v5 12/12] docs: add fileattr API documentation koraynilay
@ 2026-12-05 21:14 ` Amir Goldstein
2026-12-05 22:24 ` koraynilay
0 siblings, 1 reply; 25+ messages in thread
From: Amir Goldstein @ 2026-12-05 21:14 UTC (permalink / raw)
To: koraynilay
Cc: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner, Shuah Khan, Randy Dunlap, Chuck Lever,
Jeff Layton, Jan Kara, Alexander Aring, Darrick J . Wong,
Andrey Albershteyn, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs
On Sat, Dec 5, 2026 at 3:25 PM koraynilay <koray.fra@gmail.com> wrote:
>
> Add documentation for the fileattr API.
>
> Signed-off-by: koraynilay <koray.fra@gmail.com>
> ---
> Documentation/filesystems/fileattr.rst | 465 +++++++++++++++++++++++++
> Documentation/filesystems/index.rst | 1 +
> Documentation/filesystems/vfs.rst | 19 +-
> 3 files changed, 477 insertions(+), 8 deletions(-)
> create mode 100644 Documentation/filesystems/fileattr.rst
>
> diff --git a/Documentation/filesystems/fileattr.rst b/Documentation/filesystems/fileattr.rst
> new file mode 100644
> index 000000000000..dc52edee0ecf
> --- /dev/null
> +++ b/Documentation/filesystems/fileattr.rst
> @@ -0,0 +1,465 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +
> +============
> +Fileattr API
> +============
> +
> +Overview
> +========
> +
> +The fileattr API provides a modern way to query and modify file attributes and
> +it should be used instead of the older ``FS_IOC_[GS]ETFLAGS``
> +(:manpage:`fs_ioc_getflags(2const)` / :manpage:`fs_ioc_setflags(2const)`) and
> +``FS_IOC_FS[GS]ETXATTR`` (:manpage:`ioctl_xfs_fsgetxattr(2)` /
> +:manpage:`ioctl_xfs_fssetxattr(2)`) ioctls.
> +
> +The "file attributes" that this document refers to are an overlap of the ones
> +reported by :manpage:`statx(2)` in its ``stx_attributes`` field (e.g. immutable
> +or append-only). Not to be confused with "Extended attributes", which are
> +the ones managed by :manpage:`getxattr(2)` and :manpage:`setxattr(2)`.
> +
> +.. note::
> + For usage by userspace, see :manpage:`file_getattr(2)`,
> + :manpage:`file_setattr(2)` and :manpage:`file_attr(2type)`.
> +
> +Userspace API Summary
> +=====================
> +
> +struct file_attr is versioned by size:
> +
> +- ``VER0``: The base structure, equivalent to struct fsxattr.
> +- ``VER1``: Adds the ``fa_xflags_rw_mask`` and ``fa_xflags_ro_mask`` fields,
> + see :ref:`Masks <masks>` for more details.
> +
> +.. kernel-doc:: include/uapi/linux/fs.h
> + :identifiers: file_attr
> +
> +.. _fileattr_flags:
> +
> +Flag Reference
> +==============
> +
> +This is the full list of currently implemented ``FS_XFLAG_*`` and ``FS_*_FL``
> +flags.
> +
> +.. note::
> + Each ``FLAG`` name in the Flag column corresponds to a ``FS_XFLAG_FLAG``
> + and/or ``FS_FLAG_FL`` macro in ``include/uapi/linux/fs.h``.
> +
> + The ``Flag`` and ``XFlag`` columns show how each flag can be handled,
> + respectively, through ``FS_IOC_[GS]ETFLAGS`` and
> + ``FS_IOC_FS[GS]ETXATTR``/``file_[gs]etattr()``:
> +
> + - ``RW``: Read-write.
> + - ``RW/M``: Read-write only with :ref:`masks <masks>`.
> + - ``RO``: Read-only.
> + - ``-``: Not supported by that API.
> +
> + Filesystem support may still vary.
> +
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| Flag | XFlag | Flag | Description and Constraints |
Flag |....| Flag |
That's weird. Maybe | Attribute | ....
Also I wanted to say last time and forgot - might be good to add a Value column
where fsx_projid and friends are documented (?)
Either way feel free to add
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Thanks,
Amir.
> ++=======================+===========+======+==================================================+
> +| ``IMMUTABLE`` | RW | RW | Inode cannot be modified. Requires |
> +| | | | ``CAP_LINUX_IMMUTABLE``. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``APPEND`` | RW | RW | All writes append only. Requires |
> +| | | | ``CAP_LINUX_IMMUTABLE``. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``SYNC`` | RW | RW | File writes are synchronous. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``NOATIME`` | RW | RW | Do not update inode access time (atime). |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``NODUMP`` | RW | RW | Exclude file from dump/backup utilities. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``DAX`` | RW | RW | Direct Access (DAX) I/O (regular files and |
> +| | | | directories only); mutually exclusive with |
> +| | | | ``FS_XFLAG_VERITY``. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``VERITY`` | RO | RO | fs-verity enabled, read-only (set via verity |
> +| | | | ioctl). |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``CASEFOLD`` | RO | RW | Case-insensitive lookups. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``COMPR`` | RO | RW | Compressed file flag. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``ENCRYPT`` | RO | RO | Encrypted file flag (fscrypt). Read-only. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``PROJINHERIT`` | RW | RW | Inherit project ID on newly created files |
> +| | | | (directories only). |
> +| | | | Updates require ``init_user_ns``. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``PROJID`` | RW/M [#r]_| \- | Project ID value flag (``VER1``). |
> +| | | | Updates require ``init_user_ns``. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``REALTIME`` | RW | \- | Realtime volume storage (XFS). |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``PREALLOC`` | RO | \- | File has preallocated extents (XFS). |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``RTINHERIT`` | RW | \- | Inherit realtime bit on newly created files |
> +| | | | (directories only; XFS). |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``NOSYMLINKS`` | RW | \- | Disallow creation of symlinks (directories |
> +| | | | only; XFS). |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``EXTSIZE`` | RW | \- | Extent size allocator hint (regular files only; |
> +| | | | XFS). |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``EXTSZINHERIT`` | RW | \- | Inherit extent size allocator hint |
> +| | | | (directories only; XFS). |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``NODEFRAG`` | RW | \- | Disable filesystem defragmentation for file |
> +| | | | (XFS). |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``FILESTREAM`` | RW | \- | Enable filestream allocator (directories only; |
> +| | | | XFS). |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``COWEXTSIZE`` | RW | \- | Copy-on-Write extent size allocator hint |
> +| | | | (regular files and directories only; XFS). |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``CASENONPRESERVING`` | RO | \- | Case not preserved in directory lookups. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``HASATTR`` | RO | \- | Inode has extended attributes (XFS). |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``SECRM`` | \- | RW | Secure deletion. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``UNRM`` | \- | RW | Undelete. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``DIRTY`` | \- | RO | Dirty (reserved for compression). |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``COMPRBLK`` | \- | RO | One or more compressed clusters. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``NOCOMP`` | \- | RW | Don't compress. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``BTREE`` / | \- | RO | Btree format / hash-indexed directory. |
> +| ``INDEX`` | | | |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``IMAGIC`` | \- | RO | AFS directory. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``JOURNAL_DATA`` | \- | RW | Journaled file data. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``NOTAIL`` | \- | RW | File tail should not be merged. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``DIRSYNC`` | \- | RW | Dirsync behaviour (directories only). |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``TOPDIR`` | \- | RW | Top of directory hierarchies. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``HUGE_FILE`` | \- | RO | File size/blocks use huge-file accounting |
> +| | | | (ext4). |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``EXTENT`` | \- | RO | Inode uses extents (ext4). |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``EA_INODE`` | \- | RO | Inode used for large EA (ext4). |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``NOCOW`` | \- | RW | Do not CoW file. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +| ``INLINE_DATA`` | \- | RO | File data is stored inline in the inode. |
> ++-----------------------+-----------+------+--------------------------------------------------+
> +
> +.. [#r] The project ID can also be changed with ``FS_IOC_FS[GS]ETXATTR`` (or
> + ``file_[gs]etattr()`` without masks), by passing a modified ``fsx_projid``
> + directly, because ``FS_XFLAG_PROJID`` was added in ``VER1``, while the
> + ``fsx_projid`` field was available before that.
> +
> +.. _masks:
> +
> +Masks
> +=====
> +
> +In ``VER1``, the fileattr API introduced the ``fa_xflags_rw_mask`` and
> +``fa_xflags_ro_mask`` fields, to enable its usage without needing a
> +Read-Modify-Write cycle like ``FS_IOC_SETFLAGS`` and ``FS_IOC_FSSETXATTR``
> +require.
> +
> +To use this feature ``AT_FILEATTR_MASKS`` needs to be set in the ``at_flags``
> +argument of file_getattr() / file_setattr(), otherwise the normal behaviour is kept.
> +
> +.. note::
> + For filesystems that don't support masks (and for userspace without
> + ``AT_FILEATTR_MASKS``), conversion between the two formats on set is handled
> + by the VFS as described :ref:`below <conversion>`.
> +
> +On file_getattr()
> +-----------------
> +
> +- If the filesystem supports mask reporting, file_getattr() populates
> + ``fa_xflags_rw_mask`` with all xflags it supports modifying on this inode,
> + and ``fa_xflags_ro_mask`` with all read-only xflags it supports reporting.
> +- If the filesystem does not support masks, file_getattr() sets to ``0``
> + both ``fa_xflags_rw_mask`` and ``fa_xflags_ro_mask``.
> +
> +.. caution::
> +
> + Passing the result of file_getattr() directly into file_setattr()
> + like this (e.g. in backup/sync workloads)::
> +
> + file_getattr(file1, &fa, ..., AT_FILEATTR_MASKS);
> + file_setattr(file2, &fa, ..., AT_FILEATTR_MASKS);
> +
> + is a change of behaviour compared to the unmasked APIs, where unsupported
> + flags were often silently dropped:
> +
> + - on filesystems without mask support, file_getattr() returns
> + ``fa_xflags_rw_mask = 0``, causing file_setattr() to fail with
> + ``-EINVAL``;
> + - on filesystems with mask support, file_getattr() returns all supported
> + writable xflags in ``fa_xflags_rw_mask``, so file_setattr() tries to set
> + all of them on ``file2`` and fails with ``-EOPNOTSUPP`` if ``file2``
> + doesn't support all of them, instead of silently dropping them.
> +
> + With masks, the program can inspect ``file2``'s masks first and decide how
> + to handle unsupported flags.
> +
> +On file_setattr()
> +-----------------
> +
> +- Userspace populates ``fa_xflags_rw_mask`` with the xflags it wishes to
> + change. If ``fa_xflags_rw_mask`` is ``0``, the request fails with
> + ``-EINVAL``.
> +- Any valid flag outside ``fa_xflags_rw_mask`` is ignored and left unmodified.
> +- For boolean attributes:
> +
> + - Setting the xflag bit in both ``fa_xflags_rw_mask`` and ``fa_xflags``
> + enables the feature.
> + - Setting the xflag bit in ``fa_xflags_rw_mask`` and clearing the bit in
> + ``fa_xflags`` disables the feature.
> +
> +- For value attributes (like ``FS_XFLAG_PROJID`` and ``FS_XFLAG_COWEXTSIZE``):
> +
> + - Setting the flag bit in both ``fa_xflags_rw_mask`` and ``fa_xflags`` sets
> + the attribute, taking the value from the corresponding field in the struct.
> + - Setting the flag bit in ``fa_xflags_rw_mask``, clearing the bit in
> + ``fa_xflags`` and setting the field value to ``0`` unsets/clears the
> + attribute. If instead the field value is left non-zero, the request fails
> + with ``-EINVAL``.
> +
> +- Validation:
> +
> + - If the filesystem supports masks, requesting modification of any flag not
> + advertised in the filesystem's writable mask fails with ``-EOPNOTSUPP``.
> + - If the filesystem does not support masks, requesting modification of any
> + flag outside ``FSX_FSXATTR_SET_MASK`` fails with ``-EOPNOTSUPP``.
> +
> +Usage Examples
> +--------------
> +
> +See :manpage:`file_setattr(2)` for examples.
> +
> +Behaviour without ``AT_FILEATTR_MASKS``
> +=======================================
> +
> +When not using ``AT_FILEATTR_MASKS``, file_getattr() and file_setattr() behave
> +in the same way as ``FS_IOC_FSGETXATTR`` and ``FS_IOC_FSSETXATTR``
> +respectively.
> +
> +In-Kernel Filesystem Interface
> +==============================
> +
> +Filesystem Operations
> +---------------------
> +
> +Filesystems wanting to implement this API, need to set the ``fileattr_get`` and
> +``fileattr_set`` functions in ``struct inode_operations``:
> +
> +.. code-block:: c
> +
> + struct inode_operations {
> + ...
> + int (*fileattr_get)(struct dentry *dentry, struct file_kattr *fa);
> + int (*fileattr_set)(const struct mnt_idmap *idmap, struct dentry *dentry,
> + struct file_kattr *fa);
> + ...
> + };
> +
> +Internal Structure: struct file_kattr
> +-------------------------------------
> +
> +Defined in ``<linux/fileattr.h>``:
> +
> +.. code-block:: c
> +
> + struct file_kattr {
> + u32 flags; /* FS_*_FL legacy flags */
> + u32 fsx_xflags; /* FS_XFLAG_* modern flags */
> + u32 fsx_xflags_rw_mask; /* Supported writable flags (get) / flags to set (set) */
> + u32 fsx_xflags_ro_mask; /* Supported read-only flags (get) */
> + u32 fsx_extsize; /* Extent size hint */
> + u32 fsx_nextents; /* Extent count */
> + u32 fsx_projid; /* Project ID */
> + u32 fsx_cowextsize; /* CoW extent size hint */
> + bool flags_valid:1; /* Legacy flags valid */
> + bool fsx_valid:1; /* Modern xflags valid */
> + bool has_masks:1; /* Struct has valid masks */
> + bool use_masks:1; /* In-kernel callers need to set this to use masks (set) */
> + bool get_only_masks:1; /* Transitional: fs supports ro_mask on get, but wants an unmasked request on set */
> + };
> +
> +Fields of struct file_kattr have the same semantics as their user-facing
> +counterparts in struct file_attr above.
> +In addition, struct file_kattr has:
> +
> +``flags``
> + Bit mask of the ``FS_*_FL`` flags, used by ``FS_IOC_GETFLAGS`` and ``FS_IOC_SETFLAGS``.
> +
> +``flags_valid`` / ``fsx_valid``
> + - get: hints from the caller indicating which attributes it intends
> + to read, both may be ``true``.
> + - set: indicates which attributes were filled by the caller (``flags`` vs.
> + ``fsx_xflags``/``fsx_*``). Syscalls/ioctls only set one, in-kernel
> + callers reusing the result of a ``->fileattr_get()`` may pass both.
> + Masked requests always have ``fsx_valid = true`` and
> + ``flags_valid = false``.
> +
> +``has_masks``
> + Indicates whether ``fsx_xflags_rw_mask`` and ``fsx_xflags_ro_mask`` contain
> + valid masks.
> +
> +``use_masks``
> + Indicates whether the set request uses mask semantics (the in-kernel
> + equivalent of ``AT_FILEATTR_MASKS``).
> +
> +``get_only_masks``
> + Transitional flag indicating that the filesystem supports
> + ``fsx_xflags_ro_mask`` on get, but still expects unmasked input in
> + ``->fileattr_set()``. If a filesystem wants to accept masks on set it
> + **must** make sure all of its writable ``FS_*_FL`` flags have
> + ``FS_XFLAG_*`` counterparts, otherwise ``FS_IOC_SETFLAGS`` will fail when
> + setting a flag without an xflag counterpart.
> +
> +Filesystem Contract for Masks
> +-----------------------------
> +
> +When a filesystem accepts masks on ``->fileattr_set()``:
> +
> +- ``fsx_xflags_rw_mask`` is validated by the VFS against the ``rw_mask``
> + returned by ``->fileattr_get()``, and ``fsx_xflags`` is clamped to only
> + contain bits within ``fsx_xflags_rw_mask``.
> +- For ``AT_FILEATTR_MASKS`` calls, ``fsx_*`` value fields are ``0`` unless
> + enabled in ``fsx_xflags``; for unmasked calls converted by
> + fileattr_set_to_masks(), unchanged ``fsx_*`` fields are preserved (except for
> + ``FS_IOC_SETFLAGS``, where they remain ``0``, but in that case they also
> + won't be in ``fsx_xflags_rw_mask``).
> +- After validation and (if necessary) conversion, the VFS passes the resulting
> + struct file_kattr to ``->fileattr_set()`` with ``has_masks = true``,
> + ``fsx_valid = true``, and ``flags_valid = false``.
> +- The filesystem should validate the request with fileattr_fsx_masks_ok()
> + and must modify **only** the attributes selected in ``fsx_xflags_rw_mask``.
> +
> +VFS Helpers
> +-----------
> +
> +When implementing ``->fileattr_get()``, filesystems can populate struct
> +file_kattr using either fileattr_fill_xflags() or fileattr_fill_flags()::
> +
> + void fileattr_fill_xflags(struct file_kattr *fa, u32 xflags);
> +
> + void fileattr_fill_flags(struct file_kattr *fa, u32 flags);
> +
> +This way filesystems can handle flags internally either as ``FS_*_FL`` flags or
> +``FS_XFLAG_*`` xflags and let VFS translate the common ones (defined in
> +``FS_COMMON_FL`` / ``FSX_COMMON``).
> +
> +New and mask-aware drivers should use fileattr_fill_xflags() and set
> +``fa->has_masks = true`` along with their supported masks, while
> +``FS_*_FL``-only drivers use fileattr_fill_flags().
> +
> +Drivers that only support ``FS_*_FL`` flags can check for unsupported
> +xflags in ``->fileattr_set()`` using fileattr_has_fsx(). Drivers using
> +``FS_XFLAG_*`` can validate supported xflags and values with
> +fileattr_fsx_ok() or against allowed masks with fileattr_fsx_masks_ok()::
> +
> + bool fileattr_has_fsx(const struct file_kattr *fa);
> +
> + bool fileattr_fsx_ok(const struct file_kattr *fa, const u32 supported);
> +
> + bool fileattr_fsx_masks_ok(const struct file_kattr *fa,
> + const u32 allowed_rw,
> + const u32 allowed_ro);
> +
> +See :ref:`Flag Reference <fileattr_flags>` for the ``FS_*_FL`` to
> +``FS_XFLAG_*`` translation mapping.
> +
> +.. _conversion:
> +
> +VFS Conversion Helpers
> +----------------------
> +
> +With fileattr_set_convert(), the VFS bridges differing caller and driver
> +capabilities automatically using the inode's current attributes retrieved via
> +vfs_fileattr_get():
> +
> +- fileattr_set_to_masks(): Converts non-masked requests (``FS_IOC_SETFLAGS``,
> + ``FS_IOC_FSSETXATTR``, file_setattr() without ``AT_FILEATTR_MASKS``, or
> + in-kernel callers with ``use_masks = false``) to a masked request when
> + targeting a filesystem that accepts masks on set.
> +- fileattr_set_from_masks(): Converts masked requests (file_setattr() with
> + ``AT_FILEATTR_MASKS``) to unmasked format when targeting a
> + filesystem that doesn't accept masks on set.
> +- flags_to_xflags() / xflags_to_flags(): Convert between ``FS_XFLAG_*`` xflags
> + and ``FS_*_FL`` flags.
> +
> +Adding New Flags
> +----------------
> +
> +When adding new xflags or value attributes:
> +
> +- New flags should target the ``VER1+`` syscall API (``FSX_FILEATTR_MASK``)
> + only, keeping ``FSX_FSXATTR_MASK`` and ``FSX_RDONLY_MASK`` frozen except
> + when exposing xflag counterparts for existing ``FS_*_FL`` flags.
> +- When adding a ``FS_XFLAG_*`` counterpart to a ``FS_*_FL`` flag, add it to
> + ``FSX_COMMON`` / ``FS_COMMON_FL`` only if it has the same read-only /
> + read-write behaviour across both ``FS_IOC_SETFLAGS`` and the xflags APIs
> + [#excomm]_, add the counterpart to the :ref:`table above <fileattr_flags>`
> + and move the line up so it's grouped with the other flags with counterparts.
> +- Filesystems that only want to report new read-only flags on get without
> + converting ``->fileattr_set()`` to masks have to change their
> + ``->fileattr_get()`` so that it:
> +
> + - sets ``has_masks = true``,
> + - sets ``get_only_masks = true``,
> + - sets the xflag bit(s) they want to report as read-only in
> + ``fsx_xflags_ro_mask``.
> +
> +.. [#excomm] For example ``FS_XFLAG_CASEFOLD`` and ``FS_XFLAG_COMPR``, which
> + are writable via ``FS_IOC_SETFLAGS`` but read-only in xflags, must not be
> + added to ``FSX_COMMON``.
> +
> +Mask-Aware Driver Example
> +-------------------------
> +
> +An example of a filesystem that supports masks can be found in ``fs/ntfs/file.c``.
> +
> +Locking
> +-------
> +
> +- vfs_fileattr_set() takes inode_lock(), so no external locking is required.
> +
> +Permissions
> +-----------
> +
> +- Inode ownership or ``CAP_FOWNER`` in the owning user namespace is required.
> +- Modifying ``FS_XFLAG_IMMUTABLE`` or ``FS_XFLAG_APPEND`` requires
> + ``CAP_LINUX_IMMUTABLE`` in the initial user namespace.
> +- Modifying ``FS_XFLAG_PROJID`` (when ``fsx_projid`` changes) or
> + ``FS_XFLAG_PROJINHERIT`` requires the caller to reside in the initial user
> + namespace.
> +
> +Error Codes
> +===========
> +
> +``-EINVAL``
> + Invalid structure size, ``AT_FILEATTR_MASKS`` passed with non-mask struct,
> + ``AT_FILEATTR_MASKS`` passed to file_setattr() with ``fa_xflags_rw_mask = 0``,
> + non-zero masks passed to file_setattr() without ``AT_FILEATTR_MASKS``,
> + unknown flags in ``at_flags``, unknown bits in ``fa_xflags`` or
> + ``fa_xflags_rw_mask``, invalid inode type for the specified xflags,
> + incompatible attribute combinations (e.g. DAX on fs-verity), invalid
> + project ID or changing ``FS_XFLAG_PROJID`` / ``FS_XFLAG_PROJINHERIT``
> + outside the host namespace, specifying xflags added in or after ``VER1``
> + without ``AT_FILEATTR_MASKS``, or clearing a value attribute with a
> + non-zero field value.
> +
> +``-EOPNOTSUPP``
> + The filesystem does not implement ``fileattr`` operations for this inode,
> + or userspace requested modification of an attribute not writable by the
> + filesystem.
> diff --git a/Documentation/filesystems/index.rst b/Documentation/filesystems/index.rst
> index a556084c8858..71a1ae852e5b 100644
> --- a/Documentation/filesystems/index.rst
> +++ b/Documentation/filesystems/index.rst
> @@ -28,6 +28,7 @@ algorithms work.
> dnotify
> fiemap
> files
> + fileattr
> locks
> mmap_prepare
> multigrain-ts
> diff --git a/Documentation/filesystems/vfs.rst b/Documentation/filesystems/vfs.rst
> index 9ab182dbbd73..01fddb2dacf3 100644
> --- a/Documentation/filesystems/vfs.rst
> +++ b/Documentation/filesystems/vfs.rst
> @@ -621,16 +621,19 @@ otherwise noted.
> the end.
>
> ``fileattr_get``
> - called on ioctl(FS_IOC_GETFLAGS) and ioctl(FS_IOC_FSGETXATTR) to
> - retrieve miscellaneous file flags and attributes. Also called
> - before the relevant SET operation to check what is being changed
> - (in this case with i_rwsem locked exclusive). If unset, then
> - fall back to f_op->ioctl().
> + called on ioctl(FS_IOC_GETFLAGS), ioctl(FS_IOC_FSGETXATTR) and
> + file_getattr(2) to retrieve miscellaneous file flags and attributes
> + (see Documentation/filesystems/fileattr.rst). Also called before the
> + relevant SET operation to check what is being changed (in this case
> + with i_rwsem locked exclusive). If unset, then fall back to
> + f_op->ioctl().
>
> ``fileattr_set``
> - called on ioctl(FS_IOC_SETFLAGS) and ioctl(FS_IOC_FSSETXATTR) to
> - change miscellaneous file flags and attributes. Callers hold
> - i_rwsem exclusive. If unset, then fall back to f_op->ioctl().
> + called on ioctl(FS_IOC_SETFLAGS), ioctl(FS_IOC_FSSETXATTR) and
> + file_setattr(2) to change miscellaneous file flags and attributes (see
> + Documentation/filesystems/fileattr.rst). Callers hold i_rwsem
> + exclusive. If unset, then fall back to f_op->ioctl().
> +
> ``get_offset_ctx``
> called to get the offset context for a directory inode. A
> filesystem must define this operation to use
> --
> 2.56.1.dirty
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v5 11/12] ntfs: support the fileattr API masks in ntfs_fileattr_get/set()
2026-12-05 14:24 ` [PATCH v5 11/12] ntfs: support the fileattr API masks " koraynilay
@ 2026-12-05 21:15 ` Amir Goldstein
0 siblings, 0 replies; 25+ messages in thread
From: Amir Goldstein @ 2026-12-05 21:15 UTC (permalink / raw)
To: koraynilay
Cc: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner, Shuah Khan, Randy Dunlap, Chuck Lever,
Jeff Layton, Jan Kara, Alexander Aring, Darrick J . Wong,
Andrey Albershteyn, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs
On Sat, Dec 5, 2026 at 3:25 PM koraynilay <koray.fra@gmail.com> wrote:
>
> Add support for the new fileattr API with masks in ntfs_fileattr_get()
> and ntfs_fileattr_set().
>
> To check for unsupported xflags in the masks, add fileattr_fsx_masks_ok()
> helper and use it in place of the previous checks in ntfs_fileattr_set().
>
> Signed-off-by: koraynilay <koray.fra@gmail.com>
Nice and clean!
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
> ---
> fs/ntfs/file.c | 67 +++++++++++++++++++++-------------------
> include/linux/fileattr.h | 31 +++++++++++++++++++
> 2 files changed, 67 insertions(+), 31 deletions(-)
>
> diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
> index 68e66e7912ca..f20fa46c0d61 100644
> --- a/fs/ntfs/file.c
> +++ b/fs/ntfs/file.c
> @@ -185,6 +185,9 @@ int ntfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
> xflags |= FS_XFLAG_CASEFOLD;
>
> 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;
> }
>
> @@ -212,65 +215,67 @@ 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 = NTFS_RW_XFLAGS;
> - u32 readonly = 0;
> - u32 linuxflags = ni->linuxflags & ~NTFS_LINUXFLAGS_MASK;
> - unsigned int new_fl = 0;
> - bool forced_immutable;
> + u32 linuxflags = ni->linuxflags;
> + u32 rw_user_mask = fa->fsx_xflags_rw_mask;
> + unsigned int new_fl = 0, mask_fl = 0;
> + unsigned int new_linuxflags = 0, mask_linuxflags = 0;
> + bool forced_immutable = false;
> int err;
>
> err = ntfs_emergency_state(ni->vol);
> if (err)
> return err;
>
> - if (!fileattr_fsx_ok(fa, NTFS_RW_XFLAGS | NTFS_RO_XFLAGS))
> + if (!fileattr_fsx_masks_ok(fa, NTFS_RW_XFLAGS, NTFS_RO_XFLAGS))
> return -EOPNOTSUPP;
>
> - /* chattr passes the unchanged read-only flags back to us too. */
> - if (NInoCompressed(ni) || NInoWofCompressed(ni))
> - readonly |= FS_XFLAG_COMPR;
> - if (NInoEncrypted(ni))
> - readonly |= FS_XFLAG_ENCRYPT;
> - if (fa->flags_valid &&
> - ((fa->fsx_xflags ^ readonly) & (FS_XFLAG_COMPR | FS_XFLAG_ENCRYPT)))
> - return -EOPNOTSUPP;
> - allowed |= readonly;
> -
> - /* Case folding is a read-only, mount-wide property. */
> - if (!NVolCaseSensitive(ni->vol))
> - allowed |= FS_XFLAG_CASEFOLD;
> - if (fa->fsx_xflags & ~allowed)
> - return -EOPNOTSUPP;
> -
> - forced_immutable = ntfs_is_forced_immutable(vi);
> - if (!(fa->fsx_xflags & FS_XFLAG_IMMUTABLE) && forced_immutable)
> - return -EPERM;
> + if (rw_user_mask & FS_XFLAG_IMMUTABLE) {
> + forced_immutable = ntfs_is_forced_immutable(vi);
> + if (!(fa->fsx_xflags & FS_XFLAG_IMMUTABLE) && forced_immutable)
> + return -EPERM;
>
> + mask_fl |= S_IMMUTABLE;
> + mask_linuxflags |= NTFS_LINUXFLAGS_IMMUTABLE;
> + }
> 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;
> + new_linuxflags |= NTFS_LINUXFLAGS_IMMUTABLE;
> + }
> +
> + if (rw_user_mask & FS_XFLAG_APPEND) {
> + mask_fl |= S_APPEND;
> + mask_linuxflags |= NTFS_LINUXFLAGS_APPEND;
> }
> if (fa->fsx_xflags & FS_XFLAG_APPEND) {
> new_fl |= S_APPEND;
> - linuxflags |= NTFS_LINUXFLAGS_APPEND;
> + new_linuxflags |= NTFS_LINUXFLAGS_APPEND;
> }
> +
> + if (rw_user_mask & FS_XFLAG_NODUMP)
> + mask_linuxflags |= NTFS_LINUXFLAGS_NODUMP;
> if (fa->fsx_xflags & FS_XFLAG_NODUMP)
> - linuxflags |= NTFS_LINUXFLAGS_NODUMP;
> + new_linuxflags |= NTFS_LINUXFLAGS_NODUMP;
> +
> + if (rw_user_mask & FS_XFLAG_NOATIME) {
> + mask_fl |= S_NOATIME;
> + mask_linuxflags |= NTFS_LINUXFLAGS_NOATIME;
> + }
> if (fa->fsx_xflags & FS_XFLAG_NOATIME) {
> new_fl |= S_NOATIME;
> - linuxflags |= NTFS_LINUXFLAGS_NOATIME;
> + new_linuxflags |= NTFS_LINUXFLAGS_NOATIME;
> }
>
> mutex_lock(&ni->mrec_lock);
> - err = ntfs_ea_set_linuxflags(vi, linuxflags);
> + new_linuxflags |= linuxflags & ~mask_linuxflags;
> + err = ntfs_ea_set_linuxflags(vi, new_linuxflags);
> mutex_unlock(&ni->mrec_lock);
> if (err)
> return err;
>
> - inode_set_flags(vi, new_fl, S_IMMUTABLE | S_APPEND | S_NOATIME);
> + inode_set_flags(vi, new_fl, mask_fl);
> inode_set_ctime_current(vi);
> mark_inode_dirty(vi);
> return 0;
> diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
> index d62b1cafea84..d237465153ac 100644
> --- a/include/linux/fileattr.h
> +++ b/include/linux/fileattr.h
> @@ -129,6 +129,37 @@ static inline bool fileattr_fsx_ok(const struct file_kattr *fa,
> return true;
> }
>
> +/**
> + * fileattr_fsx_masks_ok - check if fileattr masks and values are valid and
> + * supported
> + * @fa: pointer to the input request
> + * @allowed_rw: bitmask of supported writable FS_XFLAG_* flags
> + * @allowed_ro: bitmask of supported read-only FS_XFLAG_* flags
> + *
> + * Used in ->fileattr_set() by filesystems that support masks on set, instead
> + * of fileattr_fsx_ok().
> + * See Documentation/filesystems/fileattr.rst for the full filesystem contract.
> + *
> + * Return: true if @fa satisfies mask invariants, only requests modifying flags
> + * in @allowed_rw and only contains supported xflags/values, false otherwise.
> + */
> +static inline bool fileattr_fsx_masks_ok(const struct file_kattr *fa,
> + const u32 allowed_rw,
> + const u32 allowed_ro)
> +{
> + if (WARN_ON_ONCE(!fa->fsx_valid || !fa->has_masks))
> + return false;
> +
> + if (WARN_ON_ONCE((fa->fsx_xflags & allowed_rw) &
> + ~fa->fsx_xflags_rw_mask))
> + return false;
> +
> + if (fa->fsx_xflags_rw_mask & ~allowed_rw)
> + return false;
> +
> + return fileattr_fsx_ok(fa, allowed_rw | allowed_ro);
> +}
> +
> /**
> * fileattr_has_fsx - check for extended flags/attributes
> * @fa: fileattr pointer
> --
> 2.56.1.dirty
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v5 10/12] ntfs: switch from flags to xflags in ntfs_fileattr_get/set()
2026-12-05 20:25 ` Amir Goldstein
@ 2026-12-05 21:31 ` Amir Goldstein
0 siblings, 0 replies; 25+ messages in thread
From: Amir Goldstein @ 2026-12-05 21:31 UTC (permalink / raw)
To: koraynilay
Cc: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner, Shuah Khan, Randy Dunlap, Chuck Lever,
Jeff Layton, Jan Kara, Alexander Aring, Darrick J . Wong,
Andrey Albershteyn, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs
On Sat, Dec 5, 2026 at 9:25 PM Amir Goldstein <amir73il@gmail.com> wrote:
>
> On Sat, Dec 5, 2026 at 3:25 PM koraynilay <koray.fra@gmail.com> wrote:
> >
> > Switch ntfs_fileattr_get() and ntfs_fileattr_set() to use FS_XFLAG_*
> > xflags instead of FS_*_FL flags.
> >
> > Add macros for NTFS specific RW and RO xflags.
> >
> > Add fileattr_fsx_ok() helper to let filesystems that support xflags
> > check for unsupported xflags and value fields being passed.
> >
> > Signed-off-by: koraynilay <koray.fra@gmail.com>
>
> This is nice :)
>
> Reviewed-by: Amir Goldstein <amir73il@gmail.com>
>
> > ---
> >
> > The robot suggested the _ok suffix and it works very well IMO.
> >
> >
> > fs/ntfs/file.c | 48 ++++++++++++++++++++++------------------
> > include/linux/fileattr.h | 30 +++++++++++++++++++++++++
> > 2 files changed, 56 insertions(+), 22 deletions(-)
> >
> > diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
> > index 7882e256133e..68e66e7912ca 100644
> > --- a/fs/ntfs/file.c
> > +++ b/fs/ntfs/file.c
> > @@ -150,6 +150,11 @@ int ntfs_file_release(struct inode *vi, struct file *filp)
> > return 0;
> > }
> >
> > +#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)
> > +
> > /*
> > * ntfs_fileattr_get - inode_operations::fileattr_get
> > * @dentry: dentry to report the flags of
> > @@ -159,27 +164,27 @@ 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);
> > return 0;
> > }
> >
> > @@ -207,8 +212,7 @@ 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 allowed = NTFS_RW_XFLAGS;
> > u32 readonly = 0;
> > u32 linuxflags = ni->linuxflags & ~NTFS_LINUXFLAGS_MASK;
> > unsigned int new_fl = 0;
> > @@ -219,43 +223,43 @@ int ntfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
> > if (err)
> > return err;
> >
> > - if (fileattr_has_fsx(fa))
> > + if (!fileattr_fsx_ok(fa, NTFS_RW_XFLAGS | NTFS_RO_XFLAGS))
> > return -EOPNOTSUPP;
> >
> > /* chattr passes the unchanged read-only flags back to us too. */
> > if (NInoCompressed(ni) || NInoWofCompressed(ni))
> > - readonly |= FS_COMPR_FL;
> > + readonly |= FS_XFLAG_COMPR;
> > if (NInoEncrypted(ni))
> > - readonly |= FS_ENCRYPT_FL;
> > + readonly |= FS_XFLAG_ENCRYPT;
> > if (fa->flags_valid &&
> > - ((fa->flags ^ readonly) & (FS_COMPR_FL | FS_ENCRYPT_FL)))
> > + ((fa->fsx_xflags ^ readonly) & (FS_XFLAG_COMPR | FS_XFLAG_ENCRYPT)))
> > 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)
> > + allowed |= FS_XFLAG_CASEFOLD;
> > + if (fa->fsx_xflags & ~allowed)
> > 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 4779aaf81b9f..d62b1cafea84 100644
> > --- a/include/linux/fileattr.h
> > +++ b/include/linux/fileattr.h
> > @@ -99,6 +99,36 @@ int copy_fsxattr_to_user(const struct file_kattr *fa, struct fsxattr __user *ufa
> > void fileattr_fill_xflags(struct file_kattr *fa, u32 xflags);
> > void fileattr_fill_flags(struct file_kattr *fa, u32 flags);
> >
> > +/**
> > + * fileattr_fsx_ok - check if fileattr flags and values are supported
> > + * @fa: pointer to the input request
> > + * @supported: bitmask of supported FS_XFLAG_* xflags
> > + *
> > + * Used in ->fileattr_set() by filesystems that support setting xflags but do
> > + * not support masks.
> > + *
> > + * Return: false if @fa contains xflags not present in @supported or if any
> > + * value field is non-zero while its xflag is not in @supported, true
> > + * otherwise.
> > + */
> > +static inline bool fileattr_fsx_ok(const struct file_kattr *fa,
> > + const u32 supported)
> > +{
> > + if (fa->fsx_xflags & ~supported)
> > + return false;
> > +
> > + if (fa->fsx_extsize && !(supported & FSX_EXTSIZE_MASK))
> > + return false;
> > +
> > + if (fa->fsx_projid && !(supported & FS_XFLAG_PROJID))
> > + return false;
> > +
> > + if (fa->fsx_cowextsize && !(supported & FS_XFLAG_COWEXTSIZE))
> > + return false;
> > +
> > + return true;
> > +}
> > +
> > /**
> > * fileattr_has_fsx - check for extended flags/attributes
> > * @fa: fileattr pointer
> > --
One more small improvement:
Please use fileattr_fsx_ok() for fileattr_has_fsx() to get rid of it's
awkwardness:
and also add that same "used by whom" part to its Kernel doc:
* Used in ->fileattr_set() by filesystems that do not support setting xflags
* which are not converted by vfs to FS_*_FL flags.
static inline bool fileattr_has_fsx(const struct file_kattr *fa)
{
return fa->fsx_valid && !fileattr_fsx_ok(fa, FSX_COMMON);
}
Thanks,
Amir.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v5 08/12] fs,overlayfs: add fileattr masks support on get
2026-12-05 14:24 ` [PATCH v5 08/12] fs,overlayfs: add fileattr masks support on get koraynilay
@ 2026-12-05 21:42 ` Amir Goldstein
0 siblings, 0 replies; 25+ messages in thread
From: Amir Goldstein @ 2026-12-05 21:42 UTC (permalink / raw)
To: koraynilay
Cc: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner, Shuah Khan, Randy Dunlap, Chuck Lever,
Jeff Layton, Jan Kara, Alexander Aring, Darrick J . Wong,
Andrey Albershteyn, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs
On Sat, Dec 5, 2026 at 3:25 PM koraynilay <koray.fra@gmail.com> wrote:
>
> Add transitional get_only_masks selector in file_kattr for filesystems
> that want to advertise their read-only mask on GET but don't want to
> receive masked requests on SET.
>
> Use it in ovl_fileattr_get() to ask the VFS for unmasked SET if the
> underlying filesystem returns masks on GET, otherwise ovl_set_protattr()
> treats fa->flags as the full set of flags and clears IMMUTABLE/APPEND.
>
> Signed-off-by: koraynilay <koray.fra@gmail.com>
> ---
>
> Amir, is this commit message correct?
> This is what I understood, but I'm not 100% sure.
>
> I wanted to mention the actual bugs fixed, but since I haven't
> understood them that much I didn't want to just leave the robot's
> explanation in the commit message :D
>
It's ok that you framed it as an API patch which ovl uses, but in fact
there are no other users in-tree at the moment, only a future one,
so we can frame this the other way around, as a property added to
solve an ovl problem:
ovl: do not accept masked fileattr set requests
ovl_fileattr_get() reports the real inode's masks as its own.
When the upper filesystem supports masks, the VFS would send
overlayfs masked set requests, where fa->flags only contains the
flags selected by fsx_xflags_rw_mask.
ovl_set_protattr() treats fa->flags as the full set of flags,
so for example chattr +d on an append-only file would clear the
append-only flag. The VFS CAP_LINUX_IMMUTABLE check does
not catch this because the request does not select APPEND.
Add a transitional get_only_masks selector, and set it in
ovl_fileattr_get(), so the VFS converts masked set requests to
unmasked set requests before calling ovl_fileattr_set().
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Thanks,
Amir.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v5 07/12] fs: add missing FS_XFLAG_PROJID xflag
2026-12-05 14:24 ` [PATCH v5 07/12] fs: add missing FS_XFLAG_PROJID xflag koraynilay
@ 2026-12-05 22:08 ` Amir Goldstein
0 siblings, 0 replies; 25+ messages in thread
From: Amir Goldstein @ 2026-12-05 22:08 UTC (permalink / raw)
To: koraynilay
Cc: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner, Shuah Khan, Randy Dunlap, Chuck Lever,
Jeff Layton, Jan Kara, Alexander Aring, Darrick J . Wong,
Andrey Albershteyn, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs
On Sat, Dec 5, 2026 at 3:25 PM koraynilay <koray.fra@gmail.com> wrote:
>
> Add FS_XFLAG_PROJID to the UAPI header and include it in
> FSX_FILEATTR_MASK so file_[gs]etattr() with AT_FILEATTR_MASKS can
> advertise, set and clear the project ID using masks, while keeping it
> out of FS_IOC_FS[GS]ETXATTR and non-AT_FILEATTR_MASKS callers.
>
> Add FSX_FSXATTR_SET_MASK to specify xflags that are settable by
> file_setattr with masks on non-masks filesystems. This macro is then
> used to validate input xflags in fileattr_set_from_masks().
>
> Signed-off-by: koraynilay <koray.fra@gmail.com>
> ---
> fs/file_attr.c | 32 ++++++++++++++++++++++++++------
> include/linux/fileattr.h | 12 +++++++++++-
> include/uapi/linux/fs.h | 6 ++++--
> 3 files changed, 41 insertions(+), 9 deletions(-)
>
> diff --git a/fs/file_attr.c b/fs/file_attr.c
> index 8b9785447e72..7bfd7651d1d8 100644
> --- a/fs/file_attr.c
> +++ b/fs/file_attr.c
> @@ -138,6 +138,8 @@ static void fileattr_to_file_attr(const struct file_kattr *fa,
> 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;
> }
>
> @@ -208,6 +210,13 @@ static int file_attr_to_fileattr(const struct file_attr *fattr,
> else
> fa->fsx_extsize = 0;
>
> + if (fa->fsx_xflags & FS_XFLAG_PROJID)
> + fa->fsx_projid = fattr->fa_projid;
> + else if ((rw_user_mask & FS_XFLAG_PROJID) && fattr->fa_projid)
> + return -EINVAL;
> + else
> + fa->fsx_projid = 0;
> +
> if (fa->fsx_xflags & FS_XFLAG_COWEXTSIZE)
> fa->fsx_cowextsize = fattr->fa_cowextsize;
> else if ((rw_user_mask & FS_XFLAG_COWEXTSIZE) && fattr->fa_cowextsize)
> @@ -290,8 +299,11 @@ static int fileattr_set_to_masks(struct file_kattr *fa,
> if (fa->fsx_extsize != old_ma->fsx_extsize)
> new_rw_mask |= new_xflags & FSX_EXTSIZE_MASK;
>
> - if (fa->fsx_projid != old_ma->fsx_projid)
> - return -EOPNOTSUPP;
> + if (fa->fsx_projid != old_ma->fsx_projid) {
> + new_rw_mask |= FS_XFLAG_PROJID;
> + if (fa->fsx_projid > 0)
> + new_xflags |= FS_XFLAG_PROJID;
Where did this > 0 come from
All other places including fileattr_fsx_ok() treat this as
if (fa->fsx_projid) or
if (fa->fsx_projid != 0)
if you want the uglier version of fileattr_has_fsx()
which I anyway suggested to convert to use fileattr_fsx_ok().
Other than this nit, nice readable patch, so:
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Thanks,
Amir.
> + }
>
> if ((new_xflags & FS_XFLAG_COWEXTSIZE) &&
> fa->fsx_cowextsize != old_ma->fsx_cowextsize)
> @@ -326,14 +338,14 @@ static int fileattr_set_from_masks(struct file_kattr *fa,
> u32 new_xflags = fa->fsx_xflags;
> u32 new_flags = 0;
>
> - if (rw_user_mask & ~(FSX_FSXATTR_MASK & ~FSX_RDONLY_MASK))
> + if (rw_user_mask & ~FSX_FSXATTR_SET_MASK)
> return -EOPNOTSUPP;
>
> /* Do RMW. */
> new_xflags |= old_ma->fsx_xflags & ~rw_user_mask;
>
> /* RMW filesystems only expect writable fsxattr xflags. */
> - new_xflags &= FSX_FSXATTR_MASK & ~FSX_RDONLY_MASK;
> + new_xflags &= FSX_FSXATTR_SET_MASK;
>
> new_flags = xflags_to_flags(new_xflags);
> new_flags |= old_ma->flags & ~FS_COMMON_FL;
> @@ -357,7 +369,12 @@ static int fileattr_set_from_masks(struct file_kattr *fa,
> }
> }
>
> - fa->fsx_projid = old_ma->fsx_projid;
> + if (!(rw_user_mask & FS_XFLAG_PROJID))
> + fa->fsx_projid = old_ma->fsx_projid;
> + else if (!(fa->fsx_xflags & FS_XFLAG_PROJID))
> + fa->fsx_projid = 0;
> + /* Strip PROJID now that we've used it, old format doesn't have it. */
> + new_xflags &= ~FS_XFLAG_PROJID;
>
> if (!(rw_user_mask & FS_XFLAG_COWEXTSIZE))
> fa->fsx_cowextsize = old_ma->fsx_cowextsize;
> @@ -443,7 +460,8 @@ static int fileattr_set_prepare(struct inode *inode,
> * namespace. Enforce that restriction only if we are trying to change
> * the quota ID state. Everything else is allowed in user namespaces.
> */
> - if (!fa->has_masks && old_ma->fsx_projid != fa->fsx_projid) {
> + if ((rw_user_mask & FS_XFLAG_PROJID) &&
> + old_ma->fsx_projid != fa->fsx_projid) {
> /* Caller is not allowed to change the project ID. */
> if (current_user_ns() != &init_user_ns)
> return -EINVAL;
> @@ -488,6 +506,8 @@ static int fileattr_set_prepare(struct inode *inode,
> fa->fsx_xflags &= ~FSX_EXTSIZE_MASK;
> if (fa->fsx_cowextsize == 0)
> fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE;
> + if (fa->fsx_projid == 0)
> + fa->fsx_xflags &= ~FS_XFLAG_PROJID;
>
> return 0;
> }
> diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
> index adb586e21fd5..8dcabbb294fa 100644
> --- a/include/linux/fileattr.h
> +++ b/include/linux/fileattr.h
> @@ -52,9 +52,19 @@
> (FSX_COMMON | FSX_RDONLY_MASK | FSX_VALUES_MASK | \
> FSX_DIRONLY_MASK | FSX_MISC_MASK)
>
> +/*
> + * Writable xflags for filesystems that don't support masks.
> + * The VFS converts masked requests to FS_IOC_FSSETXATTR format, which lacks
> + * FS_XFLAG_PROJID and uses only file_kattr.fsx_projid instead.
> + * Include FS_XFLAG_PROJID here so masked callers can use it to select project
> + * ID changes on unmasked filesystems.
> + */
> +#define FSX_FSXATTR_SET_MASK \
> + ((FSX_FSXATTR_MASK & ~FSX_RDONLY_MASK) | FS_XFLAG_PROJID)
> +
> /* All xflags supported by VER1+ file_[gs]etattr() with AT_FILEATTR_MASKS */
> #define FSX_FILEATTR_MASK \
> - (FSX_FSXATTR_MASK)
> + (FSX_FSXATTR_MASK | FS_XFLAG_PROJID)
>
> /*
> * Merged interface for miscellaneous file attributes. 'flags' originates from
> diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
> index d402db1a2254..337bb00b0e64 100644
> --- a/include/uapi/linux/fs.h
> +++ b/include/uapi/linux/fs.h
> @@ -236,8 +236,8 @@ struct fsxattr {
> * suggests a preferred extent size for new allocations. (in/out)
> * @fa_nextents: Number of data extents in the file, read-only. Filled in by
> * file_getattr(2) and ignored by file_setattr(2). (out)
> - * @fa_projid: Project identifier. Used by quota systems quotactl(2) to group
> - * related files. (in/out)
> + * @fa_projid: Project identifier, value of FS_XFLAG_PROJID. Used by quota
> + * systems quotactl(2) to group related files. (in/out)
> * @fa_cowextsize: Copy-on-Write (CoW) extent size hint in bytes, value of
> * FS_XFLAG_COWEXTSIZE. This value suggests a preferred extent
> * size for CoW operations. (in/out)
> @@ -294,6 +294,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.1.dirty
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v5 03/12] fs: move fileattr sizes out of uapi and factor out set_preserve()
2026-12-05 14:24 ` [PATCH v5 03/12] fs: move fileattr sizes out of uapi and factor out set_preserve() koraynilay
@ 2026-12-05 22:15 ` Amir Goldstein
0 siblings, 0 replies; 25+ messages in thread
From: Amir Goldstein @ 2026-12-05 22:15 UTC (permalink / raw)
To: koraynilay
Cc: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner, Shuah Khan, Randy Dunlap, Chuck Lever,
Jeff Layton, Jan Kara, Alexander Aring, Darrick J . Wong,
Andrey Albershteyn, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs
On Sat, Dec 5, 2026 at 3:24 PM koraynilay <koray.fra@gmail.com> wrote:
>
> Move FILE_ATTR_SIZE_* constants from the user-facing
> include/uapi/linux/fs.h to the internal include/linux/fileattr.h.
>
> Move old flags preservation from vfs_fileattr_set() to a dedicated
> helper in preparation for the addition of masks to the fileattr API.
This is a combination of two very random unrelated things so no.
Please move the move of flags to the definition of VER1 unless
you have a good reason otherwise.
>
> Signed-off-by: koraynilay <koray.fra@gmail.com>
> ---
> fs/file_attr.c | 26 +++++++++++++++++---------
> include/linux/fileattr.h | 4 ++++
> include/uapi/linux/fs.h | 3 ---
> 3 files changed, 21 insertions(+), 12 deletions(-)
>
> diff --git a/fs/file_attr.c b/fs/file_attr.c
> index cc1621d3b710..77e2f1bc22ad 100644
> --- a/fs/file_attr.c
> +++ b/fs/file_attr.c
> @@ -175,6 +175,22 @@ static int copy_fsxattr_from_user(struct file_kattr *fa,
> return 0;
> }
>
> +static void fileattr_set_preserve(struct file_kattr *fa,
> + const struct file_kattr *old_ma)
> +{
> + if (fa->flags_valid) {
> + /* FS_IOC_SETFLAGS */
> + fa->fsx_xflags |= old_ma->fsx_xflags & ~FSX_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 {
> + /* FS_IOC_FSSETXATTR or file_setattr */
> + fa->flags |= old_ma->flags & ~FS_COMMON_FL;
> + }
> +}
> +
Excellent way to make the code more readable and break into
understandable pieces but this non trivial helpers needs a comment to
explain what it does, similar to the not trivial comment that you added
above FSX_COMMON.
Thanks,
Amir.
> /*
> * Generic function to check FS_IOC_FSSETXATTR/FS_IOC_SETFLAGS values and reject
> * any invalid configurations.
> @@ -289,15 +305,7 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
> goto out;
>
> /* initialize missing bits from old_ma */
> - if (fa->flags_valid) {
> - fa->fsx_xflags |= old_ma.fsx_xflags & ~FSX_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;
> - }
> + fileattr_set_preserve(fa, &old_ma);
>
> err = fileattr_set_prepare(inode, &old_ma, fa);
> if (err)
> diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
> index 79371aa93a61..d9e89e171f3e 100644
> --- a/include/linux/fileattr.h
> +++ b/include/linux/fileattr.h
> @@ -3,6 +3,10 @@
> #ifndef _LINUX_FILEATTR_H
> #define _LINUX_FILEATTR_H
>
> +/* Version UAPI's struct file_attr based on size */
> +#define FILE_ATTR_SIZE_VER0 24
> +#define FILE_ATTR_SIZE_LATEST FILE_ATTR_SIZE_VER0
> +
> /*
> * FS_COMMON_FL/FSX_COMMON are preserved through an RMW cycle via either UAPI
> * flavor. They must NOT include flags that are read-write via one API flavor
> diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
> index a13c7b32a1bd..f77e2b929f6d 100644
> --- a/include/uapi/linux/fs.h
> +++ b/include/uapi/linux/fs.h
> @@ -240,9 +240,6 @@ struct file_attr {
> __u32 fa_cowextsize; /* CoW extsize field value (get/set) */
> };
>
> -#define FILE_ATTR_SIZE_VER0 24
> -#define FILE_ATTR_SIZE_LATEST FILE_ATTR_SIZE_VER0
> -
> /*
> * Flags for the fsx_xflags field
> */
> --
> 2.56.1.dirty
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v5 12/12] docs: add fileattr API documentation
2026-12-05 21:14 ` Amir Goldstein
@ 2026-12-05 22:24 ` koraynilay
0 siblings, 0 replies; 25+ messages in thread
From: koraynilay @ 2026-12-05 22:24 UTC (permalink / raw)
To: Amir Goldstein, koraynilay
Cc: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner, Shuah Khan, Randy Dunlap, Chuck Lever,
Jeff Layton, Jan Kara, Alexander Aring, Darrick J . Wong,
Andrey Albershteyn, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs
[-- Attachment #1: Type: text/plain, Size: 30218 bytes --]
On Sat Dec 5, 2026 at 10:14 PM CET, Amir Goldstein wrote:
> On Sat, Dec 5, 2026 at 3:25 PM koraynilay <koray.fra@gmail.com> wrote:
>>
>> Add documentation for the fileattr API.
>>
>> Signed-off-by: koraynilay <koray.fra@gmail.com>
>> ---
>> Documentation/filesystems/fileattr.rst | 465 +++++++++++++++++++++++++
>> Documentation/filesystems/index.rst | 1 +
>> Documentation/filesystems/vfs.rst | 19 +-
>> 3 files changed, 477 insertions(+), 8 deletions(-)
>> create mode 100644 Documentation/filesystems/fileattr.rst
>>
>> diff --git a/Documentation/filesystems/fileattr.rst b/Documentation/filesystems/fileattr.rst
>> new file mode 100644
>> index 000000000000..dc52edee0ecf
>> --- /dev/null
>> +++ b/Documentation/filesystems/fileattr.rst
>> @@ -0,0 +1,465 @@
>> +.. SPDX-License-Identifier: GPL-2.0
>> +
>> +============
>> +Fileattr API
>> +============
>> +
>> +Overview
>> +========
>> +
>> +The fileattr API provides a modern way to query and modify file attributes and
>> +it should be used instead of the older ``FS_IOC_[GS]ETFLAGS``
>> +(:manpage:`fs_ioc_getflags(2const)` / :manpage:`fs_ioc_setflags(2const)`) and
>> +``FS_IOC_FS[GS]ETXATTR`` (:manpage:`ioctl_xfs_fsgetxattr(2)` /
>> +:manpage:`ioctl_xfs_fssetxattr(2)`) ioctls.
>> +
>> +The "file attributes" that this document refers to are an overlap of the ones
>> +reported by :manpage:`statx(2)` in its ``stx_attributes`` field (e.g. immutable
>> +or append-only). Not to be confused with "Extended attributes", which are
>> +the ones managed by :manpage:`getxattr(2)` and :manpage:`setxattr(2)`.
>> +
>> +.. note::
>> + For usage by userspace, see :manpage:`file_getattr(2)`,
>> + :manpage:`file_setattr(2)` and :manpage:`file_attr(2type)`.
>> +
>> +Userspace API Summary
>> +=====================
>> +
>> +struct file_attr is versioned by size:
>> +
>> +- ``VER0``: The base structure, equivalent to struct fsxattr.
>> +- ``VER1``: Adds the ``fa_xflags_rw_mask`` and ``fa_xflags_ro_mask`` fields,
>> + see :ref:`Masks <masks>` for more details.
>> +
>> +.. kernel-doc:: include/uapi/linux/fs.h
>> + :identifiers: file_attr
>> +
>> +.. _fileattr_flags:
>> +
>> +Flag Reference
>> +==============
>> +
>> +This is the full list of currently implemented ``FS_XFLAG_*`` and ``FS_*_FL``
>> +flags.
>> +
>> +.. note::
>> + Each ``FLAG`` name in the Flag column corresponds to a ``FS_XFLAG_FLAG``
>> + and/or ``FS_FLAG_FL`` macro in ``include/uapi/linux/fs.h``.
>> +
>> + The ``Flag`` and ``XFlag`` columns show how each flag can be handled,
>> + respectively, through ``FS_IOC_[GS]ETFLAGS`` and
>> + ``FS_IOC_FS[GS]ETXATTR``/``file_[gs]etattr()``:
>> +
>> + - ``RW``: Read-write.
>> + - ``RW/M``: Read-write only with :ref:`masks <masks>`.
>> + - ``RO``: Read-only.
>> + - ``-``: Not supported by that API.
>> +
>> + Filesystem support may still vary.
>> +
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| Flag | XFlag | Flag | Description and Constraints |
>
> Flag |....| Flag |
>
> That's weird. Maybe | Attribute | ....
Ah, yeah, definitely.
> Also I wanted to say last time and forgot - might be good to add a Value column
> where fsx_projid and friends are documented (?)
Yeah, I agree, something like
| Attribute | XFlag | Flag | Value Field | Description and Contraints |
| IMMUTABLE | FS_XFL.. | FS_I.. | | .....
| PROJID | FS_XFL.. | - | fsx_projid | ....
so empty value (or maybe - as the other columns?) for no value field and
the name of the field if it has one.
Or would it be better just as X if it has a value field and empty (or -)
of it has none?
> Either way feel free to add
>
> Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Thanks, btw I forgot to update the live html, now it's updated:
https://koraynilay.neocities.org/vfs-masks/fileattr
Thanks,
koraynilay
> Thanks,
> Amir.
>
>> ++=======================+===========+======+==================================================+
>> +| ``IMMUTABLE`` | RW | RW | Inode cannot be modified. Requires |
>> +| | | | ``CAP_LINUX_IMMUTABLE``. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``APPEND`` | RW | RW | All writes append only. Requires |
>> +| | | | ``CAP_LINUX_IMMUTABLE``. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``SYNC`` | RW | RW | File writes are synchronous. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``NOATIME`` | RW | RW | Do not update inode access time (atime). |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``NODUMP`` | RW | RW | Exclude file from dump/backup utilities. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``DAX`` | RW | RW | Direct Access (DAX) I/O (regular files and |
>> +| | | | directories only); mutually exclusive with |
>> +| | | | ``FS_XFLAG_VERITY``. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``VERITY`` | RO | RO | fs-verity enabled, read-only (set via verity |
>> +| | | | ioctl). |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``CASEFOLD`` | RO | RW | Case-insensitive lookups. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``COMPR`` | RO | RW | Compressed file flag. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``ENCRYPT`` | RO | RO | Encrypted file flag (fscrypt). Read-only. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``PROJINHERIT`` | RW | RW | Inherit project ID on newly created files |
>> +| | | | (directories only). |
>> +| | | | Updates require ``init_user_ns``. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``PROJID`` | RW/M [#r]_| \- | Project ID value flag (``VER1``). |
>> +| | | | Updates require ``init_user_ns``. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``REALTIME`` | RW | \- | Realtime volume storage (XFS). |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``PREALLOC`` | RO | \- | File has preallocated extents (XFS). |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``RTINHERIT`` | RW | \- | Inherit realtime bit on newly created files |
>> +| | | | (directories only; XFS). |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``NOSYMLINKS`` | RW | \- | Disallow creation of symlinks (directories |
>> +| | | | only; XFS). |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``EXTSIZE`` | RW | \- | Extent size allocator hint (regular files only; |
>> +| | | | XFS). |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``EXTSZINHERIT`` | RW | \- | Inherit extent size allocator hint |
>> +| | | | (directories only; XFS). |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``NODEFRAG`` | RW | \- | Disable filesystem defragmentation for file |
>> +| | | | (XFS). |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``FILESTREAM`` | RW | \- | Enable filestream allocator (directories only; |
>> +| | | | XFS). |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``COWEXTSIZE`` | RW | \- | Copy-on-Write extent size allocator hint |
>> +| | | | (regular files and directories only; XFS). |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``CASENONPRESERVING`` | RO | \- | Case not preserved in directory lookups. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``HASATTR`` | RO | \- | Inode has extended attributes (XFS). |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``SECRM`` | \- | RW | Secure deletion. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``UNRM`` | \- | RW | Undelete. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``DIRTY`` | \- | RO | Dirty (reserved for compression). |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``COMPRBLK`` | \- | RO | One or more compressed clusters. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``NOCOMP`` | \- | RW | Don't compress. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``BTREE`` / | \- | RO | Btree format / hash-indexed directory. |
>> +| ``INDEX`` | | | |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``IMAGIC`` | \- | RO | AFS directory. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``JOURNAL_DATA`` | \- | RW | Journaled file data. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``NOTAIL`` | \- | RW | File tail should not be merged. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``DIRSYNC`` | \- | RW | Dirsync behaviour (directories only). |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``TOPDIR`` | \- | RW | Top of directory hierarchies. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``HUGE_FILE`` | \- | RO | File size/blocks use huge-file accounting |
>> +| | | | (ext4). |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``EXTENT`` | \- | RO | Inode uses extents (ext4). |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``EA_INODE`` | \- | RO | Inode used for large EA (ext4). |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``NOCOW`` | \- | RW | Do not CoW file. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +| ``INLINE_DATA`` | \- | RO | File data is stored inline in the inode. |
>> ++-----------------------+-----------+------+--------------------------------------------------+
>> +
>> +.. [#r] The project ID can also be changed with ``FS_IOC_FS[GS]ETXATTR`` (or
>> + ``file_[gs]etattr()`` without masks), by passing a modified ``fsx_projid``
>> + directly, because ``FS_XFLAG_PROJID`` was added in ``VER1``, while the
>> + ``fsx_projid`` field was available before that.
>> +
>> +.. _masks:
>> +
>> +Masks
>> +=====
>> +
>> +In ``VER1``, the fileattr API introduced the ``fa_xflags_rw_mask`` and
>> +``fa_xflags_ro_mask`` fields, to enable its usage without needing a
>> +Read-Modify-Write cycle like ``FS_IOC_SETFLAGS`` and ``FS_IOC_FSSETXATTR``
>> +require.
>> +
>> +To use this feature ``AT_FILEATTR_MASKS`` needs to be set in the ``at_flags``
>> +argument of file_getattr() / file_setattr(), otherwise the normal behaviour is kept.
>> +
>> +.. note::
>> + For filesystems that don't support masks (and for userspace without
>> + ``AT_FILEATTR_MASKS``), conversion between the two formats on set is handled
>> + by the VFS as described :ref:`below <conversion>`.
>> +
>> +On file_getattr()
>> +-----------------
>> +
>> +- If the filesystem supports mask reporting, file_getattr() populates
>> + ``fa_xflags_rw_mask`` with all xflags it supports modifying on this inode,
>> + and ``fa_xflags_ro_mask`` with all read-only xflags it supports reporting.
>> +- If the filesystem does not support masks, file_getattr() sets to ``0``
>> + both ``fa_xflags_rw_mask`` and ``fa_xflags_ro_mask``.
>> +
>> +.. caution::
>> +
>> + Passing the result of file_getattr() directly into file_setattr()
>> + like this (e.g. in backup/sync workloads)::
>> +
>> + file_getattr(file1, &fa, ..., AT_FILEATTR_MASKS);
>> + file_setattr(file2, &fa, ..., AT_FILEATTR_MASKS);
>> +
>> + is a change of behaviour compared to the unmasked APIs, where unsupported
>> + flags were often silently dropped:
>> +
>> + - on filesystems without mask support, file_getattr() returns
>> + ``fa_xflags_rw_mask = 0``, causing file_setattr() to fail with
>> + ``-EINVAL``;
>> + - on filesystems with mask support, file_getattr() returns all supported
>> + writable xflags in ``fa_xflags_rw_mask``, so file_setattr() tries to set
>> + all of them on ``file2`` and fails with ``-EOPNOTSUPP`` if ``file2``
>> + doesn't support all of them, instead of silently dropping them.
>> +
>> + With masks, the program can inspect ``file2``'s masks first and decide how
>> + to handle unsupported flags.
>> +
>> +On file_setattr()
>> +-----------------
>> +
>> +- Userspace populates ``fa_xflags_rw_mask`` with the xflags it wishes to
>> + change. If ``fa_xflags_rw_mask`` is ``0``, the request fails with
>> + ``-EINVAL``.
>> +- Any valid flag outside ``fa_xflags_rw_mask`` is ignored and left unmodified.
>> +- For boolean attributes:
>> +
>> + - Setting the xflag bit in both ``fa_xflags_rw_mask`` and ``fa_xflags``
>> + enables the feature.
>> + - Setting the xflag bit in ``fa_xflags_rw_mask`` and clearing the bit in
>> + ``fa_xflags`` disables the feature.
>> +
>> +- For value attributes (like ``FS_XFLAG_PROJID`` and ``FS_XFLAG_COWEXTSIZE``):
>> +
>> + - Setting the flag bit in both ``fa_xflags_rw_mask`` and ``fa_xflags`` sets
>> + the attribute, taking the value from the corresponding field in the struct.
>> + - Setting the flag bit in ``fa_xflags_rw_mask``, clearing the bit in
>> + ``fa_xflags`` and setting the field value to ``0`` unsets/clears the
>> + attribute. If instead the field value is left non-zero, the request fails
>> + with ``-EINVAL``.
>> +
>> +- Validation:
>> +
>> + - If the filesystem supports masks, requesting modification of any flag not
>> + advertised in the filesystem's writable mask fails with ``-EOPNOTSUPP``.
>> + - If the filesystem does not support masks, requesting modification of any
>> + flag outside ``FSX_FSXATTR_SET_MASK`` fails with ``-EOPNOTSUPP``.
>> +
>> +Usage Examples
>> +--------------
>> +
>> +See :manpage:`file_setattr(2)` for examples.
>> +
>> +Behaviour without ``AT_FILEATTR_MASKS``
>> +=======================================
>> +
>> +When not using ``AT_FILEATTR_MASKS``, file_getattr() and file_setattr() behave
>> +in the same way as ``FS_IOC_FSGETXATTR`` and ``FS_IOC_FSSETXATTR``
>> +respectively.
>> +
>> +In-Kernel Filesystem Interface
>> +==============================
>> +
>> +Filesystem Operations
>> +---------------------
>> +
>> +Filesystems wanting to implement this API, need to set the ``fileattr_get`` and
>> +``fileattr_set`` functions in ``struct inode_operations``:
>> +
>> +.. code-block:: c
>> +
>> + struct inode_operations {
>> + ...
>> + int (*fileattr_get)(struct dentry *dentry, struct file_kattr *fa);
>> + int (*fileattr_set)(const struct mnt_idmap *idmap, struct dentry *dentry,
>> + struct file_kattr *fa);
>> + ...
>> + };
>> +
>> +Internal Structure: struct file_kattr
>> +-------------------------------------
>> +
>> +Defined in ``<linux/fileattr.h>``:
>> +
>> +.. code-block:: c
>> +
>> + struct file_kattr {
>> + u32 flags; /* FS_*_FL legacy flags */
>> + u32 fsx_xflags; /* FS_XFLAG_* modern flags */
>> + u32 fsx_xflags_rw_mask; /* Supported writable flags (get) / flags to set (set) */
>> + u32 fsx_xflags_ro_mask; /* Supported read-only flags (get) */
>> + u32 fsx_extsize; /* Extent size hint */
>> + u32 fsx_nextents; /* Extent count */
>> + u32 fsx_projid; /* Project ID */
>> + u32 fsx_cowextsize; /* CoW extent size hint */
>> + bool flags_valid:1; /* Legacy flags valid */
>> + bool fsx_valid:1; /* Modern xflags valid */
>> + bool has_masks:1; /* Struct has valid masks */
>> + bool use_masks:1; /* In-kernel callers need to set this to use masks (set) */
>> + bool get_only_masks:1; /* Transitional: fs supports ro_mask on get, but wants an unmasked request on set */
>> + };
>> +
>> +Fields of struct file_kattr have the same semantics as their user-facing
>> +counterparts in struct file_attr above.
>> +In addition, struct file_kattr has:
>> +
>> +``flags``
>> + Bit mask of the ``FS_*_FL`` flags, used by ``FS_IOC_GETFLAGS`` and ``FS_IOC_SETFLAGS``.
>> +
>> +``flags_valid`` / ``fsx_valid``
>> + - get: hints from the caller indicating which attributes it intends
>> + to read, both may be ``true``.
>> + - set: indicates which attributes were filled by the caller (``flags`` vs.
>> + ``fsx_xflags``/``fsx_*``). Syscalls/ioctls only set one, in-kernel
>> + callers reusing the result of a ``->fileattr_get()`` may pass both.
>> + Masked requests always have ``fsx_valid = true`` and
>> + ``flags_valid = false``.
>> +
>> +``has_masks``
>> + Indicates whether ``fsx_xflags_rw_mask`` and ``fsx_xflags_ro_mask`` contain
>> + valid masks.
>> +
>> +``use_masks``
>> + Indicates whether the set request uses mask semantics (the in-kernel
>> + equivalent of ``AT_FILEATTR_MASKS``).
>> +
>> +``get_only_masks``
>> + Transitional flag indicating that the filesystem supports
>> + ``fsx_xflags_ro_mask`` on get, but still expects unmasked input in
>> + ``->fileattr_set()``. If a filesystem wants to accept masks on set it
>> + **must** make sure all of its writable ``FS_*_FL`` flags have
>> + ``FS_XFLAG_*`` counterparts, otherwise ``FS_IOC_SETFLAGS`` will fail when
>> + setting a flag without an xflag counterpart.
>> +
>> +Filesystem Contract for Masks
>> +-----------------------------
>> +
>> +When a filesystem accepts masks on ``->fileattr_set()``:
>> +
>> +- ``fsx_xflags_rw_mask`` is validated by the VFS against the ``rw_mask``
>> + returned by ``->fileattr_get()``, and ``fsx_xflags`` is clamped to only
>> + contain bits within ``fsx_xflags_rw_mask``.
>> +- For ``AT_FILEATTR_MASKS`` calls, ``fsx_*`` value fields are ``0`` unless
>> + enabled in ``fsx_xflags``; for unmasked calls converted by
>> + fileattr_set_to_masks(), unchanged ``fsx_*`` fields are preserved (except for
>> + ``FS_IOC_SETFLAGS``, where they remain ``0``, but in that case they also
>> + won't be in ``fsx_xflags_rw_mask``).
>> +- After validation and (if necessary) conversion, the VFS passes the resulting
>> + struct file_kattr to ``->fileattr_set()`` with ``has_masks = true``,
>> + ``fsx_valid = true``, and ``flags_valid = false``.
>> +- The filesystem should validate the request with fileattr_fsx_masks_ok()
>> + and must modify **only** the attributes selected in ``fsx_xflags_rw_mask``.
>> +
>> +VFS Helpers
>> +-----------
>> +
>> +When implementing ``->fileattr_get()``, filesystems can populate struct
>> +file_kattr using either fileattr_fill_xflags() or fileattr_fill_flags()::
>> +
>> + void fileattr_fill_xflags(struct file_kattr *fa, u32 xflags);
>> +
>> + void fileattr_fill_flags(struct file_kattr *fa, u32 flags);
>> +
>> +This way filesystems can handle flags internally either as ``FS_*_FL`` flags or
>> +``FS_XFLAG_*`` xflags and let VFS translate the common ones (defined in
>> +``FS_COMMON_FL`` / ``FSX_COMMON``).
>> +
>> +New and mask-aware drivers should use fileattr_fill_xflags() and set
>> +``fa->has_masks = true`` along with their supported masks, while
>> +``FS_*_FL``-only drivers use fileattr_fill_flags().
>> +
>> +Drivers that only support ``FS_*_FL`` flags can check for unsupported
>> +xflags in ``->fileattr_set()`` using fileattr_has_fsx(). Drivers using
>> +``FS_XFLAG_*`` can validate supported xflags and values with
>> +fileattr_fsx_ok() or against allowed masks with fileattr_fsx_masks_ok()::
>> +
>> + bool fileattr_has_fsx(const struct file_kattr *fa);
>> +
>> + bool fileattr_fsx_ok(const struct file_kattr *fa, const u32 supported);
>> +
>> + bool fileattr_fsx_masks_ok(const struct file_kattr *fa,
>> + const u32 allowed_rw,
>> + const u32 allowed_ro);
>> +
>> +See :ref:`Flag Reference <fileattr_flags>` for the ``FS_*_FL`` to
>> +``FS_XFLAG_*`` translation mapping.
>> +
>> +.. _conversion:
>> +
>> +VFS Conversion Helpers
>> +----------------------
>> +
>> +With fileattr_set_convert(), the VFS bridges differing caller and driver
>> +capabilities automatically using the inode's current attributes retrieved via
>> +vfs_fileattr_get():
>> +
>> +- fileattr_set_to_masks(): Converts non-masked requests (``FS_IOC_SETFLAGS``,
>> + ``FS_IOC_FSSETXATTR``, file_setattr() without ``AT_FILEATTR_MASKS``, or
>> + in-kernel callers with ``use_masks = false``) to a masked request when
>> + targeting a filesystem that accepts masks on set.
>> +- fileattr_set_from_masks(): Converts masked requests (file_setattr() with
>> + ``AT_FILEATTR_MASKS``) to unmasked format when targeting a
>> + filesystem that doesn't accept masks on set.
>> +- flags_to_xflags() / xflags_to_flags(): Convert between ``FS_XFLAG_*`` xflags
>> + and ``FS_*_FL`` flags.
>> +
>> +Adding New Flags
>> +----------------
>> +
>> +When adding new xflags or value attributes:
>> +
>> +- New flags should target the ``VER1+`` syscall API (``FSX_FILEATTR_MASK``)
>> + only, keeping ``FSX_FSXATTR_MASK`` and ``FSX_RDONLY_MASK`` frozen except
>> + when exposing xflag counterparts for existing ``FS_*_FL`` flags.
>> +- When adding a ``FS_XFLAG_*`` counterpart to a ``FS_*_FL`` flag, add it to
>> + ``FSX_COMMON`` / ``FS_COMMON_FL`` only if it has the same read-only /
>> + read-write behaviour across both ``FS_IOC_SETFLAGS`` and the xflags APIs
>> + [#excomm]_, add the counterpart to the :ref:`table above <fileattr_flags>`
>> + and move the line up so it's grouped with the other flags with counterparts.
>> +- Filesystems that only want to report new read-only flags on get without
>> + converting ``->fileattr_set()`` to masks have to change their
>> + ``->fileattr_get()`` so that it:
>> +
>> + - sets ``has_masks = true``,
>> + - sets ``get_only_masks = true``,
>> + - sets the xflag bit(s) they want to report as read-only in
>> + ``fsx_xflags_ro_mask``.
>> +
>> +.. [#excomm] For example ``FS_XFLAG_CASEFOLD`` and ``FS_XFLAG_COMPR``, which
>> + are writable via ``FS_IOC_SETFLAGS`` but read-only in xflags, must not be
>> + added to ``FSX_COMMON``.
>> +
>> +Mask-Aware Driver Example
>> +-------------------------
>> +
>> +An example of a filesystem that supports masks can be found in ``fs/ntfs/file.c``.
>> +
>> +Locking
>> +-------
>> +
>> +- vfs_fileattr_set() takes inode_lock(), so no external locking is required.
>> +
>> +Permissions
>> +-----------
>> +
>> +- Inode ownership or ``CAP_FOWNER`` in the owning user namespace is required.
>> +- Modifying ``FS_XFLAG_IMMUTABLE`` or ``FS_XFLAG_APPEND`` requires
>> + ``CAP_LINUX_IMMUTABLE`` in the initial user namespace.
>> +- Modifying ``FS_XFLAG_PROJID`` (when ``fsx_projid`` changes) or
>> + ``FS_XFLAG_PROJINHERIT`` requires the caller to reside in the initial user
>> + namespace.
>> +
>> +Error Codes
>> +===========
>> +
>> +``-EINVAL``
>> + Invalid structure size, ``AT_FILEATTR_MASKS`` passed with non-mask struct,
>> + ``AT_FILEATTR_MASKS`` passed to file_setattr() with ``fa_xflags_rw_mask = 0``,
>> + non-zero masks passed to file_setattr() without ``AT_FILEATTR_MASKS``,
>> + unknown flags in ``at_flags``, unknown bits in ``fa_xflags`` or
>> + ``fa_xflags_rw_mask``, invalid inode type for the specified xflags,
>> + incompatible attribute combinations (e.g. DAX on fs-verity), invalid
>> + project ID or changing ``FS_XFLAG_PROJID`` / ``FS_XFLAG_PROJINHERIT``
>> + outside the host namespace, specifying xflags added in or after ``VER1``
>> + without ``AT_FILEATTR_MASKS``, or clearing a value attribute with a
>> + non-zero field value.
>> +
>> +``-EOPNOTSUPP``
>> + The filesystem does not implement ``fileattr`` operations for this inode,
>> + or userspace requested modification of an attribute not writable by the
>> + filesystem.
>> diff --git a/Documentation/filesystems/index.rst b/Documentation/filesystems/index.rst
>> index a556084c8858..71a1ae852e5b 100644
>> --- a/Documentation/filesystems/index.rst
>> +++ b/Documentation/filesystems/index.rst
>> @@ -28,6 +28,7 @@ algorithms work.
>> dnotify
>> fiemap
>> files
>> + fileattr
>> locks
>> mmap_prepare
>> multigrain-ts
>> diff --git a/Documentation/filesystems/vfs.rst b/Documentation/filesystems/vfs.rst
>> index 9ab182dbbd73..01fddb2dacf3 100644
>> --- a/Documentation/filesystems/vfs.rst
>> +++ b/Documentation/filesystems/vfs.rst
>> @@ -621,16 +621,19 @@ otherwise noted.
>> the end.
>>
>> ``fileattr_get``
>> - called on ioctl(FS_IOC_GETFLAGS) and ioctl(FS_IOC_FSGETXATTR) to
>> - retrieve miscellaneous file flags and attributes. Also called
>> - before the relevant SET operation to check what is being changed
>> - (in this case with i_rwsem locked exclusive). If unset, then
>> - fall back to f_op->ioctl().
>> + called on ioctl(FS_IOC_GETFLAGS), ioctl(FS_IOC_FSGETXATTR) and
>> + file_getattr(2) to retrieve miscellaneous file flags and attributes
>> + (see Documentation/filesystems/fileattr.rst). Also called before the
>> + relevant SET operation to check what is being changed (in this case
>> + with i_rwsem locked exclusive). If unset, then fall back to
>> + f_op->ioctl().
>>
>> ``fileattr_set``
>> - called on ioctl(FS_IOC_SETFLAGS) and ioctl(FS_IOC_FSSETXATTR) to
>> - change miscellaneous file flags and attributes. Callers hold
>> - i_rwsem exclusive. If unset, then fall back to f_op->ioctl().
>> + called on ioctl(FS_IOC_SETFLAGS), ioctl(FS_IOC_FSSETXATTR) and
>> + file_setattr(2) to change miscellaneous file flags and attributes (see
>> + Documentation/filesystems/fileattr.rst). Callers hold i_rwsem
>> + exclusive. If unset, then fall back to f_op->ioctl().
>> +
>> ``get_offset_ctx``
>> called to get the offset context for a directory inode. A
>> filesystem must define this operation to use
>> --
>> 2.56.1.dirty
>>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v5 02/12] fs,overlayfs: rename FS_XFLAGS_MASK and shorten other internal macro names
2026-12-05 20:09 ` Amir Goldstein
@ 2026-12-05 22:42 ` koraynilay
0 siblings, 0 replies; 25+ messages in thread
From: koraynilay @ 2026-12-05 22:42 UTC (permalink / raw)
To: Amir Goldstein, koraynilay
Cc: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
Christian Brauner, Shuah Khan, Randy Dunlap, Chuck Lever,
Jeff Layton, Jan Kara, Alexander Aring, Darrick J . Wong,
Andrey Albershteyn, Miklos Szeredi, Pali Rohár, Lauri Gates,
Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
linux-doc, linux-unionfs
[-- Attachment #1: Type: text/plain, Size: 9452 bytes --]
On Sat Dec 5, 2026 at 9:09 PM CET, Amir Goldstein wrote:
> On Sat, Dec 5, 2026 at 3:24 PM koraynilay <koray.fra@gmail.com> wrote:
>>
>> Rename FS_XFLAGS_MASK to FSX_FSXATTR_MASK and make the internal xflags
>> collection macros' names shorter so the code that uses them can be
>> cleaner and more readable.
>>
>> Add an explanatory comment for FS_COMMON_FL/FSX_COMMON, FSX_RDONLY_MASK
>> and FSX_FSXATTR_MASK, so it's clearer which xflags they include.
>>
>> Also add FSX_EXTSIZE_MASK to avoid long lines caused only by OR'ing
>> FS_XFLAG_EXTSIZE and FS_XFLAG_EXTSZINHERIT.
>>
>> Don't touch the names of the actual xflags macros as those are exposed
>> to userspace so they can't be easily changed.
>>
>> Signed-off-by: koraynilay <koray.fra@gmail.com>
>> ---
>>
>> Sorry, dropped Reviewed-by: Amir Goldstein <amir73il@gmail.com> because
>> I added FSX_EXTSIZE_MASK.
>> (Wasn't sure if I could keep it or not)
>
> As long as you say what you change the re-review is easy so now
> may restore my RVB thanks.
Ok thanks.
> One comment though
>
> fs,overlayfs: rename FS_XFLAGS_MASK...
>
> lose the ",overlayfs" prefix please - it's out of context and
> a very robotic thing to do.
>
> The commit message is NOT a list of changed subsystem
>
> THIS is an fs: change. As such it can affect several filesystems
> it happens to affect only one (overlayfs)
Ah ok, yeah that makes sense.
Thanks,
koraynilay
> Thanks,
> Amir.
>
>>
>> Thanks.
>>
>> fs/file_attr.c | 16 ++++++++--------
>> fs/overlayfs/copy_up.c | 2 +-
>> fs/overlayfs/inode.c | 2 +-
>> include/linux/fileattr.h | 34 +++++++++++++++++++++++-----------
>> 4 files changed, 33 insertions(+), 21 deletions(-)
>>
>> diff --git a/fs/file_attr.c b/fs/file_attr.c
>> index 0f2975c9b7bc..cc1621d3b710 100644
>> --- a/fs/file_attr.c
>> +++ b/fs/file_attr.c
>> @@ -102,7 +102,7 @@ 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;
>> + __u32 mask = FSX_FSXATTR_MASK;
>>
>> memset(fattr, 0, sizeof(struct file_attr));
>> fattr->fa_xflags = fa->fsx_xflags & mask;
>> @@ -122,7 +122,7 @@ static void fileattr_to_file_attr(const struct file_kattr *fa,
>> int copy_fsxattr_to_user(const struct file_kattr *fa, struct fsxattr __user *ufa)
>> {
>> struct fsxattr xfa;
>> - __u32 mask = FS_XFLAGS_MASK;
>> + __u32 mask = FSX_FSXATTR_MASK;
>>
>> memset(&xfa, 0, sizeof(xfa));
>> xfa.fsx_xflags = fa->fsx_xflags & mask;
>> @@ -141,12 +141,12 @@ 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 mask = FSX_FSXATTR_MASK;
>>
>> if (fattr->fa_xflags & ~mask)
>> return -EINVAL;
>>
>> - fileattr_fill_xflags(fa, fattr->fa_xflags & ~FS_XFLAG_RDONLY_MASK);
>> + fileattr_fill_xflags(fa, fattr->fa_xflags & ~FSX_RDONLY_MASK);
>> fa->fsx_extsize = fattr->fa_extsize;
>> fa->fsx_projid = fattr->fa_projid;
>> fa->fsx_cowextsize = fattr->fa_cowextsize;
>> @@ -158,7 +158,7 @@ static int copy_fsxattr_from_user(struct file_kattr *fa,
>> struct fsxattr __user *ufa)
>> {
>> struct fsxattr xfa;
>> - __u32 mask = FS_XFLAGS_MASK;
>> + __u32 mask = FSX_FSXATTR_MASK;
>>
>> if (copy_from_user(&xfa, ufa, sizeof(xfa)))
>> return -EFAULT;
>> @@ -166,7 +166,7 @@ static int copy_fsxattr_from_user(struct file_kattr *fa,
>> if (xfa.fsx_xflags & ~mask)
>> return -EOPNOTSUPP;
>>
>> - fileattr_fill_xflags(fa, xfa.fsx_xflags & ~FS_XFLAG_RDONLY_MASK);
>> + fileattr_fill_xflags(fa, xfa.fsx_xflags & ~FSX_RDONLY_MASK);
>> fa->fsx_extsize = xfa.fsx_extsize;
>> fa->fsx_nextents = xfa.fsx_nextents;
>> fa->fsx_projid = xfa.fsx_projid;
>> @@ -247,7 +247,7 @@ static int fileattr_set_prepare(struct inode *inode,
>>
>> /* Extent size hints of zero turn off the flags. */
>> if (fa->fsx_extsize == 0)
>> - fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT);
>> + fa->fsx_xflags &= ~FSX_EXTSIZE_MASK;
>> if (fa->fsx_cowextsize == 0)
>> fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE;
>>
>> @@ -290,7 +290,7 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
>>
>> /* initialize missing bits from old_ma */
>> if (fa->flags_valid) {
>> - fa->fsx_xflags |= old_ma.fsx_xflags & ~FS_XFLAG_COMMON;
>> + fa->fsx_xflags |= old_ma.fsx_xflags & ~FSX_COMMON;
>> fa->fsx_extsize = old_ma.fsx_extsize;
>> fa->fsx_nextents = old_ma.fsx_nextents;
>> fa->fsx_projid = old_ma.fsx_projid;
>> diff --git a/fs/overlayfs/copy_up.c b/fs/overlayfs/copy_up.c
>> index c147ad155b79..20f369863faf 100644
>> --- a/fs/overlayfs/copy_up.c
>> +++ b/fs/overlayfs/copy_up.c
>> @@ -220,7 +220,7 @@ static int ovl_copy_fileattr(struct inode *inode, const struct path *old,
>> newfa.flags &= ~OVL_COPY_FS_FLAGS_MASK;
>> newfa.flags |= (oldfa.flags & OVL_COPY_FS_FLAGS_MASK);
>>
>> - BUILD_BUG_ON(OVL_COPY_FSX_FLAGS_MASK & ~FS_XFLAG_COMMON);
>> + BUILD_BUG_ON(OVL_COPY_FSX_FLAGS_MASK & ~FSX_COMMON);
>> newfa.fsx_xflags &= ~OVL_COPY_FSX_FLAGS_MASK;
>> newfa.fsx_xflags |= (oldfa.fsx_xflags & OVL_COPY_FSX_FLAGS_MASK);
>>
>> diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
>> index f1c6df39d0ae..92df4f5c071e 100644
>> --- a/fs/overlayfs/inode.c
>> +++ b/fs/overlayfs/inode.c
>> @@ -709,7 +709,7 @@ int ovl_fileattr_set(const struct mnt_idmap *idmap,
>> static void ovl_fileattr_prot_flags(struct inode *inode, struct file_kattr *fa)
>> {
>> BUILD_BUG_ON(OVL_PROT_FS_FLAGS_MASK & ~FS_COMMON_FL);
>> - BUILD_BUG_ON(OVL_PROT_FSX_FLAGS_MASK & ~FS_XFLAG_COMMON);
>> + BUILD_BUG_ON(OVL_PROT_FSX_FLAGS_MASK & ~FSX_COMMON);
>>
>> if (inode->i_flags & S_APPEND) {
>> fa->flags |= FS_APPEND_FL;
>> diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
>> index 09e32b84e02a..79371aa93a61 100644
>> --- a/include/linux/fileattr.h
>> +++ b/include/linux/fileattr.h
>> @@ -3,37 +3,49 @@
>> #ifndef _LINUX_FILEATTR_H
>> #define _LINUX_FILEATTR_H
>>
>> -/* Flags shared betwen flags/xflags */
>> +/*
>> + * FS_COMMON_FL/FSX_COMMON are preserved through an RMW cycle via either UAPI
>> + * flavor. They must NOT include flags that are read-write via one API flavor
>> + * and read-only in another (e.g. CASEFOLD).
>> + */
>> #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)
>>
>> -#define FS_XFLAG_COMMON \
>> +#define FSX_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)
>>
>> -/* Read-only inode flags */
>> -#define FS_XFLAG_RDONLY_MASK \
>> +/*
>> + * Read-only xflags via FS_IOC_FS[GS]ETXATTR and file_[gs]etattr().
>> + * The respective flags may still be read-write via FS_IOC_SETFLAGS.
>> + */
>> +#define FSX_RDONLY_MASK \
>> (FS_XFLAG_PREALLOC | FS_XFLAG_HASATTR | FS_XFLAG_VERITY | \
>> FS_XFLAG_CASEFOLD | FS_XFLAG_CASENONPRESERVING)
>>
>> /* Flags to indicate valid value of fsx_ fields */
>> -#define FS_XFLAG_VALUES_MASK \
>> +#define FSX_VALUES_MASK \
>> (FS_XFLAG_EXTSIZE | FS_XFLAG_COWEXTSIZE)
>>
>> /* Flags for directories */
>> -#define FS_XFLAG_DIRONLY_MASK \
>> +#define FSX_DIRONLY_MASK \
>> (FS_XFLAG_RTINHERIT | FS_XFLAG_NOSYMLINKS | FS_XFLAG_EXTSZINHERIT)
>>
>> /* Misc settable flags */
>> -#define FS_XFLAG_MISC_MASK \
>> +#define FSX_MISC_MASK \
>> (FS_XFLAG_REALTIME | FS_XFLAG_NODEFRAG | FS_XFLAG_FILESTREAM)
>>
>> -#define FS_XFLAGS_MASK \
>> - (FS_XFLAG_COMMON | FS_XFLAG_RDONLY_MASK | FS_XFLAG_VALUES_MASK | \
>> - FS_XFLAG_DIRONLY_MASK | FS_XFLAG_MISC_MASK)
>> +/* Flags for fa/fsx_extsize value fields */
>> +#define FSX_EXTSIZE_MASK \
>> + (FS_XFLAG_EXTSIZE | FS_XFLAG_EXTSZINHERIT)
>> +
>> +/* Flags supported by FS_IOC_FS[GS]ETXATTR and file_[gs]etattr() */
>> +#define FSX_FSXATTR_MASK \
>> + (FSX_COMMON | FSX_RDONLY_MASK | FSX_VALUES_MASK | \
>> + FSX_DIRONLY_MASK | FSX_MISC_MASK)
>>
>> /*
>> * Merged interface for miscellaneous file attributes. 'flags' originates from
>> @@ -69,7 +81,7 @@ void fileattr_fill_flags(struct file_kattr *fa, u32 flags);
>> static inline bool fileattr_has_fsx(const struct file_kattr *fa)
>> {
>> return fa->fsx_valid &&
>> - ((fa->fsx_xflags & ~FS_XFLAG_COMMON) || fa->fsx_extsize != 0 ||
>> + ((fa->fsx_xflags & ~FSX_COMMON) || fa->fsx_extsize != 0 ||
>> fa->fsx_projid != 0 || fa->fsx_cowextsize != 0);
>> }
>>
>> --
>> 2.56.1.dirty
>>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2026-12-05 22:42 UTC | newest]
Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 14:23 [PATCH v5 00/12] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay
2026-12-05 14:24 ` [PATCH v5 01/12] fs: use goto out on error in vfs_fileattr_set() koraynilay
2026-12-05 14:24 ` [PATCH v5 02/12] fs,overlayfs: rename FS_XFLAGS_MASK and shorten other internal macro names koraynilay
2026-12-05 20:09 ` Amir Goldstein
2026-12-05 22:42 ` koraynilay
2026-12-05 14:24 ` [PATCH v5 03/12] fs: move fileattr sizes out of uapi and factor out set_preserve() koraynilay
2026-12-05 22:15 ` Amir Goldstein
2026-12-05 14:24 ` [PATCH v5 04/12] fs: switch fileattr_set_prepare() to xflags and refactor projid check koraynilay
2026-12-05 14:24 ` [PATCH v5 05/12] fs: add initial implementation of xflags masks to fileattr API koraynilay
2026-12-05 14:24 ` [PATCH v5 06/12] fs: add UAPI " koraynilay
2026-12-05 14:24 ` [PATCH v5 07/12] fs: add missing FS_XFLAG_PROJID xflag koraynilay
2026-12-05 22:08 ` Amir Goldstein
2026-12-05 14:24 ` [PATCH v5 08/12] fs,overlayfs: add fileattr masks support on get koraynilay
2026-12-05 21:42 ` Amir Goldstein
2026-12-05 14:24 ` [PATCH v5 09/12] fs,ntfs: advertise COMPR/ENCRYPT xflags in file_getattr() koraynilay
2026-12-05 20:21 ` Amir Goldstein
2026-12-05 20:41 ` Amir Goldstein
2026-12-05 14:24 ` [PATCH v5 10/12] ntfs: switch from flags to xflags in ntfs_fileattr_get/set() koraynilay
2026-12-05 20:25 ` Amir Goldstein
2026-12-05 21:31 ` Amir Goldstein
2026-12-05 14:24 ` [PATCH v5 11/12] ntfs: support the fileattr API masks " koraynilay
2026-12-05 21:15 ` Amir Goldstein
2026-12-05 14:24 ` [PATCH v5 12/12] docs: add fileattr API documentation koraynilay
2026-12-05 21:14 ` Amir Goldstein
2026-12-05 22:24 ` koraynilay
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.