Add ATA drive support #27

Merged
apio merged 28 commits from please-read-my-ata-drive into main 2023-06-16 19:40:11 +00:00
3 changed files with 14 additions and 12 deletions
Showing only changes of commit 72b8ebe02c - Show all commits

View File

@ -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

View File

@ -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;

View File

@ -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);
};