]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/gpt.h
hwdb: Add mapping for Xiaomi Mipad 2 bottom bezel capacitive buttons
[thirdparty/systemd.git] / src / shared / gpt.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
0ef6f454
LP
2#pragma once
3
6b0651df
LP
4#include <uchar.h>
5
92e72028 6#include "sd-gpt.h"
e48fdd84
LP
7#include "sd-id128.h"
8
51d1c8f2 9#include "architecture.h"
19ce38ce 10#include "id128-util.h"
6b0651df 11#include "sparse-endian.h"
19ce38ce 12
6001df65
YW
13/* maximum length of gpt label */
14#define GPT_LABEL_MAX 36
15
dd894023
DDM
16typedef enum PartitionDesignator {
17 PARTITION_ROOT, /* Primary architecture */
dd894023 18 PARTITION_USR,
dd894023
DDM
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 */
dd894023 25 PARTITION_USR_VERITY,
dd894023 26 PARTITION_ROOT_VERITY_SIG, /* PKCS#7 signature for root hash for the PARTITION_ROOT partition */
dd894023 27 PARTITION_USR_VERITY_SIG,
dd894023
DDM
28 PARTITION_TMP,
29 PARTITION_VAR,
dd894023
DDM
30 _PARTITION_DESIGNATOR_MAX,
31 _PARTITION_DESIGNATOR_INVALID = -EINVAL,
32} PartitionDesignator;
33
34bool partition_designator_is_versioned(PartitionDesignator d);
35
36PartitionDesignator partition_verity_of(PartitionDesignator p);
37PartitionDesignator partition_verity_sig_of(PartitionDesignator p);
86adf4a5
LP
38PartitionDesignator partition_verity_to_data(PartitionDesignator d);
39PartitionDesignator partition_verity_sig_to_data(PartitionDesignator d);
dd894023
DDM
40
41const char* partition_designator_to_string(PartitionDesignator d) _const_;
42PartitionDesignator partition_designator_from_string(const char *name) _pure_;
43
19ce38ce
ZJS
44const char *gpt_partition_type_uuid_to_string(sd_id128_t id);
45const char *gpt_partition_type_uuid_to_string_harder(
46 sd_id128_t id,
b7416360 47 char buffer[static SD_ID128_UUID_STRING_MAX]);
dc972b07 48
1e58a0a8
DDM
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
51d1c8f2
DDM
52Architecture gpt_partition_type_uuid_to_arch(sd_id128_t id);
53
dc972b07
ZJS
54typedef struct GptPartitionType {
55 sd_id128_t uuid;
56 const char *name;
51d1c8f2 57 Architecture arch;
dd894023 58 PartitionDesignator designator;
dc972b07
ZJS
59} GptPartitionType;
60
61extern const GptPartitionType gpt_partition_type_table[];
22a0a36e
LP
62
63int gpt_partition_label_valid(const char *s);
e81acfd2 64
22e932f4
DDM
65GptPartitionType gpt_partition_type_from_uuid(sd_id128_t id);
66int gpt_partition_type_from_string(const char *s, GptPartitionType *ret);
e73309c5 67
7767b83f
DDM
68GptPartitionType gpt_partition_type_override_architecture(GptPartitionType type, Architecture arch);
69
22e932f4 70const char *gpt_partition_type_mountpoint_nulstr(GptPartitionType type);
58b4ad76 71
22e932f4
DDM
72bool gpt_partition_type_knows_read_only(GptPartitionType type);
73bool gpt_partition_type_knows_growfs(GptPartitionType type);
74bool gpt_partition_type_knows_no_auto(GptPartitionType type);
6b0651df
LP
75
76typedef 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
85typedef 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
102bool gpt_header_has_signature(const GptHeader *p);