1use crate::protocol;
7use inspect::InspectMut;
8
9pub trait VmbfsIo: Send + InspectMut {
11 fn file_info(&mut self, path: &str) -> Result<FileInfo, FileError>;
13 fn read_file(&mut self, path: &str, offset: u64, buf: &mut [u8]) -> Result<(), FileError>;
15}
16
17pub struct FileInfo {
19 pub directory: bool,
21 pub file_size: u64,
23}
24
25pub enum FileError {
27 NotFound,
29 EndOfFile,
31 Error(std::io::Error),
33}
34
35impl FileError {
36 pub(crate) fn to_protocol(&self) -> protocol::Status {
37 match self {
38 FileError::NotFound => protocol::Status::NOT_FOUND,
39 FileError::EndOfFile => protocol::Status::END_OF_FILE,
40 FileError::Error(_) => protocol::Status::ERROR,
41 }
42 }
43}
44
45impl From<std::io::Error> for FileError {
46 fn from(err: std::io::Error) -> Self {
47 match err.kind() {
48 std::io::ErrorKind::NotFound => FileError::NotFound,
49 std::io::ErrorKind::UnexpectedEof => FileError::EndOfFile,
50 _ => FileError::Error(err),
51 }
52 }
53}