]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/gpt.c
shutdown: log on container exit
[thirdparty/systemd.git] / src / shared / gpt.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "gpt.h"
4 #include "string-util.h"
5
6 const GptPartitionType gpt_partition_type_table[] = {
7 { GPT_ROOT_X86, "root-x86" },
8 { GPT_ROOT_X86_VERITY, "root-x86-verity" },
9 { GPT_ROOT_X86_64, "root-x86-64" },
10 { GPT_ROOT_X86_64_VERITY, "root-x86-64-verity" },
11 { GPT_ROOT_ARM, "root-arm" },
12 { GPT_ROOT_ARM_VERITY, "root-arm-verity" },
13 { GPT_ROOT_ARM_64, "root-arm64" },
14 { GPT_ROOT_ARM_64_VERITY, "root-arm64-verity" },
15 { GPT_ROOT_IA64, "root-ia64" },
16 { GPT_ROOT_IA64_VERITY, "root-ia64-verity" },
17 { GPT_ROOT_RISCV32, "root-riscv32" },
18 { GPT_ROOT_RISCV32_VERITY, "root-riscv32-verity" },
19 { GPT_ROOT_RISCV64, "root-riscv64" },
20 { GPT_ROOT_RISCV64_VERITY, "root-riscv64-verity" },
21 #ifdef GPT_ROOT_NATIVE
22 { GPT_ROOT_NATIVE, "root" },
23 { GPT_ROOT_NATIVE_VERITY, "root-verity" },
24 #endif
25 #ifdef GPT_ROOT_SECONDARY
26 { GPT_ROOT_SECONDARY, "root-secondary" },
27 { GPT_ROOT_SECONDARY_VERITY, "root-secondary-verity" },
28 #endif
29 { GPT_USR_X86, "usr-x86" },
30 { GPT_USR_X86_VERITY, "usr-x86-verity" },
31 { GPT_USR_X86_64, "usr-x86-64" },
32 { GPT_USR_X86_64_VERITY, "usr-x86-64-verity" },
33 { GPT_USR_ARM, "usr-arm" },
34 { GPT_USR_ARM_VERITY, "usr-arm-verity" },
35 { GPT_USR_ARM_64, "usr-arm64" },
36 { GPT_USR_ARM_64_VERITY, "usr-arm64-verity" },
37 { GPT_USR_IA64, "usr-ia64" },
38 { GPT_USR_IA64_VERITY, "usr-ia64-verity" },
39 { GPT_USR_RISCV32, "usr-riscv32" },
40 { GPT_USR_RISCV32_VERITY, "usr-riscv32-verity" },
41 { GPT_USR_RISCV64, "usr-riscv64" },
42 { GPT_USR_RISCV64_VERITY, "usr-riscv64-verity" },
43 #ifdef GPT_USR_NATIVE
44 { GPT_USR_NATIVE, "usr" },
45 { GPT_USR_NATIVE_VERITY, "usr-verity" },
46 #endif
47 #ifdef GPT_USR_SECONDARY
48 { GPT_USR_SECONDARY, "usr-secondary" },
49 { GPT_USR_SECONDARY_VERITY, "usr-secondary-verity" },
50 #endif
51 { GPT_ESP, "esp" },
52 { GPT_XBOOTLDR, "xbootldr" },
53 { GPT_SWAP, "swap" },
54 { GPT_HOME, "home" },
55 { GPT_SRV, "srv" },
56 { GPT_VAR, "var" },
57 { GPT_TMP, "tmp" },
58 { GPT_USER_HOME, "user-home" },
59 { GPT_LINUX_GENERIC, "linux-generic" },
60 {}
61 };
62
63 const char *gpt_partition_type_uuid_to_string(sd_id128_t id) {
64 for (size_t i = 0; i < ELEMENTSOF(gpt_partition_type_table) - 1; i++)
65 if (sd_id128_equal(id, gpt_partition_type_table[i].uuid))
66 return gpt_partition_type_table[i].name;
67
68 return NULL;
69 }
70
71 const char *gpt_partition_type_uuid_to_string_harder(
72 sd_id128_t id,
73 char buffer[static ID128_UUID_STRING_MAX]) {
74
75 const char *s;
76
77 assert(buffer);
78
79 s = gpt_partition_type_uuid_to_string(id);
80 if (s)
81 return s;
82
83 return id128_to_uuid_string(id, buffer);
84 }
85
86 int gpt_partition_type_uuid_from_string(const char *s, sd_id128_t *ret) {
87 assert(s);
88 assert(ret);
89
90 for (size_t i = 0; i < ELEMENTSOF(gpt_partition_type_table) - 1; i++)
91 if (streq(s, gpt_partition_type_table[i].name)) {
92 *ret = gpt_partition_type_table[i].uuid;
93 return 0;
94 }
95
96 return sd_id128_from_string(s, ret);
97 }