Skip to content

Commit 80340fe

Browse files
author
Miklos Szeredi
committed
statx: add mount_root
Determining whether a path or file descriptor refers to a mountpoint (or more precisely a mount root) is not trivial using current tools. Add a flag to statx that indicates whether the path or fd refers to the root of a mount or not. Cc: [email protected] Cc: [email protected] Reported-by: Lennart Poettering <[email protected]> Reported-by: J. Bruce Fields <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent fa2fcf4 commit 80340fe

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

fs/stat.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ int vfs_statx(int dfd, const char __user *filename, int flags,
202202
error = vfs_getattr(&path, stat, request_mask, flags);
203203
stat->mnt_id = real_mount(path.mnt)->mnt_id;
204204
stat->result_mask |= STATX_MNT_ID;
205+
if (path.mnt->mnt_root == path.dentry)
206+
stat->attributes |= STATX_ATTR_MOUNT_ROOT;
207+
stat->attributes_mask |= STATX_ATTR_MOUNT_ROOT;
205208
path_put(&path);
206209
if (retry_estale(error, lookup_flags)) {
207210
lookup_flags |= LOOKUP_REVAL;

include/uapi/linux/stat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ struct statx {
181181
#define STATX_ATTR_NODUMP 0x00000040 /* [I] File is not to be dumped */
182182
#define STATX_ATTR_ENCRYPTED 0x00000800 /* [I] File requires key to decrypt in fs */
183183
#define STATX_ATTR_AUTOMOUNT 0x00001000 /* Dir: Automount trigger */
184+
#define STATX_ATTR_MOUNT_ROOT 0x00002000 /* Root of a mount */
184185
#define STATX_ATTR_VERITY 0x00100000 /* [I] Verity protected file */
185186

186187

0 commit comments

Comments
 (0)