Re: [PATCH v3 5/5] docs: add fileattr API documentation

From: Amir Goldstein

Date: Sun Nov 29 2026 - 17:11:30 EST


On Sun, Nov 29, 2026 at 3:19 PM koraynilay <koray.fra@xxxxxxxxx> wrote:
>
> On Sun Nov 29, 2026 at 12:32 PM CET, Amir Goldstein wrote:
> > On Sun, Nov 29, 2026 at 3:43 AM koraynilay <koray.fra@xxxxxxxxx> wrote:
> >>
> >> Add documentation for the fileattr API.
> >>
> >> Signed-off-by: koraynilay <koray.fra@xxxxxxxxx>
> >> ---
> >> Documentation/filesystems/fileattr.rst | 530 +++++++++++++++++++++++++
> >> Documentation/filesystems/index.rst | 1 +
> >> Documentation/filesystems/vfs.rst | 19 +-
> >> include/uapi/linux/fs.h | 28 +-
> >> 4 files changed, 568 insertions(+), 10 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..9e3515dc4517
> >> --- /dev/null
> >> +++ b/Documentation/filesystems/fileattr.rst
> >> @@ -0,0 +1,530 @@
> >> +.. SPDX-License-Identifier: GPL-2.0
> >> +
> >> +============
> >> +Fileattr API
> >> +============
> >> +
> >> +Overview
> >> +========
> >> +
> >> +The fileattr API provides a modern way (instead of the older
> >> +``FS_IOC_[GS]ETFLAGS`` and ``FS_IOC_FS[GS]ETXATTR`` ioctls) to query and modify inode
> >> +flags (like immutable and append-only).
> >> +
> >
> > This is nice!
> > Much easier to review the UAPI this way.
> >
> > I would add something about the terminology "file attributes" which was a source
> > of confusion and bikeshedding and the relation to other UAPIs:
> >
> > The "file attributes" that this document refers to are structured file
> > attributes
> > much like the inode information advertised by stat(2) and statx(2).
> > statx(2) even advertises some of the file attributes described in this document:
> > File attributes
> > The stx_attributes field contains a set of ORed flags that
> > indicate additional attributes of the file.
>
> Yes, I used "inode flags" because "file attributes" was used for a bunch
> of other things too (even tho the API is "fileattr").
>
> > The file attributes described in this document could be described as an
> > extension to the standard inode attributes of a POSIX filesystem inode.
> > However, "extended attributes" terminology is already used for describing
> > the unstructured string key/blob value inode attributes of the
> > [gs]etxattr() api,
> > which are something completely different.
>
> I hadn't checked statx(2) but since it does report the same ones, I'll
> switch the terminology to just "file attributes" in the doc, maybe
> adding a clarification at the start (like the
> >> (like immutable and append-only).
> I already have) like the one you wrote here.
>

Yes I didnt even notice anything that needs to be changed in the doc
I only aimed for a terminology clause to help readers who are
confused by the similar names.


