]>
Commit | Line | Data |
---|---|---|
19ce38ce ZJS |
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
2 | ||
3 | #include "gpt.h" | |
4 | #include "string-util.h" | |
5 | ||
dc972b07 | 6 | const GptPartitionType gpt_partition_type_table[] = { |
19ce38ce ZJS |
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 | #ifdef GPT_ROOT_NATIVE | |
18 | { GPT_ROOT_NATIVE, "root" }, | |
19 | { GPT_ROOT_NATIVE_VERITY, "root-verity" }, | |
20 | #endif | |
21 | #ifdef GPT_ROOT_SECONDARY | |
22 | { GPT_ROOT_SECONDARY, "root-secondary" }, | |
23 | { GPT_ROOT_SECONDARY_VERITY, "root-secondary-verity" }, | |
24 | #endif | |
25 | { GPT_ESP, "esp" }, | |
26 | { GPT_XBOOTLDR, "xbootldr" }, | |
27 | { GPT_SWAP, "swap" }, | |
28 | { GPT_HOME, "home" }, | |
29 | { GPT_SRV, "srv" }, | |
30 | { GPT_VAR, "var" }, | |
31 | { GPT_TMP, "tmp" }, | |
7b11770b LP |
32 | { GPT_USER_HOME, "user-home" }, |
33 | { GPT_LINUX_GENERIC, "linux-generic" }, | |
dc972b07 | 34 | {} |
19ce38ce ZJS |
35 | }; |
36 | ||
37 | const char *gpt_partition_type_uuid_to_string(sd_id128_t id) { | |
dc972b07 | 38 | for (size_t i = 0; i < ELEMENTSOF(gpt_partition_type_table) - 1; i++) |
19ce38ce ZJS |
39 | if (sd_id128_equal(id, gpt_partition_type_table[i].uuid)) |
40 | return gpt_partition_type_table[i].name; | |
41 | ||
42 | return NULL; | |
43 | } | |
44 | ||
45 | const char *gpt_partition_type_uuid_to_string_harder( | |
46 | sd_id128_t id, | |
47 | char buffer[static ID128_UUID_STRING_MAX]) { | |
48 | ||
49 | const char *s; | |
50 | ||
51 | assert(buffer); | |
52 | ||
53 | s = gpt_partition_type_uuid_to_string(id); | |
54 | if (s) | |
55 | return s; | |
56 | ||
57 | return id128_to_uuid_string(id, buffer); | |
58 | } | |
59 | ||
60 | int gpt_partition_type_uuid_from_string(const char *s, sd_id128_t *ret) { | |
61 | assert(s); | |
62 | assert(ret); | |
63 | ||
dc972b07 | 64 | for (size_t i = 0; i < ELEMENTSOF(gpt_partition_type_table) - 1; i++) |
19ce38ce ZJS |
65 | if (streq(s, gpt_partition_type_table[i].name)) { |
66 | *ret = gpt_partition_type_table[i].uuid; | |
67 | return 0; | |
68 | } | |
69 | ||
70 | return sd_id128_from_string(s, ret); | |
71 | } |