diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2021-11-24 10:30:27 +0100 |
---|---|---|
committer | Daan De Meyer <daan.j.demeyer@gmail.com> | 2021-11-24 14:47:57 +0100 |
commit | 6ddd80ae181635515924cf9cabcd8b39db6734b7 (patch) | |
tree | aeb87d28afe82e411b27ac7045d1e700f0a61e5c /src/shared/gpt.c | |
parent | gpt: Store the architecture in GptPartitionType (diff) | |
download | systemd-6ddd80ae181635515924cf9cabcd8b39db6734b7.tar.xz systemd-6ddd80ae181635515924cf9cabcd8b39db6734b7.zip |
gpt: Store the partition type in GptPartitionType
This replaces the _GPT_ALL_ARCHES macro.
Diffstat (limited to 'src/shared/gpt.c')
-rw-r--r-- | src/shared/gpt.c | 80 |
1 files changed, 38 insertions, 42 deletions
diff --git a/src/shared/gpt.c b/src/shared/gpt.c index 75324b0fe3..bf494119b5 100644 --- a/src/shared/gpt.c +++ b/src/shared/gpt.c @@ -15,12 +15,12 @@ #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) { |