1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-25 10:04:04 +03:00

gpt: Store the partition type in GptPartitionType

This replaces the _GPT_ALL_ARCHES macro.
This commit is contained in:
Daan De Meyer 2021-11-24 10:30:27 +01:00
parent 51d1c8f2fe
commit 6ddd80ae18
2 changed files with 47 additions and 42 deletions

View File

@ -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) {

View 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);