miniOS
x86_64 hobby kernel with SMP, VFS, and POSIX process model
Toggle main menu visibility
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 */
35
typedef
struct
{
36
uint8_t
b
[16];
37
}
gpt_guid_t
;
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. */
41
typedef
struct
{
42
uint8_t
signature
[8];
/* "EFI PART" */
43
uint32_t
revision
;
/* 0x00010000 */
44
uint32_t
header_size
;
/* 92 bytes */
45
uint32_t
header_crc32
;
46
uint32_t
reserved
;
47
uint64_t
my_lba
;
/* LBA of this header */
48
uint64_t
alternate_lba
;
/* LBA of backup header */
49
uint64_t
first_usable_lba
;
50
uint64_t
last_usable_lba
;
51
gpt_guid_t
disk_guid
;
52
uint64_t
partition_entries_lba
;
/* typically 2 */
53
uint32_t
num_partition_entries
;
/* typically 128 */
54
uint32_t
partition_entry_size
;
/* typically 128 bytes */
55
uint32_t
partition_entry_array_crc32
;
56
}
__attribute__
((packed)) gpt_header_t;
57
58
/* On-disk GPT partition entry — 128 bytes. */
59
typedef
struct
{
60
gpt_guid_t
type_guid
;
/* all-zeros = unused entry */
61
gpt_guid_t
unique_guid
;
62
uint64_t
start_lba
;
63
uint64_t
end_lba
;
/* inclusive */
64
uint64_t
attributes
;
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. */
69
typedef
struct
{
70
uint64_t
lba_start
;
71
uint64_t
lba_end
;
/* inclusive */
72
gpt_guid_t
type_guid
;
73
gpt_guid_t
unique_guid
;
74
}
gpt_partition_t
;
75
88
int
gpt_parse
(
gpt_partition_t
*partitions,
int
max_count,
int
*count);
89
90
#endif
/* _MINIOS_DRIVERS_GPT_H_ */
gpt_parse
int gpt_parse(gpt_partition_t *partitions, int max_count, int *count)
Definition
gpt.c:38
__attribute__
Definition
dirent.h:6
__attribute__::end_lba
uint64_t end_lba
Definition
gpt.h:63
__attribute__::revision
uint32_t revision
Definition
gpt.h:43
__attribute__::name
uint16_t name[36]
Definition
gpt.h:65
__attribute__::partition_entries_lba
uint64_t partition_entries_lba
Definition
gpt.h:52
__attribute__::signature
uint8_t signature[8]
Definition
gpt.h:42
__attribute__::num_partition_entries
uint32_t num_partition_entries
Definition
gpt.h:53
__attribute__::partition_entry_array_crc32
uint32_t partition_entry_array_crc32
Definition
gpt.h:55
__attribute__::alternate_lba
uint64_t alternate_lba
Definition
gpt.h:48
__attribute__::reserved
uint32_t reserved
Definition
gpt.h:46
__attribute__::first_usable_lba
uint64_t first_usable_lba
Definition
gpt.h:49
__attribute__::unique_guid
gpt_guid_t unique_guid
Definition
gpt.h:61
__attribute__::type_guid
gpt_guid_t type_guid
Definition
gpt.h:60
__attribute__::my_lba
uint64_t my_lba
Definition
gpt.h:47
__attribute__::header_size
uint32_t header_size
Definition
gpt.h:44
__attribute__::last_usable_lba
uint64_t last_usable_lba
Definition
gpt.h:50
__attribute__::start_lba
uint64_t start_lba
Definition
gpt.h:62
__attribute__::disk_guid
gpt_guid_t disk_guid
Definition
gpt.h:51
__attribute__::attributes
uint64_t attributes
Definition
gpt.h:64
__attribute__::header_crc32
uint32_t header_crc32
Definition
gpt.h:45
__attribute__::partition_entry_size
uint32_t partition_entry_size
Definition
gpt.h:54
gpt_guid_t
Definition
gpt.h:35
gpt_guid_t::b
uint8_t b[16]
Definition
gpt.h:36
gpt_partition_t
Definition
gpt.h:69
gpt_partition_t::type_guid
gpt_guid_t type_guid
Definition
gpt.h:72
gpt_partition_t::unique_guid
gpt_guid_t unique_guid
Definition
gpt.h:73
gpt_partition_t::lba_end
uint64_t lba_end
Definition
gpt.h:71
gpt_partition_t::lba_start
uint64_t lba_start
Definition
gpt.h:70
types.h
uint16_t
unsigned short uint16_t
Definition
types.h:31
uint32_t
unsigned int uint32_t
Definition
types.h:34
uint64_t
unsigned long int uint64_t
Definition
types.h:37
uint8_t
unsigned char uint8_t
Definition
types.h:28
include
miniOS
drivers
gpt.h
Generated by
1.18.0