From: "koraynilay" <koray.fra@gmail.com>
To: "Amir Goldstein" <amir73il@gmail.com>,
"koraynilay" <koray.fra@gmail.com>
Cc: "Namjae Jeon" <linkinjeon@kernel.org>,
"Hyunchul Lee" <hyc.lee@gmail.com>,
"Jonathan Corbet" <corbet@lwn.net>,
"Eric Biggers" <ebiggers@kernel.org>,
"Theodore Y . Ts'o" <tytso@mit.edu>,
"Jaegeuk Kim" <jaegeuk@kernel.org>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Christian Brauner" <brauner@kernel.org>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Chuck Lever" <cel@kernel.org>,
"Jeff Layton" <jlayton@kernel.org>, "Jan Kara" <jack@suse.cz>,
"Alexander Aring" <alex.aring@gmail.com>,
"Darrick J . Wong" <djwong@kernel.org>,
"Andrey Albershteyn" <aalbersh@kernel.org>,
"Miklos Szeredi" <miklos@szeredi.hu>,
"Pali Rohár" <pali@kernel.org>,
"Lauri Gates" <lauri.gates@gmail.com>,
"Christoph Hellwig" <hch@infradead.org>,
"Dave Chinner" <dgc@kernel.org>,
linux-btrfs@vger.kernel.org, linux-xfs@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
ntfs@lists.linux.dev, linux-nfs@vger.kernel.org,
linux-api@vger.kernel.org, linux-doc@vger.kernel.org,
linux-unionfs@vger.kernel.org
Subject: Re: [PATCH v3 5/5] docs: add fileattr API documentation
Date: Sun, 29 Nov 2026 15:19:24 +0100 [thread overview]
Message-ID: <DN7RDSPJQIVY.1MM3GAPOUWKZV@gmail.com> (raw)
In-Reply-To: <CAOQ4uxgGdmxYX8kYmPbsJPVdwT9pKQTEfa+fCv_5i-ef6XGjXg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 40712 bytes --]
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@gmail.com> wrote:
>>
>> Add documentation for the fileattr API.
>>
>> Signed-off-by: koraynilay <koray.fra@gmail.com>
>> ---
>> 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.
>> +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.
> 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)?
So should we require fa_value == 0 when fa_xflags doesn't have VALUE
also for extsize/cowextsize too?
> 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?
>> ++--------------------------------+------------+--------+-------------------------------------------------------+
>> +| ``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).
> 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.
Kinda related, but should we EXPORT_SYMBOL the rmw_to_mask and back
helpers?
>
>> +
>> +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.
>> +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(),
>
>> a vfs_fileattr_set_locked() will be
>> + added for cases where inode lock is already held.
>
> This is an odd thing to write in the context of this doc.
Fair, I added it since I had to make the _locked() variant for NFS/CIFS
(iirc), so I thought it could be useful to point out in the doc that it
hasn't been added yet but it will (whenever we'll need to use it for
changing btime probably).
>> +
>> +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,
>> + 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`` (including ``FS_XFLAG_PROJID`` without
>> + ``AT_FILEATTR_MASKS``),
>
> We must get rid of this exemption somehow.
> It's unreadable.
> Possibly with V1/V0 phrasing.
Yeah.
>> invalid inode type for ``FS_XFLAG_EXTSIZE`` /
>> + ``FS_XFLAG_EXTSZINHERIT`` / ``FS_XFLAG_COWEXTSIZE`` / ``FS_XFLAG_DAX``,
>
> Note to bot: keep it general with examples. no need to bloat the doc
> with a list of all the relevant flags in current code.
Right, same as the above for the generic phrasing.
>> + incompatible attribute combinations (e.g. DAX on
>> + fs-verity), invalid project ID or
>> + changing ``FS_XFLAG_PROJID`` / ``FS_XFLAG_PROJINHERIT`` outside
>> + the host namespace.
>> +
>> +``-EOPNOTSUPP``
>> + The filesystem does not implement ``fileattr`` operations for this inode,
>> + or userspace requested modification of an attribute not writable by the
>> + filesystem.
>> +
>> +``-EPERM``
>> + Insufficient permissions (missing ``CAP_FOWNER``, missing
>> + ``CAP_LINUX_IMMUTABLE``, filesystem-enforced immutability constraints).
>> +
>> +``-EROFS``
>> + Target inode resides on a read-only mount or filesystem.
>> +
>> +``-ENOKEY``
>> + Required encryption key is unavailable (e.g. enabling ``FS_XFLAG_CASEFOLD``
>> + on an encrypted directory without its key).
>> +
>> +``-E2BIG``
>> + ``usize`` exceeds ``PAGE_SIZE``, or trailing bytes in ``attr`` are non-zero
>> + when ``usize > FILE_ATTR_SIZE_LATEST`` on file_setattr().
>> +
>> +``-EBADF``
>> + ``dfd`` is not a valid file descriptor.
>> +
>> +``-EFAULT``
>> + Invalid user memory pointer (including ``filename == NULL`` without
>> + ``AT_EMPTY_PATH``).
>> +
>> +``-ENOENT``
>> + Target file does not exist, or empty path without ``AT_EMPTY_PATH``.
>> +
>> +``-EACCES`` / ``-ENOTDIR`` / ``-ELOOP`` / ``-ENAMETOOLONG``
>> + Pathname resolution errors.
>
> This is not supposed to be a man page and this duplicates information
> not specific
> to the new UAPI and not new.
>
> Only the new EINVAL/EOPNOTSUPP related to this patch set are relevant
> in this doc.
Ah ok, will remove them.
>> 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 00fbcd549f15..e222d5025fe4 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
>> diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
>> index c1c487d07d29..5a58e1029bf8 100644
>> --- a/include/uapi/linux/fs.h
>> +++ b/include/uapi/linux/fs.h
>> @@ -225,9 +225,33 @@ 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, 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)
>> + * @fa_xflags_rw_mask: Bit mask of writeable 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.
>> + */
>> +/*
>
> Keep this with the code patch.
Ah ok.
Thanks,
koraynilay
> Thanks,
> Amir.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
next prev parent reply other threads:[~2026-11-29 14:19 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 2:42 [PATCH v3 0/5] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay
2026-11-29 2:42 ` [PATCH v3 1/5] vfs: use goto out on error in vfs_fileattr_set() koraynilay
2026-11-29 9:32 ` Amir Goldstein
2026-11-29 13:23 ` koraynilay
2026-11-29 2:42 ` [PATCH v3 2/5] vfs: add xflags masks to fileattr API koraynilay
2026-11-29 13:10 ` Lauri Gates
2026-11-29 13:57 ` Amir Goldstein
2026-11-29 14:23 ` Amir Goldstein
2026-11-29 2:42 ` [PATCH v3 3/5] vfs: add COMPR/ENCRYPT xflags from FS_COMPR_FL/FS_ENCRYPT_FL koraynilay
2026-11-29 10:11 ` Amir Goldstein
2026-11-29 2:42 ` [PATCH v3 4/5] ntfs: switch to the new xflags fileattr API koraynilay
2026-11-29 9:12 ` Amir Goldstein
2026-11-29 2:42 ` [PATCH v3 5/5] docs: add fileattr API documentation koraynilay
2026-11-29 11:32 ` Amir Goldstein
2026-11-29 14:19 ` koraynilay [this message]
2026-11-29 2:47 ` [PATCH v3 0/5] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DN7RDSPJQIVY.1MM3GAPOUWKZV@gmail.com \
--to=koray.fra@gmail.com \
--cc=aalbersh@kernel.org \
--cc=alex.aring@gmail.com \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=cel@kernel.org \
--cc=corbet@lwn.net \
--cc=dgc@kernel.org \
--cc=djwong@kernel.org \
--cc=ebiggers@kernel.org \
--cc=hch@infradead.org \
--cc=hyc.lee@gmail.com \
--cc=jack@suse.cz \
--cc=jaegeuk@kernel.org \
--cc=jlayton@kernel.org \
--cc=lauri.gates@gmail.com \
--cc=linkinjeon@kernel.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-unionfs@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=ntfs@lists.linux.dev \
--cc=pali@kernel.org \
--cc=rdunlap@infradead.org \
--cc=skhan@linuxfoundation.org \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox