use objects::error::HeddleError;
pub type Result<T> = std::result::Result<T, MountError>;
#[derive(Debug, thiserror::Error)]
pub enum MountError {
#[error("not found: {0}")]
NotFound(String),
#[error("stale node: {0}")]
Stale(String),
#[error("not a directory: {0}")]
NotADirectory(String),
#[error("thread {0} has no current state")]
UnknownThread(String),
#[error("read-only filesystem")]
ReadOnly,
#[error("already exists: {0}")]
AlreadyExists(String),
#[error("is a directory: {0}")]
IsADirectory(String),
#[error("directory not empty: {0}")]
NotEmpty(String),
#[error("invalid argument: {0}")]
InvalidArgument(String),
#[error("mount session initialization failed: {0}")]
SessionInit(String),
#[error(transparent)]
Store(#[from] HeddleError),
}
impl MountError {
pub fn to_errno(&self) -> i32 {
match self {
MountError::NotFound(_) | MountError::UnknownThread(_) => libc::ENOENT,
MountError::Stale(_) => stale_errno(),
MountError::NotADirectory(_) => libc::ENOTDIR,
MountError::ReadOnly => libc::EROFS,
MountError::AlreadyExists(_) => libc::EEXIST,
MountError::IsADirectory(_) => libc::EISDIR,
MountError::NotEmpty(_) => libc::ENOTEMPTY,
MountError::InvalidArgument(_) => libc::EINVAL,
MountError::SessionInit(_) => libc::EIO,
MountError::Store(HeddleError::NotFound(_))
| MountError::Store(HeddleError::StateNotFound(_))
| MountError::Store(HeddleError::MissingObject { .. }) => libc::ENOENT,
MountError::Store(HeddleError::Io(io)) => io.raw_os_error().unwrap_or(libc::EIO),
MountError::Store(_) => libc::EIO,
}
}
}
#[cfg(unix)]
#[inline]
fn stale_errno() -> i32 {
libc::ESTALE
}
#[cfg(windows)]
#[inline]
fn stale_errno() -> i32 {
116
}
#[cfg(any(
all(target_os = "linux", feature = "fuse"),
all(target_os = "macos", feature = "fskit"),
all(target_os = "windows", feature = "projfs"),
))]
pub(crate) fn panic_payload_str(payload: &Box<dyn std::any::Any + Send>) -> String {
if let Some(s) = payload.downcast_ref::<&'static str>() {
(*s).to_string()
} else if let Some(s) = payload.downcast_ref::<String>() {
s.clone()
} else {
"<non-string panic payload>".to_string()
}
}