From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796338777; b=ND5ZwXmjwIObjM2BCIg395R0Bayv0p2OO2VKQAE3gmq/2qpCVON+dJa417JrtazozQf3 iu2jvoOlK+V/ouR/x1jAFY9X9Waotw/Lvh0y6XzFW+MViM2zWhs8tB1IoSeKRFotHSWB6 XLJM651chCatlRcxHdYpPQ8en+W31AGuSSjC3P5EgqIIeGE2RKqeuR/NHRcR21aR/YIff 2AOP7aDpwngNL1u0ZFis6qHZsBxHjgD+qSvig6LO32ayiBXVK+NJqDvu+8AfnyX8gzwCn Jhunmdw5iH4eg5+A6F9aAP+T3aXTWZGiiIfK9m+8tCKvUQgaWL2wYV53qvL2GJYw+5g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796338777; 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:Subject:From:To:Cc:X-Mailer: References:In-Reply-To; bh=ssmx697BMNhNCv5e8jptECTDEu+OnUrUc//QOwCEy9M=; b=0lT9DDTPYInznCUoRj6NAapiCeG/luZ4TRyG1o4t/y08sXxzvN1KMCzBM129He2wMI9h Aor71bEZC1q02Q60+L9s6ns8z8vqrl3BlQpJWat6CSLyUo8voOrZsx6wcvRIukduMjGao QOdJK3A9R0GRRr/frt0cixhMHRex4biVXAolPo9qGq19FF+D7KNGZlh7Ep8RirCm0pjP/ vC+nd4pJQS8RxCHKK3uzk89Qgv1WPCeDblQ+t7iKTEyu4OtcQyhzmz+cytekqo3bip1XD L+PX0AkLxXAm3R4vFoOaonK7H6kBt04lIpoiwnBsXyPvrIQgKLmETkGNADUwkxQKm8A== 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=E7wz2yZa; arc=none smtp.remote-ip=209.85.128.47 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 6255C606A32C for ; Thu, 3 Dec 2026 22:59:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6255C606A32C 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=E7wz2yZa Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-49d05d51553so1976695e9.2 for ; Thu, 03 Dec 2026 14:59:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796338775; x=1796943575; darn=vger.kernel.org; h=in-reply-to:references:cc:to:from:subject:message-id:date :content-type:mime-version:from:to:cc:subject:date:message-id :reply-to:content-type; bh=ssmx697BMNhNCv5e8jptECTDEu+OnUrUc//QOwCEy9M=; b=E7wz2yZaTBv/s5RZiHGzP4gzBAoQOz4OFeO15MbvdNe0i7et1PieuzCFYcGmhMe9P4 vkSB6/Q6FFXaiUfOegH72g5emayRwGG1QHBAm5NM3H3VZ1rcoztynQ81eC9c+VrOcHWf Z4RGKaZ1qJVYZdthop+A3eQVEFdvVndfEIN7gLpKrjrzsfNsjpKd3LGaeG0VnNESUPqc CYMpqCnFoE4KBtLNguiQrfqyp3/kut0w+ZOWuimnp0nEb8qjSj2W5Sgd06axKxuaXJDM iGtJe4gx+fEhLbvoyBb8/ChV+Ou5iQtBSbJfnof2Cw0axJ1eyZuviRZ12DXgH/VAT/wN dt+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796338775; x=1796943575; h=in-reply-to:references:cc:to:from:subject: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=ssmx697BMNhNCv5e8jptECTDEu+OnUrUc//QOwCEy9M=; b=K1CKYQv0j8Y4j6VnGJg7Y7BmwPmt+kq1SW91iGzdBTg72ETrmRy/Ctfv9/2n1fW1q6 /SDkRWbTsunshWrwWVxnJzJj5wsc0frPsP8sQZqR65MYIhfm7heQfuAx5xj89JYWehfI OgCCfsGP0cCxUKNthYW8WsCDwmkkOICuRFtJW1hFGzBlnMngzLEjc/5aNxjr3vqrL5Rv QEjYxsmUqQEUXunikOOBEdp+ELPU+hs+Z1hxMgKnAI+VeDfGJB1w25RpHmao5riWh2yN SOtpywE+iyXsCkZ4h3JrJTFyeR1KGvtLAfErGmxo1NMSg8b/tmVhh9lX3xX8a/RB7bBM w35w== X-Forwarded-Encrypted: i=1; AL+hErEoF+oz1UWsU4fb6b+t/oy015p36sR8ppBwxIt0pVC7O93tsaNNVEOMEQRnLQd0awNOLttrA49V84aBZKVW@vger.kernel.org X-Gm-Message-State: APuU4Z+FOEtBLhQYDb3DIPzB0846S4UWqIoQGiMEcxc9I+/Mv3NvBpa+ EDf6g/xgkt3JwtRsZBvaQizCnP+5yHnQIgt2AZgxCSLPObjy/+4n3pxa X-Gm-Gg: AZFdTZdr/XGRH+wLj8gd2bdT9qE21idw5GJL3v/gTt0YX7SszNywl7WIXM2tuGrXKfc D7Ow5E4F0Y9KcfIuaNndXQeB9FrjUztwe63SKVcGJ/Gj65T4SPgpkGAmkm4DmNBa3QuBLLOaSBW nVHmQWzf4dzXYdZSBuziI0Bcetc9RpPJNNdg/nieE5/Gq1e0LPatGf5up7vdyK/1f9Imv6NGisr kV3sKW7SI36pj62Mzj60JQgvoJ8fV0VQNvwdyd0+yj4EHgRRjg/G9h7wNUWKEYCVhSjPlfdhPuL y/BKdJcZkQtT3NqXE6/aUIjmpAfJeONSrZAQXQWKZqoZURmIjqGrd/Dm5zgap2dWngifTTX9PT6 CDCs2rrR/yGFwCapQQK89WKh14s3x/rXWFr74mBFfWXhr5uk/o0LmUuc0SCQRy1RxpSplBOHpuZ 2IL3f+I5fA7BYN9NdKQkTwSf85RFGXMHNXGsutGtbs5VZm0wbrlu0PH85jREBZjPNUsD/Eh1T0T Dee4NKZ8RC6J8gdILlAQsmE53Dt31veXUqBqFVg93DgfB/IMz3AWd/Ay3rBiDMznw6QobBfXuFr 1zRT2KuSrOS25MfJX+Wkv0tt/Co= X-Received: by 2002:a05:600c:3e14:b0:4bb:e7b4:31e8 with SMTP id 5b1f17b1804b1-4bbeb60259cmr2703155e9.0.1796338774538; Thu, 03 Dec 2026 14:59:34 -0800 (PST) Received: from localhost ([2001:b07:5d26:7a6a:365a:60ff:fe0d:cfc6]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbe00dafdfsm106501045e9.12.2026.12.03.14.59.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Dec 2026 14:59:33 -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=a3e53e622a7e9098c9ec4b088a5bf3d455fa6243bb246c8156d99a71fc5f; micalg=pgp-sha512; protocol="application/pgp-signature" Date: Thu, 03 Dec 2026 23:59:30 +0100 Message-Id: Subject: Re: [PATCH v4 7/7] docs: add fileattr API documentation From: "koraynilay" To: "Amir Goldstein" , "koraynilay" 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" , , , , , , , , , X-Mailer: aerc 0.22.0-0-gc2f86b7abde3 References: <20261202215427.798262-1-koray.fra@gmail.com> <20261202215427.798262-8-koray.fra@gmail.com> In-Reply-To: --a3e53e622a7e9098c9ec4b088a5bf3d455fa6243bb246c8156d99a71fc5f Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 On Thu Dec 3, 2026 at 11:52 PM CET, Amir Goldstein wrote: > On Thu, Dec 3, 2026 at 11:20=E2=80=AFPM koraynilay = wrote: >> >> On Thu Dec 3, 2026 at 6:45 PM CET, Amir Goldstein wrote: >> > On Wed, Dec 2, 2026 at 10:54=E2=80=AFPM koraynilay wrote: >> >> >> >> Add documentation for the fileattr API. >> >> >> >> Signed-off-by: koraynilay >> >> --- >> >> Documentation/filesystems/fileattr.rst | 469 +++++++++++++++++++++++= ++ >> >> Documentation/filesystems/index.rst | 1 + >> >> Documentation/filesystems/vfs.rst | 19 +- >> >> 3 files changed, 481 insertions(+), 8 deletions(-) >> >> create mode 100644 Documentation/filesystems/fileattr.rst >> >> >> >> diff --git a/Documentation/filesystems/fileattr.rst b/Documentation/f= ilesystems/fileattr.rst >> >> new file mode 100644 >> >> index 000000000000..ee47ae2c9447 >> >> --- /dev/null >> >> +++ b/Documentation/filesystems/fileattr.rst >> >> @@ -0,0 +1,469 @@ >> >> +.. 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 attr= ibutes and >> >> +it should be used instead of the older ``FS_IOC_[GS]ETFLAGS`` >> >> +(:manpage:`fs_ioc_getflags(2const)` / :manpage:`fs_ioc_setflags(2con= st)`) 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", whic= h 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 >> >> +=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``= fields, >> >> + 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 xflags. >> >> + >> >> +.. note:: >> >> + In the Mode column, "RO/RW" means that the flag is read-only via = the xflags >> >> + APIs (``FS_IOC_FSSETXATTR`` and file_setattr()), while some files= ystems >> >> + allow modifying its ``FS_*_FL`` counterpart via ``FS_IOC_SETFLAGS= ``. >> >> + >> >> + "RW" means the flag is writable via file_setattr() (and via >> >> + ``FS_IOC_FSSETXATTR`` / ``FS_IOC_SETFLAGS`` where applicable), an= d "RO" >> >> + means it is read-only across all fileattr userspace APIs. Filesys= tem support >> >> + may still vary. >> >> + >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| Flag Macro | Hex Value | Mode | Description= and Constraints | >> >> ++=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=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D+ >> >> +| ``FS_XFLAG_REALTIME`` | 0x00000001 | RW | Realtime vo= lume storage (XFS). | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_PREALLOC`` | 0x00000002 | RO | File has pr= eallocated extents. | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_IMMUTABLE`` | 0x00000008 | RW | Inode canno= t 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 upda= te inode access time (atime). | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_NODUMP`` | 0x00000080 | RW | Exclude fil= e from dump/backup utilities. | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_RTINHERIT`` | 0x00000100 | RW | Inherit rea= ltime bit on newly created files | >> >> +| | | | (directorie= s only). | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_PROJINHERIT`` | 0x00000200 | RW | Inherit pro= ject ID on newly created files | >> >> +| | | | (directorie= s only). | >> >> +| | | | Updates req= uire ``init_user_ns``. | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_NOSYMLINKS`` | 0x00000400 | RW | Disallow cr= eation of symlinks (directories only). | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_EXTSIZE`` | 0x00000800 | RW | Extent size= allocator hint (regular files only). | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_EXTSZINHERIT`` | 0x00001000 | RW | Inherit ext= ent size allocator hint | >> >> +| | | | (directorie= s only). | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_NODEFRAG`` | 0x00002000 | RW | Disable fil= esystem defragmentation for file. | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_FILESTREAM`` | 0x00004000 | RW | Enable file= stream allocator (directories only; XFS). | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_DAX`` | 0x00008000 | RW | Direct Acce= ss (DAX) I/O (regular files and | >> >> +| | | | directories= only); mutually exclusive with | >> >> +| | | | ``FS_XFLAG_= VERITY``. | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_COWEXTSIZE`` | 0x00010000 | RW | Copy-on-Wri= te extent size allocator hint | >> >> +| | | | (regular fi= les and directories only). | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_VERITY`` | 0x00020000 | RO | fs-verity e= nabled, read-only (set via verity ioctl). | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_CASEFOLD`` | 0x00040000 | RO/RW | Case-insens= itive lookups. | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_CASENONPRESERVING`` | 0x00080000 | RO | Case not pr= eserved in directory lookups. | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_PROJID`` | 0x00100000 | RW | Project ID = value flag (VER1). | >> >> +| | | | Updates req= uire ``init_user_ns``. | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_COMPR`` | 0x00200000 | RO/RW | Compressed = file flag. | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_ENCRYPT`` | 0x00400000 | RO | Encrypted f= ile flag (fscrypt). Read-only. | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_HASATTR`` | 0x80000000 | RO | Inode has e= xtended attributes. Read-only. | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> + >> >> + >> >> +.. _masks: >> >> + >> >> +Masks >> >> +=3D=3D=3D=3D=3D >> >> + >> >> +In ``VER1``, the fileattr API introduced the ``fa_xflags_rw_mask`` a= nd >> >> +``fa_xflags_ro_mask`` fields, to enable its usage without needing a >> >> +Read-Modify-Write cycle like ``FS_IOC_SETFLAGS`` and ``FS_IOC_FSSETX= ATTR`` >> >> +require. >> >> + >> >> +To use this feature ``AT_FILEATTR_MASKS`` needs to be set in the ``a= t_flags`` >> >> +argument of file_getattr() / file_setattr(), otherwise the normal be= haviour is kept. >> >> + >> >> +.. note:: >> >> + For filesystems that don't support masks (and for userspace witho= ut >> >> + ``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() populate= s >> >> + ``fa_xflags_rw_mask`` with all xflags it supports modifying on thi= s inode, >> >> + and ``fa_xflags_ro_mask`` with all read-only xflags it supports re= porting. >> >> +- 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 old RMW APIs, where unsu= pported >> >> + flags were often silently dropped: >> >> + >> >> + - on filesystems without mask support, file_getattr() returns >> >> + ``fa_xflags_rw_mask =3D 0``, causing file_setattr() to fail wit= h >> >> + ``-EINVAL``; >> >> + - on filesystems with mask support, file_getattr() returns all su= pported >> >> + writable xflags in ``fa_xflags_rw_mask``, so file_setattr() tri= es to set >> >> + all of them on ``file2`` and fails with ``-EOPNOTSUPP`` if ``fi= le2`` >> >> + doesn't support all of them, instead of silently dropping them. >> >> + >> >> + With masks, the program can inspect ``file2``'s masks first and d= ecide how >> >> + to handle unsupported flags. >> >> + >> >> +On file_setattr() >> >> +----------------- >> >> + >> >> +- Userspace populates ``fa_xflags_rw_mask`` with the xflags it wishe= s 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 u= nmodified. >> >> +- For boolean attributes: >> >> + >> >> + - Setting the xflag bit in both ``fa_xflags_rw_mask`` and ``fa_xfl= ags`` >> >> + 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_COWE= XTSIZE``): >> >> + >> >> + - Setting the flag bit in both ``fa_xflags_rw_mask`` and ``fa_xfla= gs`` 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 requ= est fails >> >> + with ``-EINVAL``. >> >> + >> >> +- Validation: >> >> + >> >> + - If the filesystem supports masks, requesting modification of any= flag not >> >> + advertised in the filesystem's writable mask fails with ``-EOPNO= TSUPP``. >> >> + - If the filesystem does not support masks, requesting modificatio= n 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`` >> >> +=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_setatt= r() 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 ``fileatt= r_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 de= ntry *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) /= 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; /* Set request uses masks (AT_FILEA= TTR_MASKS) */ >> >> + bool get_only_masks:1; /* Transitional: fs supports ro_mas= k on get, RMW on set */ >> >> + }; >> >> + >> >> +Fields of struct file_kattr have the same semantics as their user-fa= cing >> >> +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`` a= nd ``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. >> > >> > Not accurate. On get they are hints, and on set both may be true (e.g.= ksmbd). >> > Please describe what each means on get and on set. >> >> Ah, yes, will do. >> >> >> + >> >> +``has_masks`` >> >> + Indicates whether ``fsx_xflags_rw_mask`` and ``fsx_xflags_ro_mas= k`` contain >> >> + valid masks. >> >> + >> >> +``use_masks`` >> >> + Indicates whether the set request uses mask semantics (the in-ke= rnel >> >> + equivalent of ``AT_FILEATTR_MASKS``). >> > >> > Please describe the contract for a filesystem that accepts masks in se= t: >> > what it receives (only bits within fsx_xflags_rw_mask, value fields ze= ro unless >> > selected, flags_valid false) and that it must change only what rw_mask= selects. >> >> Yes, right, will add. >> >> >> + >> >> +``get_only_masks`` >> >> + Transitional flag indicating that the filesystem supports ``fsx_= xflags_ro_mask`` >> >> + on get, but still expects unmasked RMW input in ``->fileattr_set= ()``. >> > >> > Please document the rule that a filesystem should accept masks on set >> > only after all of its writable FS_*_FL flags have xflag counterparts, >> > because FS_IOC_SETFLAGS of a flag without an xflag will fail with >> > EOPNOTSUPP. Until then, use get_only_masks. >> >> Right, that's what I was missing about get_only_masks (since I mentioned >> it only in the "adding new flags" part, I had a hunch I missed something= ). >> >> >> + >> >> +VFS Helpers >> >> +----------- >> >> + >> >> +When implementing ``->fileattr_get()``, filesystems can populate str= uct >> >> +file_kattr using either fileattr_fill_xflags() or fileattr_fill_flag= s():: >> >> + >> >> + 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 unsupporte= d >> >> +xflags in ``->fileattr_set()`` using fileattr_has_fsx(), while >> >> +mask-aware drivers can validate against their allowed xflags masks w= ith >> >> +fileattr_has_invalid_fsx_masks():: >> >> + >> >> + bool fileattr_has_fsx(const struct file_kattr *fa); >> >> + >> >> + bool fileattr_has_invalid_fsx_masks(const struct file_kattr *fa, >> >> + const u32 allowed_rw, >> >> + const u32 allowed_ro); >> >> + >> >> +The table below lists all ``FS_*_FL`` and ``FS_XFLAG_*`` flags and t= heir >> >> +corresponding translations: >> >> + >> >> ++------------------------+--------------------------------+ >> >> +| ``FS_*_FL`` | ``FS_XFLAG_*`` | >> >> ++=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+ >> >> +| ``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`` | >> >> ++------------------------+--------------------------------+ >> > >> > Still very much not happy about this section. >> > How about merging only some of it with with XFLAGS table above >> > For example: >> > >> >> +| Flag Macro | Hex Value | Xflags mode | Flags = mode | Description and Constraints | >> > ... >> >> +| ``FS_XFLAG_CASEFOLD`` | 0x00040000 | RO | RW | Case-inse= nsitive lookups. | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_CASENONPRESERVING`` | 0x00080000 | RO | - | Case not = preserved in directory lookups. | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_PROJID`` | 0x00100000 | RW | - | Project = ID value flag (VER1). | >> >> +| | | | Updates req= uire ``init_user_ns``. | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_COMPR`` | 0x00200000 | RO | RW | Compresse= d file flag. | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> +| ``FS_XFLAG_ENCRYPT`` | 0x00400000 | RO | RO | Encrypted = file flag (fscrypt). Read-only. | >> >> ++--------------------------------+------------+--------+------------= -------------------------------------------+ >> >> Oh, yeah, the 2 columns for RO/RW are nicer and I can add a column so we > > Yes. > >> have "Flag Macro" "XFlag Macro" ((I really don't like "Xflag")) and have >> only 1 table instead of 2? > > One table, yes. > Writing all the flags there like this and their hex values: > > FS_XFLAG_ENCRYPT | FS_XFLAG_ENCRYPT (Assuming you meant FS_XFLAG_ENCRYPT | FS_ENCRYPT_FL) > > I think it's just silly and has no place in this doc. Hmm, can you check how it looks? https://koraynilay.neocities.org/vfs-masks= /fileattr (don't mind the unclear writing in the note above it, I haven't read it manually yet) > If you want you can tell the story about file attributes, some can be > access by one API, some by another and some by both the story can > tell about the template of the FS_*_FL and FS_XFLAG_* constants etc > and the table could be keyed by the attr name (e.g. ENCRYPT) > and the table will say for each what it is and which API can access it > with which mode, hence: > > | Attribute | xflags | flags | Description and > Constraints | > ... > | ``NOCOMP`` | - | RW | .... > +------------------------+-----+-------+---------------------------------= ----------------------+ > | ``COMPR`` | RO | RW | Compressed file flag. > | > +-------------------------+-----+------+---------------------------------= ----------------------+ > | ``ENCRYPT`` | RO | RO | Encrypted file flag (fscrypt). > Read-only. | > +-------------------------+-----+-----+----------------------------------= ---------------------+ So you mean only saying the attribute name and not the flag/xflags macros? In that case, I would still keep the flag|xflag table as it is in this patch series (so devs have a visual way to know which flags have a xflag counterpart and which don't) > And then somehow also represent masked only xflags, maybe: > > | ``MAYSHAREEXT`` | MRO | - | Maye sharing data extends with other > files. | > | ``BTIME`` | MRW | - | Birth time (modifiable on > some filesystems). | Yes, but IMO this could be done in the same table as in the link above, just like all other FS_XFLAG_*. Thanks, koraynilay > Thanks, > Amir. --a3e53e622a7e9098c9ec4b088a5bf3d455fa6243bb246c8156d99a71fc5f Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQSgVimKafU5DQMcjcDmj22qf5IGXAUCaxH0UgAKCRDmj22qf5IG XBtfAQD7wW4nJ6yU3j64hko+CxhS+xY/gf4AcYvuFy64H4B0xgD+OXnq0yJxLOJG sWK/2ekw0yAvZ1NL4MYostyg8miLxw4= =r9Fq -----END PGP SIGNATURE----- --a3e53e622a7e9098c9ec4b088a5bf3d455fa6243bb246c8156d99a71fc5f--