summaryrefslogtreecommitdiffstats
path: root/src/shared/gpt.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2023-08-15 09:52:38 +0200
committerLennart Poettering <lennart@poettering.net>2023-08-24 15:25:38 +0200
commit6b0651df60ef3cbb69911d44461bab2a64396b8c (patch)
tree52853afe0191f10f2f9a1a21a5227ce3a01886a1 /src/shared/gpt.c
parentalloc-util: add free_many() helper (diff)
downloadsystemd-6b0651df60ef3cbb69911d44461bab2a64396b8c.tar.xz
systemd-6b0651df60ef3cbb69911d44461bab2a64396b8c.zip
gpt: move basic header/partition structure of GPT into common code
This way we can use it at other places too, not just when dissecting images.
Diffstat (limited to 'src/shared/gpt.c')
-rw-r--r--src/shared/gpt.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/shared/gpt.c b/src/shared/gpt.c
index 34180a32c5..2846bad5b8 100644
--- a/src/shared/gpt.c
+++ b/src/shared/gpt.c
@@ -336,3 +336,24 @@ bool gpt_partition_type_knows_no_auto(GptPartitionType type) {
PARTITION_XBOOTLDR,
PARTITION_SWAP);
}
+
+bool gpt_header_has_signature(const GptHeader *p) {
+ assert(p);
+
+ if (memcmp(p->signature, (const char[8]) { 'E', 'F', 'I', ' ', 'P', 'A', 'R', 'T' }, 8) != 0)
+ return false;
+
+ if (le32toh(p->revision) != UINT32_C(0x00010000)) /* the only known revision of the spec: 1.0 */
+ return false;
+
+ if (le32toh(p->header_size) < sizeof(GptHeader))
+ return false;
+
+ if (le32toh(p->header_size) > 4096) /* larger than a sector? something is off… */
+ return false;
+
+ if (le64toh(p->my_lba) != 1) /* this sector must claim to be at sector offset 1 */
+ return false;
+
+ return true;
+}