feature (MBR): implemented MBR

This commit is contained in:
antifallobst 2023-05-07 23:14:43 +02:00
parent 7d104a2745
commit b8cafaf24d
3 changed files with 73 additions and 3 deletions

40
inc/drivers/fs/mbr.h Normal file
View File

@ -0,0 +1,40 @@
// This file is part of noxos and licensed under the MIT open source license
#ifndef KERNEL_MBR_H
#define KERNEL_MBR_H
#include "utils/stdtypes.h"
#include "utils/string.h"
typedef enum {
MBR_PARTITION_TYPE_UNUSED = 0x00,
MBR_PARTITION_TYPE_GPT = 0xEE,
MBR_PARTITION_TYPE_EXT2 = 0x83,
MBR_PARTITION_TYPE_FAT12 = 0x01,
MBR_PARTITION_TYPE_FAT16 = 0x04,
MBR_PARTITION_TYPE_FAT32_CHS = 0x0B,
MBR_PARTITION_TYPE_FAT32_LBA = 0x0C
} mbr_partition_types_E;
typedef struct {
uint8_t boot_indicator;
uint8_t start_head;
uint16_t start_sector:6;
uint16_t start_cylinder:10;
uint8_t partition_type;
uint8_t end_head;
uint16_t end_sector:6;
uint16_t end_cylinder:10;
uint32_t start_lba;
uint32_t num_sectors;
}__attribute__((packed)) mbr_partition_header_T;
typedef struct {
uint8_t bootstrap [446];
mbr_partition_header_T partitions [4];
uint8_t signature [2];
} mbr_header_T;
string_t mbr_partition_type_to_string(mbr_partition_types_E type);
#endif //KERNEL_MBR_H

View File

@ -1,6 +1,7 @@
// This file is part of noxos and licensed under the MIT open source license
#include "drivers/ahci.h"
#include "drivers/fs/mbr.h"
#include "utils/memory.h"
#include "utils/logger.h"
#include "mm/page_map.h"
@ -50,9 +51,22 @@ ahci_controller_T* ahci_controller_alloc(pci_device_T* pci_device) {
for (int i = 0; i < controller->num_ports; i++) {
log(LOG_INFO, " %s", g_ahci_device_type_strings[controller->ports[i].type]);
ahci_port_init(&controller->ports[i]);
uint8_t* buffer = memory_allocate(512 + PFRAME_SIZE);
if (ahci_port_read(&controller->ports[i], 0, 1, CEIL_TO((uint64_t)buffer, PFRAME_SIZE)))
memory_hexdump(CEIL_TO((uint64_t)buffer, PFRAME_SIZE), 512);
uint8_t* addr = memory_allocate(512 + PFRAME_SIZE);
void* buffer = (void*)CEIL_TO((uint64_t)addr, PFRAME_SIZE);
if (ahci_port_read(&controller->ports[i], 0, 1, buffer)) {
mbr_header_T* mbr = (mbr_header_T*)buffer;
log(LOG_INFO, " MBR:");
for (int j = 0; j < 4; j++) {
mbr_partition_types_E type = mbr->partitions[j].partition_type;
if (type == MBR_PARTITION_TYPE_UNUSED) continue;
log(LOG_INFO, " p%d: 0x%xb - %s", j, type, mbr_partition_type_to_string(type));
}
}
memory_free(addr);
}
return controller;

16
src/drivers/fs/mbr.c Normal file
View File

@ -0,0 +1,16 @@
// This file is part of noxos and licensed under the MIT open source license
#include "drivers/fs/mbr.h"
string_t mbr_partition_type_to_string(mbr_partition_types_E type) {
switch (type) {
case MBR_PARTITION_TYPE_UNUSED: return "Unused";
case MBR_PARTITION_TYPE_GPT: return "GUID Partition Table";
case MBR_PARTITION_TYPE_EXT2: return "EXT2";
case MBR_PARTITION_TYPE_FAT12: return "FAT12";
case MBR_PARTITION_TYPE_FAT16: return "FAT16";
case MBR_PARTITION_TYPE_FAT32_CHS: return "FAT32 (CHS)";
case MBR_PARTITION_TYPE_FAT32_LBA: return "FAT32 (LBA)";
default: return "Unknown";
}
}