]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mountfsd: also return suggested mount point paths for the returned partitions
authorLennart Poettering <lennart@poettering.net>
Tue, 11 Mar 2025 10:43:17 +0000 (11:43 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 11 Mar 2025 17:20:31 +0000 (18:20 +0100)
When mounting a disk image we return a bunch of mount fds referencing
the various partitions in the disk, along with some metadata about them.
One key metadata field is the "designator" which is supposed to tell
clients what is what, and where to mount it.

Let's make this more explicit: let's also include the literal relative
path where each mount shall be placed, to simplify implementations of
clients that do not care about the concept of designators.

src/mountfsd/mountwork.c
src/shared/gpt.c
src/shared/gpt.h
src/shared/varlink-io.systemd.MountFileSystem.c

index ded0f3c4bcae7a5805a8f4b3d98ff8ed2dccbf4e..eaf72893aab432a6229dfbc96b50fd464053691c 100644 (file)
@@ -510,6 +510,14 @@ static int vl_method_mount_image(
 
                 TAKE_FD(pp->fsmount_fd);
 
+                const char *m = partition_mountpoint_to_string(d);
+                _cleanup_strv_free_ char **l = NULL;
+                if (!isempty(m)) {
+                        l = strv_split_nulstr(m);
+                        if (!l)
+                                return log_oom_debug();
+                }
+
                 r = sd_json_variant_append_arraybo(
                                 &aj,
                                 SD_JSON_BUILD_PAIR("designator", SD_JSON_BUILD_STRING(partition_designator_to_string(d))),
@@ -522,7 +530,8 @@ static int vl_method_mount_image(
                                 SD_JSON_BUILD_PAIR_CONDITION(!!pp->label, "partitionLabel", SD_JSON_BUILD_STRING(pp->label)),
                                 SD_JSON_BUILD_PAIR("size", SD_JSON_BUILD_INTEGER(pp->size)),
                                 SD_JSON_BUILD_PAIR("offset", SD_JSON_BUILD_INTEGER(pp->offset)),
-                                SD_JSON_BUILD_PAIR("mountFileDescriptor", SD_JSON_BUILD_INTEGER(fd_idx)));
+                                SD_JSON_BUILD_PAIR("mountFileDescriptor", SD_JSON_BUILD_INTEGER(fd_idx)),
+                                JSON_BUILD_PAIR_STRV_NON_EMPTY("mountPoint", l));
                 if (r < 0)
                         return r;
         }
index 9d7ffcecd9d60337daf9b77dc82f97173470d24d..a443cc5e993c204a85d0b66e7f99be6817fd90e8 100644 (file)
@@ -115,7 +115,7 @@ static const char *const partition_mountpoint_table[_PARTITION_DESIGNATOR_MAX] =
         [PARTITION_VAR]                       = "/var\0",
 };
 
-DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(partition_mountpoint, PartitionDesignator);
+DEFINE_STRING_TABLE_LOOKUP_TO_STRING(partition_mountpoint, PartitionDesignator);
 
 #define _GPT_ARCH_SEXTET(arch, name)                                   \
         { SD_GPT_ROOT_##arch,              "root-" name,               ARCHITECTURE_##arch, .designator = PARTITION_ROOT            },  \
index e64ba8439d3dd0844ab687324451c5a8488b89f7..7a67eddebeea79b4078f64d5b7fd8adcaa523707 100644 (file)
@@ -41,6 +41,8 @@ PartitionDesignator partition_verity_sig_to_data(PartitionDesignator d);
 const char* partition_designator_to_string(PartitionDesignator d) _const_;
 PartitionDesignator partition_designator_from_string(const char *name) _pure_;
 
+const char* partition_mountpoint_to_string(PartitionDesignator d) _const_;
+
 const char* gpt_partition_type_uuid_to_string(sd_id128_t id);
 const char* gpt_partition_type_uuid_to_string_harder(
                 sd_id128_t id,
index 977552dd2d1be3cdeaba233817ab3c3ceeb389f0..54f500a7c5b31710205fb916eacd1140eabf0434 100644 (file)
@@ -42,7 +42,9 @@ static SD_VARLINK_DEFINE_STRUCT_TYPE(
                 SD_VARLINK_FIELD_COMMENT("The start offset of the partition in bytes."),
                 SD_VARLINK_DEFINE_FIELD(offset, SD_VARLINK_INT, 0),
                 SD_VARLINK_FIELD_COMMENT("A mount file descriptor to assign to a location."),
-                SD_VARLINK_DEFINE_FIELD(mountFileDescriptor, SD_VARLINK_INT, 0));
+                SD_VARLINK_DEFINE_FIELD(mountFileDescriptor, SD_VARLINK_INT, 0),
+                SD_VARLINK_FIELD_COMMENT("A relative path indicating the intended mount point for this file system, if applicable. May contain multiple paths, for certain partitions that can be mounted to multiple distinct places."),
+                SD_VARLINK_DEFINE_FIELD(mountPoint, SD_VARLINK_STRING, SD_VARLINK_NULLABLE|SD_VARLINK_ARRAY));
 
 static SD_VARLINK_DEFINE_METHOD(
                 MountImage,