kernel: Make the MBR code read from a device instead of an inode
Some checks failed
continuous-integration/drone/pr Build is failing

This commit is contained in:
apio 2023-06-04 11:25:16 +02:00
parent 72e798cedb
commit 72b8ebe02c
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 14 additions and 12 deletions

View File

@ -332,15 +332,16 @@ namespace ATA
return false; 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); kwarnln("ata: Failed to register ATA drive %d:%d in DeviceRegistry", m_channel_index, drive);
continue; continue;
} }
// FIXME: Do not hardcode the path like this. auto device = rc.release_value();
/* auto inode = VFS::resolve_path("/dev/cdrom", Credentials {}).value(); MBR::identify(device);
MBR::identify(inode); */
} }
} }
@ -728,11 +729,12 @@ namespace ATA
static u32 next_minor = 0; 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())); auto device = TRY(adopt_shared_if_nonnull(new (std::nothrow) ATADevice()));
device->m_drive = drive; 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 Result<u64> ATADevice::read(u8* buf, usize offset, usize size) const

View File

@ -3,13 +3,13 @@
namespace MBR 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? // Cannot read a partition table from a character device! Who is even coming up with this silliness?
if (!VFS::is_seekable(inode)) return false; if (!device->is_block_device()) return false;
DiskHeader hdr; 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); check(nread == 512);
if (hdr.signature[0] != MBR_SIGNATURE_1 || hdr.signature[1] != MBR_SIGNATURE_2) return false; if (hdr.signature[0] != MBR_SIGNATURE_1 || hdr.signature[1] != MBR_SIGNATURE_2) return false;

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "fs/VFS.h" #include "fs/devices/DeviceRegistry.h"
#include <luna/Types.h> #include <luna/Types.h>
#define MBR_BOOTABLE 0x80 #define MBR_BOOTABLE 0x80
@ -31,5 +31,5 @@ namespace MBR
static_assert(sizeof(DiskHeader) == 512ul); static_assert(sizeof(DiskHeader) == 512ul);
Result<bool> identify(SharedPtr<VFS::Inode> inode); Result<bool> identify(SharedPtr<Device> device);
}; };