use bincode::error::{DecodeError, EncodeError};
use embedded_io::*;
use crate::*;
#[non_exhaustive]
#[derive(Debug)]
pub enum InternalFSError {
StorageTooSmall,
InvalidBPBSig,
InvalidFSInfoSig,
MismatchingFATTables,
MalformedClusterChain,
MalformedEntryChain,
}
#[non_exhaustive]
#[derive(Debug)]
pub enum FSError<I>
where
I: Error,
{
InternalFSError(InternalFSError),
MalformedPath,
BincodeError(BincodeError),
NotADirectory,
IsADirectory,
DirectoryNotEmpty,
ReadOnlyFile,
NotFound,
AlreadyExists,
PermissionDenied,
InvalidInput,
StorageFull,
RootDirectoryFull,
DirEntryLimitReached,
UnsupportedFS,
UnexpectedEof,
IOError(I),
}
#[derive(Debug)]
pub enum BincodeError {
DecodeError(DecodeError),
EncodeError(EncodeError),
}
impl<I> From<I> for FSError<I>
where
I: Error,
{
#[inline]
fn from(value: I) -> Self {
FSError::IOError(value)
}
}
impl<I> From<ReadExactError<I>> for FSError<I>
where
I: Error,
{
#[inline]
fn from(value: ReadExactError<I>) -> Self {
match value {
ReadExactError::UnexpectedEof => FSError::UnexpectedEof,
ReadExactError::Other(e) => FSError::IOError(e),
}
}
}
impl<I> From<RWFileError<I>> for FSError<I>
where
I: Error,
{
fn from(value: RWFileError<I>) -> Self {
match value {
RWFileError::StorageFull => FSError::StorageFull,
RWFileError::IOError(e) => FSError::IOError(e),
}
}
}
pub type FSResult<T, E> = Result<T, FSError<E>>;