Fix rcore-fs-ext2 tests

master
Jiajie Chen 6 years ago
parent 17aea0d930
commit 037d00f566

@ -8,15 +8,17 @@ extern crate ext2;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
use alloc::string::String;
use alloc::sync::Arc; use alloc::sync::Arc;
use alloc::vec;
use core::ops::Range;
use ext2::error::Error;
use ext2::fs::sync::Synced; use ext2::fs::sync::Synced;
use ext2::fs::Ext2; use ext2::fs::Ext2;
use ext2::error::Error; use ext2::sector::{Address, Size512};
use ext2::sector::{Size512, Address};
use ext2::volume::size::Size; use ext2::volume::size::Size;
use ext2::volume::{Volume, VolumeCommit, VolumeSlice}; use ext2::volume::{Volume, VolumeCommit, VolumeSlice};
use core::ops::Range; use rcore_fs::dev::{DevError, Device};
use rcore_fs::dev::Device;
use rcore_fs::vfs; use rcore_fs::vfs;
#[derive(Clone)] #[derive(Clone)]
@ -33,21 +35,33 @@ pub struct Ext2FileSystem {
/// A conversion between vfs::FsError and ext2::Error /// A conversion between vfs::FsError and ext2::Error
#[derive(Debug)] #[derive(Debug)]
struct Ext2Error { struct Ext2Error {
inner: Error inner: Error,
} }
impl core::convert::From<Ext2Error> for vfs::FsError { impl core::convert::From<Ext2Error> for vfs::FsError {
fn from(err: Ext2Error) -> Self { fn from(err: Ext2Error) -> Self {
match err.inner { match err.inner {
_ => vfs::FsError::DeviceError _ => vfs::FsError::DeviceError,
} }
} }
} }
impl core::convert::From<Ext2Error> for Error {
fn from(err: Ext2Error) -> Self {
err.inner
}
}
impl core::convert::From<Error> for Ext2Error { impl core::convert::From<Error> for Ext2Error {
fn from(err: Error) -> Self { fn from(err: Error) -> Self {
Ext2Error { inner: err }
}
}
impl core::convert::From<DevError> for Ext2Error {
fn from(_: DevError) -> Self {
Ext2Error { Ext2Error {
inner: err inner: Error::Other(String::from("unknown")),
} }
} }
} }
@ -58,34 +72,45 @@ impl Ext2FileSystem {
} }
fn open_internal(device: Arc<Device>) -> Result<Arc<Self>, Ext2Error> { fn open_internal(device: Arc<Device>) -> Result<Arc<Self>, Ext2Error> {
let volume = Ext2Volume { let volume = Ext2Volume { inner: device };
inner: device
};
let fs = Synced::new(volume.clone())?; let fs = Synced::new(volume.clone())?;
Ok(Arc::new(Ext2FileSystem { Ok(Arc::new(Ext2FileSystem { inner: fs, volume }))
inner: fs,
volume,
}))
} }
} }
impl Volume<u8, Size512> for Ext2Volume { impl Volume<u8, Size512> for Ext2Volume {
type Error = Error; type Error = Ext2Error;
fn size(&self) -> Size<Size512> { fn size(&self) -> Size<Size512> {
Size::Unbounded Size::Unbounded
} }
fn commit(&mut self, slice: Option<VolumeCommit<u8, Size512>>) -> Result<(), Self::Error> { fn commit(&mut self, _slice: Option<VolumeCommit<u8, Size512>>) -> Result<(), Self::Error> {
unimplemented!() unimplemented!()
} }
unsafe fn slice_unchecked<'a>(&'a self, range: Range<Address<Size512>>) -> VolumeSlice<'a, u8, Size512> { unsafe fn slice_unchecked<'a>(
unimplemented!() &'a self,
range: Range<Address<Size512>>,
) -> VolumeSlice<'a, u8, Size512> {
let index = range.start;
let len = range.end - range.start;
let mut vec = vec![0; len.into_index() as usize];
self.inner
.read_at(index.into_index() as usize, vec.as_mut_slice())
.unwrap();
VolumeSlice::new_owned(vec, index)
} }
fn slice<'a>(&'a self, range: Range<Address<Size512>>) -> Result<VolumeSlice<'a, u8, Size512>, Self::Error> { fn slice<'a>(
unimplemented!() &'a self,
range: Range<Address<Size512>>,
) -> Result<VolumeSlice<'a, u8, Size512>, Self::Error> {
let index = range.start;
let len = range.end - range.start;
let mut vec = vec![0; len.into_index() as usize];
self.inner
.read_at(index.into_index() as usize, vec.as_mut_slice())?;
Ok(VolumeSlice::new_owned(vec, index))
} }
} }

@ -17,5 +17,5 @@ fn open_sample_file() -> Arc<Ext2FileSystem> {
#[test] #[test]
fn test_open() { fn test_open() {
let fs = open_sample_file(); let _ = open_sample_file();
} }

Loading…
Cancel
Save