]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mount-util: add helper to get source from mountinfo
authorLuca Boccassi <luca.boccassi@gmail.com>
Mon, 12 May 2025 17:19:02 +0000 (18:19 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Wed, 14 May 2025 14:13:28 +0000 (15:13 +0100)
src/shared/mount-util.c
src/shared/mount-util.h

index 5f747c209a848c8507aa022c0789bcf46e3d3920..90912dde4f8572fd181ced57e37f65bf596f3d7e 100644 (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;
 
index 5541d0cab383b3ee7cb1d268f814048a4e09a0ae..005ea93ec9ff6659c82e7da76613b8781b6ad9ed 100644 (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);