diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2021-11-23 17:52:27 +0100 |
---|---|---|
committer | Daan De Meyer <daan.j.demeyer@gmail.com> | 2021-11-24 14:47:21 +0100 |
commit | 51d1c8f2feef9eac7c242354a79559ccc2dff174 (patch) | |
tree | c04fbf32113e160b4bb75296645229585707fc76 /src/shared/gpt.c | |
parent | basic: Rename SECONDARY_ARCHITECTURE to ARCHITECTURE_SECONDARY (diff) | |
download | systemd-51d1c8f2feef9eac7c242354a79559ccc2dff174.tar.xz systemd-51d1c8f2feef9eac7c242354a79559ccc2dff174.zip |
gpt: Store the architecture in GptPartitionType
We also add a function gpt_partition_type_uuid_to_arch() to get the
architecture of a partition type uuid.
Diffstat (limited to 'src/shared/gpt.c')
-rw-r--r-- | src/shared/gpt.c | 61 |
1 files changed, 39 insertions, 22 deletions
diff --git a/src/shared/gpt.c b/src/shared/gpt.c index 87b893beed..75324b0fe3 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 }, \ - { GPT_ROOT_##arch##_VERITY, "root-" name "-verity" }, \ - { GPT_ROOT_##arch##_VERITY_SIG, "root-" name "-verity-sig" }, \ - { GPT_USR_##arch, "usr-" name }, \ - { GPT_USR_##arch##_VERITY, "usr-" name "-verity" }, \ - { GPT_USR_##arch##_VERITY_SIG, "usr-" name "-verity-sig" } + { 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 } const GptPartitionType gpt_partition_type_table[] = { _GPT_ARCH_SEXTET(ALPHA, "alpha"), @@ -28,7 +28,16 @@ const GptPartitionType gpt_partition_type_table[] = { _GPT_ARCH_SEXTET(ARM, "arm"), _GPT_ARCH_SEXTET(ARM64, "arm64"), _GPT_ARCH_SEXTET(IA64, "ia64"), - _GPT_ARCH_SEXTET(LOONGARCH64, "loongarch64"), + + // 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_ARCH_SEXTET(MIPS_LE, "mips-le"), _GPT_ARCH_SEXTET(MIPS64_LE, "mips64-le"), _GPT_ARCH_SEXTET(PPC, "ppc"), @@ -42,26 +51,26 @@ 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" }, - { GPT_ROOT_NATIVE_VERITY, "root-verity" }, - { GPT_ROOT_NATIVE_VERITY_SIG, "root-verity-sig" }, - { GPT_USR_NATIVE, "usr" }, - { GPT_USR_NATIVE_VERITY, "usr-verity" }, - { GPT_USR_NATIVE_VERITY_SIG, "usr-verity-sig" }, + { 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() }, #endif #ifdef GPT_ROOT_SECONDARY _GPT_ARCH_SEXTET(SECONDARY, "secondary"), #endif - { GPT_ESP, "esp" }, - { GPT_XBOOTLDR, "xbootldr" }, - { GPT_SWAP, "swap" }, - { GPT_HOME, "home" }, - { GPT_SRV, "srv" }, - { GPT_VAR, "var" }, - { GPT_TMP, "tmp" }, - { GPT_USER_HOME, "user-home" }, - { GPT_LINUX_GENERIC, "linux-generic" }, + { GPT_ESP, "esp", _ARCHITECTURE_INVALID }, + { GPT_XBOOTLDR, "xbootldr", _ARCHITECTURE_INVALID }, + { GPT_SWAP, "swap", _ARCHITECTURE_INVALID }, + { GPT_HOME, "home", _ARCHITECTURE_INVALID }, + { GPT_SRV, "srv", _ARCHITECTURE_INVALID }, + { GPT_VAR, "var", _ARCHITECTURE_INVALID }, + { GPT_TMP, "tmp", _ARCHITECTURE_INVALID }, + { GPT_USER_HOME, "user-home", _ARCHITECTURE_INVALID }, + { GPT_LINUX_GENERIC, "linux-generic", _ARCHITECTURE_INVALID }, {} }; @@ -121,6 +130,14 @@ int gpt_partition_type_uuid_from_string(const char *s, sd_id128_t *ret) { return sd_id128_from_string(s, ret); } +Architecture gpt_partition_type_uuid_to_arch(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].arch; + + return _ARCHITECTURE_INVALID; +} + int gpt_partition_label_valid(const char *s) { _cleanup_free_ char16_t *recoded = NULL; |