mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v1] ntfs: support persistent noatime attribute
@ 2026-10-16  3:09 Xuewen Wang
  2026-10-16  4:23 ` liubaolin
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Xuewen Wang @ 2026-10-16  3:09 UTC (permalink / raw)
  To: linkinjeon, hyc.lee; +Cc: ntfs, linux-kernel, Xuewen Wang, Baolin Liu

NTFS currently rejects FS_NOATIME_FL in its fileattr setter. This prevents
users from disabling automatic access-time updates on individual files or
directories with chattr +A.

Store noatime in bit 3 of the private $LINUXFLAGS EA and restore S_NOATIME
when loading an inode. Report and accept FS_NOATIME_FL in the fileattr
callbacks, updating the in-memory flag only after the EA update succeeds.
The VFS then suppresses automatic atime updates for the inode, while
chattr -A restores the mount's atime policy.

Document the new on-disk bit and that newly created children do not inherit
the attribute.

Suggested-by: Baolin Liu <liubaolin@kylinos.cn>
Reviewed-by: Baolin Liu <liubaolin@kylinos.cn>
Signed-off-by: Xuewen Wang <wangxuewen@kylinos.cn>
---
Tested in QEMU (x86-64, UP, NTFS debug and lockdep enabled) on disposable
NTFS images mounted with strictatime. The unpatched kernel rejects +A on
files and directories with EOPNOTSUPP. With this patch, chattr +A prevents
atime updates on reads and directory enumeration, and chattr -A restores
them. The attribute survives cache dropping, read-only/read-write remounts,
unmount/mount and a fresh boot; clearing it also survives a fresh boot.

Also checked the on-disk EA value, non-inheritance by new children,
combinations with immutable/append-only/nodump, FSGETXATTR/FSSETXATTR,
owner/nonowner permissions, EROFS on a read-only mount, rejection of direct
EA writes, and preservation of unrelated EAs and unknown flag bits.

 Documentation/filesystems/ntfs.rst | 15 ++++++++++-----
 fs/ntfs/ea.c                       |  2 ++
 fs/ntfs/ea.h                       |  4 +++-
 fs/ntfs/file.c                     | 11 +++++++++--
 4 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/Documentation/filesystems/ntfs.rst b/Documentation/filesystems/ntfs.rst
index 699e91f884d4..d5819da6ab53 100644
--- a/Documentation/filesystems/ntfs.rst
+++ b/Documentation/filesystems/ntfs.rst
@@ -38,15 +38,20 @@ The project is available at:
 Linux file attributes
 =====================
 
-The driver supports lsattr(1) and chattr(1). Immutable, append-only and
-nodump are stored in a private ``$LINUXFLAGS`` extended attribute within the
+The driver supports lsattr(1) and chattr(1). Immutable, append-only, nodump
+and noatime are stored in a private ``$LINUXFLAGS`` extended attribute within the
 standard NTFS ``$EA``/``$EA_INFORMATION`` attributes. Its value is a
 32-bit little-endian bitmask: bit 0 is immutable, bit 1 is append-only,
-and bit 2 is nodump. Unknown bits are preserved when updating the flags;
-the entry is removed when the entire value becomes zero. These settings
+bit 2 is nodump, and bit 3 is noatime. Unknown bits are preserved when updating
+the flags; the entry is removed when the entire value becomes zero. These settings
 survive inode eviction, unmount and reboot. Direct writes to this EA
 through setxattr(2) or removexattr(2) are rejected; use chattr(1) instead.
 
+The noatime attribute (``chattr +A``) suppresses automatic access-time
+updates for the inode, including when mounted with ``strictatime``. It
+applies to directories as well as files, but is not inherited by newly
+created children. Use ``chattr -A`` to restore the mount's access-time policy.
+
 System metadata files and files protected by the ``sys_immutable`` mount
 option cannot have their immutable protection cleared with chattr(1).
 Protection derived solely from the mount option is not stored in the EA.
@@ -55,7 +60,7 @@ configured per file. Compression and encryption are reported but cannot
 be changed through chattr(1).
 
 These Linux flags are enforced by Linux. Storing them in an NTFS EA does
-not make Windows enforce immutable, append-only or nodump semantics.
+not make Windows enforce immutable, append-only, nodump or noatime semantics.
 
 
 Supported mount options
diff --git a/fs/ntfs/ea.c b/fs/ntfs/ea.c
index a1f948c4d2ec..fd97da73ff5c 100644
--- a/fs/ntfs/ea.c
+++ b/fs/ntfs/ea.c
@@ -501,6 +501,8 @@ int ntfs_ea_get_linuxflags(struct inode *inode)
 		inode->i_flags |= S_IMMUTABLE;
 	if (ni->linuxflags & NTFS_LINUXFLAGS_APPEND)
 		inode->i_flags |= S_APPEND;
+	if (ni->linuxflags & NTFS_LINUXFLAGS_NOATIME)
+		inode->i_flags |= S_NOATIME;
 	return 0;
 }
 
diff --git a/fs/ntfs/ea.h b/fs/ntfs/ea.h
index 8f144fa4f9bb..3ad20431877b 100644
--- a/fs/ntfs/ea.h
+++ b/fs/ntfs/ea.h
@@ -11,8 +11,10 @@
 #define NTFS_LINUXFLAGS_IMMUTABLE	BIT(0)
 #define NTFS_LINUXFLAGS_APPEND	BIT(1)
 #define NTFS_LINUXFLAGS_NODUMP	BIT(2)
+#define NTFS_LINUXFLAGS_NOATIME	BIT(3)
 #define NTFS_LINUXFLAGS_MASK	(NTFS_LINUXFLAGS_IMMUTABLE | \
-				 NTFS_LINUXFLAGS_APPEND | NTFS_LINUXFLAGS_NODUMP)
+				 NTFS_LINUXFLAGS_APPEND | NTFS_LINUXFLAGS_NODUMP | \
+				 NTFS_LINUXFLAGS_NOATIME)
 
 extern const struct xattr_handler *const ntfs_xattr_handlers[];
 
diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
index 58aad7f5c6c5..2cbe780758e3 100644
--- a/fs/ntfs/file.c
+++ b/fs/ntfs/file.c
@@ -167,6 +167,8 @@ int ntfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
 		flags |= FS_IMMUTABLE_FL;
 	if (vi->i_flags & S_APPEND)
 		flags |= FS_APPEND_FL;
+	if (vi->i_flags & S_NOATIME)
+		flags |= FS_NOATIME_FL;
 	if (ni->linuxflags & NTFS_LINUXFLAGS_NODUMP)
 		flags |= FS_NODUMP_FL;
 	if (!NVolCaseSensitive(ni->vol))
@@ -200,7 +202,8 @@ int ntfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,
 {
 	struct inode *vi = d_inode(dentry);
 	struct ntfs_inode *ni = NTFS_I(vi);
-	u32 allowed = FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL;
+	u32 allowed = FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL |
+		      FS_NOATIME_FL;
 	u32 readonly = 0;
 	u32 linuxflags = ni->linuxflags & ~NTFS_LINUXFLAGS_MASK;
 	unsigned int new_fl = 0;
@@ -245,6 +248,10 @@ int ntfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,
 	}
 	if (fa->flags & FS_NODUMP_FL)
 		linuxflags |= NTFS_LINUXFLAGS_NODUMP;
+	if (fa->flags & FS_NOATIME_FL) {
+		new_fl |= S_NOATIME;
+		linuxflags |= NTFS_LINUXFLAGS_NOATIME;
+	}
 
 	mutex_lock(&ni->mrec_lock);
 	err = ntfs_ea_set_linuxflags(vi, linuxflags);
@@ -252,7 +259,7 @@ int ntfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,
 	if (err)
 		return err;
 
-	inode_set_flags(vi, new_fl, S_IMMUTABLE | S_APPEND);
+	inode_set_flags(vi, new_fl, S_IMMUTABLE | S_APPEND | S_NOATIME);
 	inode_set_ctime_current(vi);
 	mark_inode_dirty(vi);
 	return 0;
-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-17  1:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-16  3:09 [PATCH v1] ntfs: support persistent noatime attribute Xuewen Wang
2026-10-16  4:23 ` liubaolin
2026-10-16  6:41 ` Hyunchul Lee
2026-10-17  1:34 ` Namjae Jeon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®