1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-19 22:50:17 +03:00

mountfsd: also return suggested mount point paths for the returned partitions

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.
This commit is contained in:
Lennart Poettering 2025-03-11 11:43:17 +01:00
parent 00c17ad5cf
commit 0ecfcc9790
4 changed files with 16 additions and 3 deletions

View 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;
}

View 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 }, \

View 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,

View 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,