#include "fs/MBR.h" #include "Log.h" namespace MBR { Result identify(SharedPtr inode) { // Cannot read a partition table from a pipe/socket/character device! Who is even coming up with this silliness? if (!VFS::is_seekable(inode)) return false; DiskHeader hdr; usize nread = TRY(inode->read((u8*)&hdr, 0, sizeof(hdr))); check(nread == 512); if (hdr.signature[0] != MBR_SIGNATURE_1 || hdr.signature[1] != MBR_SIGNATURE_2) return false; for (int i = 0; i < 4; i++) { const auto& part = hdr.partitions[i]; if (part.partition_type == 0) continue; // Not active. bool bootable = part.attributes & MBR_BOOTABLE; kinfoln("mbr: Partition #%d is active: bootable=%d, type=%x, start=%d, sectors=%d", i, bootable, part.partition_type, part.start_lba, part.num_sectors); } return true; } }