diff --git a/ext2.bin b/ext2.bin new file mode 100644 index 0000000..939c3d1 Binary files /dev/null and b/ext2.bin differ diff --git a/src/error.rs b/src/error.rs index 353d8f2..8cb3fb6 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,9 +1,14 @@ +#[cfg(any(test, not(feature = "no_std")))] +use std::io; + /// The set of all possible errors -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[derive(Debug)] pub enum Error { BadMagic(u16), OutOfBounds(usize), BadBlockGroupCount(u32, u32), + #[cfg(any(test, not(feature = "no_std")))] + Io(io::Error), } impl From for Error { @@ -12,4 +17,11 @@ impl From for Error { } } +#[cfg(any(test, not(feature = "no_std")))] +impl From for Error { + fn from(err: io::Error) -> Error { + Error::Io(err) + } +} + pub enum Infallible {} diff --git a/src/fs.rs b/src/fs.rs index bad1c3f..f802ded 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -27,3 +27,18 @@ where } } } + +#[cfg(test)] +mod tests { + use std::fs::File; + use std::cell::RefCell; + + use super::Ext2; + + #[test] + fn file() { + let file = RefCell::new(File::open("ext2.bin").unwrap()); + let mut fs = Ext2::new(file); + assert!(fs.init().is_ok()); + } +}