]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
gpt: Replace bitfields with designator field in GptPartitionType
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Tue, 27 Sep 2022 10:20:20 +0000 (12:20 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 10 Nov 2022 15:40:33 +0000 (16:40 +0100)
To achieve this we move the PartitionDesignator enum from
dissect-image.h to gpt.h

src/shared/dissect-image.c
src/shared/dissect-image.h
src/shared/gpt.c
src/shared/gpt.h

index 2f1903121636aca5b88fd68e43b5055a38e5ab96..5064c6bc0ed860fda73cd506a917220684aaa51e 100644 (file)
@@ -668,7 +668,7 @@ static int dissect_image(
                                         continue;
 
                                 assert_se((architecture = gpt_partition_type_uuid_to_arch(type_id)) >= 0);
-                                designator = PARTITION_ROOT_OF_ARCH(architecture);
+                                designator = partition_root_of_arch(architecture);
                                 rw = !(pflags & SD_GPT_FLAG_READ_ONLY);
                                 growfs = FLAGS_SET(pflags, SD_GPT_FLAG_GROWFS);
 
@@ -693,7 +693,7 @@ static int dissect_image(
                                         continue;
 
                                 assert_se((architecture = gpt_partition_type_uuid_to_arch(type_id)) >= 0);
-                                designator = PARTITION_VERITY_OF(PARTITION_ROOT_OF_ARCH(architecture));
+                                designator = partition_verity_of(partition_root_of_arch(architecture));
                                 fstype = "DM_verity_hash";
                                 rw = false;
 
@@ -713,7 +713,7 @@ static int dissect_image(
                                         continue;
 
                                 assert_se((architecture = gpt_partition_type_uuid_to_arch(type_id)) >= 0);
-                                designator = PARTITION_VERITY_SIG_OF(PARTITION_ROOT_OF_ARCH(architecture));
+                                designator = partition_verity_sig_of(partition_root_of_arch(architecture));
                                 fstype = "verity_hash_signature";
                                 rw = false;
 
@@ -730,7 +730,7 @@ static int dissect_image(
                                         continue;
 
                                 assert_se((architecture = gpt_partition_type_uuid_to_arch(type_id)) >= 0);
-                                designator = PARTITION_USR_OF_ARCH(architecture);
+                                designator = partition_usr_of_arch(architecture);
                                 rw = !(pflags & SD_GPT_FLAG_READ_ONLY);
                                 growfs = FLAGS_SET(pflags, SD_GPT_FLAG_GROWFS);
 
@@ -754,7 +754,7 @@ static int dissect_image(
                                         continue;
 
                                 assert_se((architecture = gpt_partition_type_uuid_to_arch(type_id)) >= 0);
-                                designator = PARTITION_VERITY_OF(PARTITION_USR_OF_ARCH(architecture));
+                                designator = partition_verity_of(partition_usr_of_arch(architecture));
                                 fstype = "DM_verity_hash";
                                 rw = false;
 
@@ -774,7 +774,7 @@ static int dissect_image(
                                         continue;
 
                                 assert_se((architecture = gpt_partition_type_uuid_to_arch(type_id)) >= 0);
-                                designator = PARTITION_VERITY_SIG_OF(PARTITION_USR_OF_ARCH(architecture));
+                                designator = partition_verity_sig_of(partition_usr_of_arch(architecture));
                                 fstype = "verity_hash_signature";
                                 rw = false;
 
@@ -864,7 +864,7 @@ static int dissect_image(
                                          * let the newest version win. This permits a simple A/B versioning
                                          * scheme in OS images. */
 
-                                        if (!PARTITION_DESIGNATOR_VERSIONED(designator) ||
+                                        if (!partition_designator_is_versioned(designator) ||
                                             strverscmp_improved(m->partitions[designator].label, label) >= 0)
                                                 continue;
 
@@ -2349,7 +2349,7 @@ int dissected_image_decrypt(
                 if (r < 0)
                         return r;
 
-                k = PARTITION_VERITY_OF(i);
+                k = partition_verity_of(i);
                 if (k >= 0) {
                         r = verity_partition(i, p, m->partitions + k, verity, flags | DISSECT_IMAGE_VERITY_SHARE, d);
                         if (r < 0)
@@ -2691,7 +2691,7 @@ int dissected_image_load_verity_sig_partition(
         if (r == 0)
                 return 0;
 
-        d = PARTITION_VERITY_SIG_OF(verity->designator < 0 ? PARTITION_ROOT : verity->designator);
+        d = partition_verity_sig_of(verity->designator < 0 ? PARTITION_ROOT : verity->designator);
         assert(d >= 0);
 
         p = m->partitions + d;
@@ -3150,7 +3150,7 @@ bool dissected_image_verity_candidate(const DissectedImage *image, PartitionDesi
         if (image->single_file_system)
                 return partition_designator == PARTITION_ROOT && image->has_verity;
 
-        return PARTITION_VERITY_OF(partition_designator) >= 0;
+        return partition_verity_of(partition_designator) >= 0;
 }
 
 bool dissected_image_verity_ready(const DissectedImage *image, PartitionDesignator partition_designator) {
@@ -3167,7 +3167,7 @@ bool dissected_image_verity_ready(const DissectedImage *image, PartitionDesignat
         if (image->single_file_system)
                 return partition_designator == PARTITION_ROOT;
 
-        k = PARTITION_VERITY_OF(partition_designator);
+        k = partition_verity_of(partition_designator);
         return k >= 0 && image->partitions[k].found;
 }
 
@@ -3184,7 +3184,7 @@ bool dissected_image_verity_sig_ready(const DissectedImage *image, PartitionDesi
         if (image->single_file_system)
                 return partition_designator == PARTITION_ROOT;
 
-        k = PARTITION_VERITY_SIG_OF(partition_designator);
+        k = partition_verity_sig_of(partition_designator);
         return k >= 0 && image->partitions[k].found;
 }
 
@@ -3286,34 +3286,6 @@ int mount_image_privately_interactively(
         return 0;
 }
 
-static const char *const partition_designator_table[] = {
-        [PARTITION_ROOT]                      = "root",
-        [PARTITION_ROOT_SECONDARY]            = "root-secondary",
-        [PARTITION_ROOT_OTHER]                = "root-other",
-        [PARTITION_USR]                       = "usr",
-        [PARTITION_USR_SECONDARY]             = "usr-secondary",
-        [PARTITION_USR_OTHER]                 = "usr-other",
-        [PARTITION_HOME]                      = "home",
-        [PARTITION_SRV]                       = "srv",
-        [PARTITION_ESP]                       = "esp",
-        [PARTITION_XBOOTLDR]                  = "xbootldr",
-        [PARTITION_SWAP]                      = "swap",
-        [PARTITION_ROOT_VERITY]               = "root-verity",
-        [PARTITION_ROOT_SECONDARY_VERITY]     = "root-secondary-verity",
-        [PARTITION_ROOT_OTHER_VERITY]         = "root-other-verity",
-        [PARTITION_USR_VERITY]                = "usr-verity",
-        [PARTITION_USR_SECONDARY_VERITY]      = "usr-secondary-verity",
-        [PARTITION_USR_OTHER_VERITY]          = "usr-other-verity",
-        [PARTITION_ROOT_VERITY_SIG]           = "root-verity-sig",
-        [PARTITION_ROOT_SECONDARY_VERITY_SIG] = "root-secondary-verity-sig",
-        [PARTITION_ROOT_OTHER_VERITY_SIG]     = "root-other-verity-sig",
-        [PARTITION_USR_VERITY_SIG]            = "usr-verity-sig",
-        [PARTITION_USR_SECONDARY_VERITY_SIG]  = "usr-secondary-verity-sig",
-        [PARTITION_USR_OTHER_VERITY_SIG]      = "usr-other-verity-sig",
-        [PARTITION_TMP]                       = "tmp",
-        [PARTITION_VAR]                       = "var",
-};
-
 static bool mount_options_relax_extension_release_checks(const MountOptions *options) {
         if (!options)
                 return false;
@@ -3441,5 +3413,3 @@ int verity_dissect_and_mount(
 
         return 0;
 }
-
-DEFINE_STRING_TABLE_LOOKUP(partition_designator, PartitionDesignator);
index 46675d22ab3a981f47ee810241560d4b095700b6..6bd8d17e6ce9bf3c1a8bc5c646ff48409c859148 100644 (file)
@@ -6,6 +6,7 @@
 #include "sd-id128.h"
 
 #include "architecture.h"
+#include "gpt.h"
 #include "list.h"
 #include "loop-util.h"
 #include "macro.h"
@@ -41,147 +42,6 @@ struct DissectedPartition {
                 .mount_node_fd = -1,                                    \
         })
 
-typedef enum PartitionDesignator {
-        PARTITION_ROOT,
-        PARTITION_ROOT_SECONDARY,  /* Secondary architecture */
-        PARTITION_ROOT_OTHER,
-        PARTITION_USR,
-        PARTITION_USR_SECONDARY,
-        PARTITION_USR_OTHER,
-        PARTITION_HOME,
-        PARTITION_SRV,
-        PARTITION_ESP,
-        PARTITION_XBOOTLDR,
-        PARTITION_SWAP,
-        PARTITION_ROOT_VERITY, /* verity data for the PARTITION_ROOT partition */
-        PARTITION_ROOT_SECONDARY_VERITY, /* verity data for the PARTITION_ROOT_SECONDARY partition */
-        PARTITION_ROOT_OTHER_VERITY,
-        PARTITION_USR_VERITY,
-        PARTITION_USR_SECONDARY_VERITY,
-        PARTITION_USR_OTHER_VERITY,
-        PARTITION_ROOT_VERITY_SIG, /* PKCS#7 signature for root hash for the PARTITION_ROOT partition */
-        PARTITION_ROOT_SECONDARY_VERITY_SIG, /* ditto for the PARTITION_ROOT_SECONDARY partition */
-        PARTITION_ROOT_OTHER_VERITY_SIG,
-        PARTITION_USR_VERITY_SIG,
-        PARTITION_USR_SECONDARY_VERITY_SIG,
-        PARTITION_USR_OTHER_VERITY_SIG,
-        PARTITION_TMP,
-        PARTITION_VAR,
-        _PARTITION_DESIGNATOR_MAX,
-        _PARTITION_DESIGNATOR_INVALID = -EINVAL,
-} PartitionDesignator;
-
-static inline bool PARTITION_DESIGNATOR_VERSIONED(PartitionDesignator d) {
-        /* Returns true for all designators where we want to support a concept of "versioning", i.e. which
-         * likely contain software binaries (or hashes thereof) that make sense to be versioned as a
-         * whole. We use this check to automatically pick the newest version of these partitions, by version
-         * comparing the partition labels. */
-
-        return IN_SET(d,
-                      PARTITION_ROOT,
-                      PARTITION_ROOT_SECONDARY,
-                      PARTITION_ROOT_OTHER,
-                      PARTITION_USR,
-                      PARTITION_USR_SECONDARY,
-                      PARTITION_USR_OTHER,
-                      PARTITION_ROOT_VERITY,
-                      PARTITION_ROOT_SECONDARY_VERITY,
-                      PARTITION_ROOT_OTHER_VERITY,
-                      PARTITION_USR_VERITY,
-                      PARTITION_USR_SECONDARY_VERITY,
-                      PARTITION_USR_OTHER_VERITY,
-                      PARTITION_ROOT_VERITY_SIG,
-                      PARTITION_ROOT_SECONDARY_VERITY_SIG,
-                      PARTITION_ROOT_OTHER_VERITY_SIG,
-                      PARTITION_USR_VERITY_SIG,
-                      PARTITION_USR_SECONDARY_VERITY_SIG,
-                      PARTITION_USR_OTHER_VERITY_SIG);
-}
-
-static inline PartitionDesignator PARTITION_VERITY_OF(PartitionDesignator p) {
-        switch (p) {
-
-        case PARTITION_ROOT:
-                return PARTITION_ROOT_VERITY;
-
-        case PARTITION_ROOT_SECONDARY:
-                return PARTITION_ROOT_SECONDARY_VERITY;
-
-        case PARTITION_ROOT_OTHER:
-                return PARTITION_ROOT_OTHER_VERITY;
-
-        case PARTITION_USR:
-                return PARTITION_USR_VERITY;
-
-        case PARTITION_USR_SECONDARY:
-                return PARTITION_USR_SECONDARY_VERITY;
-
-        case PARTITION_USR_OTHER:
-                return PARTITION_USR_OTHER_VERITY;
-
-        default:
-                return _PARTITION_DESIGNATOR_INVALID;
-        }
-}
-
-static inline PartitionDesignator PARTITION_VERITY_SIG_OF(PartitionDesignator p) {
-        switch (p) {
-
-        case PARTITION_ROOT:
-                return PARTITION_ROOT_VERITY_SIG;
-
-        case PARTITION_ROOT_SECONDARY:
-                return PARTITION_ROOT_SECONDARY_VERITY_SIG;
-
-        case PARTITION_ROOT_OTHER:
-                return PARTITION_ROOT_OTHER_VERITY_SIG;
-
-        case PARTITION_USR:
-                return PARTITION_USR_VERITY_SIG;
-
-        case PARTITION_USR_SECONDARY:
-                return PARTITION_USR_SECONDARY_VERITY_SIG;
-
-        case PARTITION_USR_OTHER:
-                return PARTITION_USR_OTHER_VERITY_SIG;
-
-        default:
-                return _PARTITION_DESIGNATOR_INVALID;
-        }
-}
-
-static inline PartitionDesignator PARTITION_ROOT_OF_ARCH(Architecture arch) {
-        switch (arch) {
-
-        case native_architecture():
-                return PARTITION_ROOT;
-
-#ifdef ARCHITECTURE_SECONDARY
-        case ARCHITECTURE_SECONDARY:
-                return PARTITION_ROOT_SECONDARY;
-#endif
-
-        default:
-                return PARTITION_ROOT_OTHER;
-        }
-}
-
-static inline PartitionDesignator PARTITION_USR_OF_ARCH(Architecture arch) {
-        switch (arch) {
-
-        case native_architecture():
-                return PARTITION_USR;
-
-#ifdef ARCHITECTURE_SECONDARY
-        case ARCHITECTURE_SECONDARY:
-                return PARTITION_USR_SECONDARY;
-#endif
-
-        default:
-                return PARTITION_USR_OTHER;
-        }
-}
-
 typedef enum DissectImageFlags {
         DISSECT_IMAGE_DEVICE_READ_ONLY         = 1 << 0,  /* Make device read-only */
         DISSECT_IMAGE_DISCARD_ON_LOOP          = 1 << 1,  /* Turn on "discard" if on a loop device and file system supports it */
@@ -297,9 +157,6 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(DecryptedImage*, decrypted_image_unref);
 
 int dissected_image_relinquish(DissectedImage *m);
 
-const char* partition_designator_to_string(PartitionDesignator d) _const_;
-PartitionDesignator partition_designator_from_string(const char *name) _pure_;
-
 int verity_settings_load(VeritySettings *verity, const char *image, const char *root_hash_path, const char *root_hash_sig_path);
 void verity_settings_done(VeritySettings *verity);
 
index a15833b21dbf44ff7db1359b731d37efc1b03837..1670b90ad4e3417b6465b257009fc0ff4a61ac6e 100644 (file)
@@ -1,6 +1,7 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
 #include "gpt.h"
+#include "string-table.h"
 #include "string-util.h"
 #include "utf8.h"
 
 #pragma message "Please define GPT partition types for your architecture."
 #endif
 
+bool partition_designator_is_versioned(PartitionDesignator d) {
+        /* Returns true for all designators where we want to support a concept of "versioning", i.e. which
+         * likely contain software binaries (or hashes thereof) that make sense to be versioned as a
+         * whole. We use this check to automatically pick the newest version of these partitions, by version
+         * comparing the partition labels. */
+
+        return IN_SET(d,
+                      PARTITION_ROOT,
+                      PARTITION_ROOT_SECONDARY,
+                      PARTITION_ROOT_OTHER,
+                      PARTITION_USR,
+                      PARTITION_USR_SECONDARY,
+                      PARTITION_USR_OTHER,
+                      PARTITION_ROOT_VERITY,
+                      PARTITION_ROOT_SECONDARY_VERITY,
+                      PARTITION_ROOT_OTHER_VERITY,
+                      PARTITION_USR_VERITY,
+                      PARTITION_USR_SECONDARY_VERITY,
+                      PARTITION_USR_OTHER_VERITY,
+                      PARTITION_ROOT_VERITY_SIG,
+                      PARTITION_ROOT_SECONDARY_VERITY_SIG,
+                      PARTITION_ROOT_OTHER_VERITY_SIG,
+                      PARTITION_USR_VERITY_SIG,
+                      PARTITION_USR_SECONDARY_VERITY_SIG,
+                      PARTITION_USR_OTHER_VERITY_SIG);
+}
+
+PartitionDesignator partition_verity_of(PartitionDesignator p) {
+        switch (p) {
+
+        case PARTITION_ROOT:
+                return PARTITION_ROOT_VERITY;
+
+        case PARTITION_ROOT_SECONDARY:
+                return PARTITION_ROOT_SECONDARY_VERITY;
+
+        case PARTITION_ROOT_OTHER:
+                return PARTITION_ROOT_OTHER_VERITY;
+
+        case PARTITION_USR:
+                return PARTITION_USR_VERITY;
+
+        case PARTITION_USR_SECONDARY:
+                return PARTITION_USR_SECONDARY_VERITY;
+
+        case PARTITION_USR_OTHER:
+                return PARTITION_USR_OTHER_VERITY;
+
+        default:
+                return _PARTITION_DESIGNATOR_INVALID;
+        }
+}
+
+PartitionDesignator partition_verity_sig_of(PartitionDesignator p) {
+        switch (p) {
+
+        case PARTITION_ROOT:
+                return PARTITION_ROOT_VERITY_SIG;
+
+        case PARTITION_ROOT_SECONDARY:
+                return PARTITION_ROOT_SECONDARY_VERITY_SIG;
+
+        case PARTITION_ROOT_OTHER:
+                return PARTITION_ROOT_OTHER_VERITY_SIG;
+
+        case PARTITION_USR:
+                return PARTITION_USR_VERITY_SIG;
+
+        case PARTITION_USR_SECONDARY:
+                return PARTITION_USR_SECONDARY_VERITY_SIG;
+
+        case PARTITION_USR_OTHER:
+                return PARTITION_USR_OTHER_VERITY_SIG;
+
+        default:
+                return _PARTITION_DESIGNATOR_INVALID;
+        }
+}
+
+PartitionDesignator partition_root_of_arch(Architecture arch) {
+        switch (arch) {
+
+        case native_architecture():
+                return PARTITION_ROOT;
+
+#ifdef ARCHITECTURE_SECONDARY
+        case ARCHITECTURE_SECONDARY:
+                return PARTITION_ROOT_SECONDARY;
+#endif
+
+        default:
+                return PARTITION_ROOT_OTHER;
+        }
+}
+
+PartitionDesignator partition_usr_of_arch(Architecture arch) {
+        switch (arch) {
+
+        case native_architecture():
+                return PARTITION_USR;
+
+#ifdef ARCHITECTURE_SECONDARY
+        case ARCHITECTURE_SECONDARY:
+                return PARTITION_USR_SECONDARY;
+#endif
+
+        default:
+                return PARTITION_USR_OTHER;
+        }
+}
+
+static const char *const partition_designator_table[] = {
+        [PARTITION_ROOT]                      = "root",
+        [PARTITION_ROOT_SECONDARY]            = "root-secondary",
+        [PARTITION_ROOT_OTHER]                = "root-other",
+        [PARTITION_USR]                       = "usr",
+        [PARTITION_USR_SECONDARY]             = "usr-secondary",
+        [PARTITION_USR_OTHER]                 = "usr-other",
+        [PARTITION_HOME]                      = "home",
+        [PARTITION_SRV]                       = "srv",
+        [PARTITION_ESP]                       = "esp",
+        [PARTITION_XBOOTLDR]                  = "xbootldr",
+        [PARTITION_SWAP]                      = "swap",
+        [PARTITION_ROOT_VERITY]               = "root-verity",
+        [PARTITION_ROOT_SECONDARY_VERITY]     = "root-secondary-verity",
+        [PARTITION_ROOT_OTHER_VERITY]         = "root-other-verity",
+        [PARTITION_USR_VERITY]                = "usr-verity",
+        [PARTITION_USR_SECONDARY_VERITY]      = "usr-secondary-verity",
+        [PARTITION_USR_OTHER_VERITY]          = "usr-other-verity",
+        [PARTITION_ROOT_VERITY_SIG]           = "root-verity-sig",
+        [PARTITION_ROOT_SECONDARY_VERITY_SIG] = "root-secondary-verity-sig",
+        [PARTITION_ROOT_OTHER_VERITY_SIG]     = "root-other-verity-sig",
+        [PARTITION_USR_VERITY_SIG]            = "usr-verity-sig",
+        [PARTITION_USR_SECONDARY_VERITY_SIG]  = "usr-secondary-verity-sig",
+        [PARTITION_USR_OTHER_VERITY_SIG]      = "usr-other-verity-sig",
+        [PARTITION_TMP]                       = "tmp",
+        [PARTITION_VAR]                       = "var",
+        [PARTITION_USER_HOME]                 = "user-home",
+        [PARTITION_LINUX_GENERIC]             = "linux-generic",
+};
+
+DEFINE_STRING_TABLE_LOOKUP(partition_designator, PartitionDesignator);
+
 #define _GPT_ARCH_SEXTET(arch, name)                                   \
-        { SD_GPT_ROOT_##arch,              "root-" name,               ARCHITECTURE_##arch, .is_root = true            },  \
-        { SD_GPT_ROOT_##arch##_VERITY,     "root-" name "-verity",     ARCHITECTURE_##arch, .is_root_verity = true     },  \
-        { SD_GPT_ROOT_##arch##_VERITY_SIG, "root-" name "-verity-sig", ARCHITECTURE_##arch, .is_root_verity_sig = true },  \
-        { SD_GPT_USR_##arch,               "usr-" name,                ARCHITECTURE_##arch, .is_usr = true             },  \
-        { SD_GPT_USR_##arch##_VERITY,      "usr-" name "-verity",      ARCHITECTURE_##arch, .is_usr_verity = true      },  \
-        { SD_GPT_USR_##arch##_VERITY_SIG,  "usr-" name "-verity-sig",  ARCHITECTURE_##arch, .is_usr_verity_sig = true  }
+        { 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     },  \
+        { SD_GPT_ROOT_##arch##_VERITY_SIG, "root-" name "-verity-sig", ARCHITECTURE_##arch, .designator = PARTITION_ROOT_OTHER_VERITY_SIG },  \
+        { SD_GPT_USR_##arch,               "usr-" name,                ARCHITECTURE_##arch, .designator = PARTITION_USR_OTHER             },  \
+        { SD_GPT_USR_##arch##_VERITY,      "usr-" name "-verity",      ARCHITECTURE_##arch, .designator = PARTITION_USR_OTHER_VERITY      },  \
+        { SD_GPT_USR_##arch##_VERITY_SIG,  "usr-" name "-verity-sig",  ARCHITECTURE_##arch, .designator = PARTITION_USR_OTHER_VERITY_SIG  }
 
 const GptPartitionType gpt_partition_type_table[] = {
         _GPT_ARCH_SEXTET(ALPHA,       "alpha"),
@@ -43,26 +187,31 @@ const GptPartitionType gpt_partition_type_table[] = {
         _GPT_ARCH_SEXTET(X86,         "x86"),
         _GPT_ARCH_SEXTET(X86_64,      "x86-64"),
 #ifdef SD_GPT_ROOT_NATIVE
-        { SD_GPT_ROOT_NATIVE,            "root",            native_architecture(), .is_root = true            },
-        { SD_GPT_ROOT_NATIVE_VERITY,     "root-verity",     native_architecture(), .is_root_verity = true     },
-        { SD_GPT_ROOT_NATIVE_VERITY_SIG, "root-verity-sig", native_architecture(), .is_root_verity_sig = true },
-        { SD_GPT_USR_NATIVE,             "usr",             native_architecture(), .is_usr = true             },
-        { SD_GPT_USR_NATIVE_VERITY,      "usr-verity",      native_architecture(), .is_usr_verity = true      },
-        { SD_GPT_USR_NATIVE_VERITY_SIG,  "usr-verity-sig",  native_architecture(), .is_usr_verity_sig = true  },
+        { SD_GPT_ROOT_NATIVE,            "root",            native_architecture(), .designator = PARTITION_ROOT            },
+        { SD_GPT_ROOT_NATIVE_VERITY,     "root-verity",     native_architecture(), .designator = PARTITION_ROOT_VERITY     },
+        { SD_GPT_ROOT_NATIVE_VERITY_SIG, "root-verity-sig", native_architecture(), .designator = PARTITION_ROOT_VERITY_SIG },
+        { SD_GPT_USR_NATIVE,             "usr",             native_architecture(), .designator = PARTITION_USR             },
+        { SD_GPT_USR_NATIVE_VERITY,      "usr-verity",      native_architecture(), .designator = PARTITION_USR_VERITY      },
+        { SD_GPT_USR_NATIVE_VERITY_SIG,  "usr-verity-sig",  native_architecture(), .designator = PARTITION_USR_VERITY_SIG  },
 #endif
 #ifdef SD_GPT_ROOT_SECONDARY
-        _GPT_ARCH_SEXTET(SECONDARY,   "secondary"),
+        { SD_GPT_ROOT_NATIVE,            "root-secondary",            native_architecture(), .designator = PARTITION_ROOT_SECONDARY            },
+        { SD_GPT_ROOT_NATIVE_VERITY,     "root-secondary-verity",     native_architecture(), .designator = PARTITION_ROOT_SECONDARY_VERITY     },
+        { SD_GPT_ROOT_NATIVE_VERITY_SIG, "root-secondary-verity-sig", native_architecture(), .designator = PARTITION_ROOT_SECONDARY_VERITY_SIG },
+        { SD_GPT_USR_NATIVE,             "usr-secondary",             native_architecture(), .designator = PARTITION_USR_SECONDARY             },
+        { SD_GPT_USR_NATIVE_VERITY,      "usr-secondary-verity",      native_architecture(), .designator = PARTITION_USR_SECONDARY_VERITY      },
+        { SD_GPT_USR_NATIVE_VERITY_SIG,  "usr-secondary-verity-sig",  native_architecture(), .designator = PARTITION_USR_SECONDARY_VERITY_SIG  },
 #endif
 
-        { SD_GPT_ESP,                    "esp",           _ARCHITECTURE_INVALID },
-        { SD_GPT_XBOOTLDR,               "xbootldr",      _ARCHITECTURE_INVALID },
-        { SD_GPT_SWAP,                   "swap",          _ARCHITECTURE_INVALID },
-        { SD_GPT_HOME,                   "home",          _ARCHITECTURE_INVALID },
-        { SD_GPT_SRV,                    "srv",           _ARCHITECTURE_INVALID },
-        { SD_GPT_VAR,                    "var",           _ARCHITECTURE_INVALID },
-        { SD_GPT_TMP,                    "tmp",           _ARCHITECTURE_INVALID },
-        { SD_GPT_USER_HOME,              "user-home",     _ARCHITECTURE_INVALID },
-        { SD_GPT_LINUX_GENERIC,          "linux-generic", _ARCHITECTURE_INVALID },
+        { SD_GPT_ESP,                    "esp",           _ARCHITECTURE_INVALID, .designator = PARTITION_ESP },
+        { SD_GPT_XBOOTLDR,               "xbootldr",      _ARCHITECTURE_INVALID, .designator = PARTITION_XBOOTLDR },
+        { SD_GPT_SWAP,                   "swap",          _ARCHITECTURE_INVALID, .designator = PARTITION_SWAP },
+        { SD_GPT_HOME,                   "home",          _ARCHITECTURE_INVALID, .designator = PARTITION_HOME },
+        { SD_GPT_SRV,                    "srv",           _ARCHITECTURE_INVALID, .designator = PARTITION_SRV },
+        { SD_GPT_VAR,                    "var",           _ARCHITECTURE_INVALID, .designator = PARTITION_VAR },
+        { SD_GPT_TMP,                    "tmp",           _ARCHITECTURE_INVALID, .designator = PARTITION_TMP },
+        { SD_GPT_USER_HOME,              "user-home",     _ARCHITECTURE_INVALID, .designator = PARTITION_USER_HOME },
+        { SD_GPT_LINUX_GENERIC,          "linux-generic", _ARCHITECTURE_INVALID, .designator = PARTITION_LINUX_GENERIC },
         {}
 };
 
@@ -140,55 +289,78 @@ static GptPartitionType gpt_partition_type_from_uuid(sd_id128_t id) {
         if (pt)
                 return *pt;
 
-        return (GptPartitionType) { .uuid = id, .arch = _ARCHITECTURE_INVALID };
+        return (GptPartitionType) {
+                .uuid = id,
+                .arch = _ARCHITECTURE_INVALID,
+                .designator = _PARTITION_DESIGNATOR_INVALID,
+        };
 }
 
 bool gpt_partition_type_is_root(sd_id128_t id) {
-        return gpt_partition_type_from_uuid(id).is_root;
+        return IN_SET(gpt_partition_type_from_uuid(id).designator,
+                      PARTITION_ROOT,
+                      PARTITION_ROOT_SECONDARY,
+                      PARTITION_ROOT_OTHER);
 }
 
 bool gpt_partition_type_is_root_verity(sd_id128_t id) {
-        return gpt_partition_type_from_uuid(id).is_root_verity;
+        return IN_SET(gpt_partition_type_from_uuid(id).designator,
+                      PARTITION_ROOT_VERITY,
+                      PARTITION_ROOT_SECONDARY_VERITY,
+                      PARTITION_ROOT_OTHER_VERITY);
 }
 
 bool gpt_partition_type_is_root_verity_sig(sd_id128_t id) {
-        return gpt_partition_type_from_uuid(id).is_root_verity_sig;
+        return IN_SET(gpt_partition_type_from_uuid(id).designator,
+                      PARTITION_ROOT_VERITY_SIG,
+                      PARTITION_ROOT_SECONDARY_VERITY_SIG,
+                      PARTITION_ROOT_OTHER_VERITY_SIG);
 }
 
 bool gpt_partition_type_is_usr(sd_id128_t id) {
-        return gpt_partition_type_from_uuid(id).is_usr;
+        return IN_SET(gpt_partition_type_from_uuid(id).designator,
+                      PARTITION_USR,
+                      PARTITION_USR_SECONDARY,
+                      PARTITION_USR_OTHER);
 }
 
 bool gpt_partition_type_is_usr_verity(sd_id128_t id) {
-        return gpt_partition_type_from_uuid(id).is_usr_verity;
+        return IN_SET(gpt_partition_type_from_uuid(id).designator,
+                      PARTITION_USR_VERITY,
+                      PARTITION_USR_SECONDARY_VERITY,
+                      PARTITION_USR_OTHER_VERITY);
 }
 
 bool gpt_partition_type_is_usr_verity_sig(sd_id128_t id) {
-        return gpt_partition_type_from_uuid(id).is_usr_verity_sig;
+        return IN_SET(gpt_partition_type_from_uuid(id).designator,
+                      PARTITION_USR_VERITY_SIG,
+                      PARTITION_USR_SECONDARY_VERITY_SIG,
+                      PARTITION_USR_OTHER_VERITY_SIG);
 }
 
 bool gpt_partition_type_knows_read_only(sd_id128_t id) {
         return gpt_partition_type_is_root(id) ||
                 gpt_partition_type_is_usr(id) ||
-                sd_id128_in_set(id,
-                                SD_GPT_HOME,
-                                SD_GPT_SRV,
-                                SD_GPT_VAR,
-                                SD_GPT_TMP,
-                                SD_GPT_XBOOTLDR) ||
-                gpt_partition_type_is_root_verity(id) || /* pretty much implied, but let's set the bit to make things really clear */
-                gpt_partition_type_is_usr_verity(id);    /* ditto */
+                /* pretty much implied, but let's set the bit to make things really clear */
+                gpt_partition_type_is_root_verity(id) ||
+                gpt_partition_type_is_usr_verity(id) ||
+                IN_SET(gpt_partition_type_from_uuid(id).designator,
+                       PARTITION_HOME,
+                       PARTITION_SRV,
+                       PARTITION_VAR,
+                       PARTITION_TMP,
+                       PARTITION_XBOOTLDR);
 }
 
 bool gpt_partition_type_knows_growfs(sd_id128_t id) {
         return gpt_partition_type_is_root(id) ||
                 gpt_partition_type_is_usr(id) ||
-                sd_id128_in_set(id,
-                                SD_GPT_HOME,
-                                SD_GPT_SRV,
-                                SD_GPT_VAR,
-                                SD_GPT_TMP,
-                                SD_GPT_XBOOTLDR);
+                IN_SET(gpt_partition_type_from_uuid(id).designator,
+                       PARTITION_HOME,
+                       PARTITION_SRV,
+                       PARTITION_VAR,
+                       PARTITION_TMP,
+                       PARTITION_XBOOTLDR);
 }
 
 bool gpt_partition_type_knows_no_auto(sd_id128_t id) {
@@ -196,11 +368,11 @@ bool gpt_partition_type_knows_no_auto(sd_id128_t id) {
                 gpt_partition_type_is_root_verity(id) ||
                 gpt_partition_type_is_usr(id) ||
                 gpt_partition_type_is_usr_verity(id) ||
-                sd_id128_in_set(id,
-                                SD_GPT_HOME,
-                                SD_GPT_SRV,
-                                SD_GPT_VAR,
-                                SD_GPT_TMP,
-                                SD_GPT_XBOOTLDR,
-                                SD_GPT_SWAP);
+                IN_SET(gpt_partition_type_from_uuid(id).designator,
+                       PARTITION_HOME,
+                       PARTITION_SRV,
+                       PARTITION_VAR,
+                       PARTITION_TMP,
+                       PARTITION_XBOOTLDR,
+                       PARTITION_SWAP);
 }
index f673194d4af9f9df5cfdcf7c2c53d0791afd0f1f..70e79550db3f9769a4f97fbaa873383f95688d9f 100644 (file)
 /* maximum length of gpt label */
 #define GPT_LABEL_MAX 36
 
+typedef enum PartitionDesignator {
+        PARTITION_ROOT, /* Primary architecture */
+        PARTITION_ROOT_SECONDARY, /* Secondary architecture */
+        PARTITION_ROOT_OTHER, /* Any architecture not covered by the primary or secondary architecture. */
+        PARTITION_USR,
+        PARTITION_USR_SECONDARY,
+        PARTITION_USR_OTHER,
+        PARTITION_HOME,
+        PARTITION_SRV,
+        PARTITION_ESP,
+        PARTITION_XBOOTLDR,
+        PARTITION_SWAP,
+        PARTITION_ROOT_VERITY, /* verity data for the PARTITION_ROOT partition */
+        PARTITION_ROOT_SECONDARY_VERITY, /* verity data for the PARTITION_ROOT_SECONDARY partition */
+        PARTITION_ROOT_OTHER_VERITY,
+        PARTITION_USR_VERITY,
+        PARTITION_USR_SECONDARY_VERITY,
+        PARTITION_USR_OTHER_VERITY,
+        PARTITION_ROOT_VERITY_SIG, /* PKCS#7 signature for root hash for the PARTITION_ROOT partition */
+        PARTITION_ROOT_SECONDARY_VERITY_SIG, /* ditto for the PARTITION_ROOT_SECONDARY partition */
+        PARTITION_ROOT_OTHER_VERITY_SIG,
+        PARTITION_USR_VERITY_SIG,
+        PARTITION_USR_SECONDARY_VERITY_SIG,
+        PARTITION_USR_OTHER_VERITY_SIG,
+        PARTITION_TMP,
+        PARTITION_VAR,
+        PARTITION_USER_HOME,
+        PARTITION_LINUX_GENERIC,
+        _PARTITION_DESIGNATOR_MAX,
+        _PARTITION_DESIGNATOR_INVALID = -EINVAL,
+} PartitionDesignator;
+
+bool partition_designator_is_versioned(PartitionDesignator d);
+
+PartitionDesignator partition_verity_of(PartitionDesignator p);
+PartitionDesignator partition_verity_sig_of(PartitionDesignator p);
+PartitionDesignator partition_root_of_arch(Architecture arch);
+PartitionDesignator partition_usr_of_arch(Architecture arch);
+
+const char* partition_designator_to_string(PartitionDesignator d) _const_;
+PartitionDesignator partition_designator_from_string(const char *name) _pure_;
+
 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,
@@ -25,13 +67,7 @@ typedef struct GptPartitionType {
         sd_id128_t uuid;
         const char *name;
         Architecture arch;
-
-        bool is_root:1;
-        bool is_root_verity:1;
-        bool is_root_verity_sig:1;
-        bool is_usr:1;
-        bool is_usr_verity:1;
-        bool is_usr_verity_sig:1;
+        PartitionDesignator designator;
 } GptPartitionType;
 
 extern const GptPartitionType gpt_partition_type_table[];