Kernel: Add common {read,write}_blocks() api to BlockDevice
This commit is contained in:
@@ -25,6 +25,12 @@ namespace Kernel
|
||||
|
||||
class BlockDevice : public Device
|
||||
{
|
||||
public:
|
||||
virtual BAN::ErrorOr<void> read_blocks(uint64_t first_block, size_t block_count, BAN::ByteSpan) = 0;
|
||||
virtual BAN::ErrorOr<void> write_blocks(uint64_t first_block, size_t block_count, BAN::ConstByteSpan) = 0;
|
||||
|
||||
virtual blksize_t blksize() const = 0;
|
||||
|
||||
protected:
|
||||
BlockDevice(mode_t mode, uid_t uid, gid_t gid)
|
||||
: Device(mode, uid, gid)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <BAN/HashMap.h>
|
||||
#include <kernel/Storage/StorageDevice.h>
|
||||
#include <kernel/Storage/Partition.h>
|
||||
#include <kernel/FS/FileSystem.h>
|
||||
#include <kernel/FS/Ext2/Inode.h>
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Kernel
|
||||
class Partition final : public BlockDevice
|
||||
{
|
||||
public:
|
||||
static BAN::ErrorOr<BAN::RefPtr<Partition>> create(BAN::RefPtr<BlockDevice>, const BAN::GUID& type, const BAN::GUID& guid, uint64_t first_sector, uint64_t last_sector, uint64_t attr, const char* label, uint32_t index);
|
||||
static BAN::ErrorOr<BAN::RefPtr<Partition>> create(BAN::RefPtr<BlockDevice>, const BAN::GUID& type, const BAN::GUID& guid, uint64_t first_block, uint64_t last_block, uint64_t attr, const char* label, uint32_t index);
|
||||
|
||||
const BAN::GUID& partition_type() const { return m_type; }
|
||||
const BAN::GUID& partition_guid() const { return m_guid; }
|
||||
@@ -17,8 +17,11 @@ namespace Kernel
|
||||
|
||||
virtual blksize_t blksize() const { return m_device->blksize(); }
|
||||
|
||||
virtual BAN::ErrorOr<void> read_sectors(uint64_t first_sector, size_t sector_count, BAN::ByteSpan) override;
|
||||
virtual BAN::ErrorOr<void> write_sectors(uint64_t first_sector, size_t sector_count, BAN::ConstByteSpan) override;
|
||||
BAN::ErrorOr<void> read_sectors(uint64_t first_block, size_t block_count, BAN::ByteSpan buffer) { return read_blocks(first_block, block_count, buffer); }
|
||||
BAN::ErrorOr<void> write_sectors(uint64_t first_block, size_t block_count, BAN::ConstByteSpan buffer) { return write_blocks(first_block, block_count, buffer); }
|
||||
|
||||
virtual BAN::ErrorOr<void> read_blocks(uint64_t first_block, size_t block_count, BAN::ByteSpan) override;
|
||||
virtual BAN::ErrorOr<void> write_blocks(uint64_t first_block, size_t block_count, BAN::ConstByteSpan) override;
|
||||
|
||||
virtual BAN::StringView name() const override { return m_name; }
|
||||
|
||||
@@ -29,8 +32,8 @@ namespace Kernel
|
||||
BAN::RefPtr<BlockDevice> m_device;
|
||||
const BAN::GUID m_type;
|
||||
const BAN::GUID m_guid;
|
||||
const uint64_t m_first_sector;
|
||||
const uint64_t m_last_sector;
|
||||
const uint64_t m_first_block;
|
||||
const uint64_t m_last_block;
|
||||
const uint64_t m_attributes;
|
||||
char m_label[36 * 4 + 1];
|
||||
const BAN::String m_name;
|
||||
|
||||
@@ -18,9 +18,13 @@ namespace Kernel
|
||||
|
||||
BAN::ErrorOr<void> initialize_partitions();
|
||||
|
||||
virtual BAN::ErrorOr<void> read_blocks(uint64_t lba, size_t sector_count, BAN::ByteSpan buffer) override { return read_sectors(lba, sector_count, buffer); }
|
||||
virtual BAN::ErrorOr<void> write_blocks(uint64_t lba, size_t sector_count, BAN::ConstByteSpan buffer) override { return write_sectors(lba, sector_count, buffer); }
|
||||
|
||||
BAN::ErrorOr<void> read_sectors(uint64_t lba, size_t sector_count, BAN::ByteSpan);
|
||||
BAN::ErrorOr<void> write_sectors(uint64_t lba, size_t sector_count, BAN::ConstByteSpan);
|
||||
|
||||
virtual blksize_t blksize() const { return sector_size(); }
|
||||
virtual uint32_t sector_size() const = 0;
|
||||
virtual uint64_t total_size() const = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user