mirror of
https://github.com/limine-bootloader/limine
synced 2025-01-21 03:52:04 +03:00
Add MBR parsing
This commit is contained in:
parent
59ea2f0b59
commit
52125cd07f
@ -4,7 +4,7 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int read_sector(int, void *, uint64_t, uint64_t);
|
||||
int read(int, void *, uint64_t, uint64_t);
|
||||
int read_sector(int drive, void *buffer, uint64_t lba, uint64_t count);
|
||||
int read(int drive, void *buffer, uint64_t loc, uint64_t count);
|
||||
|
||||
#endif
|
||||
|
29
lib/mbr.c
Normal file
29
lib/mbr.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include <lib/mbr.h>
|
||||
#include <drivers/disk.h>
|
||||
#include <stddef.h>
|
||||
|
||||
struct mbr_entry {
|
||||
uint8_t status;
|
||||
uint8_t chs_first_sect[3];
|
||||
uint8_t type;
|
||||
uint8_t chs_last_sect[3];
|
||||
uint32_t first_sect;
|
||||
uint32_t sect_count;
|
||||
} __attribute__((packed));
|
||||
|
||||
int mbr_get_part(struct mbr_part *part, int drive, int partition) {
|
||||
// Variables.
|
||||
struct mbr_entry entry;
|
||||
const size_t entry_address = 0x1be + sizeof(struct mbr_entry) * partition;
|
||||
|
||||
// Read the entry of the MBR.
|
||||
int ret;
|
||||
if ((ret = read(drive, &entry, entry_address, sizeof(struct mbr_entry)))) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Assign the final fields and return.
|
||||
part->first_sect = entry.first_sect;
|
||||
part->sect_count = entry.sect_count;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user