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:
Lennart Poettering
2017-11-21 11:37:12 +01:00
parent cbfb8679dd
commit c2a986d509
3 changed files with 78 additions and 0 deletions
+10
View File
@@ -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;
+2
View File
@@ -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);