diff --git a/easy-fs/src/bin/main.rs b/easy-fs/src/bin/main.rs index 6eb7d0e7..51c08248 100644 --- a/easy-fs/src/bin/main.rs +++ b/easy-fs/src/bin/main.rs @@ -9,7 +9,6 @@ use std::fs::{File, OpenOptions, read_dir}; use std::io::{Read, Write, Seek, SeekFrom}; use std::sync::Mutex; use alloc::sync::Arc; -use rand; const BLOCK_SZ: usize = 512; @@ -17,7 +16,6 @@ struct BlockFile(Mutex); impl BlockDevice for BlockFile { fn read_block(&self, block_id: usize, buf: &mut [u8]) { - println!("reading block {}", block_id); let mut file = self.0.lock().unwrap(); file.seek(SeekFrom::Start((block_id * BLOCK_SZ) as u64)) .expect("Error when seeking!"); @@ -25,7 +23,6 @@ impl BlockDevice for BlockFile { } fn write_block(&self, block_id: usize, buf: &[u8]) { - println!("writing block {}", block_id); let mut file = self.0.lock().unwrap(); file.seek(SeekFrom::Start((block_id * BLOCK_SZ) as u64)) .expect("Error when seeking!"); @@ -46,7 +43,7 @@ fn easy_fs_pack() -> std::io::Result<()> { .write(true) .create(true) .open(format!("{}{}", TARGET_PATH, "fs.img"))?; - f.set_len(8192 * 512); + f.set_len(8192 * 512).unwrap(); f }))); // 4MiB, at most 4095 files @@ -55,7 +52,7 @@ fn easy_fs_pack() -> std::io::Result<()> { 8192, 1, ); - let mut root_inode = Arc::new(EasyFileSystem::root_inode(&efs)); + let root_inode = Arc::new(EasyFileSystem::root_inode(&efs)); let apps: Vec<_> = read_dir("../user/src/bin") .unwrap() .into_iter() @@ -69,7 +66,7 @@ fn easy_fs_pack() -> std::io::Result<()> { // load app data from host file system let mut host_file = File::open(format!("{}{}", TARGET_PATH, app)).unwrap(); let mut all_data: Vec = Vec::new(); - let app_size = host_file.read_to_end(&mut all_data).unwrap(); + host_file.read_to_end(&mut all_data).unwrap(); // create a file in easy-fs let inode = root_inode.create(app.as_str()).unwrap(); // write data to easy-fs @@ -119,6 +116,7 @@ fn efs_test() -> std::io::Result<()> { 0, ); let mut str = String::new(); + use rand; // random digit for _ in 0..len { str.push(char::from('0' as u8 + rand::random::() % 10)); diff --git a/easy-fs/src/efs.rs b/easy-fs/src/efs.rs index 34c6ad82..f2103740 100644 --- a/easy-fs/src/efs.rs +++ b/easy-fs/src/efs.rs @@ -82,7 +82,6 @@ impl EasyFileSystem { let super_block_dirty: Dirty = Dirty::new(0, 0, block_device.clone()); let super_block = super_block_dirty.get_ref(); assert!(super_block.is_valid(), "Error loading EFS!"); - println!("{:?}", super_block); let inode_total_blocks = super_block.inode_bitmap_blocks + super_block.inode_area_blocks; let efs = Self { diff --git a/easy-fs/src/layout.rs b/easy-fs/src/layout.rs index 3723d0f7..725c1e44 100644 --- a/easy-fs/src/layout.rs +++ b/easy-fs/src/layout.rs @@ -122,7 +122,6 @@ impl DiskInode { new_blocks: Vec, block_device: &Arc, ) { - println!("increase_size new_size={}, new_blocks={:?}", new_size, new_blocks); assert_eq!(new_blocks.len() as u32, self.blocks_num_needed(new_size)); let last_blocks = self.blocks(); self.size = new_size; diff --git a/easy-fs/src/lib.rs b/easy-fs/src/lib.rs index dfd1725e..961efa65 100644 --- a/easy-fs/src/lib.rs +++ b/easy-fs/src/lib.rs @@ -1,3 +1,5 @@ +#![no_std] + extern crate alloc; mod block_dev; diff --git a/easy-fs/src/vfs.rs b/easy-fs/src/vfs.rs index b373172d..d7631354 100644 --- a/easy-fs/src/vfs.rs +++ b/easy-fs/src/vfs.rs @@ -41,13 +41,11 @@ impl Inode { name: &str, inode: &Dirty, ) -> Option { - println!("into find_inode_id"); // assert it is a directory assert!(inode.read(|inode| inode.is_dir())); let file_count = inode.read(|inode| { inode.size as usize }) / DIRENT_SZ; - println!("file_count = {}", file_count); let mut dirent_space: DirentBytes = Default::default(); for i in 0..file_count { assert_eq!( @@ -94,7 +92,6 @@ impl Inode { let blocks_needed = inode.read(|inode| { inode.blocks_num_needed(new_size) }); - println!("blocks_num_needed = {}", blocks_needed); let mut v: Vec = Vec::new(); for _ in 0..blocks_needed { v.push(fs.alloc_data()); @@ -106,7 +103,6 @@ impl Inode { pub fn create(&self, name: &str) -> Option> { let mut fs = self.fs.lock(); - println!("creating name {}", name); let mut inode = self.get_disk_inode(&mut fs); // assert it is a directory assert!(inode.read(|inode| inode.is_dir())); @@ -114,13 +110,11 @@ impl Inode { if let Some(_) = self.find_inode_id(name, &inode) { return None; } - println!("stop1"); // create a new file // alloc a inode with an indirect block let new_inode_id = fs.alloc_inode(); let indirect1 = fs.alloc_data(); - println!("creating new file, new_inode_id={}, indirect={}", new_inode_id, indirect1); // initialize inode fs.get_disk_inode(new_inode_id).modify(|inode| { inode.initialize( @@ -133,7 +127,6 @@ impl Inode { let file_count = inode.read(|inode| inode.size as usize) / DIRENT_SZ; let new_size = (file_count + 1) * DIRENT_SZ; - println!("expected new_size={}", new_size); // increase size self.increase_size(new_size as u32, &mut inode, &mut fs); // write dirent @@ -155,13 +148,11 @@ impl Inode { } pub fn ls(&self) -> Vec { - println!("into ls!"); let mut fs = self.fs.lock(); let inode = self.get_disk_inode(&mut fs); let file_count = inode.read(|inode| { (inode.size as usize) / DIRENT_SZ }); - println!("file_count = {}", file_count); let mut v: Vec = Vec::new(); for i in 0..file_count { let mut dirent_bytes: DirentBytes = Default::default(); diff --git a/os/Cargo.toml b/os/Cargo.toml index 0d8c42af..bded6409 100644 --- a/os/Cargo.toml +++ b/os/Cargo.toml @@ -17,6 +17,7 @@ virtio-drivers = { git = "https://github.com/rcore-os/virtio-drivers" } k210-pac = { git = "https://github.com/wyfcyx/k210-pac" } k210-hal = { git = "https://github.com/wyfcyx/k210-hal" } k210-soc = { git = "https://github.com/wyfcyx/k210-soc" } +easy-fs = { path = "../easy-fs" } [features] board_qemu = []