From: koraynilay <koray.fra@gmail.com>
To: 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>
Cc: "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>,
"Amir Goldstein" <amir73il@gmail.com>,
"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, koraynilay <koray.fra@gmail.com>
Subject: [PATCH v3 5/5] docs: add fileattr API documentation
Date: Sun, 29 Nov 2026 03:42:33 +0100 [thread overview]
Message-ID: <20261129024233.2361718-6-koray.fra@gmail.com> (raw)
In-Reply-To: <20261129024233.2361718-1-koray.fra@gmail.com>
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).
+
+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``
+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.
+
+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.
+
+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``):
+
+ - 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
+ 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".
+
+.. _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. |
++--------------------------------+------------+--------+-------------------------------------------------------+
+| ``FS_XFLAG_CASENONPRESERVING`` | 0x00080000 | RO | Case not preserved in directory lookups. |
++--------------------------------+------------+--------+-------------------------------------------------------+
+| ``FS_XFLAG_PROJID`` | 0x00100000 | RW | Project ID value flag (Linux >= 7.X). |
+| | | | Updates require ``init_user_ns``. |
++--------------------------------+------------+--------+-------------------------------------------------------+
+| ``FS_XFLAG_COMPR`` | 0x00200000 | RO/RW | Compressed file flag. |
++--------------------------------+------------+--------+-------------------------------------------------------+
+| ``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.
+
+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`` |
++------------------------+--------------------------------+
+
+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.
+
+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.
+
+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``), invalid inode type for ``FS_XFLAG_EXTSIZE`` /
+ ``FS_XFLAG_EXTSZINHERIT`` / ``FS_XFLAG_COWEXTSIZE`` / ``FS_XFLAG_DAX``,
+ 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.
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.
+ */
+/*
* Note. This is alternative to the structure 'struct file_kattr'/'struct fsxattr'.
* As this structure is passed to/from userspace with its size, this can
* be versioned based on the size.
--
2.56.0
next prev parent reply other threads:[~2026-11-29 2:43 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 ` koraynilay [this message]
2026-11-29 11:32 ` [PATCH v3 5/5] docs: add fileattr API documentation Amir Goldstein
2026-11-29 14:19 ` koraynilay
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=20261129024233.2361718-6-koray.fra@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