use alloc::string::String;
use derive_more::derive::Display;
use super::superblock::EXT2_SIGNATURE;
#[allow(clippy::module_name_repetitions)]
#[derive(Debug, PartialEq, Eq, Display)]
#[display("Ext2 Error: {_variant}")]
pub enum Ext2Error {
#[display("Bad File Type: an inode contain the mode {_0}, which does not correspond to a valid file type")]
BadFileType(u16),
#[display("Bad Magic: {_0} has been found while {EXT2_SIGNATURE} was expected")]
BadMagic(u16),
#[display("Bad String: a ill-formed C-string has been found")]
BadString,
#[display("Block Already Free: tried to set the {_0} block free while already being free")]
BlockAlreadyFree(u32),
#[display("Block Already in Use: tried to set the {_0} block in use while already being used")]
BlockAlreadyInUse(u32),
#[display(
"File Too Large: Tried to write a large file while the filesystem does not have the LARGE_FILE feature set"
)]
FileTooLarge,
#[display("GID Too Large: tried to write a GID containing the value {_0}, which cannot be contained on a u16")]
GidTooLarge(u32),
#[display("Inode Already Free: tried to set the inode {_0} as free but is already")]
InodeAlreadyFree(u32),
#[display("Inode Already in Use: tried to set the inode {_0} in use while already being used")]
InodeAlreadyInUse(u32),
#[display("Invalid State: {_0} has been found while 1 or 2 was expected")]
InvalidState(u16),
#[display("Invalid Error Handling Method: {_0} was found while 1, 2 or 3 was expected")]
InvalidErrorHandlingMethod(u16),
#[display("Invalid Compression Algorithm: {_0} was found while 0, 1, 2, 3 or 4 was expected")]
InvalidCompressionAlgorithm(u32),
#[display("Name Too Long: {_0} is too long to be written in a directory entry")]
NameTooLong(String),
#[display("No Extend Field: tried to access an extended field in a superblock that only contains basic fields")]
NoExtendedFields,
#[display("Non Existing Block Group: tried to access the {_0} block group which does not exist")]
NonExistingBlockGroup(u32),
#[display("Non Existing Block: tried to access the {_0} block which does not exist")]
NonExistingBlock(u32),
#[display("Non Existing Inode: tried to access the {_0} inode which does not exist")]
NonExistingInode(u32),
#[display("Not Enough Free Blocks: requested {requested} free blocks while only {available} are available")]
NotEnoughFreeBlocks {
requested: u32,
available: u32,
},
#[display("Not Enough Inodes: requested an inode but all inodes are in use")]
NotEnoughInodes,
#[display("UID Too Large: tried to write a UID containing the value {_0}, which cannot be contained on a u16")]
UidTooLarge(u32),
#[display("Unknown Entry File Type: an unknown file type has been obtained while parsing a directory entry")]
UnknownEntryFileType,
#[display("Unsupported Feature: filesystem requires the {_0} feature which is not supported")]
UnsupportedFeature(String),
}
impl core::error::Error for Ext2Error {}