feature (GPT): improved GPT decoding and GUID representation in code
This commit is contained in:
parent
c9d57639c1
commit
7e5fee1437
|
@ -4,12 +4,12 @@
|
|||
#define NOXOS_GPT_H
|
||||
|
||||
#include "utils/stdtypes.h"
|
||||
|
||||
#define GPT_PARTITION_TYPE_GUID_MATCH(g, t) ((g[0] == g_gpt_partition_type_guides[t][0]) && (g[1] == g_gpt_partition_type_guides[t][1]))
|
||||
#include "utils/string.h"
|
||||
|
||||
typedef enum {
|
||||
GPT_PARTITION_GUID_UNUSED,
|
||||
GPT_PARTITION_GUID_BASIC_DATA,
|
||||
GPT_PARTITION_GUID_UNKNOWN,
|
||||
GPT_PARTITION_GUID_PRIMARY,
|
||||
GPT_PARTITION_GUID_EFI_SYSTEM,
|
||||
|
||||
GPT_PARTITION_GUID_ENUM_END
|
||||
|
@ -25,7 +25,7 @@ typedef struct {
|
|||
uint64_t backup_lba;
|
||||
uint64_t first_usable_lba;
|
||||
uint64_t last_usable_lba;
|
||||
uint64_t disk_guid [2];
|
||||
uint8_t disk_guid [16];
|
||||
uint64_t starting_lba;
|
||||
uint32_t num_partitions;
|
||||
uint32_t partition_entry_size;
|
||||
|
@ -34,14 +34,17 @@ typedef struct {
|
|||
}__attribute__((packed)) gpt_table_header_T;
|
||||
|
||||
typedef struct {
|
||||
uint64_t partition_type_guid [2];
|
||||
uint64_t partition_guid [2];
|
||||
uint8_t partition_type_guid [16];
|
||||
uint8_t partition_guid [16];
|
||||
uint64_t starting_lba;
|
||||
uint64_t ending_lba;
|
||||
uint64_t attributes;
|
||||
uint8_t name [72];
|
||||
uint16_t name [36]; // UTF-16 encoded
|
||||
}__attribute__((packed)) gpt_partition_entry_T;
|
||||
|
||||
extern uint64_t g_gpt_partition_type_guides[GPT_PARTITION_GUID_ENUM_END][2];
|
||||
gpt_partition_type_guids_E gpt_get_partition_type (uint8_t guid[16]);
|
||||
string_t gpt_partition_type_to_string(gpt_partition_type_guids_E type);
|
||||
|
||||
extern uint8_t g_gpt_partition_type_guides[GPT_PARTITION_GUID_ENUM_END][16];
|
||||
|
||||
#endif //NOXOS_GPT_H
|
||||
|
|
|
@ -139,8 +139,23 @@ void ahci_port_init_partitions_gpt(ahci_port_T* port) {
|
|||
log(LOG_INFO, " GPT:");
|
||||
for (int i = 0; i < gpt->num_partitions; i++) {
|
||||
gpt_partition_entry_T* entry = &entries[i];
|
||||
if (GPT_PARTITION_TYPE_GUID_MATCH(entry->partition_type_guid, GPT_PARTITION_GUID_UNUSED)) continue;
|
||||
log(LOG_INFO, " p%d: %x%x", i, entry->partition_type_guid[0], entry->partition_type_guid[1]);
|
||||
gpt_partition_type_guids_E type = gpt_get_partition_type(entry->partition_type_guid);
|
||||
|
||||
if (type == GPT_PARTITION_GUID_UNUSED) continue;
|
||||
if (type == GPT_PARTITION_GUID_UNKNOWN) {
|
||||
log(LOG_INFO, " p%d: (%d)<--LBA-->(%d) Unknown(%xb%xb%xb%xb-%xb%xb-%xb%xb-%xb%xb-%xb%xb%xb%xb%xb%xb)", i,
|
||||
entry->starting_lba, entry->ending_lba,
|
||||
entry->partition_type_guid[0x0], entry->partition_type_guid[0x1],
|
||||
entry->partition_type_guid[0x2], entry->partition_type_guid[0x3],
|
||||
entry->partition_type_guid[0x4], entry->partition_type_guid[0x5],
|
||||
entry->partition_type_guid[0x6], entry->partition_type_guid[0x7],
|
||||
entry->partition_type_guid[0x8], entry->partition_type_guid[0x9],
|
||||
entry->partition_type_guid[0xA], entry->partition_type_guid[0xB],
|
||||
entry->partition_type_guid[0xC], entry->partition_type_guid[0xD],
|
||||
entry->partition_type_guid[0xE], entry->partition_type_guid[0xF]);
|
||||
} else {
|
||||
log(LOG_INFO, " p%d: (%d)<--LBA-->(%d) %s", i, entry->starting_lba, entry->ending_lba, gpt_partition_type_to_string(type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,31 @@
|
|||
// This file is part of noxos and licensed under the MIT open source license
|
||||
|
||||
#include "drivers/fs/gpt.h"
|
||||
#include "utils/memory.h"
|
||||
|
||||
uint64_t g_gpt_partition_type_guides[GPT_PARTITION_GUID_ENUM_END][2] = {
|
||||
{0x0000000000000000, 0x0000000000000000},
|
||||
{0x11D2F81FC12A7328, 0x3BC93EC9A0004BBA},
|
||||
{0x28732AC11FF8D211, 0xBA4B00A0C93EC93B}
|
||||
uint8_t g_gpt_partition_type_guides[GPT_PARTITION_GUID_ENUM_END][16] = {
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0xA2, 0xA0, 0xD0, 0xEB, 0xE5, 0xB9, 0x33, 0x44, 0x87, 0xC0, 0x68, 0xB6, 0xB7, 0x26, 0x99, 0xC7 },
|
||||
{ 0x28, 0x73, 0x2A, 0xC1, 0x1F, 0xF8, 0xD2, 0x11, 0xBA, 0x4B, 0x00, 0xA0, 0xC9, 0x3E, 0xC9, 0x3B }
|
||||
};
|
||||
|
||||
gpt_partition_type_guids_E gpt_get_partition_type(uint8_t guid[16]) {
|
||||
for (int i = 0; i < GPT_PARTITION_GUID_ENUM_END; i++) {
|
||||
if (memory_compare(guid, g_gpt_partition_type_guides[i], 16)) {
|
||||
return (gpt_partition_type_guids_E) i;
|
||||
}
|
||||
}
|
||||
return GPT_PARTITION_GUID_UNKNOWN;
|
||||
}
|
||||
|
||||
string_t gpt_partition_type_to_string(gpt_partition_type_guids_E type) {
|
||||
switch (type) {
|
||||
case GPT_PARTITION_GUID_UNUSED: return "Unused";
|
||||
case GPT_PARTITION_GUID_PRIMARY: return "Primary";
|
||||
case GPT_PARTITION_GUID_EFI_SYSTEM: return "EFI System";
|
||||
|
||||
case GPT_PARTITION_GUID_UNKNOWN:
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue