Kernel: Make all storage devices readable and writable
I only had a {read,write}_impl defined for ATABaseDevice. This patch moves that implmentation to general storage device.
This commit is contained in:
parent
2d3810874d
commit
8b1514e575
|
@ -32,9 +32,6 @@ namespace Kernel
|
|||
|
||||
virtual dev_t rdev() const override { return m_rdev; }
|
||||
|
||||
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
||||
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
|
||||
|
||||
protected:
|
||||
ATABaseDevice();
|
||||
BAN::ErrorOr<void> initialize(BAN::Span<const uint16_t> identify_data);
|
||||
|
|
|
@ -40,6 +40,9 @@ namespace Kernel
|
|||
virtual BAN::ErrorOr<void> write_sectors_impl(uint64_t lba, uint64_t sector_count, BAN::ConstByteSpan) = 0;
|
||||
void add_disk_cache();
|
||||
|
||||
virtual BAN::ErrorOr<size_t> read_impl(off_t, BAN::ByteSpan) override;
|
||||
virtual BAN::ErrorOr<size_t> write_impl(off_t, BAN::ConstByteSpan) override;
|
||||
|
||||
virtual bool can_read_impl() const override { return true; }
|
||||
virtual bool can_write_impl() const override { return true; }
|
||||
virtual bool has_error_impl() const override { return false; }
|
||||
|
|
|
@ -77,26 +77,6 @@ namespace Kernel
|
|||
return {};
|
||||
}
|
||||
|
||||
BAN::ErrorOr<size_t> detail::ATABaseDevice::read_impl(off_t offset, BAN::ByteSpan buffer)
|
||||
{
|
||||
if (offset % sector_size())
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
if (buffer.size() % sector_size())
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
TRY(read_sectors(offset / sector_size(), buffer.size() / sector_size(), buffer));
|
||||
return buffer.size();
|
||||
}
|
||||
|
||||
BAN::ErrorOr<size_t> detail::ATABaseDevice::write_impl(off_t offset, BAN::ConstByteSpan buffer)
|
||||
{
|
||||
if (offset % sector_size())
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
if (buffer.size() % sector_size())
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
TRY(write_sectors(offset / sector_size(), buffer.size() / sector_size(), buffer));
|
||||
return buffer.size();
|
||||
}
|
||||
|
||||
BAN::ErrorOr<BAN::RefPtr<ATADevice>> ATADevice::create(BAN::RefPtr<ATABus> bus, ATABus::DeviceType type, bool is_secondary, BAN::Span<const uint16_t> identify_data)
|
||||
{
|
||||
auto* device_ptr = new ATADevice(bus, type, is_secondary);
|
||||
|
|
|
@ -264,4 +264,24 @@ namespace Kernel
|
|||
return {};
|
||||
}
|
||||
|
||||
BAN::ErrorOr<size_t> StorageDevice::read_impl(off_t offset, BAN::ByteSpan buffer)
|
||||
{
|
||||
if (offset % sector_size())
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
if (buffer.size() % sector_size())
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
TRY(read_sectors(offset / sector_size(), buffer.size() / sector_size(), buffer));
|
||||
return buffer.size();
|
||||
}
|
||||
|
||||
BAN::ErrorOr<size_t> StorageDevice::write_impl(off_t offset, BAN::ConstByteSpan buffer)
|
||||
{
|
||||
if (offset % sector_size())
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
if (buffer.size() % sector_size())
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
TRY(write_sectors(offset / sector_size(), buffer.size() / sector_size(), buffer));
|
||||
return buffer.size();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue