From: Luca Boccassi Date: Mon, 12 May 2025 17:19:02 +0000 (+0100) Subject: mount-util: add helper to get source from mountinfo X-Git-Tag: v258-rc1~570^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab5cb21e3220cfb15fc771e0b350385af1b9ffcb;p=thirdparty%2Fsystemd.git mount-util: add helper to get source from mountinfo --- diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c index 5f747c209a8..90912dde4f8 100644 --- a/src/shared/mount-util.c +++ b/src/shared/mount-util.c @@ -1881,11 +1881,12 @@ char* umount_and_unlink_and_free(char *p) { return mfree(p); } -static int path_get_mount_info_at( +int path_get_mount_info_at( int dir_fd, const char *path, char **ret_fstype, - char **ret_options) { + char **ret_options, + char **ret_source) { _cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL; _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL; @@ -1918,7 +1919,7 @@ static int path_get_mount_info_at( if (mnt_fs_get_id(fs) != mnt_id) continue; - _cleanup_free_ char *fstype = NULL, *options = NULL; + _cleanup_free_ char *fstype = NULL, *options = NULL, *source = NULL; if (ret_fstype) { fstype = strdup(strempty(mnt_fs_get_fstype(fs))); @@ -1932,10 +1933,18 @@ static int path_get_mount_info_at( return log_oom_debug(); } + if (ret_source) { + source = strdup(strempty(mnt_fs_get_source(fs))); + if (!source) + return log_oom_debug(); + } + if (ret_fstype) *ret_fstype = TAKE_PTR(fstype); if (ret_options) *ret_options = TAKE_PTR(options); + if (ret_source) + *ret_source = TAKE_PTR(source); return 0; } @@ -1958,7 +1967,7 @@ int path_is_network_fs_harder_at(int dir_fd, const char *path) { return r; _cleanup_free_ char *fstype = NULL, *options = NULL; - r = path_get_mount_info_at(fd, /* path = */ NULL, &fstype, &options); + r = path_get_mount_info_at(fd, /* path = */ NULL, &fstype, &options, /* source = */ NULL); if (r < 0) return r; diff --git a/src/shared/mount-util.h b/src/shared/mount-util.h index 5541d0cab38..005ea93ec9f 100644 --- a/src/shared/mount-util.h +++ b/src/shared/mount-util.h @@ -189,6 +189,11 @@ int mount_credentials_fs(const char *path, size_t size, bool ro); int make_fsmount(int error_log_level, const char *what, const char *type, unsigned long flags, const char *options, int userns_fd); +int path_get_mount_info_at(int dir_fd, const char *path, char **ret_fstype, char **ret_options, char **ret_source); +static inline int path_get_mount_info(const char *path, char **ret_fstype, char **ret_options, char **ret_source) { + return path_get_mount_info_at(AT_FDCWD, path, ret_fstype, ret_options, ret_source); +} + int path_is_network_fs_harder_at(int dir_fd, const char *path); static inline int path_is_network_fs_harder(const char *path) { return path_is_network_fs_harder_at(AT_FDCWD, path);