From c12928502dd5e2b23867786864dd12652224e09c Mon Sep 17 00:00:00 2001 From: WangRunji Date: Mon, 5 Nov 2018 11:55:33 +0800 Subject: [PATCH] Cargo fix. --- src/blocked_device.rs | 8 ++++---- src/lib.rs | 1 - src/sfs.rs | 16 ++++++++-------- src/structs.rs | 8 ++++---- src/tests.rs | 2 +- src/vfs.rs | 7 ++----- 6 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/blocked_device.rs b/src/blocked_device.rs index f8802fe..f55ebe1 100644 --- a/src/blocked_device.rs +++ b/src/blocked_device.rs @@ -10,7 +10,7 @@ pub trait BlockedDevice { macro_rules! try0 { ($len:expr, $res:expr) => { - if(!$res) {return Some($len);} + if !$res {return Some($len);} }; } @@ -24,7 +24,7 @@ impl Device for T { }; // For each block - for mut range in iter { + for range in iter { let len = range.origin_begin() - offset; let buf = &mut buf[range.origin_begin() - offset..range.origin_end() - offset]; if range.is_full() { @@ -51,7 +51,7 @@ impl Device for T { }; // For each block - for mut range in iter { + for range in iter { let len = range.origin_begin() - offset; let buf = &buf[range.origin_begin() - offset..range.origin_end() - offset]; if range.is_full() { @@ -121,7 +121,7 @@ mod test { #[test] fn write() { let mut buf: [u8; 16] = [0; 16]; - let mut res: [u8; 6] = [3, 4, 5, 6, 7, 8]; + let res: [u8; 6] = [3, 4, 5, 6, 7, 8]; // all inside let ret = Device::write_at(&mut buf, 3, &res); diff --git a/src/lib.rs b/src/lib.rs index 1be886b..7916c8e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,6 @@ #[cfg(any(test, feature = "std"))] #[macro_use] extern crate std; -#[macro_use] extern crate alloc; extern crate bit_vec; #[macro_use] diff --git a/src/sfs.rs b/src/sfs.rs index b442e60..425e2f9 100644 --- a/src/sfs.rs +++ b/src/sfs.rs @@ -1,6 +1,6 @@ use bit_vec::BitVec; use alloc::{boxed::Box, vec::Vec, collections::BTreeMap, sync::{Arc, Weak}, string::String}; -use core::mem::{uninitialized, size_of}; +use core::mem::uninitialized; use core::slice; use core::fmt::{Debug, Formatter, Error}; use core::any::Any; @@ -98,11 +98,11 @@ impl INodeImpl { self._read_at(i as usize * BLKSIZE, entry.as_buf_mut()).unwrap(); (entry, i) }) - .find(|(entry, id)| entry.name.as_ref() == name) + .find(|(entry, _)| entry.name.as_ref() == name) .map(|(entry, id)| (entry.id as INodeId, id as usize)) } fn get_file_inode_id(&self, name: &str) -> Option { - self.get_file_inode_and_entry_id(name).map(|(inode_id, entry_id)| { inode_id }) + self.get_file_inode_and_entry_id(name).map(|(inode_id, _)| inode_id) } /// Init dir content. Insert 2 init entries. /// This do not init nlinks, please modify the nlinks in the invoker. @@ -248,7 +248,7 @@ impl INodeImpl { } impl vfs::INode for INodeImpl { - fn open(&self, flags: u32) -> vfs::Result<()> { + fn open(&self, _flags: u32) -> vfs::Result<()> { // Do nothing Ok(()) } @@ -339,7 +339,7 @@ impl vfs::INode for INodeImpl { inode.nlinks_dec(); //for . self.nlinks_dec(); //for .. } - self.remove_dirent_page(entry_id); + self.remove_dirent_page(entry_id)?; Ok(()) } @@ -401,7 +401,7 @@ impl vfs::INode for INodeImpl { dest._resize(old_size + BLKSIZE).unwrap(); dest._write_at(old_size, entry.as_buf()).unwrap(); - self.remove_dirent_page(entry_id); + self.remove_dirent_page(entry_id)?; if inode.info()?.type_ == vfs::FileType::Dir { self.nlinks_dec(); @@ -436,7 +436,7 @@ impl Drop for INodeImpl { fn drop(&mut self) { self.sync().expect("failed to sync"); if self.disk_inode.read().nlinks <= 0 { - self._resize(0); + self._resize(0).unwrap(); self.disk_inode.write().sync(); self.fs.free_block(self.id); } @@ -481,7 +481,7 @@ impl SimpleFileSystem { }.wrap()) } /// Create a new SFS on blank disk - pub fn create(mut device: Box, space: usize) -> Arc { + pub fn create(device: Box, space: usize) -> Arc { let blocks = (space / BLKSIZE).min(BLKBITS); assert!(blocks >= 16, "space too small"); diff --git a/src/structs.rs b/src/structs.rs index ff7bb55..e5e14a0 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -6,7 +6,7 @@ use core::fmt::{Debug, Formatter, Error}; use alloc::str; /// On-disk superblock -#[repr(C, packed)] +#[repr(C)] #[derive(Debug)] pub struct SuperBlock { /// magic number, should be SFS_MAGIC @@ -20,7 +20,7 @@ pub struct SuperBlock { } /// inode (on disk) -#[repr(C, packed)] +#[repr(C)] #[derive(Debug)] pub struct DiskINode { /// size of the file (in bytes) @@ -41,13 +41,13 @@ pub struct DiskINode { pub db_indirect: u32, } -#[repr(C, packed)] +#[repr(C)] pub struct IndirectBlock { pub entries: [u32; BLK_NENTRY], } /// file entry (on disk) -#[repr(C, packed)] +#[repr(C)] #[derive(Debug)] pub struct DiskEntry { /// inode number diff --git a/src/tests.rs b/src/tests.rs index 2762126..682fa3a 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -32,7 +32,7 @@ fn open_sample_file() { #[test] fn create_new_sfs() { let sfs = _create_new_sfs(); - let root = sfs.root_inode(); + let _root = sfs.root_inode(); } // #[test] diff --git a/src/vfs.rs b/src/vfs.rs index 7adadef..85327ca 100644 --- a/src/vfs.rs +++ b/src/vfs.rs @@ -1,7 +1,4 @@ -use alloc::{vec::Vec, string::String, sync::{Arc, Weak}}; -use core::cell::RefCell; -use core::mem::size_of; -use core; +use alloc::{vec::Vec, string::String, sync::Arc}; use core::fmt::Debug; use core::any::Any; @@ -57,7 +54,7 @@ impl INode { let mut rest_path = path; while rest_path != "" { assert_eq!(result.info()?.type_, FileType::Dir); - let mut name; + let name; match rest_path.find('/') { None => { name = rest_path;