affs_read/
error.rs

1//! Error types for AFFS operations.
2
3use core::fmt;
4
5/// Error type for AFFS operations.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum AffsError {
8    /// Block read failed.
9    BlockReadError,
10    /// Invalid DOS type signature.
11    InvalidDosType,
12    /// Invalid block type.
13    InvalidBlockType,
14    /// Invalid secondary type.
15    InvalidSecType,
16    /// Checksum verification failed.
17    ChecksumMismatch,
18    /// Block number out of valid range.
19    BlockOutOfRange,
20    /// Entry not found.
21    EntryNotFound,
22    /// Name too long (max 30 characters).
23    NameTooLong,
24    /// Invalid filesystem state.
25    InvalidState,
26    /// End of file reached.
27    EndOfFile,
28    /// Not a file entry.
29    NotAFile,
30    /// Not a directory entry.
31    NotADirectory,
32    /// Buffer too small.
33    BufferTooSmall,
34    /// Invalid data block sequence.
35    InvalidDataSequence,
36    /// Not a symlink entry.
37    NotASymlink,
38    /// Symlink target too long.
39    SymlinkTooLong,
40}
41
42impl fmt::Display for AffsError {
43    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
44        match self {
45            Self::BlockReadError => write!(f, "block read error"),
46            Self::InvalidDosType => write!(f, "invalid DOS type signature"),
47            Self::InvalidBlockType => write!(f, "invalid block type"),
48            Self::InvalidSecType => write!(f, "invalid secondary type"),
49            Self::ChecksumMismatch => write!(f, "checksum mismatch"),
50            Self::BlockOutOfRange => write!(f, "block out of range"),
51            Self::EntryNotFound => write!(f, "entry not found"),
52            Self::NameTooLong => write!(f, "name too long"),
53            Self::InvalidState => write!(f, "invalid filesystem state"),
54            Self::EndOfFile => write!(f, "end of file"),
55            Self::NotAFile => write!(f, "not a file"),
56            Self::NotADirectory => write!(f, "not a directory"),
57            Self::BufferTooSmall => write!(f, "buffer too small"),
58            Self::InvalidDataSequence => write!(f, "invalid data block sequence"),
59            Self::NotASymlink => write!(f, "not a symlink"),
60            Self::SymlinkTooLong => write!(f, "symlink target too long"),
61        }
62    }
63}
64
65#[cfg(feature = "std")]
66impl std::error::Error for AffsError {}
67
68/// Result type for AFFS operations.
69pub type Result<T> = core::result::Result<T, AffsError>;