mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-25 18:52:22 -05:00
c02b8b715d
This implements a basic MBR partition loader, which removes the reliance on a hard-coded filesystem offset in the stage2 init.
61 lines
1.5 KiB
C++
61 lines
1.5 KiB
C++
#include <AK/ByteBuffer.h>
|
|
#include <Kernel/Devices/MBRPartitionTable.h>
|
|
|
|
#define MBR_DEBUG
|
|
|
|
MBRPartitionTable::MBRPartitionTable(Retained<DiskDevice>&& device)
|
|
: m_device(move(device))
|
|
{
|
|
}
|
|
|
|
MBRPartitionTable::~MBRPartitionTable()
|
|
{
|
|
}
|
|
|
|
const MBRPartitionHeader& MBRPartitionTable::header() const
|
|
{
|
|
return *reinterpret_cast<const MBRPartitionHeader*>(m_cached_header);
|
|
}
|
|
|
|
bool MBRPartitionTable::initialize()
|
|
{
|
|
if (!m_device->read_block(0, m_cached_header)) {
|
|
return false;
|
|
}
|
|
|
|
auto& header = this->header();
|
|
|
|
#ifdef MBR_DEBUG
|
|
kprintf("MBRPartitionTable::initialize: mbr_signature=%#x\n", header.mbr_signature);
|
|
#endif
|
|
|
|
if (header.mbr_signature != MBR_SIGNATURE) {
|
|
kprintf("MBRPartitionTable::initialize: bad mbr signature %#x\n", header.mbr_signature);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
RetainPtr<DiskPartition> MBRPartitionTable::partition(unsigned index)
|
|
{
|
|
ASSERT(index >= 1 && index <= 4);
|
|
|
|
auto& header = this->header();
|
|
auto& entry = header.entry[index - 1];
|
|
|
|
if (header.mbr_signature != MBR_SIGNATURE) {
|
|
kprintf("MBRPartitionTable::initialize: bad mbr signature - not initalized? %#x\n", header.mbr_signature);
|
|
return nullptr;
|
|
}
|
|
|
|
#ifdef MBR_DEBUG
|
|
kprintf("MBRPartitionTable::partition: status=%#x offset=%#x\n", entry.status, entry.offset);
|
|
#endif
|
|
|
|
if (entry.status == 0x00) {
|
|
return nullptr;
|
|
}
|
|
|
|
return DiskPartition::create(m_device.copy_ref(), entry.offset);
|
|
}
|