> >> +Userspace API
> >> +=============
> >> +
> >> +System Call Interface
> >> +---------------------
> >> +
> >> +::
> >> +
> >> + #include <linux/fcntl.h>
> >> + #include <linux/fs.h>
> >> + #include <sys/syscall.h>
> >> + #include <unistd.h>
> >> +
> >> + long syscall(SYS_file_getattr, int dfd, const char *filename,
> >> + struct file_attr *attr, size_t usize,
> >> + unsigned int at_flags);
> >> +
> >> + long syscall(SYS_file_setattr, int dfd, const char *filename,
> >> + struct file_attr *attr, size_t usize,
> >> + unsigned int at_flags);
> >> +
> >> +Since C library wrappers don't exist yet, file_getattr() and
> >> +file_setattr() need to be called using :manpage:`syscall(2)`.
> >> +
> >> +Parameters
> >> +----------
> >> +
> >> +``dfd``
> >> + Directory file descriptor for relative path lookups, ``AT_FDCWD`` for the
> >> + current working directory, or the target file descriptor when used with
> >> + ``AT_EMPTY_PATH``.
> >> +
> >> +``filename``
> >> + Target pathname (relative to ``dfd`` when not absolute).
> >> +
> >> +``attr``
> >> + Pointer to a struct file_attr buffer.
> >> +
> >> +``usize``
> >> + Size of the buffer pointed to by ``attr``, in bytes.
> >> +
> >> +``at_flags``
> >> + Bitwise OR of control flags:
> >> +
> >> + - ``AT_FILEATTR_MASKS``: Enable mask semantics (as detailed in :ref:`Masks <masks>`).
> >> + - ``AT_SYMLINK_NOFOLLOW``: Do not follow symbolic links, operate on the
> >> + link itself.
> >> + - ``AT_EMPTY_PATH``: If ``filename`` is an empty string (``""`` or
> >> + ``NULL``), operate directly on ``dfd``.
> >> +
> >> +
> >> +The struct file_attr Structure
> >> +------------------------------
> >> +
> >> +.. kernel-doc:: include/uapi/linux/fs.h
> >> + :identifiers: file_attr
> >> +
> >> +.. _masks:
> >> +
> >> +Masks
> >> +=====
> >> +
> >> +In 7.X, the fileattr API introduced ``_masks`` fields (``fa_xflags_rw_mask``
> >
> > The "in 7.x" language is inspired by man-pages, but it has no place here
> > because this document lives in the same repo as the code.
> >
> > I think you should mention the versions V0 V1 somewhere in the doc and
> > then you can refer to them instead of saying 7.x or when describing a flag
> > which applies only to V1 (PROJID).
>
> Ah ok, will do.
>
> >> +and ``fa_xflags_ro_mask``), to enable usage of this API without having to do 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 the syscall, otherwise the normal behaviour is kept.
> >> +
> >> +.. note::
> >> + Currently most filesystems don't support masks, but this only has a visible
> >> + effect with file_getattr(), since file_setattr() is handled internally.
> >
> > I understand it, but don't think it is clear to readers what this note means.
>
> Yeah I wanted to explain a bit about the conversions but I thought that
> since this is the userspace section it was too detailed.
> I'll change it to mention the format conversion without many details and
> make a reference to the detailed in-kernel explanation below.
>
> > Also please avoid text that will go stale as "Currently most filesystems"
> > Use language that is not dependent on how many fs are converted.
>
> Right, makes sense.
>
> > Nore to bot: this doc should not go stale/incorrect while filesystems
> > are converted and support for more flags added in the future.
> >
> >> +
> >> +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::
> >> +
> >> + file_getattr(file1, &fa, ..., AT_FILEATTR_MASKS);
> >> + file_setattr(file2, &fa, ..., AT_FILEATTR_MASKS);
> >> +
> >> + does not always work as-is because of the different semantics of
> >> + ``fa_xflags_rw_mask`` on get vs set:
> >> +
> >> + - on filesystems without mask support, file_getattr() returns
> >> + ``fa_xflags_rw_mask = 0``, turning file_setattr() into a no-op (because of
> >> + the meaning of ``fa_xflags_rw_mask``);
> >> + - on filesystems with mask support, file_getattr() returns all supported
> >> + writable xflags in ``fa_xflags_rw_mask``, so file_setattr() sets all of
> >> + them on ``file2``, which could fail if ``file2`` is on a different
> >> + filesystem that supports a different subset of xflags.
> >
> > This sounds like a caution for regressing sync/backup workloads
>
> Mainly yes, I added it also because you had mentioned get -> set should
> work directly (so users may expect that), but since it can't I put it as
> caution.
>
> > with the new UAPI, but isn't it the same with the old UAPI when
> > file2 is on an fs that does not accept a flag that file1 advertizes?
>
> Yes.
>
> > I anything, the new UAPI improves the situation by making it
> > transparent and testable for the sync/backup program and allows
> > the program to make intelligent decisions based on the advertized
> > information in the masks.
> >
> > So the caution should be framed as change of behavior for
> > backup/sync - instead of silently dropping unsupported flags,
> > the new apis may reject them and provide the reason to the program
> > so that it can handle the situation correctly.
>
> Hmm yes, the main reason for this caution was non masks filesystems
> returning 0 as rw_mask -> no-op, which could be unexpected by programs.
> I'll update it so it's clearer and mentions sync/backups, since yeah, I
> can't really think of many use-cases where this get -> set (using masks)
> would make sense apart from that.
>
> >> +
> >> +On file_setattr()
> >> +-----------------
> >> +
> >> +- Userspace populates ``fa_xflags_rw_mask`` with the xflags it wishes to
> >> + change. If ``fa_xflags_rw_mask`` is ``0``, VFS treats it as a no-op, checking
> >> + only inode permissions and if the filesystem supports the fileattr API.
> >> +- 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 bit in ``fa_xflags_rw_mask`` and clearing the bit in
> >> + ``fa_xflags`` disables the feature.
> >> +
> >> +- For value attributes (``FS_XFLAG_PROJID``, ``FS_XFLAG_EXTSIZE``,
> >> + ``FS_XFLAG_EXTSZINHERIT``, ``FS_XFLAG_COWEXTSIZE``):
> >
> > Phrase as generic rule with examples so doc won't go stale when adding
> > new value fields.
>
> Right.
>
> >> +
> >> + - Setting the flag bit in both ``fa_xflags_rw_mask`` and ``fa_xflags`` sets
> >> + the attribute from the corresponding struct field.
> >> + - Setting the flag bit in ``fa_xflags_rw_mask`` and clearing the bit in
> >> + ``fa_xflags`` unsets/clears the attribute (resetting the value to 0).
> >> +
> >> +- Validation and capability rules:
> >> +
> >> + - 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 any flag outside
> >> + ``((FS_XFLAGS_MASK & ~FS_XFLAG_RDONLY_MASK) | FS_XFLAG_PROJID)`` fails
> >
> > Sorry this is too ugly to live.
> Lmao.
> Yeah and FS_XFLAGS_MASK etc aren't even exposed to userspace, forgot
> about that.
> > Need to do something about this.
> > Nobody can understand and follow this PROJID exemption
> > it needs to be better abstracted.
>
> Hmm, maybe in the userspace part we should treat FS_XFLAG_PROJID as part
> of FS_XFLAGS_MASK, since that's basically how we treat it as, and I'll
> rephrase that so it's actually understandable by people.
>
> >
> >> + with ``-EOPNOTSUPP``.
> >> +
> >> +Usage Examples
> >> +--------------
> >> +
> >> +Setting normal boolean flags::
> >> +
> >> + struct file_attr fa = {
> >> + .fa_xflags = FS_XFLAG_NOATIME | FS_XFLAG_NODUMP,
> >> + .fa_xflags_rw_mask = FS_XFLAG_NOATIME | FS_XFLAG_NODUMP,
> >> + };
> >> + syscall(SYS_file_setattr, dfd, path, &fa, sizeof(fa), AT_FILEATTR_MASKS);
> >> +
> >> +Clearing both flags in one call::
> >> +
> >> + struct file_attr fa = {
> >> + .fa_xflags = 0,
> >> + .fa_xflags_rw_mask = FS_XFLAG_NOATIME | FS_XFLAG_NODUMP,
> >> + };
> >> + syscall(SYS_file_setattr, dfd, path, &fa, sizeof(fa), AT_FILEATTR_MASKS);
> >> +
> >> +Setting one flag while clearing another::
> >> +
> >> + struct file_attr fa = {
> >> + .fa_xflags = FS_XFLAG_NOATIME,
> >> + .fa_xflags_rw_mask = FS_XFLAG_NOATIME | FS_XFLAG_NODUMP,
> >> + };
> >> + syscall(SYS_file_setattr, dfd, path, &fa, sizeof(fa), AT_FILEATTR_MASKS);
> >> +
> >> +Setting a value flag (``FS_XFLAG_PROJID``)::
> >> +
> >> + struct file_attr fa = {
> >> + .fa_xflags = FS_XFLAG_PROJID,
> >> + .fa_xflags_rw_mask = FS_XFLAG_PROJID,
> >> + .fa_projid = 67,
> >> + };
> >> + syscall(SYS_file_setattr, dfd, path, &fa, sizeof(fa), AT_FILEATTR_MASKS);
> >> +
> >> +Clearing/unsetting a value flag (``FS_XFLAG_PROJID``)::
> >> +
> >> + struct file_attr fa = {
> >> + .fa_xflags = 0,
> >> + .fa_xflags_rw_mask = FS_XFLAG_PROJID,
> >> + };
> >> + syscall(SYS_file_setattr, dfd, path, &fa, sizeof(fa), AT_FILEATTR_MASKS);
> >> +
> >> +.. note::
> >> + Here, there is no need to also set ``fa.fa_projid = 0`` since the above
> >> + code already means "unset".
> >
> > I still very much dislike this.
> > Yes, it is elegant and consistent, but humans sometimes
> > have expectations from apis which are different than documentation
> > and this becomes a source of bugs.
> >
> > I ask again, what do we lose by requiring fa.fa_projid = 0
> > along with clearing FS_XFLAG_PROJID?
>
> The possibility for filesystems to use a value that is not 0 to mean
> "unset" for a specific field, but since
> > We can always relax it later if the need arises
> that's fair.

