]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/gpt.h
cryptenroll: allow to use a public key on a token
[thirdparty/systemd.git] / src / shared / gpt.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <uchar.h>
5
6 #include "sd-gpt.h"
7 #include "sd-id128.h"
8
9 #include "architecture.h"
10 #include "id128-util.h"
11 #include "sparse-endian.h"
12
13 /* maximum length of gpt label */
14 #define GPT_LABEL_MAX 36
15
16 typedef enum PartitionDesignator {
17 PARTITION_ROOT, /* Primary architecture */
18 PARTITION_USR,
19 PARTITION_HOME,
20 PARTITION_SRV,
21 PARTITION_ESP,
22 PARTITION_XBOOTLDR,
23 PARTITION_SWAP,
24 PARTITION_ROOT_VERITY, /* verity data for the PARTITION_ROOT partition */
25 PARTITION_USR_VERITY,
26 PARTITION_ROOT_VERITY_SIG, /* PKCS#7 signature for root hash for the PARTITION_ROOT partition */
27 PARTITION_USR_VERITY_SIG,
28 PARTITION_TMP,
29 PARTITION_VAR,
30 _PARTITION_DESIGNATOR_MAX,
31 _PARTITION_DESIGNATOR_INVALID = -EINVAL,
32 } PartitionDesignator;
33
34 bool partition_designator_is_versioned(PartitionDesignator d);
35
36 PartitionDesignator partition_verity_of(PartitionDesignator p);
37 PartitionDesignator partition_verity_sig_of(PartitionDesignator p);
38 PartitionDesignator partition_verity_to_data(PartitionDesignator d);
39 PartitionDesignator partition_verity_sig_to_data(PartitionDesignator d);
40
41 const char* partition_designator_to_string(PartitionDesignator d) _const_;
42 PartitionDesignator partition_designator_from_string(const char *name) _pure_;
43
44 const char *gpt_partition_type_uuid_to_string(sd_id128_t id);
45 const char *gpt_partition_type_uuid_to_string_harder(
46 sd_id128_t id,
47 char buffer[static SD_ID128_UUID_STRING_MAX]);
48
49 #define GPT_PARTITION_TYPE_UUID_TO_STRING_HARDER(id) \
50 gpt_partition_type_uuid_to_string_harder((id), (char[SD_ID128_UUID_STRING_MAX]) {})
51
52 Architecture gpt_partition_type_uuid_to_arch(sd_id128_t id);
53
54 typedef struct GptPartitionType {
55 sd_id128_t uuid;
56 const char *name;
57 Architecture arch;
58 PartitionDesignator designator;
59 } GptPartitionType;
60
61 extern const GptPartitionType gpt_partition_type_table[];
62
63 int gpt_partition_label_valid(const char *s);
64
65 GptPartitionType gpt_partition_type_from_uuid(sd_id128_t id);
66 int gpt_partition_type_from_string(const char *s, GptPartitionType *ret);
67
68 GptPartitionType gpt_partition_type_override_architecture(GptPartitionType type, Architecture arch);
69
70 const char *gpt_partition_type_mountpoint_nulstr(GptPartitionType type);
71
72 bool gpt_partition_type_knows_read_only(GptPartitionType type);
73 bool gpt_partition_type_knows_growfs(GptPartitionType type);
74 bool gpt_partition_type_knows_no_auto(GptPartitionType type);
75
76 typedef struct {
77 uint8_t partition_type_guid[16];
78 uint8_t unique_partition_guid[16];
79 le64_t starting_lba;
80 le64_t ending_lba;
81 le64_t attributes;
82 char16_t partition_name[36];
83 } _packed_ GptPartitionEntry;
84
85 typedef struct {
86 char signature[8];
87 le32_t revision;
88 le32_t header_size;
89 le32_t crc32;
90 le32_t reserved;
91 le64_t my_lba;
92 le64_t alternate_lba;
93 le64_t first_usable_lba;
94 le64_t last_usable_lba;
95 uint8_t disk_guid[16];
96 le64_t partition_entry_lba;
97 le32_t number_of_partition_entries;
98 le32_t size_of_partition_entry;
99 le32_t partition_entry_array_crc32;
100 } _packed_ GptHeader;
101
102 bool gpt_header_has_signature(const GptHeader *p);