From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.43 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796480691; b=1OF8jkNapYDyiBDjA++GYvRFPtLT9CsvWbOszOLsDG1+Ysg+ZG7zFHtWk9IHyd81bQ85 /0BmlvtQnLz+ZVt7QUOK4FWfGNuFrLPvKQc/wLkBTVAq4L2+dKyBobHsPLM6vSq/ufTUL 4Ld1c9Ax+9mO5in3b45X/AyZezHt4CIr7a9vrRdomAt4uxceQkBpCXdDNwQ4RMJ56GkpK Sqy2xfsCobf46b8qkRo+9gulJfl7rNzZ/711RebUwTrkN0PxfF6GDVeYDATGdYrQvotVZ mx2jYhu2PzPLjg+uIHtVQHxCRfdgEV/CFefu0feoOUqt6UD8RgnBYLKZKMBiZZQEkMA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796480691; 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=rjo3nxJAHCVik2tbCDtWRWWgyefTWvJvK6clOX7n03c=; b=nCE8Z1Kmah+YM4LElacYlsQCeisqpvPbsxH80KnsAMFUXBVzJaAySSasF/rBK3ENVvY2 POOaklD3Nsb+e8C57MrxMXLZNbNDLw3d1UPAMpwFBpTbJ0g56awd21yqAN6cdNFRelzri hyiKduASUxxHGX/YAYrBYH3LeqtxGab8XhDCcRc+WzOegm+vEZBIWeBT2gr1tQteIBtvr H63DvfmT/NTKnWi7wQ3eohB+W7NwiIW11l+hdSkO0FItx4TXrhlJa0PTQ6UoYR2PiV6Aj WuEndGqjkGrSjmZKIWPuoPwo2/OjivgfMTrTYxWuxfe/ipyazaY4ttq7tY4s23KlexA== 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=AYOhCFNu; arc=none smtp.remote-ip=209.85.221.43 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 38A6E606A332 for ; Sat, 5 Dec 2026 14:24:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 38A6E606A332 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=AYOhCFNu Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-4a9be758734so1506354f8f.1 for ; Sat, 05 Dec 2026 06:24:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796480690; x=1797085490; 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=rjo3nxJAHCVik2tbCDtWRWWgyefTWvJvK6clOX7n03c=; b=AYOhCFNuNiPu5WbaxK4lY4NOjZHvjdvFvuXqa0853leqel6knF5QwM89fpIHPfjZ7b TzCL8gK/IQsliJRD8RaGXxK/bl0+amURAMeeyMmfmp5SYXBtdH307RiD5S1Ff8t9ei2P I3b3d9lEVxabAZmiP7CObFg1sVUCUD19vjU/J0ODA9UVgwiwaqiapYWmTtW21uIhVMv0 dJvix9MBUnYRqfd1LpHU9pBH1aWcVVsfwh8ctZfW4tCspQBLp2nYWulruD+OZxfupJ/Q 0lh+FOn9WnwlbQpvHnOvzwxRHx7NxwQ2u5fq9raAd+h1eSKCN2VxgsvNTpMjBPmqi2sN PNjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796480690; x=1797085490; 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=rjo3nxJAHCVik2tbCDtWRWWgyefTWvJvK6clOX7n03c=; b=1StZ2EADVqTlhJbxDmSPLC6yBL5Wl0CwlHjvH9WzKqPwa2NUizgB7LSpgEmHXYq245 zy6rRHAcBvrcpGIUw/BSFMqfGJ9AP0Ew6J4qPEXu5TqoKrvyoAyQhcszf0EKlIHyPrLL scVKy4ljp2xgUmyTjlzWkSe6WNd8Xc2B6U4DwntAasgvvSwRjMfaupQVxmoCJA0iJ4Ha XVywSewoZqzS4KENBnMpEkMDD9c3nyBXiTqE4UhRcHF1UZTczoE/LjBy9/HLlg2HugYx BwgwyZcIGQddOXCocFpRVQ11nr3VGpw22qTxfgRn2rsP3YOraMzwnF6/zN7jI/bZHJcY bfBg== X-Forwarded-Encrypted: i=1; AL+hErEjJ6/Soq2L3Yg6RUW8xXJ/MgQ2LDzqGYy0teZFALOXkhvPjnWmgovOsrJu98Ujf4rG0mbSlJ4WIFA=@vger.kernel.org X-Gm-Message-State: AB4q+uENpZwC9Dn2Zkg8K9emfFdBrNoegzJ12SeDkvTSgkorI1XN2PwV CPXxGRKtYTb+ADytAEOJr0k4Qo0RjeYCU10rOLptJY+EJj2YhXUtqShw X-Gm-Gg: AZFdTZdMpDHewQkUbNgsv+aS0Flek9Bm8Uz95GSw/kEsRgczfVWyx6LNpf++jUqdC+U JX7YJ/rPFm0OWJf8dMvFT43Trc+jQcEXS4jfgAa2DzOkw5uEl3sN6alPB09+bS7DViMY5KLYVP7 SI+5gbhEY5OAXV4DuGnJN4QdBI/3LqL7QT0VhAmp/LmI1uX5Eh+P1OpxLAHDfaJWwtl+F4IAvB6 Vy5Kd8x6kyQ3bRw8KI+0x+ANN5uAqP5hkWta1T/ydCOA44dpB3QIh62ulPCNCVJY+tJSNMYjfX+ KW2ZO1orZDSds6r9RTBOMBhdJFORmLroZ790HaQKHngpkfB8rgLGiqT082uBKS0NcDw5uwAA7vy xsFJQRaSm/J9HSmfSrnI5hsyuMIQ2V34v/ZNcovxryicrbRersaHCK17vFobPUqm7OzDK2YzX/I AIVW/V9aYJTTnFiLltwHR6sBDJsMqTFCBJMvcDyKVMfZW5IRqIrEaRgty22To/LjA3JCNikjHSp 2wPZFmy2JrC5YrnzRWm0Jnyzk/YZQ4XEbC5MypU/0GBWQPvFwLnuPOBS5ha+aDq5sLD9WigGpLN jWZF0Ua+q6R6jOg0HJatlS3v X-Received: by 2002:a05:6000:2b89:b0:4d1:5412:fc56 with SMTP id ffacd0b85a97d-4d1e8dbcef0mr6594052f8f.12.1796480689371; Sat, 05 Dec 2026 06:24:49 -0800 (PST) Received: from infinity ([2001:b07:5d26:7a6a:365a:60ff:fe0d:cfc6]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d174d08d42sm10776969f8f.55.2026.12.05.06.24.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 06:24:48 -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 v5 00/12] Add f*_xflags_{rw,ro}_mask flags to the fileattr API Date: Sat, 5 Dec 2026 15:23:59 +0100 Message-ID: <20261205142411.164484-1-koray.fra@gmail.com> X-Mailer: git-send-email 2.56.1.dirty X-Mailing-List: linux-api@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. The series extends the fileattr API with xflags masks by introducing: - fa_xflags_{rw,ro}_mask fields to struct file_attr - fsx_xflags_{rw,ro}_mask fields and has_masks / use_masks / get_only_masks selectors 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 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. The series 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 FSX_FSXATTR_MASK and defined as part of the new FSX_FILEATTR_MASK group of xflags that will be used moving forward for any new xflag (like the one proposed in [2]). In addition, FS_XFLAG_COMPR and FS_XFLAG_ENCRYPT are added (as FS_COMPR_FL and FS_ENCRYPT_FL counterparts) for fs/ntfs, which is converted to the new mask API as an example. Old programs will also get these new flags, which should be fine since xflags were made to be expandable. Documentation/filesystems/fileattr.rst explains how this API can be used by both userspace and filesystems along with 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]. Please also check the specific patch comments. 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]. To help me develop this patch series I used Gemini 4 Hydrogen/Neon in antigravity-cli to audit the code, find edge-cases, propose possible fixes, develop and run the tests above and help with comments/language/style. Thanks, koraynilay v5 changes: - split the v4 masks patch (3/7) into smaller patches, and separate get_only_masks into the overlayfs fix patch; - move FSX_COMMON / FSX_RDONLY_MASK comments into the rename patch; - add FSX_EXTSIZE_MASK to the rename patch to avoid having to always OR the two extsize macros in the later patches; - simplify file_attr_to_fileattr() with an early return when !use_masks; - fix mid-series ntfs regression by guarding the COMPR/ENCRYPT check with fa->flags_valid (kept in xflags conversion patch, removed in the masks conversion patch); - move NTFS_{RO,RW}_XFLAGS macros into the xflags conversion patch; - replace open-coded extsize/projid/cowextsize check with fileattr_fsx_ok(), rename fileattr_has_invalid_fsx_masks() to fileattr_fsx_masks_ok(), and build it on top of fileattr_fsx_ok() in the masks conversion patch; - docs: merge the two flag tables (ordered BOTH, XFLAGS-only, FLAGS-only, drop RESERVED/EOFBLOCKS, add single-fs notes and descriptions); - docs: clarify {flags,fsx}_valid for get vs set; - docs: document get_only_masks's writable-counterpart requirement; - docs: add the Filesystem Contract for Masks section; - add patch comments for 2/12, 8/12, 9/12 and 10/12. v4 changes: - add patch 2/7 to shorten internal xflag macro names (FSX_*) and document FSX_COMMON / FSX_RDONLY_MASK; - split ntfs conversion into flags->xflags (5/7) and masks support (6/7); - add use_masks and get_only_masks selectors to struct file_kattr, and clamp FS_IOC_SETFLAGS in fileattr_set_convert() (as discussed in [9]); - rename fileattr_set_{rmw_to_mask,mask_to_rmw}() to fileattr_set_{to,from}_masks(); - reject rw_mask == 0 and clearing value attributes with non-zero values with -EINVAL; - add FSX_FSXATTR_SET_MASK and clamp unmasked new_xflags in fileattr_set_from_masks(); - add fileattr_has_invalid_fsx_masks() and use it in ntfs_fileattr_set(); - update docs per v3 review (focus on internals, reference man-pages, VER0/VER1 phrasing); - dropped all Assisted-by tags and add LLM-usage explanation above. 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; [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/vfs-masks/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/ [9]: https://lore.kernel.org/DN8RMUP6F5CI.2KSDF5TMCRO1X@gmail.com/ koraynilay (12): fs: use goto out on error in vfs_fileattr_set() fs,overlayfs: rename FS_XFLAGS_MASK and shorten other internal macro names fs: move fileattr sizes out of uapi and factor out set_preserve() fs: switch fileattr_set_prepare() to xflags and refactor projid check fs: add initial implementation of xflags masks to fileattr API fs: add UAPI implementation of xflags masks to fileattr API fs: add missing FS_XFLAG_PROJID xflag fs,overlayfs: add fileattr masks support on get fs,ntfs: advertise COMPR/ENCRYPT xflags in file_getattr() ntfs: switch from flags to xflags in ntfs_fileattr_get/set() ntfs: support the fileattr API masks in ntfs_fileattr_get/set() docs: add fileattr API documentation Documentation/filesystems/fileattr.rst | 463 +++++++++++++++++++++++++ Documentation/filesystems/index.rst | 1 + Documentation/filesystems/vfs.rst | 19 +- fs/file_attr.c | 402 ++++++++++++++++++--- fs/ntfs/file.c | 98 +++--- fs/overlayfs/copy_up.c | 2 +- fs/overlayfs/inode.c | 5 +- include/linux/fileattr.h | 129 ++++++- include/uapi/linux/fcntl.h | 6 + include/uapi/linux/fs.h | 38 +- 10 files changed, 1038 insertions(+), 125 deletions(-) create mode 100644 Documentation/filesystems/fileattr.rst base-commit: d8d9179592a52044a52591b31b914cfc0edbf36d -- 2.56.1.dirty