SimpleKernel 1.17.0
Loading...
Searching...
No Matches
block_device.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include <cstddef>
8#include <cstdint>
9
10#include "expected.hpp"
11
12namespace vfs {
13
20 public:
21 virtual ~BlockDevice() = default;
22
33 [[nodiscard]] virtual auto ReadSectors(uint64_t sector_start,
34 uint32_t sector_count, void* buffer)
35 -> Expected<size_t> = 0;
36
46 [[nodiscard]] virtual auto WriteSectors(uint64_t sector_start,
47 uint32_t sector_count,
48 const void* buffer)
49 -> Expected<size_t> = 0;
50
55 [[nodiscard]] virtual auto GetSectorSize() const -> uint32_t = 0;
56
61 [[nodiscard]] virtual auto GetSectorCount() const -> uint64_t = 0;
62
67 [[nodiscard]] virtual auto GetName() const -> const char* = 0;
68
73 [[nodiscard]] virtual auto Flush() -> Expected<void> { return {}; }
74};
75
76} // namespace vfs
块设备抽象基类
virtual auto ReadSectors(uint64_t sector_start, uint32_t sector_count, void *buffer) -> Expected< size_t >=0
读取连续扇区
virtual auto GetName() const -> const char *=0
获取设备名称(如 "virtio-blk0")
virtual auto Flush() -> Expected< void >
刷新设备缓存到物理介质
virtual auto GetSectorCount() const -> uint64_t=0
获取设备总扇区数
virtual ~BlockDevice()=default
virtual auto GetSectorSize() const -> uint32_t=0
获取扇区大小(通常为 512 字节)
virtual auto WriteSectors(uint64_t sector_start, uint32_t sector_count, const void *buffer) -> Expected< size_t >=0
写入连续扇区
std::expected< T, Error > Expected
std::expected 别名模板
Definition expected.hpp:365