-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e50401d
commit 16e2acf
Showing
4 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#ifndef __GPT_H | ||
#define __GPT_H | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <mbr.h> | ||
|
||
#define GPT_EFI_PMBR_SECTOR 0 | ||
#define GPT_EFI_PART_HEADER_SECTOR 1 | ||
#define GPT_PARTITION_ENTRIES_SECTOR 2 | ||
#define GPT_PART_ATTRIB_FIRMWARE 0b1 | ||
#define GPT_PART_ATTRIB_USED_BY_OS 0b10 | ||
#define GPT_ENTRIES_SIZE (512*31)/sizeof(GPT_PartitionEntry) | ||
|
||
#if defined(__cplusplus) | ||
extern "C" { | ||
#endif | ||
|
||
extern uint8_t GPT_EFI_SIGNATURE[]; // it's just "EFI PART" | ||
|
||
struct GPT_PartTableHeader{ | ||
uint8_t Signature[8]; // MUST BE "EFI PART" | ||
uint32_t Revision; | ||
uint32_t HeaderSize; | ||
uint32_t CRC32_Checksum; | ||
uint32_t Reserved0; | ||
uint64_t ThisHdrLBA; | ||
uint64_t AlternateHdrLBA; | ||
uint64_t FirstUsableGptEntryBlock; | ||
uint64_t LastUsableGptEntryBlock; | ||
uint8_t GUID[16]; | ||
uint64_t StartLBA_GUID_Entries; | ||
uint32_t NumEntries; | ||
uint32_t PartitionEntrySize; // In bytes! | ||
uint32_t CRC32_PartitionEntries; | ||
uint8_t Reserved1[512-0x5C]; // Should be zeroed | ||
} __attribute__((packed)) ; | ||
|
||
struct GPT_PartitionEntry{ | ||
uint8_t PartitionTypeGUID[16]; // 0 == unused entry | ||
uint8_t UniqueGUID[16]; | ||
uint64_t StartLBA; | ||
uint64_t EndLBA; | ||
uint8_t Attributes; | ||
uint8_t PartitionName[72]; | ||
} __attribute__((packed)) ; | ||
|
||
struct GPT_START{ | ||
MBR PMBR; // Protected MBR | ||
GPT_PartTableHeader PartitionTableHeader; | ||
} __attribute__((packed)) ; | ||
|
||
struct GPT_END{ | ||
GPT_PartTableHeader PartitionTableHeaderMirror; // Has to be same as at the start | ||
} __attribute__((packed)) ; | ||
|
||
#if defined(__cplusplus) | ||
} // extern "C" | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* | ||
* Master Boot Record (partition table) | ||
* | ||
*/ | ||
#ifndef __MBR_H | ||
#define __MBR_H | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
|
||
#define MBR_PART_BOOTABLE 0x80 | ||
#define MBR_VALID_MBR 0xaa55 | ||
|
||
#if defined( __cplusplus ) | ||
extern "C" { | ||
#endif | ||
|
||
struct MBR_Partition{ | ||
uint8_t Attributes; | ||
|
||
uint8_t StartHead; | ||
uint8_t StartSector : 6; | ||
uint16_t StartCylinder : 10; | ||
|
||
uint8_t SystemID; | ||
|
||
uint8_t EndHead; | ||
uint8_t EndSector : 6; | ||
uint16_t EndCylinder : 10; | ||
|
||
uint32_t LBA_Start; | ||
uint32_t SectorCount; | ||
} __attribute__((packed)) ; | ||
|
||
struct MBR{ | ||
uint8_t Bootloader[440]; | ||
uint32_t UniqueDiskID; | ||
uint16_t Reserved0; | ||
MBR_Partition Partitions[4]; | ||
uint16_t ValidationSignature; | ||
} __attribute__((packed)) ; | ||
|
||
|
||
#if defined( __cplusplus ) | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters