| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "sd-gpt.h" /* IWYU pragma: export */ |
| 5 |
#include "sd-id128.h" |
| 6 |
|
| 7 |
#include "architecture.h" |
| 8 |
#include "shared-forward.h" |
| 9 |
#include "sparse-endian.h" |
| 10 |
|
| 11 |
/* maximum length of gpt label */ |
| 12 |
#define GPT_LABEL_MAX 36 |
| 13 |
|
| 14 |
typedef enum PartitionDesignator { |
| 15 |
PARTITION_ROOT, /* Primary architecture */ |
| 16 |
PARTITION_USR, |
| 17 |
PARTITION_HOME, |
| 18 |
PARTITION_SRV, |
| 19 |
PARTITION_ESP, |
| 20 |
PARTITION_XBOOTLDR, |
| 21 |
PARTITION_SWAP, |
| 22 |
PARTITION_ROOT_VERITY, /* verity data for the PARTITION_ROOT partition */ |
| 23 |
PARTITION_USR_VERITY, |
| 24 |
PARTITION_ROOT_VERITY_SIG, /* PKCS#7 signature for root hash for the PARTITION_ROOT partition */ |
| 25 |
PARTITION_USR_VERITY_SIG, |
| 26 |
PARTITION_TMP, |
| 27 |
PARTITION_VAR, |
| 28 |
_PARTITION_DESIGNATOR_MAX, |
| 29 |
_PARTITION_DESIGNATOR_INVALID = -EINVAL, |
| 30 |
} PartitionDesignator; |
| 31 |
|
| 32 |
bool partition_designator_is_versioned(PartitionDesignator d) _const_; |
| 33 |
|
| 34 |
PartitionDesignator partition_verity_hash_of(PartitionDesignator p) _const_; |
| 35 |
PartitionDesignator partition_verity_sig_of(PartitionDesignator p) _const_; |
| 36 |
PartitionDesignator partition_verity_hash_to_data(PartitionDesignator d) _const_; |
| 37 |
PartitionDesignator partition_verity_sig_to_data(PartitionDesignator d) _const_; |
| 38 |
PartitionDesignator partition_verity_to_data(PartitionDesignator d) _const_; |
| 39 |
|
| 40 |
static inline bool partition_designator_is_verity_hash(PartitionDesignator d) { |
| 41 |
return partition_verity_hash_to_data(d) >= 0; |
| 42 |
} |
| 43 |
|
| 44 |
static inline bool partition_designator_is_verity_sig(PartitionDesignator d) { |
| 45 |
return partition_verity_sig_to_data(d) >= 0; |
| 46 |
} |
| 47 |
|
| 48 |
static inline bool partition_designator_is_verity(PartitionDesignator d) { |
| 49 |
return partition_verity_to_data(d) >= 0; |
| 50 |
} |
| 51 |
|
| 52 |
DECLARE_STRING_TABLE_LOOKUP(partition_designator, PartitionDesignator); |
| 53 |
|
| 54 |
DECLARE_STRING_TABLE_LOOKUP_TO_STRING(partition_mountpoint, PartitionDesignator); |
| 55 |
|
| 56 |
DECLARE_STRING_TABLE_LOOKUP_TO_STRING(gpt_partition_type_uuid, sd_id128_t); |
| 57 |
const char* gpt_partition_type_uuid_to_string_harder( |
| 58 |
sd_id128_t id, |
| 59 |
char buffer[static SD_ID128_UUID_STRING_MAX]); |
| 60 |
|
| 61 |
#define GPT_PARTITION_TYPE_UUID_TO_STRING_HARDER(id) \ |
| 62 |
gpt_partition_type_uuid_to_string_harder((id), (char[SD_ID128_UUID_STRING_MAX]) {}) |
| 63 |
|
| 64 |
Architecture gpt_partition_type_uuid_to_arch(sd_id128_t id) _const_; |
| 65 |
|
| 66 |
typedef struct GptPartitionType { |
| 67 |
sd_id128_t uuid; |
| 68 |
const char *name; |
| 69 |
Architecture arch; |
| 70 |
PartitionDesignator designator; |
| 71 |
} GptPartitionType; |
| 72 |
|
| 73 |
extern const GptPartitionType gpt_partition_type_table[]; |
| 74 |
|
| 75 |
int gpt_partition_label_valid(const char *s); |
| 76 |
|
| 77 |
GptPartitionType gpt_partition_type_from_uuid(sd_id128_t id); |
| 78 |
int gpt_partition_type_from_string(const char *s, GptPartitionType *ret); |
| 79 |
|
| 80 |
GptPartitionType gpt_partition_type_override_architecture(GptPartitionType type, Architecture arch) _const_; |
| 81 |
|
| 82 |
const char* gpt_partition_type_mountpoint_nulstr(GptPartitionType type); |
| 83 |
|
| 84 |
bool gpt_partition_type_knows_read_only(GptPartitionType type) _const_; |
| 85 |
bool gpt_partition_type_knows_growfs(GptPartitionType type) _const_; |
| 86 |
bool gpt_partition_type_knows_no_auto(GptPartitionType type) _const_; |
| 87 |
bool gpt_partition_type_has_filesystem(GptPartitionType type) _const_; |
| 88 |
|
| 89 |
typedef struct { |
| 90 |
uint8_t partition_type_guid[16]; |
| 91 |
uint8_t unique_partition_guid[16]; |
| 92 |
le64_t starting_lba; |
| 93 |
le64_t ending_lba; |
| 94 |
le64_t attributes; |
| 95 |
char16_t partition_name[36]; |
| 96 |
} _packed_ GptPartitionEntry; |
| 97 |
|
| 98 |
typedef struct { |
| 99 |
char signature[8]; |
| 100 |
le32_t revision; |
| 101 |
le32_t header_size; |
| 102 |
le32_t crc32; |
| 103 |
le32_t reserved; |
| 104 |
le64_t my_lba; |
| 105 |
le64_t alternate_lba; |
| 106 |
le64_t first_usable_lba; |
| 107 |
le64_t last_usable_lba; |
| 108 |
uint8_t disk_guid[16]; |
| 109 |
le64_t partition_entry_lba; |
| 110 |
le32_t number_of_partition_entries; |
| 111 |
le32_t size_of_partition_entry; |
| 112 |
le32_t partition_entry_array_crc32; |
| 113 |
} _packed_ GptHeader; |
| 114 |
|
| 115 |
bool gpt_header_has_signature(const GptHeader *p) _pure_; |
| 116 |
|
| 117 |
ssize_t gpt_probe( |
| 118 |
int fd, |
| 119 |
GptHeader *ret_header, |
| 120 |
void **ret_entries, |
| 121 |
uint32_t *ret_n_entries, |
| 122 |
uint32_t *ret_entry_size); |