mount-util: add new path_get_mnt_id() call that queries the mnt ID of a path
This is a simple wrapper around name_to_handle_at_loop() and fd_fdinfo_mnt_id() to query the mnt ID of a path. It uses name_to_handle_at() where it can, and falls back to to fd_fdinfo_mnt_id() where that doesn't work. This is a best-effort thing of course, since neither name_to_handle_at() nor the fdinfo logic work on all kernels.
This commit is contained in:
@@ -302,6 +302,16 @@ int path_is_mount_point(const char *t, const char *root, int flags) {
|
||||
return fd_is_mount_point(fd, basename(t), flags);
|
||||
}
|
||||
|
||||
int path_get_mnt_id(const char *path, int *ret) {
|
||||
int r;
|
||||
|
||||
r = name_to_handle_at_loop(AT_FDCWD, path, NULL, ret, 0);
|
||||
if (IN_SET(r, -EOPNOTSUPP, -ENOSYS, -EACCES, -EPERM)) /* kernel/fs don't support this, or seccomp blocks access */
|
||||
return fd_fdinfo_mnt_id(AT_FDCWD, path, 0, ret);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int umount_recursive(const char *prefix, int flags) {
|
||||
bool again;
|
||||
int n = 0, r;
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
|
||||
int name_to_handle_at_loop(int fd, const char *path, struct file_handle **ret_handle, int *ret_mnt_id, int flags);
|
||||
|
||||
int path_get_mnt_id(const char *path, int *ret);
|
||||
|
||||
int fd_is_mount_point(int fd, const char *filename, int flags);
|
||||
int path_is_mount_point(const char *path, const char *root, int flags);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user