SimpleKernel 1.17.0
Loading...
Searching...
No Matches
read.cpp
Go to the documentation of this file.
1
5#include "filesystem.hpp"
6#include "kernel_log.hpp"
7#include "kstd_cstring"
8#include "spinlock.hpp"
9#include "vfs_internal.hpp"
10
11namespace vfs {
12
13auto Read(File* file, void* buf, size_t count) -> Expected<size_t> {
14 if (file == nullptr || buf == nullptr) {
15 return std::unexpected(Error(ErrorCode::kInvalidArgument));
16 }
17
18 LockGuard<SpinLock> guard(GetVfsState().vfs_lock_);
19 if (file->ops == nullptr) {
20 return std::unexpected(Error(ErrorCode::kDeviceNotSupported));
21 }
22
23 return file->ops->Read(file, buf, count);
24}
25
26} // namespace vfs
RAII 风格的锁守卫模板类
Definition spinlock.hpp:131
@ kInvalidArgument
@ kDeviceNotSupported
std::expected< T, Error > Expected
std::expected 别名模板
Definition expected.hpp:365
auto Read(File *file, void *buf, size_t count) -> Expected< size_t >
从文件读取数据
Definition read.cpp:13
auto GetVfsState() -> VfsState &
Definition vfs.cpp:17
错误类型,用于 std::expected
Definition expected.hpp:343
File — 打开的文件实例(每次 open 产生一个)
Definition vfs.hpp:65