Exactly. We do not gain ANYTHING from doing this now.
By treating this as EINVAL now, we reserve the right to relax
it in the future. The other way (deciding to disallow it later)
is much less nice for users and UAPI breakage.

> > and in the meanwhile
> > we make sure that all programs do not reset projid by mistake.
> > This is a bug so easy to write by mistake or by using a stale copy of
> > the constant FS_XFLAGS_MASK in a program, which copied it
> > from the kernel headers.
>
> You mean someone forgetting to set FS_XFLAG_PROJID in fa_xflags and
> setting it only in rw_mask (along with fa_projid > 0), since PROJID in
> fa_xflags was never required before (unlike extsize/cowextsize)?
>

Yes, something like that or as part of some RMW cycle during backup/sync.

> So should we require fa_value == 0 when fa_xflags doesn't have VALUE
> also for extsize/cowextsize too?
>

Yes, in my opinion we should.
For the same reason - there is no use case that makes sense for any
program to do that. And by denying it now, we could still relax it later,
but not the other way around.

> > People do not read the fine print of documentation and man pages
> > when writing software!
>
> Yeah fair.
>
> >> +
> >> +.. _fileattr_flags:
> >> +
> >> +Flag Reference
> >> +==============
> >> +
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| Flag Macro | Hex Value | Mode | Description and Constraints |
> >> ++================================+============+========+=======================================================+
> >> +| ``FS_XFLAG_REALTIME`` | 0x00000001 | RW | Realtime volume storage (XFS). |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_PREALLOC`` | 0x00000002 | RO | File has preallocated extents. |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_IMMUTABLE`` | 0x00000008 | RW | Inode cannot be modified. Requires |
> >> +| | | | ``CAP_LINUX_IMMUTABLE``. |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_APPEND`` | 0x00000010 | RW | All writes append only. Requires |
> >> +| | | | ``CAP_LINUX_IMMUTABLE``. |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_SYNC`` | 0x00000020 | RW | File writes are synchronous. |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_NOATIME`` | 0x00000040 | RW | Do not update inode access time (atime). |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_NODUMP`` | 0x00000080 | RW | Exclude file from dump/backup utilities. |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_RTINHERIT`` | 0x00000100 | RW | Inherit realtime bit on newly created files |
> >> +| | | | (directories only). |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_PROJINHERIT`` | 0x00000200 | RW | Inherit project ID on newly created files |
> >> +| | | | (directories only). |
> >> +| | | | Updates require ``init_user_ns``. |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_NOSYMLINKS`` | 0x00000400 | RW | Disallow creation of symlinks (directories only). |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_EXTSIZE`` | 0x00000800 | RW | Extent size allocator hint (regular files only). |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_EXTSZINHERIT`` | 0x00001000 | RW | Inherit extent size allocator hint |
> >> +| | | | (directories only). |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_NODEFRAG`` | 0x00002000 | RW | Disable filesystem defragmentation for file. |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_FILESTREAM`` | 0x00004000 | RW | Enable filestream allocator (directories only; XFS). |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_DAX`` | 0x00008000 | RW | Direct Access (DAX) I/O (regular files and |
> >> +| | | | directories only); mutually exclusive with |
> >> +| | | | ``FS_XFLAG_VERITY``. |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_COWEXTSIZE`` | 0x00010000 | RW | Copy-on-Write extent size allocator hint |
> >> +| | | | (regular files and directories only). |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_VERITY`` | 0x00020000 | RO | fs-verity enabled, read-only (set via verity ioctl). |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_CASEFOLD`` | 0x00040000 | RO/RW | Case-insensitive lookups. |
> >
> > RO/RW not very clear. Maybe a footnote RO/RW[*] for RW only via SETFLAGS
>
> Huh why only via SETFLAGS? It should be settable also by file_setattr
> once filesystems that support it as rw switch to using xflags (without
> even the need for supporting masks) no?
>

