| 11 | namespace vfs { |
| 12 | |
| 13 | auto 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 |