miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
Loading...
Searching...
No Matches
gpt.h
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2026 Christian Spoo
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22
23#ifndef _MINIOS_DRIVERS_GPT_H_
24#define _MINIOS_DRIVERS_GPT_H_
25
26#include <miniOS/types.h>
27
28/* GPT header lives at LBA 1; backup at the last sector of the disk. */
29#define GPT_HEADER_LBA 1
30#define GPT_REVISION 0x00010000U
31
32#define GPT_MAX_PARTITIONS 128
33
34/* 16-byte GUID */
35typedef struct {
38
39/* On-disk GPT header (UEFI spec §5.3.2). First 92 bytes are defined; the
40 * rest of the 512-byte sector is unused / reserved. */
41typedef struct {
42 uint8_t signature[8]; /* "EFI PART" */
43 uint32_t revision; /* 0x00010000 */
44 uint32_t header_size; /* 92 bytes */
47 uint64_t my_lba; /* LBA of this header */
48 uint64_t alternate_lba; /* LBA of backup header */
53 uint32_t num_partition_entries; /* typically 128 */
54 uint32_t partition_entry_size; /* typically 128 bytes */
56} __attribute__((packed)) gpt_header_t;
57
58/* On-disk GPT partition entry — 128 bytes. */
59typedef struct {
60 gpt_guid_t type_guid; /* all-zeros = unused entry */
63 uint64_t end_lba; /* inclusive */
65 uint16_t name[36]; /* UTF-16LE, null-terminated partition name */
66} __attribute__((packed)) gpt_partition_entry_t;
67
68/* Caller-facing parsed partition info. */
75
88int gpt_parse(gpt_partition_t *partitions, int max_count, int *count);
89
90#endif /* _MINIOS_DRIVERS_GPT_H_ */
int gpt_parse(gpt_partition_t *partitions, int max_count, int *count)
Definition gpt.c:38
uint64_t end_lba
Definition gpt.h:63
uint32_t revision
Definition gpt.h:43
uint16_t name[36]
Definition gpt.h:65
uint64_t partition_entries_lba
Definition gpt.h:52
uint8_t signature[8]
Definition gpt.h:42
uint32_t num_partition_entries
Definition gpt.h:53
uint32_t partition_entry_array_crc32
Definition gpt.h:55
uint64_t alternate_lba
Definition gpt.h:48
uint32_t reserved
Definition gpt.h:46
uint64_t first_usable_lba
Definition gpt.h:49
gpt_guid_t unique_guid
Definition gpt.h:61
gpt_guid_t type_guid
Definition gpt.h:60
uint64_t my_lba
Definition gpt.h:47
uint32_t header_size
Definition gpt.h:44
uint64_t last_usable_lba
Definition gpt.h:50
uint64_t start_lba
Definition gpt.h:62
gpt_guid_t disk_guid
Definition gpt.h:51
uint64_t attributes
Definition gpt.h:64
uint32_t header_crc32
Definition gpt.h:45
uint32_t partition_entry_size
Definition gpt.h:54
Definition gpt.h:35
uint8_t b[16]
Definition gpt.h:36
Definition gpt.h:69
gpt_guid_t type_guid
Definition gpt.h:72
gpt_guid_t unique_guid
Definition gpt.h:73
uint64_t lba_end
Definition gpt.h:71
uint64_t lba_start
Definition gpt.h:70
unsigned short uint16_t
Definition types.h:31
unsigned int uint32_t
Definition types.h:34
unsigned long int uint64_t
Definition types.h:37
unsigned char uint8_t
Definition types.h:28
typedef __attribute__