From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795920210; b=c4zOu45xX+Ks375yYZH1NXwQNQ1jejWA++ZQA3gl1uYcZWR0Hf0NZ73luFBZkM+gl4T8 aV1AEsKqVB7zomc1f/u7/TpQk8hBhRJ4O9uQ7Mi5TaUyq+78Eh0UsFii6x/xI3s98f8zt eTBKSlA2M9CZV8u0jJKDeZ48Myg46ZtzzPBnptrol8TEGwoDKIp2VxqWNJrkDGZYzV7du e1QWzS/iOJgY5sFoqjuNdi/QKGT4NEmp22GDOp6Qf5oNpaoDSogL7NDVP+Nq7MdtV0v+H hYtBrQdyH6fYIIaC/i0JOEq0AX4AiAiE1lh1qEpZjAPmN/BsD6bQl8/h9Z6FOE4MuiA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795920210; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=3CaNphA2/6V8UNcSalG5w305ta+5iT96FUlJJg+0fBQ=; b=fm7DjLERBuJu5hARaGgd3b3RnKXgengLG6QYkaBejUJI8Wlab59qIJMptX7xgAA4wMoU dZaTIiUYOVmCY2n1o5QyGoC7S3IBz/U75OZc7eAkV56Mz2ytjUSi1dBJwqMUjn52Ii1kk ipjD7K8aih6nQzDdq2xfsuI43FrmYE4hdwuD6N/O2UsjKUTD+zmtXSfOTRminqEinZYTo 1XkMMOLx8ubld1D6uXpXtEm/CviLyZcuif2I8SqLDyVjjqILlh+ehBdAgVyrIj+wwyfwB Ii9/Zyjgv3Cv235T4HyPOWc0ZNsMSevkncRTAIpXYo/hMh5nitySoDQDyWCOZaBfN+w== 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=VVaiJiEm; arc=none smtp.remote-ip=209.85.221.51 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (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 3C81F606A327 for ; Sun, 29 Nov 2026 02:43:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3C81F606A327 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=VVaiJiEm Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-491846221ffso8170763f8f.3 for ; Sat, 28 Nov 2026 18:43:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795920208; x=1796525008; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=3CaNphA2/6V8UNcSalG5w305ta+5iT96FUlJJg+0fBQ=; b=VVaiJiEmHBwqq7G40SEwfkZyBOwo7WJ2QnOpVDDlL2vwXkAl7gf9E1Awga4fSOwINO wuPN3HMz6s/2/jBz8IejQSNJniN+wKqtBqN10aXCWwN6sgtaV25WfqrEJ2B1oQOITwf7 IWcZ47l4w+/gf4hOVgGB2IFxVwNBU4G+T/dVwr4qA2WOOYxfUw6cXTmSUI5fepzu5rJm Tu580a+0yfylxMJLb16EpXotF/xTx0UIEPC8ak5XcD2njuaq2LZQrEsT3yDqqEQT/Bda 4//OG50p2cHZl4Nqr53YGPN6dsUWLUPgEEF+Lf2vQG1biEZ0xy8kUR/jAbEkgQSb4Wfv 72AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795920208; x=1796525008; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3CaNphA2/6V8UNcSalG5w305ta+5iT96FUlJJg+0fBQ=; b=d/k9zSLd0aCUM4yC5n6WQd5mfAMUTxFBomUpCY4KA4jhgyvzRTt/PoFRjGFyw9xXSm yd6qLvfGJhHDNRdUdCRHoWiGt1VyFBG/rCvGQD6jUJM+0SNiWEYA+kyrUPAQq74x1srT LaYzeW4M9GG80l/Q1Yvx9tY9xbLa1OOxuzGuaf717fu6lVj9fPTHkkDbU/FLcvar+tgu eW7dFGdNK1qs58nwqJZNYO4lzicuEZ72q1XafwIBYeAbtPAPpg0joicwcbRKHHIsas4n LPYi5XrMKGmniCh49HS/BZ1vr76UOJKP/9z0ozDpUcG7QuXl8dcLYRLHuK2DJEpzX5r6 XEow== X-Forwarded-Encrypted: i=1; AL+hErHJRI7WX5niQfncZWHVxDmI+qDVbx+hXAn8gobkxC2l+45XK0OzRAdBccN/WNOtjVqHOfN8mCoIzQBpEw==@vger.kernel.org X-Gm-Message-State: APuU4Z+nSBr9F3GziC31D8XaXlysTA+waYvG1e8iIaY+YHV8rZ2DcURN Krv3d/iPg/IgQUBl0wqHS2uTEOkCiX7SyczTSO/ZRlkYckSHUybBlhC5 X-Gm-Gg: AZFdTZd0NgIOBz3oKOU0pTfP+B02uXxrd+voykU4LOCrdhQfJCB7a1xQD83TqdzH5r1 zXejSmgfL0xz4dIGBdFUIufq3r7PsRGSTv8TNHu9caKaHd4Lv3EsNQAAb00zzt9PREmfJUhE/hR M05pW5MOnA+/bQF6gOvJvH3KV5WtVP+PWHkItllo69JkjGgC3E6U+c0V8bc+EUdl78EznuVoEHS REjCusK3H/7VE2GDg4t1wSwA7KeUpAgOyuhaaMUA2w3yHuOoQpRAD1UHHovLAhL0TPNiOuCESci 6mrQvrmSLUN1fY+245lROOZgl+xTLW2bn69yNl7+sjyt99TK+1JvsGyUdtt8u4Or6jYZDJTCUoI whRGiqZYtP+itNi/IYf5J5GkBwX8UCfmYVvIfk50acIhB8Y5B+06Nlh4D9tq8mnVDZonwMGB9Vn 6MUTNEmC5xEE7XIdL9cPoVsgn1HkJyooakD/f7zTcYnfV2bEDE4+oIRSLFVGee2081f9koFSLuv kLcSdRgWJnkgTf4Ya3N5M61JFqd13cQ7Fw1pnbYId7LzK29ybqz9r31cG+y09tz/f/+JkDyGD5j gwe2WvAbYqAt07JjVfPOpKZq X-Received: by 2002:a05:6000:4026:b0:4c1:4d45:f5e6 with SMTP id ffacd0b85a97d-4c14d45f76cmr8517039f8f.12.1795920208339; Sat, 28 Nov 2026 18:43:28 -0800 (PST) Received: from infinity ([2001:b07:5d26:7a6a:365a:60ff:fe0d:cfc6]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4ab6b110ba3sm46551960f8f.35.2026.11.28.18.43.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2026 18:43:27 -0800 (PST) From: koraynilay To: Namjae Jeon , Hyunchul Lee , Jonathan Corbet , Eric Biggers , "Theodore Y . Ts'o" , Jaegeuk Kim , Alexander Viro , Christian Brauner Cc: Shuah Khan , Randy Dunlap , Chuck Lever , Jeff Layton , Jan Kara , Alexander Aring , "Darrick J . Wong" , Andrey Albershteyn , Amir Goldstein , Miklos Szeredi , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Lauri Gates , Christoph Hellwig , Dave Chinner , 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 Subject: [PATCH v3 0/5] Add f*_xflags_{rw,ro}_mask flags to the fileattr API Date: Sun, 29 Nov 2026 03:42:28 +0100 Message-ID: <20261129024233.2361718-1-koray.fra@gmail.com> X-Mailer: git-send-email 2.56.0 X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This is a follow up patch series stemmed from [1] and [2], splitting the _mask change for the fileattr API into its own separate patch series. Patch 1 is a preparatory cleanup so that the code in the later patches can be formatted better. Patch 2 is the actual implementation, which introduces: - fa_xflags_{rw,ro}_mask fields to struct file_attr - fsx_xflags_{rw,ro}_mask fields and has_masks selector to struct file_kattr - AT_FILEATTR_MASKS at_flag for file_[gs]etattr() These masks have the following semantics: - rw_mask: * for filesystems: advertise which xflags they support changing * for userspace: specify which xflags it wants to modify - ro_mask: * for filesystems: advertise which xflags they support only reading * for userspace: ignored (More details available in Patch 5) This allows userspace to not have to do a RMW cycle when using the file_[gs]etattr() syscalls, avoiding possible race conditions and simplifying their usage. This patch also introduces the missing FS_XFLAG_PROJID flag so that programs like chattr can leverage the new mask API. FS_XFLAG_PROJID is kept out of the legacy FS_XFLAGS_MASK and so it's defined as part of a new FS_FILE_ATTR_XFLAGS_MASK group of xflags that will be used moving forward for any new xflag (like the one proposed in [2]). Patch 3 adds FS_XFLAG_COMPR and FS_XFLAG_ENCRYPT (as FS_COMPR_FL and FS_ENCRYPT_FL counterparts), which are needed for Patch 4. This means that old programs will also get these new flags, but that should be fine since xflags were made to be expandable. Patch 4 converts fs/ntfs to this new API, to show how it can benefit filesystem drivers too. Patch 5 adds the Documentation/filesystems/fileattr.rst page that explains well how this API can be used by both userspace and by filesystems and the various semantics. (It doesn't go into *too much* detail though, since that would mean writing the code itself). The rendered page can be found at [4]. The series has been tested with custom xfstests [3] (generic/816-835, xfs/611, xfs/673) across NTFS, ext4 (project quotas), XFS (project quotas and extent size hints), Btrfs, and F2FS. Note: these tests were written by gemini and not manually checked, before sending them upstream (if needed) I'll have to review/rewrite them manually. IMPORTANT NOTE: there are quite a few bugs with overlayfs (generic/832-835 above) when using a masks filesystem, I haven't investigated them deeply yet since I would first need to understand a lot more how overlayfs works, but the robot's report is in [5]. v3 changes: - refactor the big if/else in vfs_fileattr_set() to a fileattr_set_convert() helper and simplify (hopefully?) its code; - drop fscrypt flags -> xflags patch and just use xflags_to_flags() in vfs; - add FS_XFLAG_COMPR/ENCRYPT in a separate patch instead of in the ntfs one ([6]); - move FILE_ATTR_SIZE_VER* variables from the uapi header to the internal header ([7]); - rename AT_FILE_ATTR_MASKS to AT_FILEATTR_MASKS ([8]); - change "legacy" references to "rmw" references in both comments and helper names ([8]); - add docs. v2 changes: - make fa_xflags_{rw,ro}_mask in struct file_attr __u64; - add AT_FILE_ATTR_MASKS to opt in to mask semantics instead of needing unreliable heuristics on usize and mask values; - reject intermediate sizes between VER0 and VER1; - reject non-zero masks on SET without AT_FILE_ATTR_MASKS; - add patch 2/4 for fscrypt_prepare_setflags; - add xflags_to_flags() / flags_to_xflags() and fileattr_set_{legacy_to_mask,mask_to_legacy}() to translate between legacy RMW callers/filesystems and _mask callers/filesystems; - clamp fa->fsx_xflags to rw_user_mask in file_attr_to_fileattr(); - update fileattr_set_prepare() to validate capabilities and projid changes against rw_user_mask / xflags; - move the rw_mask == 0 early-return no-op from file_setattr() into vfs_fileattr_set(); - put FS_XFLAG_COMPR in FS_XFLAG_RDONLY_MASK only (keep FS_XFLAG_ENCRYPT in both FS_XFLAG_COMMON and FS_XFLAG_RDONLY_MASK); - update ntfs_fileattr_set() to apply only bits selected in fsx_xflags_rw_mask; Thanks, koraynilay [1]: https://lore.kernel.org/CAOQ4uxg8aVcWyNiFDk8djdn-M3xJcu_7-kRxVq9jjFsbcGp1ew@mail.gmail.com/ [2]: https://lore.kernel.org/CAOQ4uxjVQ9cjV=_jBjQtNg9zCuWUEJT9KNYMKV+1jwBkHen5OA@mail.gmail.com/ [3]: https://github.com/koraynilay/xfstests/tree/patches-in-queue [4]: https://koraynilay.neocities.org/linuxdocs/fileattr [5]: https://koraynilay.neocities.org/vfs-masks/overlayfs-fileattr-bugs [6]: https://lore.kernel.org/CAOQ4uxgJjy3TaORBkMOdef-JvzX2uA5K2sbMDEcLqmpkedsESw@mail.gmail.com/ [7]: https://lore.kernel.org/CAOQ4uxi6oyFj_A9nPbgGeSufGo11L2N=QxLi2DW=ZKy25YQ5Tw@mail.gmail.com/ [8]: https://lore.kernel.org/CAOQ4uxhA+93bo5WseLxe7cAvJHJ8eQodoQHLwh=iToyEVkeXEA@mail.gmail.com/ koraynilay (5): vfs: use goto out on error in vfs_fileattr_set() vfs: add xflags masks to fileattr API vfs: add COMPR/ENCRYPT xflags from FS_COMPR_FL/FS_ENCRYPT_FL ntfs: switch to the new xflags fileattr API docs: add fileattr API documentation Documentation/filesystems/fileattr.rst | 530 +++++++++++++++++++++++++ Documentation/filesystems/index.rst | 1 + Documentation/filesystems/vfs.rst | 19 +- fs/file_attr.c | 379 +++++++++++++++--- fs/ntfs/file.c | 109 ++--- include/linux/fileattr.h | 19 +- include/uapi/linux/fcntl.h | 6 + include/uapi/linux/fs.h | 37 +- 8 files changed, 985 insertions(+), 115 deletions(-) create mode 100644 Documentation/filesystems/fileattr.rst base-commit: 3857587d9d6fa44d40d1c73bde6a39f6f7a5216c -- 2.56.0