fuser_async/
error.rs

1/// Error type, which maps to a [`libc`] error.
2#[derive(thiserror::Error, Debug)]
3pub enum Error {
4    #[error("Not implemented")]
5    Unimplemented,
6    #[error("Not a directory")]
7    NotDirectory,
8    #[error("No such file or directory")]
9    NoFileDir,
10    #[error("Invalid Argument")]
11    InvalidArgument,
12    #[error("File already exists")]
13    Exists,
14    #[error("Bad file descriptor")]
15    BadFileDescriptor,
16    #[error("Too many open files")]
17    TooManyOpenFiles,
18    #[error("Read-only filesystem")]
19    ReadOnly,
20    #[error("Unsupported encoding")]
21    Encoding,
22    #[error("I/O error: {0}")]
23    IO(String),
24    #[error("No inodes left")]
25    NoInodes,
26    #[error("{0}")]
27    Other(String),
28}
29impl Error {
30    pub fn io(message: &str) -> Self {
31        Self::IO(message.into())
32    }
33}
34impl From<&Error> for libc::c_int {
35    fn from(source: &Error) -> Self {
36        match source {
37            Error::Unimplemented | Error::Encoding => libc::ENOSYS,
38            Error::NotDirectory => libc::ENOTDIR,
39            Error::NoFileDir => libc::ENOENT,
40            Error::NoInodes => libc::ENOSPC,
41            Error::Exists => libc::EEXIST,
42            Error::ReadOnly => libc::EROFS,
43            Error::TooManyOpenFiles => libc::EMFILE,
44            Error::InvalidArgument => libc::EINVAL,
45            Error::BadFileDescriptor => libc::EBADF,
46            Error::IO(_) => libc::EIO,
47            Error::Other(_) => libc::EIO,
48        }
49    }
50}