]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
gpt: Store the partition type in GptPartitionType
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 24 Nov 2021 09:30:27 +0000 (10:30 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 24 Nov 2021 13:47:57 +0000 (14:47 +0100)
This replaces the _GPT_ALL_ARCHES macro.

src/shared/gpt.c
src/shared/gpt.h

index 75324b0fe39223b4f1ab4f75e73d6010b9ff1308..bf494119b58743e227c27372aff1f9329c6e09ee 100644 (file)
 #endif
 
 #define _GPT_ARCH_SEXTET(arch, name)                                   \
-        { GPT_ROOT_##arch,              "root-" name,               ARCHITECTURE_##arch },  \
-        { GPT_ROOT_##arch##_VERITY,     "root-" name "-verity",     ARCHITECTURE_##arch },  \
-        { GPT_ROOT_##arch##_VERITY_SIG, "root-" name "-verity-sig", ARCHITECTURE_##arch },  \
-        { GPT_USR_##arch,               "usr-" name,                ARCHITECTURE_##arch },  \
-        { GPT_USR_##arch##_VERITY,      "usr-" name "-verity",      ARCHITECTURE_##arch },  \
-        { GPT_USR_##arch##_VERITY_SIG,  "usr-" name "-verity-sig",  ARCHITECTURE_##arch }
+        { GPT_ROOT_##arch,              "root-" name,               ARCHITECTURE_##arch, .is_root = true            },  \
+        { GPT_ROOT_##arch##_VERITY,     "root-" name "-verity",     ARCHITECTURE_##arch, .is_root_verity = true     },  \
+        { GPT_ROOT_##arch##_VERITY_SIG, "root-" name "-verity-sig", ARCHITECTURE_##arch, .is_root_verity_sig = true },  \
+        { GPT_USR_##arch,               "usr-" name,                ARCHITECTURE_##arch, .is_usr = true             },  \
+        { GPT_USR_##arch##_VERITY,      "usr-" name "-verity",      ARCHITECTURE_##arch, .is_usr_verity = true      },  \
+        { GPT_USR_##arch##_VERITY_SIG,  "usr-" name "-verity-sig",  ARCHITECTURE_##arch, .is_usr_verity_sig = true  }
 
 const GptPartitionType gpt_partition_type_table[] = {
         _GPT_ARCH_SEXTET(ALPHA,       "alpha"),
@@ -31,12 +31,12 @@ const GptPartitionType gpt_partition_type_table[] = {
 
         // TODO: Replace with `_GPT_ARCH_SEXTET(LOONGARCH64, "loongarch64")` once
         // https://github.com/systemd/systemd/pull/21288 is merged. */
-        { GPT_ROOT_LOONGARCH64,            "root-loongarch64",            _ARCHITECTURE_INVALID },
-        { GPT_ROOT_LOONGARCH64_VERITY,     "root-loongarch64-verity",     _ARCHITECTURE_INVALID },
-        { GPT_ROOT_LOONGARCH64_VERITY_SIG, "root-loongarch64-verity-sig", _ARCHITECTURE_INVALID },
-        { GPT_USR_LOONGARCH64,             "usr-loongarch64",             _ARCHITECTURE_INVALID },
-        { GPT_USR_LOONGARCH64_VERITY,      "usr-loongarch64-verity",      _ARCHITECTURE_INVALID },
-        { GPT_USR_LOONGARCH64_VERITY_SIG,  "usr-loongarch64-verity-sig",  _ARCHITECTURE_INVALID },
+        { GPT_ROOT_LOONGARCH64,            "root-loongarch64",            _ARCHITECTURE_INVALID, .is_root = true            },
+        { GPT_ROOT_LOONGARCH64_VERITY,     "root-loongarch64-verity",     _ARCHITECTURE_INVALID, .is_root_verity = true     },
+        { GPT_ROOT_LOONGARCH64_VERITY_SIG, "root-loongarch64-verity-sig", _ARCHITECTURE_INVALID, .is_root_verity_sig = true },
+        { GPT_USR_LOONGARCH64,             "usr-loongarch64",             _ARCHITECTURE_INVALID, .is_usr = true             },
+        { GPT_USR_LOONGARCH64_VERITY,      "usr-loongarch64-verity",      _ARCHITECTURE_INVALID, .is_usr_verity = true      },
+        { GPT_USR_LOONGARCH64_VERITY_SIG,  "usr-loongarch64-verity-sig",  _ARCHITECTURE_INVALID, .is_usr_verity_sig = true  },
 
         _GPT_ARCH_SEXTET(MIPS_LE,     "mips-le"),
         _GPT_ARCH_SEXTET(MIPS64_LE,   "mips64-le"),
@@ -51,12 +51,12 @@ const GptPartitionType gpt_partition_type_table[] = {
         _GPT_ARCH_SEXTET(X86,         "x86"),
         _GPT_ARCH_SEXTET(X86_64,      "x86-64"),
 #ifdef GPT_ROOT_NATIVE
-        { GPT_ROOT_NATIVE,            "root",            native_architecture() },
-        { GPT_ROOT_NATIVE_VERITY,     "root-verity",     native_architecture() },
-        { GPT_ROOT_NATIVE_VERITY_SIG, "root-verity-sig", native_architecture() },
-        { GPT_USR_NATIVE,             "usr",             native_architecture() },
-        { GPT_USR_NATIVE_VERITY,      "usr-verity",      native_architecture() },
-        { GPT_USR_NATIVE_VERITY_SIG,  "usr-verity-sig",  native_architecture() },
+        { GPT_ROOT_NATIVE,            "root",            native_architecture(), .is_root = true            },
+        { GPT_ROOT_NATIVE_VERITY,     "root-verity",     native_architecture(), .is_root_verity = true     },
+        { GPT_ROOT_NATIVE_VERITY_SIG, "root-verity-sig", native_architecture(), .is_root_verity_sig = true },
+        { GPT_USR_NATIVE,             "usr",             native_architecture(), .is_usr = true             },
+        { GPT_USR_NATIVE_VERITY,      "usr-verity",      native_architecture(), .is_usr_verity = true      },
+        { GPT_USR_NATIVE_VERITY_SIG,  "usr-verity-sig",  native_architecture(), .is_usr_verity_sig = true  },
 #endif
 #ifdef GPT_ROOT_SECONDARY
         _GPT_ARCH_SEXTET(SECONDARY,   "secondary"),
@@ -74,26 +74,6 @@ const GptPartitionType gpt_partition_type_table[] = {
         {}
 };
 
-#define _GPT_ALL_ARCHES(type,suffix)                    \
-        GPT_##type##_ALPHA##suffix,                     \
-        GPT_##type##_ARC##suffix,                       \
-        GPT_##type##_ARM##suffix,                       \
-        GPT_##type##_ARM64##suffix,                     \
-        GPT_##type##_IA64##suffix,                      \
-        GPT_##type##_LOONGARCH64##suffix,               \
-        GPT_##type##_MIPS_LE##suffix,                   \
-        GPT_##type##_MIPS64_LE##suffix,                 \
-        GPT_##type##_PPC##suffix,                       \
-        GPT_##type##_PPC64##suffix,                     \
-        GPT_##type##_PPC64_LE##suffix,                  \
-        GPT_##type##_RISCV32##suffix,                   \
-        GPT_##type##_RISCV64##suffix,                   \
-        GPT_##type##_S390##suffix,                      \
-        GPT_##type##_S390X##suffix,                     \
-        GPT_##type##_TILEGX##suffix,                    \
-        GPT_##type##_X86##suffix,                       \
-        GPT_##type##_X86_64##suffix
-
 const char *gpt_partition_type_uuid_to_string(sd_id128_t id) {
         for (size_t i = 0; i < ELEMENTSOF(gpt_partition_type_table) - 1; i++)
                 if (sd_id128_equal(id, gpt_partition_type_table[i].uuid))
@@ -148,20 +128,36 @@ int gpt_partition_label_valid(const char *s) {
         return char16_strlen(recoded) <= GPT_LABEL_MAX;
 }
 
+static GptPartitionType gpt_partition_type_from_uuid(sd_id128_t id) {
+        for (size_t i = 0; i < ELEMENTSOF(gpt_partition_type_table) - 1; i++)
+                if (sd_id128_equal(id, gpt_partition_type_table[i].uuid))
+                        return gpt_partition_type_table[i];
+
+        return (GptPartitionType) { .uuid = id, .arch = _ARCHITECTURE_INVALID };
+}
+
 bool gpt_partition_type_is_root(sd_id128_t id) {
-        return sd_id128_in_set(id, _GPT_ALL_ARCHES(ROOT,));
+        return gpt_partition_type_from_uuid(id).is_root;
 }
 
 bool gpt_partition_type_is_root_verity(sd_id128_t id) {
-        return sd_id128_in_set(id, _GPT_ALL_ARCHES(ROOT, _VERITY));
+        return gpt_partition_type_from_uuid(id).is_root_verity;
+}
+
+bool gpt_partition_type_is_root_verity_sig(sd_id128_t id) {
+        return gpt_partition_type_from_uuid(id).is_root_verity_sig;
 }
 
 bool gpt_partition_type_is_usr(sd_id128_t id) {
-        return sd_id128_in_set(id, _GPT_ALL_ARCHES(USR,));
+        return gpt_partition_type_from_uuid(id).is_usr;
 }
 
 bool gpt_partition_type_is_usr_verity(sd_id128_t id) {
-        return sd_id128_in_set(id, _GPT_ALL_ARCHES(USR, _VERITY));
+        return gpt_partition_type_from_uuid(id).is_usr_verity;
+}
+
+bool gpt_partition_type_is_usr_verity_sig(sd_id128_t id) {
+        return gpt_partition_type_from_uuid(id).is_usr_verity_sig;
 }
 
 bool gpt_partition_type_knows_read_only(sd_id128_t id) {
index 9b335d02aa48be00dec42d96b77d18e6cf3210bb..00c829ca79aaf70c3d5dd17cdf3a5e06fac5c8a7 100644 (file)
@@ -295,6 +295,13 @@ 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;
 } GptPartitionType;
 
 extern const GptPartitionType gpt_partition_type_table[];
@@ -303,8 +310,10 @@ int gpt_partition_label_valid(const char *s);
 
 bool gpt_partition_type_is_root(sd_id128_t id);
 bool gpt_partition_type_is_root_verity(sd_id128_t id);
+bool gpt_partition_type_is_root_verity_sig(sd_id128_t id);
 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);
 
 bool gpt_partition_type_knows_read_only(sd_id128_t id);
 bool gpt_partition_type_knows_growfs(sd_id128_t id);