1use thiserror::Error;
2
3pub type Result<T, E = Error> = std::result::Result<T, E>;
4pub type FSResult<T, E = FSError> = Result<T, E>;
5
6#[derive(Error, Debug)]
7pub enum PolyfuseError {
8 #[error(transparent)]
9 DecodeError(#[from] polyfuse::op::DecodeError),
10
11 #[error("error occured while calling Request::reply_err")]
12 ReplyErrError(std::io::Error),
13
14 #[error("error occured while calling Request::reply")]
15 ReplyError(std::io::Error),
16}
17
18#[derive(Error, Debug)]
19pub enum Error {
20 #[error(transparent)]
21 PolyfuseError(#[from] PolyfuseError),
22
23 #[error(transparent)]
24 IoError(#[from] std::io::Error),
25}
26
27#[derive(Error, Debug)]
29pub enum FSError {
30 #[error("No such file or directory exists")]
31 NoEntry,
32
33 #[error("Not a file")]
34 NotFile,
35
36 #[error("Not a directory")]
37 NotDirectory,
38
39 #[error("Function not implemented")]
40 NotImplemented,
41
42 #[error("Invalid flags passed")]
43 InvalidFlags(u32),
44
45 #[error("Buffer would overflow")]
46 BufferWouldOverflow,
47}
48
49impl FSError {
50 pub const fn to_libc_error(self) -> i32 {
51 match self {
52 Self::NoEntry => libc::ENOENT,
53 Self::NotFile => libc::EINVAL, Self::NotDirectory => libc::ENOTDIR,
55 Self::NotImplemented => libc::ENOSYS,
56 Self::InvalidFlags(_) => libc::EINVAL,
57 Self::BufferWouldOverflow => libc::ERANGE,
58 }
59 }
60}