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 v5 12/12] docs: add fileattr API documentation
Date: Sat, 05 Dec 2026 23:24:46 +0100 [thread overview]
Message-ID: <DND5GOIOHJU9.1BMA9RXXZL35F@gmail.com> (raw)
In-Reply-To: <CAOQ4uxjtk4co38fiRQY_7TQ2vJwUgGHA4xsrLtaoQ6Orr0+cgA@mail.gmail.com>
[-- 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 --]
prev parent reply other threads:[~2026-12-05 22:24 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
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=DND5GOIOHJU9.1BMA9RXXZL35F@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