Ah ok so something like this?
[*] depends on the filesystem

The comment was just that it's not clear what RO/RW mode means


> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_CASENONPRESERVING`` | 0x00080000 | RO | Case not preserved in directory lookups. |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_PROJID`` | 0x00100000 | RW | Project ID value flag (Linux >= 7.X). |
> >
> > No 7.x please, V1 or something
> >
> >> +| | | | Updates require ``init_user_ns``. |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_COMPR`` | 0x00200000 | RO/RW | Compressed file flag. |
> >
> > Same RO/RW[*]
> >
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_ENCRYPT`` | 0x00400000 | RO | Encrypted file flag (fscrypt). Read-only. |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +| ``FS_XFLAG_HASATTR`` | 0x80000000 | RO | Inode has extended attributes. Read-only. |
> >> ++--------------------------------+------------+--------+-------------------------------------------------------+
> >> +
> >> +
> >> +Behaviour without ``AT_FILEATTR_MASKS``
> >> +=======================================
> >> +
> >> +When not using ``AT_FILEATTR_MASKS``, file_getattr() and
> >> +file_setattr() behave in the same way as :manpage:`ioctl_xfs_fsgetxattr(2)`
> >> +and :manpage:`ioctl_xfs_fssetxattr(2)` 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; /* Mask API supported */
> >> + };
> >> +
> >> +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``
> >> + Selector indicating whether the field to be used is ``flags`` or
> >> + ``fsx_xflags``. They should be treated as mutually exclusive.
> >> +
> >> +``has_masks``
> >> + Selector indicating whether the filesystem (on get) or request (on set)
> >> + uses the mask API.
> >
> > Probably better as Kerneldoc in the patch itself.
>
> Ah yeah, I forgot to add an explanation comment there.
>
> >> +
> >> +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);
> >> +
> >> +fileattr_fill_xflags() sets ``fa->fsx_valid`` to ``true``,
> >> +copies ``xflags`` into ``fa->fsx_xflags`` and translates the passed
> >> +``FS_XFLAG_*`` xflags to their corresponding ``FS_*_FL`` flags into
> >> +``fa->flags``.
> >> +
> >> +fileattr_fill_flags() sets ``fa->flags_valid`` to ``true``, copies ``flags``
> >> +into ``fa->flags`` and translates the passed ``FS_*_FL`` flags to their
> >> +corresponding ``FS_XFLAG_*`` xflags into ``fa->fsx_xflags``.
> >> +
> >> +The table below lists all ``FS_*_FL`` and ``FS_XFLAG_*`` flags and their
> >> +corresponding translations:
> >> +
> >> ++------------------------+--------------------------------+
> >> +| ``FS_*_FL`` | ``FS_XFLAG_*`` |
> >> ++========================+================================+
> >> +| ``FS_IMMUTABLE_FL`` | ``FS_XFLAG_IMMUTABLE`` |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_APPEND_FL`` | ``FS_XFLAG_APPEND`` |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_SYNC_FL`` | ``FS_XFLAG_SYNC`` |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_NOATIME_FL`` | ``FS_XFLAG_NOATIME`` |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_NODUMP_FL`` | ``FS_XFLAG_NODUMP`` |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_DAX_FL`` | ``FS_XFLAG_DAX`` |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_PROJINHERIT_FL`` | ``FS_XFLAG_PROJINHERIT`` |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_VERITY_FL`` | ``FS_XFLAG_VERITY`` |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_CASEFOLD_FL`` | ``FS_XFLAG_CASEFOLD`` |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_COMPR_FL`` | ``FS_XFLAG_COMPR`` |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_ENCRYPT_FL`` | ``FS_XFLAG_ENCRYPT`` |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_SECRM_FL`` | |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_UNRM_FL`` | |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_DIRTY_FL`` | |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_COMPRBLK_FL`` | |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_NOCOMP_FL`` | |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_BTREE_FL`` / | |
> >> +| ``FS_INDEX_FL`` | |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_IMAGIC_FL`` | |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_JOURNAL_DATA_FL`` | |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_NOTAIL_FL`` | |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_DIRSYNC_FL`` | |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_TOPDIR_FL`` | |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_HUGE_FILE_FL`` | |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_EXTENT_FL`` | |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_EA_INODE_FL`` | |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_EOFBLOCKS_FL`` | |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_NOCOW_FL`` | |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_INLINE_DATA_FL`` | |
> >> ++------------------------+--------------------------------+
> >> +| ``FS_RESERVED_FL`` | |
> >> ++------------------------+--------------------------------+
> >> +| | ``FS_XFLAG_REALTIME`` |
> >> ++------------------------+--------------------------------+
> >> +| | ``FS_XFLAG_PREALLOC`` |
> >> ++------------------------+--------------------------------+
> >> +| | ``FS_XFLAG_RTINHERIT`` |
> >> ++------------------------+--------------------------------+
> >> +| | ``FS_XFLAG_NOSYMLINKS`` |
> >> ++------------------------+--------------------------------+
> >> +| | ``FS_XFLAG_EXTSIZE`` |
> >> ++------------------------+--------------------------------+
> >> +| | ``FS_XFLAG_EXTSZINHERIT`` |
> >> ++------------------------+--------------------------------+
> >> +| | ``FS_XFLAG_NODEFRAG`` |
> >> ++------------------------+--------------------------------+
> >> +| | ``FS_XFLAG_FILESTREAM`` |
> >> ++------------------------+--------------------------------+
> >> +| | ``FS_XFLAG_COWEXTSIZE`` |
> >> ++------------------------+--------------------------------+
> >> +| | ``FS_XFLAG_CASENONPRESERVING`` |
> >> ++------------------------+--------------------------------+
> >> +| | ``FS_XFLAG_PROJID`` |
> >> ++------------------------+--------------------------------+
> >> +| | ``FS_XFLAG_HASATTR`` |
> >> ++------------------------+--------------------------------+
> >
> > Come on! This is writing the code in the doc.
>
> I like having the visual table here though :(
> since in the headers they're just separate lists (and actually, I
> thought the overlap between FS_*_FL flags and FS_XFLAG_* xflags was a
> lot more before having this table).
>

