mount-util: add helper to get source from mountinfo

This commit is contained in:
Luca Boccassi
2025-05-14 15:13:28 +01:00
parent 4fc9940760
commit ab5cb21e32
2 changed files with 18 additions and 4 deletions
+13 -4
View File
@@ -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;
+5
View File
@@ -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);