diff --git a/src/error.rs b/src/error.rs index d109c39..f1c1003 100644 --- a/src/error.rs +++ b/src/error.rs @@ -74,18 +74,27 @@ impl IOErrorKind for std::io::ErrorKind { } } -/// An error indicating that a filesystem-related operation has failed +/// An error type that denotes that there is something wrong +/// with the filesystem's structure itself (perhaps the FS itself is malformed/corrupted) #[derive(Debug, displaydoc::Display)] -pub enum FSError -where - I: IOError, -{ +pub enum InternalFSError { /// The storage medium isn't large enough to accompany a FAT filesystem StorageTooSmall, /// Invalid boot sector signature. Perharps this isn't a FAT filesystem? InvalidBPBSig, /// Encountered a malformed cluster chain MalformedClusterChain, +} + +/// An error indicating that a filesystem-related operation has failed +#[derive(Debug, displaydoc::Display)] +pub enum FSError +where + I: IOError, +{ + /// An internal FS error occured + #[displaydoc("An internal FS error occured: {0}")] + InternalFSError(InternalFSError), /** The [PathBuf](`crate::path::PathBuf`) provided is malformed. @@ -99,8 +108,6 @@ where IsADirectory, /// A file or directory wasn't found NotFound, - /// Found an unexpected EOF while reading a file - UnexpectedEOF, /// An IO error occured #[displaydoc("An IO error occured: {0}")] IOError(I), diff --git a/src/fs.rs b/src/fs.rs index fb72914..6a50481 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -865,7 +865,7 @@ where let bytes_read = storage.read(&mut buffer)?; if bytes_read < mem::size_of::() { - return Err(FSError::StorageTooSmall); + return Err(FSError::InternalFSError(InternalFSError::StorageTooSmall)); } let boot_record: BootRecord = unsafe { mem::transmute_copy(&buffer) }; @@ -876,7 +876,7 @@ where match fat_type { FATType::FAT12 | FATType::FAT16 | FATType::FAT32 => { if unsafe { boot_record.fat.verify_signature() } { - return Err(FSError::InvalidBPBSig); + return Err(FSError::InternalFSError(InternalFSError::InvalidBPBSig)); } } FATType::ExFAT => todo!("ExFAT not yet implemented"), @@ -1007,7 +1007,9 @@ where if file.cluster_chain_is_healthy()? { Ok(file) } else { - Err(FSError::MalformedClusterChain) + Err(FSError::InternalFSError( + InternalFSError::MalformedClusterChain, + )) } } None => Err(FSError::NotFound), @@ -1166,7 +1168,11 @@ where // this cluster chain goes on, follow it FATEntry::Allocated(next_cluster) => data_cluster = next_cluster, // any other case (whether a bad, reserved or free cluster) is invalid, consider this cluster chain malformed - _ => return Err(FSError::MalformedClusterChain), + _ => { + return Err(FSError::InternalFSError( + InternalFSError::MalformedClusterChain, + )) + } } }