ok.

> > This document should tell the high level story of why those converters
> > exist and when and why they should be used by vfs and/or
> > filesystems.
> >
> > The documentation of each helper interface belongs in Kerneldoc
> > not here.
>
> Right, for now I only added a simple comments but I should add the full
> kernel-doc for them.

Well you do not have to add a full kernel doc for the static helpers.
I just meant if you are going to describe some helper full kerneldoc style
here it would be better doing that in the code, but I guess this is
not the case.

>
> Kinda related, but should we EXPORT_SYMBOL the rmw_to_mask and back
> helpers?
>

Why? Do any kernel modules need them?

> >
> >> +
> >> +Drivers that only support ``FS_*_FL`` flags can check for unsupported
> >> +extended attributes in ``->fileattr_set()`` using fileattr_has_fsx()::
> >> +
> >> + bool fileattr_has_fsx(const struct file_kattr *fa);
> >> +
> >> +fileattr_has_fsx() returns ``true`` if ``fa->fsx_valid`` is set with any
> >> +xflags outside ``FS_XFLAG_COMMON`` or with non-zero ``fsx_extsize``,
> >> +``fsx_projid``, or ``fsx_cowextsize``.
> >> +
> >> +VFS Translation 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_rmw_to_mask(): Converts Read-Modify-Write requests
> >> + (``FS_IOC_SETFLAGS``, ``FS_IOC_FSSETXATTR``, or file_setattr() without
> >> + ``AT_FILEATTR_MASKS``) to a request with masks when targeting a filesystem
> >> + that supports them. It does RMW itself, computing which flags and value
> >> + attributes changed, then populates ``fa->fsx_xflags`` and
> >> + ``fa->fsx_xflags_rw_mask`` accordingly.
> >> +- fileattr_set_mask_to_rmw(): Converts masked requests (file_setattr() with
> >> + ``AT_FILEATTR_MASKS``) to Read-Modify-Write format when targeting a
> >> + filesystem that doesn't support masks. It rejects changes to read-only or
> >> + unsupported flags and then merges the new values with the current ones,
> >> + preserving unchanged flags and clearing the masks.
> >> +- flags_to_xflags() / xflags_to_flags(): Convert between ``FS_XFLAG_*`` xflags
> >> + and ``FS_*_FL`` flags using fileattr_fill_xflags() and fileattr_fill_flags()
> >> + and returning only the new bitmask.
> >> +
> >
> > This is a hard read, try to simplify if you can, less interface, more high
> > level maybe. not sure.
>
> Hmm, for me it's high level enough, but since I already know what these
> functions do I'll ask friends/other people too and take it from there.
>

Let's see how that looks after rename to fileattr_set_v0_to_v1()
and with the has_masks/masks_valid/accepts_mask properties.
If you accept all of the above suggestions, then we will see how
it affects documentation - hopefully for the better.

Thanks,
Amir.