Kevin Lange 984fa1d4c6 EXT2 backed by block device
WARNING: THIS BREAKS PARTITIONS

Until I get partition maps and can produce device entries like
/dev/hda1, partitions will be broken, so DON'T TRY TO BUILD AN IMAGE
WITH THE IMAGE BUILDER.

Hopefully this is all rectified in under 24 hours...
2014-03-16 01:33:01 -07:00

45 lines
1.1 KiB
C

#include <system.h>
#include <logging.h>
#include <ata.h>
#define SECTORSIZE 512
#define DISK_PORT 0x1F0
mbr_t mbr;
int read_partition_map(fs_node_t * device) {
read_fs(device, 0, SECTORSIZE, (uint8_t *)&mbr);
if (mbr.signature[0] == 0x55 && mbr.signature[1] == 0xAA) {
debug_print(INFO, "Partition table found.");
for (int i = 0; i < 4; ++i) {
if (mbr.partitions[i].status & 0x80) {
debug_print(NOTICE, "Partition #%d: @%d+%d", i+1, mbr.partitions[i].lba_first_sector, mbr.partitions[i].sector_count);
} else {
debug_print(NOTICE, "Partition #%d: inactive", i+1);
}
}
return 0;
} else {
debug_print(ERROR, "Did not find partition table.");
debug_print(ERROR, "Signature was 0x%x 0x%x instead of 0x55 0xAA", mbr.signature[0], mbr.signature[1]);
debug_print(ERROR, "Parsing anyone yields:");
for (int i = 0; i < 4; ++i) {
if (mbr.partitions[i].status & 0x80) {
debug_print(NOTICE, "Partition #%d: @%d+%d", i+1, mbr.partitions[i].lba_first_sector, mbr.partitions[i].sector_count);
} else {
debug_print(NOTICE, "Partition #%d: inactive", i+1);
}
}
}
return 1;
}