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 <gpt_partition_type_is_usr_verity>:

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 <gpt_partition_type_is_usr_verity+0xb>
   b:   31 c0                   xor    %eax,%eax
   d:   4c 8b 0d 00 00 00 00    mov    0x0(%rip),%r9        # 14 <gpt_partition_type_is_usr_verity+0x14>
  14:   48 8b 15 00 00 00 00    mov    0x0(%rip),%rdx        # 1b <gpt_partition_type_is_usr_verity+0x1b>
  1b:   48 8b 0d 00 00 00 00    mov    0x0(%rip),%rcx        # 22 <gpt_partition_type_is_usr_verity+0x22>
  22:   6a 00                   pushq  $0x0
  24:   6a 00                   pushq  $0x0
  26:   ff 35 00 00 00 00       pushq  0x0(%rip)        # 2c <gpt_partition_type_is_usr_verity+0x2c>
  2c:   ff 35 00 00 00 00       pushq  0x0(%rip)        # 32 <gpt_partition_type_is_usr_verity+0x32>
  32:   ff 35 00 00 00 00       pushq  0x0(%rip)        # 38 <gpt_partition_type_is_usr_verity+0x38>
  38:   ff 35 00 00 00 00       pushq  0x0(%rip)        # 3e <gpt_partition_type_is_usr_verity+0x3e>
  3e:   ff 35 00 00 00 00       pushq  0x0(%rip)        # 44 <gpt_partition_type_is_usr_verity+0x44>
  44:   ff 35 00 00 00 00       pushq  0x0(%rip)        # 4a <gpt_partition_type_is_usr_verity+0x4a>
  4a:   ff 35 00 00 00 00       pushq  0x0(%rip)        # 50 <gpt_partition_type_is_usr_verity+0x50>
  50:   ff 35 00 00 00 00       pushq  0x0(%rip)        # 56 <gpt_partition_type_is_usr_verity+0x56>
  56:   ff 35 00 00 00 00       pushq  0x0(%rip)        # 5c <gpt_partition_type_is_usr_verity+0x5c>
  5c:   ff 35 00 00 00 00       pushq  0x0(%rip)        # 62 <gpt_partition_type_is_usr_verity+0x62>
  62:   e8 00 00 00 00          callq  67 <gpt_partition_type_is_usr_verity+0x67>
  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
)
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2021-04-21 17:51:24 +02:00
parent 64b21afc72
commit 580f48cc02
2 changed files with 38 additions and 34 deletions
+1 -2
View File
@@ -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);
+37 -32
View File
@@ -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 */
}