| 11 | namespace vfs { |
| 12 | |
| 13 | auto Write(File* file, const void* buf, size_t count) -> Expected<size_t> { |
| 14 | if (file == nullptr || buf == nullptr) { |
| 15 | return std::unexpected(Error(ErrorCode::kInvalidArgument)); |
| 16 | } |
| 17 | |
| 18 | // 检查写入权限 |
| 19 | LockGuard<SpinLock> guard(GetVfsState().vfs_lock_); |
| 20 | if ((file->flags & OpenFlags::kOWriteOnly) == 0U && |
| 21 | (file->flags & OpenFlags::kOReadWrite) == 0U) { |
| 22 | return std::unexpected(Error(ErrorCode::kFsPermissionDenied)); |
| 23 | } |
| 24 | |
| 25 | if (file->ops == nullptr) { |
| 26 | return std::unexpected(Error(ErrorCode::kDeviceNotSupported)); |
| 27 | } |
| 28 | |
| 29 | return file->ops->Write(file, buf, count); |
| 30 | } |
| 31 | |
| 32 | } // namespace vfs |