From: Daan De Meyer Date: Tue, 14 Mar 2023 21:00:11 +0000 (+0100) Subject: mountpoint-util: Add path_get_mnt_id_at() X-Git-Tag: v254-rc1~1016^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9bf8441503c1aefe1ab3ee8e5a1bd90248c11677;p=thirdparty%2Fsystemd.git mountpoint-util: Add path_get_mnt_id_at() --- diff --git a/src/basic/mountpoint-util.c b/src/basic/mountpoint-util.c index e285702388a..24e38a34e82 100644 --- a/src/basic/mountpoint-util.c +++ b/src/basic/mountpoint-util.c @@ -355,11 +355,19 @@ int path_is_mount_point(const char *t, const char *root, int flags) { return fd_is_mount_point(fd, last_path_component(t), flags); } -int path_get_mnt_id(const char *path, int *ret) { +int path_get_mnt_id_at(int dir_fd, const char *path, int *ret) { STRUCT_NEW_STATX_DEFINE(buf); int r; - if (statx(AT_FDCWD, path, AT_SYMLINK_NOFOLLOW|AT_NO_AUTOMOUNT, STATX_MNT_ID, &buf.sx) < 0) { + assert(dir_fd >= 0 || dir_fd == AT_FDCWD); + assert(path); + assert(ret); + + if (statx(dir_fd, + path, + AT_NO_AUTOMOUNT|(isempty(path) ? AT_EMPTY_PATH : AT_SYMLINK_NOFOLLOW), + STATX_MNT_ID, + &buf.sx) < 0) { if (!ERRNO_IS_NOT_SUPPORTED(errno) && !ERRNO_IS_PRIVILEGE(errno)) return -errno; @@ -371,11 +379,11 @@ int path_get_mnt_id(const char *path, int *ret) { return 0; } - r = name_to_handle_at_loop(AT_FDCWD, path, NULL, ret, 0); + r = name_to_handle_at_loop(dir_fd, path, NULL, ret, isempty(path) ? AT_EMPTY_PATH : 0); if (r == 0 || is_name_to_handle_at_fatal_error(r)) return r; - return fd_fdinfo_mnt_id(AT_FDCWD, path, 0, ret); + return fd_fdinfo_mnt_id(dir_fd, path, isempty(path) ? AT_EMPTY_PATH : 0, ret); } bool fstype_is_network(const char *fstype) { diff --git a/src/basic/mountpoint-util.h b/src/basic/mountpoint-util.h index 977e8e738dd..8c4cee2f544 100644 --- a/src/basic/mountpoint-util.h +++ b/src/basic/mountpoint-util.h @@ -37,7 +37,10 @@ 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 path_get_mnt_id_at(int dir_fd, const char *path, int *ret); +static inline int path_get_mnt_id(const char *path, int *ret) { + return path_get_mnt_id_at(AT_FDCWD, path, 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);