From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796509494; b=UFv+XFp58TVvc7Wis3FC+PMOJXcALPPHyL4jOwpFAK9Vojv4Eycdo7vdKAwUM+96LfyQ Xkxp3b6hh4TgogYAnZXwNkUfTtKMTXTXtNJzo+SdaRhNzTtyHaYHVRhxOE1pCphNVJFfE hCn2HEzgxsdic/ju0WTY/BUmMkOHhjF8bOO6QUNti5XhPJ+QNLpMNVT0xvrOZzsRku2ie pMZmpOH+RvuvXzqplj1IhXz5+8aKPCMYEBn0qj+7CDvJaCFXvoCF4YVPVNh9/X8kmyrpL FCBxjzK3VBvJsjLnGiV1+wtNH3sj8Fbl7n3s6GnXD1vcFUPewnRph7y699pENSndsTg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796509494; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To:X-Mailer: References:In-Reply-To; bh=A35q0UB3InwwhjuXNXqzfQKYt6HlB7VYmZL9josMR8U=; b=uK+89YYn2L87uW818I3fSF98qZLhZRqgHayySgxEivxlD7KhrZtTUqR6ZDgySOURf7L4 +t0T+aPFVYBgeKz4MnULPiIi9qLOv52RE8pEIOsPk4sGumtigfL+wKYs25u5i8l6ZNtp5 +7a5U3jxd1H6K5yX8cmTSse2F8+wOU/a4pbaHS1J+m/QF5ThhHYyNcLtScPvzBx33nu1y 7TmKKPml1j+41UxcOeZUdZ1uwBi6u+z8dsTjBJT0LaP9YRPYGNK39fCIrkE0rVPg1tIYo ljlWBd41zMKxx1yheTjtYvbsARbyC0Z0O00TGqX/MMZvZ05DuB1xJOt7MGHES3J7e/g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=dqbdmYNa; arc=none smtp.remote-ip=209.85.221.41 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9DF9606A680 for ; Sat, 5 Dec 2026 22:24:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D9DF9606A680 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=dqbdmYNa Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-4c84abcb549so1698237f8f.1 for ; Sat, 05 Dec 2026 14:24:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796509491; x=1797114291; darn=vger.kernel.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-type:mime-version:from:to:cc:subject:date:message-id :reply-to:content-type; bh=A35q0UB3InwwhjuXNXqzfQKYt6HlB7VYmZL9josMR8U=; b=dqbdmYNaC1Ols7JwEq+OPXKShnmbhRfSpUdwDMJKStmMqhy0nWY2jHx1Kp1r6nR90O EqLOqrorvFA2My1sBW1288kHdWUc4x8luidPISz2F4PZXtWa6lPXdIPGyyFeHOMuMbZS /msrgzhc7rVj9NqnjnSLtVb37XxvY090CmLe9V0LDJ93pef+RhQ8oX/mmsKVWC0QbpFo CLz3fixCq5kot7iv47hJPBdaEsvx9E0HMz41k7ZMcwnz/i6y4cmOB0BVdfh0eVKc4Mvj ZTYWRM6HGFmEUKOrlUHuYgHkAN967403VBHrm1mnrYlTvLRdhxCwyyy2AlinDIj0y4b7 JeDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796509491; x=1797114291; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-type:mime-version:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=A35q0UB3InwwhjuXNXqzfQKYt6HlB7VYmZL9josMR8U=; b=n20tytXn5Q7zWvlIQi2k2pMCa7k0AawBsKIEZlZiRfbKWbYsbfcc8qHwbPHY1rxIIi qLePU8DqweDP3H67f6Nr8NZUah9Vlh36wPWZIbUByjI13wEejQZ8vI1HWlMlSCkoHkGK IFPs+EyoyT8w2e73f21zyZtv9gJgIOFdkrp1zmXo4oGv40MnMiwUJgzIzU80AZ0Je3jZ 4N7R6WDQmzpxPz7Jo5ePgBNnKMNvGZtn9GmApP2NVCCq1IPDYw/qP6roJlPmNvhGjHWz 3o6jnXt37/Ei/BMMr0hFl1lNpUxdJ/N/gSYd8N9UnWbn5V8K5a3MTT7aN4tohdbpinxA kS9g== X-Forwarded-Encrypted: i=1; AL+hErHzig47fILHWfNsY0HVnndRHf3xVxT08g3IJ4YUm7AMP/EXmSDSKgYwAgBJ9KUInf6v3AKNdCBLuTnk0P58@vger.kernel.org X-Gm-Message-State: AB4q+uFjItLsbSu6HG7gj1WhSjwpLogJzLTFrW82SW9a3xwP5F265gK4 q5hGt9KA/YD/ym1GKVIzZyiQTyr/7Cydm16b+9RP0LuZK+jUUI5iK09X X-Gm-Gg: AZFdTZfzD+RNcRnq5mh8DroY8WWatsJ7bojYtSKfSRfncSfnKk5vZDg17xGIWBHXP72 WIOFFzrDoOX65ZpPy6fqBxwVbHfyxrF21NawzXZTk4Sloni7RSpcWU3KoVEiAscs9KWGJ9T0aUz mvtlOVx6uJyohHfOzdJkACIPk0q8nwY5cwWFfjS9cnB1ePDTEVYQd3Lz3Z5zKAGherjkyNp3nvb AFCgMfVoBWeSwSafT71iqAwgV1pmiB49z7RW5FHgE4lVqYMBE8sefZLGQivTFjm/pEagLA93YUs 4rcDiS9Empra5ytAxwY4eHIo0nTJnZawI+9Rrf5p7ITdevy3YDofhi7MUikWvFPqZGCkOlBRt9b QxujAtTyjH0JGqQJihlwmK2kJDPh+Z12AET3bP6rQaG1Fb/kjhy/cGf+1agyyBBEvZEVCWb2WU+ /Sv+khvlZ5Uu/SJ61dsTuicQ7KD9v9KzB0bLUCEpmCR5zkjlaHZDAAq5njJ+o5pUCuI0rDieO5u TsjXGOKc46sgdB7oe3OAumcmjlyiJz/ktMp1Ryyx7POM4rhfB+cD6mWUPwjleKFiRq8l3uR2kjn JMfVAVSLLuQs8s4piFVsbmccqg== X-Received: by 2002:a05:6000:188a:b0:48f:fcac:a5e2 with SMTP id ffacd0b85a97d-4d1eb6e1723mr11518552f8f.38.1796509490827; Sat, 05 Dec 2026 14:24:50 -0800 (PST) Received: from localhost ([2001:b07:5d26:7a6a:365a:60ff:fe0d:cfc6]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d17445284esm14448333f8f.44.2026.12.05.14.24.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 05 Dec 2026 14:24:50 -0800 (PST) X-Mailing-List: linux-unionfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 Content-Type: multipart/signed; boundary=93f3998d25bf29ee8c1b50c0204064cf4dc2647a4f6242b5efb938f22d41; micalg=pgp-sha512; protocol="application/pgp-signature" Date: Sat, 05 Dec 2026 23:24:46 +0100 Message-Id: Cc: "Namjae Jeon" , "Hyunchul Lee" , "Jonathan Corbet" , "Eric Biggers" , "Theodore Y . Ts'o" , "Jaegeuk Kim" , "Alexander Viro" , "Christian Brauner" , "Shuah Khan" , "Randy Dunlap" , "Chuck Lever" , "Jeff Layton" , "Jan Kara" , "Alexander Aring" , "Darrick J . Wong" , "Andrey Albershteyn" , "Miklos Szeredi" , =?utf-8?q?Pali_Roh=C3=A1r?= , "Lauri Gates" , "Christoph Hellwig" , "Dave Chinner" , , , , , , , , , Subject: Re: [PATCH v5 12/12] docs: add fileattr API documentation From: "koraynilay" To: "Amir Goldstein" , "koraynilay" X-Mailer: aerc 0.22.0-0-gc2f86b7abde3 References: <20261205142411.164484-1-koray.fra@gmail.com> <20261205142411.164484-13-koray.fra@gmail.com> In-Reply-To: --93f3998d25bf29ee8c1b50c0204064cf4dc2647a4f6242b5efb938f22d41 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 On Sat Dec 5, 2026 at 10:14 PM CET, Amir Goldstein wrote: > On Sat, Dec 5, 2026 at 3:25=E2=80=AFPM koraynilay w= rote: >> >> Add documentation for the fileattr API. >> >> Signed-off-by: koraynilay >> --- >> 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/file= systems/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 >> + >> +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> +Fileattr API >> +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> + >> +Overview >> +=3D=3D=3D=3D=3D=3D=3D=3D >> + >> +The fileattr API provides a modern way to query and modify file attribu= tes 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 th= e ones >> +reported by :manpage:`statx(2)` in its ``stx_attributes`` field (e.g. i= mmutable >> +or append-only). Not to be confused with "Extended attributes", which a= re >> +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 >> +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> + >> +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`` fi= elds, >> + see :ref:`Masks ` for more details. >> + >> +.. kernel-doc:: include/uapi/linux/fs.h >> + :identifiers: file_attr >> + >> +.. _fileattr_flags: >> + >> +Flag Reference >> +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> + >> +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_FL= AG`` >> + 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 `. >> + - ``RO``: Read-only. >> + - ``-``: Not supported by that API. >> + >> + Filesystem support may still vary. >> + >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| Flag | XFlag | Flag | Description and Constraint= s | > > 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 Contraint= s | | 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 Thanks, btw I forgot to update the live html, now it's updated: https://koraynilay.neocities.org/vfs-masks/fileattr Thanks, koraynilay > Thanks, > Amir. > >> ++=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D+=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+ >> +| ``IMMUTABLE`` | RW | RW | Inode cannot be modified. = Requires | >> +| | | | ``CAP_LINUX_IMMUTABLE``. = | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``APPEND`` | RW | RW | All writes append only. Re= quires | >> +| | | | ``CAP_LINUX_IMMUTABLE``. = | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``SYNC`` | RW | RW | File writes are synchronou= s. | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``NOATIME`` | RW | RW | Do not update inode access= time (atime). | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``NODUMP`` | RW | RW | Exclude file from dump/bac= kup utilities. | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``DAX`` | RW | RW | Direct Access (DAX) I/O (r= egular files and | >> +| | | | directories only); mutuall= y exclusive with | >> +| | | | ``FS_XFLAG_VERITY``. = | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``VERITY`` | RO | RO | fs-verity enabled, read-on= ly (set via verity | >> +| | | | ioctl). = | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``CASEFOLD`` | RO | RW | Case-insensitive lookups. = | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``COMPR`` | RO | RW | Compressed file flag. = | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``ENCRYPT`` | RO | RO | Encrypted file flag (fscry= pt). Read-only. | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``PROJINHERIT`` | RW | RW | Inherit project ID on newl= y created files | >> +| | | | (directories only). = | >> +| | | | Updates require ``init_use= r_ns``. | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``PROJID`` | RW/M [#r]_| \- | Project ID value flag (``V= ER1``). | >> +| | | | Updates require ``init_use= r_ns``. | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``REALTIME`` | RW | \- | Realtime volume storage (X= FS). | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``PREALLOC`` | RO | \- | File has preallocated exte= nts (XFS). | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``RTINHERIT`` | RW | \- | Inherit realtime bit on ne= wly created files | >> +| | | | (directories only; XFS). = | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``NOSYMLINKS`` | RW | \- | Disallow creation of symli= nks (directories | >> +| | | | only; XFS). = | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``EXTSIZE`` | RW | \- | Extent size allocator hint= (regular files only; | >> +| | | | XFS). = | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``EXTSZINHERIT`` | RW | \- | Inherit extent size alloca= tor hint | >> +| | | | (directories only; XFS). = | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``NODEFRAG`` | RW | \- | Disable filesystem defragm= entation for file | >> +| | | | (XFS). = | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``FILESTREAM`` | RW | \- | Enable filestream allocato= r (directories only; | >> +| | | | XFS). = | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``COWEXTSIZE`` | RW | \- | Copy-on-Write extent size = allocator hint | >> +| | | | (regular files and directo= ries only; XFS). | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``CASENONPRESERVING`` | RO | \- | Case not preserved in dire= ctory lookups. | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``HASATTR`` | RO | \- | Inode has extended attribu= tes (XFS). | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``SECRM`` | \- | RW | Secure deletion. = | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``UNRM`` | \- | RW | Undelete. = | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``DIRTY`` | \- | RO | Dirty (reserved for compre= ssion). | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``COMPRBLK`` | \- | RO | One or more compressed clu= sters. | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``NOCOMP`` | \- | RW | Don't compress. = | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``BTREE`` / | \- | RO | Btree format / hash-indexe= d directory. | >> +| ``INDEX`` | | | = | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``IMAGIC`` | \- | RO | AFS directory. = | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``JOURNAL_DATA`` | \- | RW | Journaled file data. = | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``NOTAIL`` | \- | RW | File tail should not be me= rged. | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``DIRSYNC`` | \- | RW | Dirsync behaviour (directo= ries only). | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``TOPDIR`` | \- | RW | Top of directory hierarchi= es. | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``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 (e= xt4). | >> ++-----------------------+-----------+------+---------------------------= -----------------------+ >> +| ``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_pr= ojid`` >> + directly, because ``FS_XFLAG_PROJID`` was added in ``VER1``, while t= he >> + ``fsx_projid`` field was available before that. >> + >> +.. _masks: >> + >> +Masks >> +=3D=3D=3D=3D=3D >> + >> +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_FSSETXATT= R`` >> +require. >> + >> +To use this feature ``AT_FILEATTR_MASKS`` needs to be set in the ``at_f= lags`` >> +argument of file_getattr() / file_setattr(), otherwise the normal behav= iour 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 `. >> + >> +On file_getattr() >> +----------------- >> + >> +- If the filesystem supports mask reporting, file_getattr() populates >> + ``fa_xflags_rw_mask`` with all xflags it supports modifying on this i= node, >> + and ``fa_xflags_ro_mask`` with all read-only xflags it supports repor= ting. >> +- 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 unsupp= orted >> + flags were often silently dropped: >> + >> + - on filesystems without mask support, file_getattr() returns >> + ``fa_xflags_rw_mask =3D 0``, causing file_setattr() to fail with >> + ``-EINVAL``; >> + - on filesystems with mask support, file_getattr() returns all suppo= rted >> + 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 deci= de how >> + to handle unsupported flags. >> + >> +On file_setattr() >> +----------------- >> + >> +- Userspace populates ``fa_xflags_rw_mask`` with the xflags it wishes t= o >> + 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 unmo= dified. >> +- 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_COWEXTS= IZE``): >> + >> + - 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 th= e >> + 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 fl= ag not >> + advertised in the filesystem's writable mask fails with ``-EOPNOTSU= PP``. >> + - If the filesystem does not support masks, requesting modification o= f any >> + flag outside ``FSX_FSXATTR_SET_MASK`` fails with ``-EOPNOTSUPP``. >> + >> +Usage Examples >> +-------------- >> + >> +See :manpage:`file_setattr(2)` for examples. >> + >> +Behaviour without ``AT_FILEATTR_MASKS`` >> +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> + >> +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 >> +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D >> + >> +Filesystem Operations >> +--------------------- >> + >> +Filesystems wanting to implement this API, need to set the ``fileattr_g= et`` and >> +``fileattr_set`` functions in ``struct inode_operations``: >> + >> +.. code-block:: c >> + >> + struct inode_operations { >> + ... >> + int (*fileattr_get)(struct dentry *dentry, struct file_kattr *f= a); >> + int (*fileattr_set)(const struct mnt_idmap *idmap, struct dentr= y *dentry, >> + struct file_kattr *fa); >> + ... >> + }; >> + >> +Internal Structure: struct file_kattr >> +------------------------------------- >> + >> +Defined in ````: >> + >> +.. 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) / fl= ags 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 o= n get, but wants an unmasked request on set */ >> + }; >> + >> +Fields of struct file_kattr have the same semantics as their user-facin= g >> +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 (``flag= s`` vs. >> + ``fsx_xflags``/``fsx_*``). Syscalls/ioctls only set one, in-kern= el >> + callers reusing the result of a ``->fileattr_get()`` may pass bot= h. >> + Masked requests always have ``fsx_valid =3D true`` and >> + ``flags_valid =3D 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-kerne= l >> + 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 fai= l 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 on= ly >> + contain bits within ``fsx_xflags_rw_mask``. >> +- For ``AT_FILEATTR_MASKS`` calls, ``fsx_*`` value fields are ``0`` unl= ess >> + enabled in ``fsx_xflags``; for unmasked calls converted by >> + fileattr_set_to_masks(), unchanged ``fsx_*`` fields are preserved (ex= cept for >> + ``FS_IOC_SETFLAGS``, where they remain ``0``, but in that case they a= lso >> + won't be in ``fsx_xflags_rw_mask``). >> +- After validation and (if necessary) conversion, the VFS passes the re= sulting >> + struct file_kattr to ``->fileattr_set()`` with ``has_masks =3D true``= , >> + ``fsx_valid =3D true``, and ``flags_valid =3D false``. >> +- The filesystem should validate the request with fileattr_fsx_masks_ok= () >> + and must modify **only** the attributes selected in ``fsx_xflags_rw_m= ask``. >> + >> +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 =3D 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 support= ed); >> + >> + bool fileattr_fsx_masks_ok(const struct file_kattr *fa, >> + const u32 allowed_rw, >> + const u32 allowed_ro); >> + >> +See :ref:`Flag Reference ` for the ``FS_*_FL`` to >> +``FS_XFLAG_*`` translation mapping. >> + >> +.. _conversion: >> + >> +VFS Conversion Helpers >> +---------------------- >> + >> +With fileattr_set_convert(), the VFS bridges differing caller and drive= r >> +capabilities automatically using the inode's current attributes retriev= ed via >> +vfs_fileattr_get(): >> + >> +- fileattr_set_to_masks(): Converts non-masked requests (``FS_IOC_SETFL= AGS``, >> + ``FS_IOC_FSSETXATTR``, file_setattr() without ``AT_FILEATTR_MASKS``, = or >> + in-kernel callers with ``use_masks =3D false``) to a masked request w= hen >> + targeting a filesystem that accepts masks on set. >> +- fileattr_set_from_masks(): Converts masked requests (file_setattr() w= ith >> + ``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_MAS= K``) >> + only, keeping ``FSX_FSXATTR_MASK`` and ``FSX_RDONLY_MASK`` frozen exc= ept >> + when exposing xflag counterparts for existing ``FS_*_FL`` flags. >> +- When adding a ``FS_XFLAG_*`` counterpart to a ``FS_*_FL`` flag, add i= t 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 A= PIs >> + [#excomm]_, add the counterpart to the :ref:`table above ` >> + and move the line up so it's grouped with the other flags with counte= rparts. >> +- Filesystems that only want to report new read-only flags on get witho= ut >> + converting ``->fileattr_set()`` to masks have to change their >> + ``->fileattr_get()`` so that it: >> + >> + - sets ``has_masks =3D true``, >> + - sets ``get_only_masks =3D 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 n= ot be >> + added to ``FSX_COMMON``. >> + >> +Mask-Aware Driver Example >> +------------------------- >> + >> +An example of a filesystem that supports masks can be found in ``fs/ntf= s/file.c``. >> + >> +Locking >> +------- >> + >> +- vfs_fileattr_set() takes inode_lock(), so no external locking is requ= ired. >> + >> +Permissions >> +----------- >> + >> +- Inode ownership or ``CAP_FOWNER`` in the owning user namespace is req= uired. >> +- 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 >> +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> + >> +``-EINVAL`` >> + Invalid structure size, ``AT_FILEATTR_MASKS`` passed with non-mask = struct, >> + ``AT_FILEATTR_MASKS`` passed to file_setattr() with ``fa_xflags_rw_= mask =3D 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), invali= d >> + project ID or changing ``FS_XFLAG_PROJID`` / ``FS_XFLAG_PROJINHERIT= `` >> + outside the host namespace, specifying xflags added in or after ``V= ER1`` >> + 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/filesys= tems/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/filesyste= ms/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 attribu= tes >> + (see Documentation/filesystems/fileattr.rst). Also called befor= e the >> + relevant SET operation to check what is being changed (in this c= ase >> + 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 attribute= s (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 >> --93f3998d25bf29ee8c1b50c0204064cf4dc2647a4f6242b5efb938f22d41 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQSgVimKafU5DQMcjcDmj22qf5IGXAUCaxSPLgAKCRDmj22qf5IG XOB/AQCQOPi+SQhtlSzE5MGo5LgeDDNEy+hMgJPwnDcCC5HFHgD/eZY/DGiyHeHZ YTEKSVwqy44TZRo2yMwTEeEXxYk+0wA= =dAGZ -----END PGP SIGNATURE----- --93f3998d25bf29ee8c1b50c0204064cf4dc2647a4f6242b5efb938f22d41--