#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Error {
Io { token: &'static str, offset: u64 },
BadSuperblock(SuperblockReason),
UnsupportedFeature(&'static str),
BadCrc {
ag: u32,
ag_block: u32,
what: &'static str,
},
Inconsistent {
token: &'static str,
where_: Location,
},
NotFound { component: &'static str },
NotARegularFile,
NotASymlink,
FileTooLarge { size: u64, max: u64 },
OutOfMemory { site: &'static str },
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SuperblockReason {
BadMagic,
BadCrc,
UnsupportedVersion,
BadGeometry,
ExternalLog,
RealtimeDevice,
DirtyLog,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Location {
Inode { ino: u64 },
Bmbt { ino: u64, block: u32 },
Dir { ino: u64, block: u32 },
Symlink { ino: u64 },
}
impl Error {
pub fn token(&self) -> &'static str {
match self {
Error::Io { token, .. } => token,
Error::BadSuperblock(r) => r.token(),
Error::UnsupportedFeature(t) => t,
Error::BadCrc { what, .. } => what,
Error::Inconsistent { token, .. } => token,
Error::NotFound { .. } => "not_found",
Error::NotARegularFile => "not_a_regular_file",
Error::NotASymlink => "not_a_symlink",
Error::FileTooLarge { .. } => "file_too_large",
Error::OutOfMemory { site } => site,
}
}
}
impl SuperblockReason {
pub(crate) fn token(self) -> &'static str {
match self {
SuperblockReason::BadMagic => "sb_bad_magic",
SuperblockReason::BadCrc => "sb_bad_crc",
SuperblockReason::UnsupportedVersion => "sb_unsupported_version",
SuperblockReason::BadGeometry => "sb_bad_geometry",
SuperblockReason::ExternalLog => "sb_external_log",
SuperblockReason::RealtimeDevice => "sb_realtime_device",
SuperblockReason::DirtyLog => "sb_dirty_log",
}
}
}
impl core::fmt::Display for Error {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "lamxfs: {}", self.token())
}
}
#[cfg(feature = "std")]
extern crate std;
#[cfg(feature = "std")]
impl std::error::Error for Error {}
pub(crate) type Result<T> = core::result::Result<T, Error>;