remove warning+add FsError, pt2

master
Ben Pig Chu 6 years ago
parent eb347c890c
commit 0a3f4218fe

@ -1,5 +1,6 @@
#![feature(alloc)] #![feature(alloc)]
#![feature(const_fn)] #![feature(const_fn)]
#![feature(const_str_len)]
#![feature(nll)] #![feature(nll)]
#![cfg_attr(target_arch = "riscv", feature(match_default_bindings))] #![cfg_attr(target_arch = "riscv", feature(match_default_bindings))]
#![no_std] #![no_std]
@ -14,6 +15,7 @@ extern crate static_assertions;
extern crate spin; extern crate spin;
#[cfg(not(test))] #[cfg(not(test))]
#[allow(unused_macros)]
macro_rules! eprintln { macro_rules! eprintln {
() => (); () => ();
($fmt:expr) => (); ($fmt:expr) => ();

@ -330,10 +330,10 @@ impl vfs::INode for INodeImpl {
if info.type_!=vfs::FileType::Dir { if info.type_!=vfs::FileType::Dir {
return Err(FsError::NotDir) return Err(FsError::NotDir)
} }
if name != "." { if name == "." {
return Err(FsError::IsDir) return Err(FsError::IsDir)
} }
if name != ".." { if name == ".." {
return Err(FsError::IsDir) return Err(FsError::IsDir)
} }
@ -522,7 +522,7 @@ impl SimpleFileSystem {
magic: MAGIC, magic: MAGIC,
blocks: blocks as u32, blocks: blocks as u32,
unused_blocks: blocks as u32 - 3, unused_blocks: blocks as u32 - 3,
info: Str32::from("simple file system"), info: Str32::from(DEFAULT_INFO),
}; };
let free_map = { let free_map = {
let mut bitset = BitVec::from_elem(BLKBITS, false); let mut bitset = BitVec::from_elem(BLKBITS, false);

@ -168,6 +168,8 @@ pub const BLKSIZE: usize = 1usize << BLKSIZE_LOG2;
pub const BLKSIZE_LOG2: u8 = 12; pub const BLKSIZE_LOG2: u8 = 12;
/// number of direct blocks in inode /// number of direct blocks in inode
pub const NDIRECT: usize = 12; pub const NDIRECT: usize = 12;
/// default sfs infomation string
pub const DEFAULT_INFO: &str = "simple file system";
/// max length of infomation /// max length of infomation
pub const MAX_INFO_LEN: usize = 31; pub const MAX_INFO_LEN: usize = 31;
/// max length of filename /// max length of filename
@ -182,7 +184,7 @@ pub const BLKN_ROOT: BlockId = 1;
pub const BLKN_FREEMAP: BlockId = 2; pub const BLKN_FREEMAP: BlockId = 2;
/// number of bits in a block /// number of bits in a block
pub const BLKBITS: usize = BLKSIZE * 8; pub const BLKBITS: usize = BLKSIZE * 8;
/// /// size of one entry
pub const ENTRY_SIZE: usize = 4; pub const ENTRY_SIZE: usize = 4;
/// number of entries in a block /// number of entries in a block
pub const BLK_NENTRY: usize = BLKSIZE / ENTRY_SIZE; pub const BLK_NENTRY: usize = BLKSIZE / ENTRY_SIZE;
@ -203,3 +205,4 @@ const_assert!(o1; size_of::<SuperBlock>() <= BLKSIZE);
const_assert!(o2; size_of::<DiskINode>() <= BLKSIZE); const_assert!(o2; size_of::<DiskINode>() <= BLKSIZE);
const_assert!(o3; size_of::<DiskEntry>() <= BLKSIZE); const_assert!(o3; size_of::<DiskEntry>() <= BLKSIZE);
const_assert!(o4; size_of::<IndirectBlock>() == BLKSIZE); const_assert!(o4; size_of::<IndirectBlock>() == BLKSIZE);
const_assert!(o5; DEFAULT_INFO.len() <= MAX_INFO_LEN);

@ -22,7 +22,8 @@ fn _create_new_sfs() -> Arc<SimpleFileSystem> {
SimpleFileSystem::create(Box::new(file), 32 * 4096) SimpleFileSystem::create(Box::new(file), 32 * 4096)
} }
//#[test] #[test]
#[ignore]
fn open_sample_file() { fn open_sample_file() {
_open_sample_file(); _open_sample_file();
} }
@ -33,7 +34,8 @@ fn create_new_sfs() {
let _root = sfs.root_inode(); let _root = sfs.root_inode();
} }
// #[test] #[test]
#[ignore]
fn print_root() -> Result<()> { fn print_root() -> Result<()> {
let sfs = _open_sample_file(); let sfs = _open_sample_file();
let root = sfs.root_inode(); let root = sfs.root_inode();
@ -86,26 +88,26 @@ fn resize() -> Result<()> {
Ok(()) Ok(())
} }
// FIXME: `should_panic` tests will panic again on exit, due to `Dirty` drop #[test]
fn resize_on_dir_should_panic() -> Result<()> {
//#[test] let sfs = _create_new_sfs();
//#[should_panic] let root = sfs.root_inode();
//fn resize_on_dir_should_panic() { assert!(root.resize(4096).is_err());
// let sfs = _create_new_sfs(); sfs.sync()?;
// let root = sfs.root_inode();
// root.resize(4096).unwrap(); Ok(())
// sfs.sync().unwrap(); }
//}
// #[test]
//#[test] fn resize_too_large_should_panic() -> Result<()> {
//#[should_panic] let sfs = _create_new_sfs();
//fn resize_too_large_should_panic() { let root = sfs.root_inode();
// let sfs = _create_new_sfs(); let file1 = root.create("file1", FileType::File)?;
// let root = sfs.root_inode(); assert!(file1.resize(1 << 28).is_err());
// let file1 = root.create("file1", FileType::File).unwrap(); sfs.sync()?;
// file1.resize(1 << 28).unwrap();
// sfs.sync().unwrap(); Ok(())
//} }
#[test] #[test]
fn create_then_lookup() -> Result<()> { fn create_then_lookup() -> Result<()> {
@ -142,7 +144,8 @@ fn arc_layout() {
assert_eq!(ns, &[1usize, 1]); assert_eq!(ns, &[1usize, 1]);
} }
// #[test] #[test]
#[ignore]
fn kernel_image_file_create() -> Result<()> { fn kernel_image_file_create() -> Result<()> {
let sfs = _open_sample_file(); let sfs = _open_sample_file();
let root = sfs.root_inode(); let root = sfs.root_inode();
@ -156,7 +159,8 @@ fn kernel_image_file_create() -> Result<()> {
Ok(()) Ok(())
} }
// #[test] #[test]
#[ignore]
fn kernel_image_file_unlink() -> Result<()> { fn kernel_image_file_unlink() -> Result<()> {
let sfs = _open_sample_file(); let sfs = _open_sample_file();
let root = sfs.root_inode(); let root = sfs.root_inode();
@ -170,8 +174,8 @@ fn kernel_image_file_unlink() -> Result<()> {
Ok(()) Ok(())
} }
#[test]
// #[test] #[ignore]
fn kernel_image_file_rename() -> Result<()> { fn kernel_image_file_rename() -> Result<()> {
let sfs = _open_sample_file(); let sfs = _open_sample_file();
let root = sfs.root_inode(); let root = sfs.root_inode();
@ -186,7 +190,8 @@ fn kernel_image_file_rename() -> Result<()> {
Ok(()) Ok(())
} }
// #[test] #[test]
#[ignore]
fn kernel_image_file_move() -> Result<()> { fn kernel_image_file_move() -> Result<()> {
let sfs = _open_sample_file(); let sfs = _open_sample_file();
let root = sfs.root_inode(); let root = sfs.root_inode();

@ -42,7 +42,7 @@ impl INode {
} }
pub fn list(&self) -> Result<Vec<String>> { pub fn list(&self) -> Result<Vec<String>> {
let info = self.info()?; let info = self.info()?;
if(info.type_ != FileType::Dir){ if info.type_ != FileType::Dir {
return Err(FsError::NotDir); return Err(FsError::NotDir);
} }
Ok((0..info.size).map(|i| { Ok((0..info.size).map(|i| {
@ -50,13 +50,13 @@ impl INode {
}).collect()) }).collect())
} }
pub fn lookup(&self, path: &str) -> Result<Arc<INode>> { pub fn lookup(&self, path: &str) -> Result<Arc<INode>> {
if(self.info()?.type_ != FileType::Dir){ if self.info()?.type_ != FileType::Dir {
return Err(FsError::NotDir); return Err(FsError::NotDir);
} }
let mut result = self.find(".")?; let mut result = self.find(".")?;
let mut rest_path = path; let mut rest_path = path;
while rest_path != "" { while rest_path != "" {
if(result.info()?.type_!= FileType::Dir){ if result.info()?.type_!= FileType::Dir {
return Err(FsError::NotDir); return Err(FsError::NotDir);
} }
let name; let name;

Loading…
Cancel
Save