use thiserror::Error;
pub type Result<T> = std::result::Result<T, FsError>;
#[derive(Debug, Error)]
pub enum FsError {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),
#[error("invalid path: {0}")]
InvalidPath(String),
#[error("file not found: {0}")]
NotFound(String),
#[error("permission denied: {0}")]
PermissionDenied(String),
#[error("operation not supported: {0}")]
NotSupported(String),
#[error("FUSE error: {0}")]
Fuse(String),
#[error("cache error: {0}")]
Cache(String),
#[error("invalid file handle: {0}")]
InvalidHandle(u64),
}
impl FsError {
#[must_use]
pub fn to_errno(&self) -> i32 {
match self {
Self::Io(e) => e.raw_os_error().unwrap_or(libc::EIO),
Self::InvalidPath(_) => libc::EINVAL,
Self::NotFound(_) => libc::ENOENT,
Self::PermissionDenied(_) => libc::EACCES,
Self::NotSupported(_) => libc::ENOSYS,
Self::Fuse(_) | Self::Cache(_) => libc::EIO,
Self::InvalidHandle(_) => libc::EBADF,
}
}
}