remove warning+add FsError, pt2

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

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

@ -330,10 +330,10 @@ impl vfs::INode for INodeImpl {
if info.type_!=vfs::FileType::Dir {
return Err(FsError::NotDir)
}
if name != "." {
if name == "." {
return Err(FsError::IsDir)
}
if name != ".." {
if name == ".." {
return Err(FsError::IsDir)
}
@ -522,7 +522,7 @@ impl SimpleFileSystem {
magic: MAGIC,
blocks: blocks as u32,
unused_blocks: blocks as u32 - 3,
info: Str32::from("simple file system"),
info: Str32::from(DEFAULT_INFO),
};
let free_map = {
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;
/// number of direct blocks in inode
pub const NDIRECT: usize = 12;
/// default sfs infomation string
pub const DEFAULT_INFO: &str = "simple file system";
/// max length of infomation
pub const MAX_INFO_LEN: usize = 31;
/// max length of filename
@ -182,7 +184,7 @@ pub const BLKN_ROOT: BlockId = 1;
pub const BLKN_FREEMAP: BlockId = 2;
/// number of bits in a block
pub const BLKBITS: usize = BLKSIZE * 8;
///
/// size of one entry
pub const ENTRY_SIZE: usize = 4;
/// number of entries in a block
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!(o3; size_of::<DiskEntry>() <= 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)
}
//#[test]
#[test]
#[ignore]
fn open_sample_file() {
_open_sample_file();
}
@ -33,7 +34,8 @@ fn create_new_sfs() {
let _root = sfs.root_inode();
}
// #[test]
#[test]
#[ignore]
fn print_root() -> Result<()> {
let sfs = _open_sample_file();
let root = sfs.root_inode();
@ -86,26 +88,26 @@ fn resize() -> Result<()> {
Ok(())
}
// FIXME: `should_panic` tests will panic again on exit, due to `Dirty` drop
//#[test]
//#[should_panic]
//fn resize_on_dir_should_panic() {
// let sfs = _create_new_sfs();
// let root = sfs.root_inode();
// root.resize(4096).unwrap();
// sfs.sync().unwrap();
//}
//
//#[test]
//#[should_panic]
//fn resize_too_large_should_panic() {
// let sfs = _create_new_sfs();
// let root = sfs.root_inode();
// let file1 = root.create("file1", FileType::File).unwrap();
// file1.resize(1 << 28).unwrap();
// sfs.sync().unwrap();
//}
#[test]
fn resize_on_dir_should_panic() -> Result<()> {
let sfs = _create_new_sfs();
let root = sfs.root_inode();
assert!(root.resize(4096).is_err());
sfs.sync()?;
Ok(())
}
#[test]
fn resize_too_large_should_panic() -> Result<()> {
let sfs = _create_new_sfs();
let root = sfs.root_inode();
let file1 = root.create("file1", FileType::File)?;
assert!(file1.resize(1 << 28).is_err());
sfs.sync()?;
Ok(())
}
#[test]
fn create_then_lookup() -> Result<()> {
@ -142,7 +144,8 @@ fn arc_layout() {
assert_eq!(ns, &[1usize, 1]);
}
// #[test]
#[test]
#[ignore]
fn kernel_image_file_create() -> Result<()> {
let sfs = _open_sample_file();
let root = sfs.root_inode();
@ -156,7 +159,8 @@ fn kernel_image_file_create() -> Result<()> {
Ok(())
}
// #[test]
#[test]
#[ignore]
fn kernel_image_file_unlink() -> Result<()> {
let sfs = _open_sample_file();
let root = sfs.root_inode();
@ -170,8 +174,8 @@ fn kernel_image_file_unlink() -> Result<()> {
Ok(())
}
// #[test]
#[test]
#[ignore]
fn kernel_image_file_rename() -> Result<()> {
let sfs = _open_sample_file();
let root = sfs.root_inode();
@ -186,7 +190,8 @@ fn kernel_image_file_rename() -> Result<()> {
Ok(())
}
// #[test]
#[test]
#[ignore]
fn kernel_image_file_move() -> Result<()> {
let sfs = _open_sample_file();
let root = sfs.root_inode();

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

Loading…
Cancel
Save