-
-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathpartition_table.hexpat
75 lines (66 loc) · 1.6 KB
/
partition_table.hexpat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#pragma author RadxaYuntian
#pragma description Master Boot Record & GUID Partition Table
#pragma endian little
import type.base;
import type.guid;
#ifndef SECTOR_SIZE
#define SECTOR_SIZE 512
#endif
bitfield CHSAddress {
u8 head;
sector : 6;
cylinder: 10;
};
struct MBREntry {
u8 status;
CHSAddress first_chs;
u8 type;
CHSAddress last_chs;
u32 first_lba;
u32 sector_count;
};
struct MasterBootRecord {
padding[446];
MBREntry entries[4];
type::Hex<u16> boot_signature;
padding[SECTOR_SIZE - 512];
};
bitfield GPTAttributes {
bool platform_required : 1;
padding : 59;
bool read_only : 1;
bool shadow_copy : 1;
bool hidden : 1;
bool no_drive_letter : 1;
};
struct GPTEntry {
type::GUID partition_type;
type::GUID partition_guid;
u64 first_lba;
u64 last_lba;
GPTAttributes attribute;
char16 partition_name[36];
padding[parent.entry_size - 128];
};
struct GUIDPartitionTable {
char signature[8]; // "EFI PART"
u16 version_minor;
u16 version_major;
u32 header_size;
type::Hex<u32> header_crc32; // from 0x0 to 0x5b
u32 reserved; // must be 0
u64 current_lba;
u64 backup_lba;
u64 first_usable_lba;
u64 last_usable_lba;
type::GUID disk_guid;
u64 entry_lba;
u32 entry_count;
u32 entry_size;
type::Hex<u32> entry_crc32;
padding[SECTOR_SIZE - 92]; // end of first LBA
padding[SECTOR_SIZE * (entry_lba - current_lba - 1)]; // non-GPT data
GPTEntry entries[entry_count];
};
MasterBootRecord mbr @ 0 * SECTOR_SIZE;
GUIDPartitionTable gpt @ 1 * SECTOR_SIZE;