SimpleKernel 1.17.0
Loading...
Searching...
No Matches
readdir.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 ReadDir(File* file, DirEntry* dirent, size_t count) -> Expected<size_t> {
14 if (file == nullptr || dirent == nullptr) {
15 return std::unexpected(Error(ErrorCode::kInvalidArgument));
16 }
17
18 LockGuard<SpinLock> guard(GetVfsState().vfs_lock_);
19 if (file->inode == nullptr || file->inode->type != FileType::kDirectory) {
20 return std::unexpected(Error(ErrorCode::kFsNotADirectory));
21 }
22
23 if (file->ops == nullptr) {
24 return std::unexpected(Error(ErrorCode::kDeviceNotSupported));
25 }
26
27 return file->ops->ReadDir(file, dirent, count);
28}
29} // namespace vfs
RAII 风格的锁守卫模板类
Definition spinlock.hpp:131
@ kInvalidArgument
@ kDeviceNotSupported
@ kFsNotADirectory
std::expected< T, Error > Expected
std::expected 别名模板
Definition expected.hpp:365
@ kDirectory
目录
auto ReadDir(File *file, DirEntry *dirent, size_t count) -> Expected< size_t >
读取目录内容
Definition readdir.cpp:13
auto GetVfsState() -> VfsState &
Definition vfs.cpp:17
错误类型,用于 std::expected
Definition expected.hpp:343
目录项结构(用于 readdir)
File — 打开的文件实例(每次 open 产生一个)
Definition vfs.hpp:65