kernel: Make the MBR code read from a device instead of an inode
Some checks failed
continuous-integration/drone/pr Build is failing
Some checks failed
continuous-integration/drone/pr Build is failing
This commit is contained in:
parent
072b13b023
commit
9de4b392a2
@ -332,15 +332,16 @@ namespace ATA
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ATADevice::create(m_drives[drive]).has_error())
|
||||
auto rc = ATADevice::create(m_drives[drive]);
|
||||
|
||||
if (rc.has_error())
|
||||
{
|
||||
kwarnln("ata: Failed to register ATA drive %d:%d in DeviceRegistry", m_channel_index, drive);
|
||||
continue;
|
||||
}
|
||||
|
||||
// FIXME: Do not hardcode the path like this.
|
||||
/* auto inode = VFS::resolve_path("/dev/cdrom", Credentials {}).value();
|
||||
MBR::identify(inode); */
|
||||
auto device = rc.release_value();
|
||||
MBR::identify(device);
|
||||
}
|
||||
}
|
||||
|
||||
@ -728,11 +729,12 @@ namespace ATA
|
||||
|
||||
static u32 next_minor = 0;
|
||||
|
||||
Result<void> ATADevice::create(SharedPtr<ATA::Drive> drive)
|
||||
Result<SharedPtr<Device>> ATADevice::create(SharedPtr<ATA::Drive> drive)
|
||||
{
|
||||
auto device = TRY(adopt_shared_if_nonnull(new (std::nothrow) ATADevice()));
|
||||
device->m_drive = drive;
|
||||
return DeviceRegistry::register_special_device(DeviceRegistry::Disk, next_minor++, device, "cdrom", 0400);
|
||||
TRY(DeviceRegistry::register_special_device(DeviceRegistry::Disk, next_minor++, device, "cdrom", 0400));
|
||||
return (SharedPtr<Device>)device;
|
||||
}
|
||||
|
||||
Result<u64> ATADevice::read(u8* buf, usize offset, usize size) const
|
||||
|
@ -3,13 +3,13 @@
|
||||
|
||||
namespace MBR
|
||||
{
|
||||
Result<bool> identify(SharedPtr<VFS::Inode> inode)
|
||||
Result<bool> identify(SharedPtr<Device> device)
|
||||
{
|
||||
// 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;
|
||||
// Cannot read a partition table from a character device! Who is even coming up with this silliness?
|
||||
if (!device->is_block_device()) return false;
|
||||
|
||||
DiskHeader hdr;
|
||||
usize nread = TRY(inode->read((u8*)&hdr, 0, sizeof(hdr)));
|
||||
usize nread = TRY(device->read((u8*)&hdr, 0, sizeof(hdr)));
|
||||
check(nread == 512);
|
||||
|
||||
if (hdr.signature[0] != MBR_SIGNATURE_1 || hdr.signature[1] != MBR_SIGNATURE_2) return false;
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "fs/VFS.h"
|
||||
#include "fs/devices/DeviceRegistry.h"
|
||||
#include <luna/Types.h>
|
||||
|
||||
#define MBR_BOOTABLE 0x80
|
||||
@ -31,5 +31,5 @@ namespace MBR
|
||||
|
||||
static_assert(sizeof(DiskHeader) == 512ul);
|
||||
|
||||
Result<bool> identify(SharedPtr<VFS::Inode> inode);
|
||||
Result<bool> identify(SharedPtr<Device> device);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user