]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
gpt: Add gpt_partition_type_mountpoint_nulstr()
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 27 Sep 2022 10:30:55 +0000 (12:30 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 10 Nov 2022 15:40:33 +0000 (16:40 +0100)
src/shared/gpt.c
src/shared/gpt.h

index 1670b90ad4e3417b6465b257009fc0ff4a61ac6e..af969ff9d5782f35876f10046028f5f074bfe91f 100644 (file)
@@ -158,6 +158,23 @@ static const char *const partition_designator_table[] = {
 
 DEFINE_STRING_TABLE_LOOKUP(partition_designator, PartitionDesignator);
 
+static const char *const partition_mountpoint_table[] = {
+        [PARTITION_ROOT]                      = "/\0",
+        [PARTITION_ROOT_SECONDARY]            = "/\0",
+        [PARTITION_ROOT_OTHER]                = "/\0",
+        [PARTITION_USR]                       = "/usr\0",
+        [PARTITION_USR_SECONDARY]             = "/usr\0",
+        [PARTITION_USR_OTHER]                 = "/usr\0",
+        [PARTITION_HOME]                      = "/home\0",
+        [PARTITION_SRV]                       = "/srv\0",
+        [PARTITION_ESP]                       = "/efi\0/boot\0",
+        [PARTITION_XBOOTLDR]                  = "/boot\0",
+        [PARTITION_TMP]                       = "/var/tmp\0",
+        [PARTITION_VAR]                       = "/var\0",
+};
+
+DEFINE_PRIVATE_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_OTHER            },  \
         { SD_GPT_ROOT_##arch##_VERITY,     "root-" name "-verity",     ARCHITECTURE_##arch, .designator = PARTITION_ROOT_OTHER_VERITY     },  \
@@ -338,6 +355,14 @@ bool gpt_partition_type_is_usr_verity_sig(sd_id128_t id) {
                       PARTITION_USR_OTHER_VERITY_SIG);
 }
 
+const char *gpt_partition_type_mountpoint_nulstr(sd_id128_t id) {
+        PartitionDesignator d = gpt_partition_type_from_uuid(id).designator;
+        if (d < 0)
+                return NULL;
+
+        return partition_mountpoint_to_string(d);
+}
+
 bool gpt_partition_type_knows_read_only(sd_id128_t id) {
         return gpt_partition_type_is_root(id) ||
                 gpt_partition_type_is_usr(id) ||
index 70e79550db3f9769a4f97fbaa873383f95688d9f..e0ab44a6427a85d441e962425ee377ffaad32a65 100644 (file)
@@ -81,6 +81,8 @@ bool gpt_partition_type_is_usr(sd_id128_t id);
 bool gpt_partition_type_is_usr_verity(sd_id128_t id);
 bool gpt_partition_type_is_usr_verity_sig(sd_id128_t id);
 
+const char *gpt_partition_type_mountpoint_nulstr(sd_id128_t id);
+
 bool gpt_partition_type_knows_read_only(sd_id128_t id);
 bool gpt_partition_type_knows_growfs(sd_id128_t id);
 bool gpt_partition_type_knows_no_auto(sd_id128_t id);