From: Zbigniew Jędrzejewski-Szmek Date: Mon, 19 Apr 2021 13:42:05 +0000 (+0200) Subject: partition,shared/gpt: use sd_id128_in_set() X-Git-Tag: v249-rc1~368^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=580f48cc024681f8e018278d6807e5481501fac9;p=thirdparty%2Fsystemd.git partition,shared/gpt: use sd_id128_in_set() I was worried that the text size will grow, but apparently that's not the case: With --optimization=2: $ size build/src/shared/libsystemd-shared-248.a.p/gpt.c.o* text data bss dec hex filename 3674 1104 0 4778 12aa build/src/shared/libsystemd-shared-248.a.p/gpt.c.o.old 3085 1104 0 4189 105d build/src/shared/libsystemd-shared-248.a.p/gpt.c.o (I don't understand the generated assembly, even though it seems to work: Disassembly of section .text.gpt_partition_type_is_usr_verity: 0000000000000000 : bool gpt_partition_type_is_usr_verity(sd_id128_t id) { 0: 48 83 ec 08 sub $0x8,%rsp return sd_id128_in_set(id, 4: 4c 8b 05 00 00 00 00 mov 0x0(%rip),%r8 # b b: 31 c0 xor %eax,%eax d: 4c 8b 0d 00 00 00 00 mov 0x0(%rip),%r9 # 14 14: 48 8b 15 00 00 00 00 mov 0x0(%rip),%rdx # 1b 1b: 48 8b 0d 00 00 00 00 mov 0x0(%rip),%rcx # 22 22: 6a 00 pushq $0x0 24: 6a 00 pushq $0x0 26: ff 35 00 00 00 00 pushq 0x0(%rip) # 2c 2c: ff 35 00 00 00 00 pushq 0x0(%rip) # 32 32: ff 35 00 00 00 00 pushq 0x0(%rip) # 38 38: ff 35 00 00 00 00 pushq 0x0(%rip) # 3e 3e: ff 35 00 00 00 00 pushq 0x0(%rip) # 44 44: ff 35 00 00 00 00 pushq 0x0(%rip) # 4a 4a: ff 35 00 00 00 00 pushq 0x0(%rip) # 50 50: ff 35 00 00 00 00 pushq 0x0(%rip) # 56 56: ff 35 00 00 00 00 pushq 0x0(%rip) # 5c 5c: ff 35 00 00 00 00 pushq 0x0(%rip) # 62 62: e8 00 00 00 00 callq 67 67: 85 c0 test %eax,%eax 69: 0f 95 c0 setne %al GPT_USR_ARM_VERITY, GPT_USR_ARM_64_VERITY, GPT_USR_IA64_VERITY, GPT_USR_RISCV32_VERITY, GPT_USR_RISCV64_VERITY); } 6c: 48 83 c4 68 add $0x68,%rsp 70: c3 retq ) --- diff --git a/src/partition/repart.c b/src/partition/repart.c index 356fd9152c5..38e65195ac6 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -3115,8 +3115,7 @@ static int partition_acquire_uuid(Context *context, Partition *p, sd_id128_t *re if (p == q) continue; - if (sd_id128_equal(q->current_uuid, result.id) || - sd_id128_equal(q->new_uuid, result.id)) { + if (sd_id128_in_set(result.id, q->current_uuid, q->new_uuid)) { log_warning("Partition UUID calculated from seed for partition %" PRIu64 " exists already, reverting to randomized UUID.", p->partno); r = sd_id128_randomize(&result.id); diff --git a/src/shared/gpt.c b/src/shared/gpt.c index 846b2fe48ff..6b1a5761388 100644 --- a/src/shared/gpt.c +++ b/src/shared/gpt.c @@ -108,52 +108,57 @@ int gpt_partition_label_valid(const char *s) { } bool gpt_partition_type_is_root(sd_id128_t id) { - return sd_id128_equal(id, GPT_ROOT_X86) || - sd_id128_equal(id, GPT_ROOT_X86_64) || - sd_id128_equal(id, GPT_ROOT_ARM) || - sd_id128_equal(id, GPT_ROOT_ARM_64) || - sd_id128_equal(id, GPT_ROOT_IA64) || - sd_id128_equal(id, GPT_ROOT_RISCV32) || - sd_id128_equal(id, GPT_ROOT_RISCV64); + return sd_id128_in_set(id, + GPT_ROOT_X86, + GPT_ROOT_X86_64, + GPT_ROOT_ARM, + GPT_ROOT_ARM_64, + GPT_ROOT_IA64, + GPT_ROOT_RISCV32, + GPT_ROOT_RISCV64); } bool gpt_partition_type_is_root_verity(sd_id128_t id) { - return sd_id128_equal(id, GPT_ROOT_X86_VERITY) || - sd_id128_equal(id, GPT_ROOT_X86_64_VERITY) || - sd_id128_equal(id, GPT_ROOT_ARM_VERITY) || - sd_id128_equal(id, GPT_ROOT_ARM_64_VERITY) || - sd_id128_equal(id, GPT_ROOT_IA64_VERITY) || - sd_id128_equal(id, GPT_ROOT_RISCV32_VERITY) || - sd_id128_equal(id, GPT_ROOT_RISCV64_VERITY); + return sd_id128_in_set(id, + GPT_ROOT_X86_VERITY, + GPT_ROOT_X86_64_VERITY, + GPT_ROOT_ARM_VERITY, + GPT_ROOT_ARM_64_VERITY, + GPT_ROOT_IA64_VERITY, + GPT_ROOT_RISCV32_VERITY, + GPT_ROOT_RISCV64_VERITY); } bool gpt_partition_type_is_usr(sd_id128_t id) { - return sd_id128_equal(id, GPT_USR_X86) || - sd_id128_equal(id, GPT_USR_X86_64) || - sd_id128_equal(id, GPT_USR_ARM) || - sd_id128_equal(id, GPT_USR_ARM_64) || - sd_id128_equal(id, GPT_USR_IA64) || - sd_id128_equal(id, GPT_USR_RISCV32) || - sd_id128_equal(id, GPT_USR_RISCV64); + return sd_id128_in_set(id, + GPT_USR_X86, + GPT_USR_X86_64, + GPT_USR_ARM, + GPT_USR_ARM_64, + GPT_USR_IA64, + GPT_USR_RISCV32, + GPT_USR_RISCV64); } bool gpt_partition_type_is_usr_verity(sd_id128_t id) { - return sd_id128_equal(id, GPT_USR_X86_VERITY) || - sd_id128_equal(id, GPT_USR_X86_64_VERITY) || - sd_id128_equal(id, GPT_USR_ARM_VERITY) || - sd_id128_equal(id, GPT_USR_ARM_64_VERITY) || - sd_id128_equal(id, GPT_USR_IA64_VERITY) || - sd_id128_equal(id, GPT_USR_RISCV32_VERITY) || - sd_id128_equal(id, GPT_USR_RISCV64_VERITY); + return sd_id128_in_set(id, + GPT_USR_X86_VERITY, + GPT_USR_X86_64_VERITY, + GPT_USR_ARM_VERITY, + GPT_USR_ARM_64_VERITY, + GPT_USR_IA64_VERITY, + GPT_USR_RISCV32_VERITY, + GPT_USR_RISCV64_VERITY); } 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_equal(id, GPT_HOME) || - sd_id128_equal(id, GPT_SRV) || - sd_id128_equal(id, GPT_VAR) || - sd_id128_equal(id, GPT_TMP) || + sd_id128_in_set(id, + GPT_HOME, + GPT_SRV, + GPT_VAR, + GPT_TMP) || 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 */ }