master
WangRunji 6 years ago
parent d1112a3768
commit c12928502d

@ -10,7 +10,7 @@ pub trait BlockedDevice {
macro_rules! try0 { macro_rules! try0 {
($len:expr, $res:expr) => { ($len:expr, $res:expr) => {
if(!$res) {return Some($len);} if !$res {return Some($len);}
}; };
} }
@ -24,7 +24,7 @@ impl<T: BlockedDevice> Device for T {
}; };
// For each block // For each block
for mut range in iter { for range in iter {
let len = range.origin_begin() - offset; let len = range.origin_begin() - offset;
let buf = &mut buf[range.origin_begin() - offset..range.origin_end() - offset]; let buf = &mut buf[range.origin_begin() - offset..range.origin_end() - offset];
if range.is_full() { if range.is_full() {
@ -51,7 +51,7 @@ impl<T: BlockedDevice> Device for T {
}; };
// For each block // For each block
for mut range in iter { for range in iter {
let len = range.origin_begin() - offset; let len = range.origin_begin() - offset;
let buf = &buf[range.origin_begin() - offset..range.origin_end() - offset]; let buf = &buf[range.origin_begin() - offset..range.origin_end() - offset];
if range.is_full() { if range.is_full() {
@ -121,7 +121,7 @@ mod test {
#[test] #[test]
fn write() { fn write() {
let mut buf: [u8; 16] = [0; 16]; 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 // all inside
let ret = Device::write_at(&mut buf, 3, &res); let ret = Device::write_at(&mut buf, 3, &res);

@ -7,7 +7,6 @@
#[cfg(any(test, feature = "std"))] #[cfg(any(test, feature = "std"))]
#[macro_use] #[macro_use]
extern crate std; extern crate std;
#[macro_use]
extern crate alloc; extern crate alloc;
extern crate bit_vec; extern crate bit_vec;
#[macro_use] #[macro_use]

@ -1,6 +1,6 @@
use bit_vec::BitVec; use bit_vec::BitVec;
use alloc::{boxed::Box, vec::Vec, collections::BTreeMap, sync::{Arc, Weak}, string::String}; 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::slice;
use core::fmt::{Debug, Formatter, Error}; use core::fmt::{Debug, Formatter, Error};
use core::any::Any; use core::any::Any;
@ -98,11 +98,11 @@ impl INodeImpl {
self._read_at(i as usize * BLKSIZE, entry.as_buf_mut()).unwrap(); self._read_at(i as usize * BLKSIZE, entry.as_buf_mut()).unwrap();
(entry, i) (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)) .map(|(entry, id)| (entry.id as INodeId, id as usize))
} }
fn get_file_inode_id(&self, name: &str) -> Option<INodeId> { fn get_file_inode_id(&self, name: &str) -> Option<INodeId> {
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. /// Init dir content. Insert 2 init entries.
/// This do not init nlinks, please modify the nlinks in the invoker. /// This do not init nlinks, please modify the nlinks in the invoker.
@ -248,7 +248,7 @@ impl INodeImpl {
} }
impl vfs::INode for INodeImpl { impl vfs::INode for INodeImpl {
fn open(&self, flags: u32) -> vfs::Result<()> { fn open(&self, _flags: u32) -> vfs::Result<()> {
// Do nothing // Do nothing
Ok(()) Ok(())
} }
@ -339,7 +339,7 @@ impl vfs::INode for INodeImpl {
inode.nlinks_dec(); //for . inode.nlinks_dec(); //for .
self.nlinks_dec(); //for .. self.nlinks_dec(); //for ..
} }
self.remove_dirent_page(entry_id); self.remove_dirent_page(entry_id)?;
Ok(()) Ok(())
} }
@ -401,7 +401,7 @@ impl vfs::INode for INodeImpl {
dest._resize(old_size + BLKSIZE).unwrap(); dest._resize(old_size + BLKSIZE).unwrap();
dest._write_at(old_size, entry.as_buf()).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 { if inode.info()?.type_ == vfs::FileType::Dir {
self.nlinks_dec(); self.nlinks_dec();
@ -436,7 +436,7 @@ impl Drop for INodeImpl {
fn drop(&mut self) { fn drop(&mut self) {
self.sync().expect("failed to sync"); self.sync().expect("failed to sync");
if self.disk_inode.read().nlinks <= 0 { if self.disk_inode.read().nlinks <= 0 {
self._resize(0); self._resize(0).unwrap();
self.disk_inode.write().sync(); self.disk_inode.write().sync();
self.fs.free_block(self.id); self.fs.free_block(self.id);
} }
@ -481,7 +481,7 @@ impl SimpleFileSystem {
}.wrap()) }.wrap())
} }
/// Create a new SFS on blank disk /// Create a new SFS on blank disk
pub fn create(mut device: Box<Device>, space: usize) -> Arc<Self> { pub fn create(device: Box<Device>, space: usize) -> Arc<Self> {
let blocks = (space / BLKSIZE).min(BLKBITS); let blocks = (space / BLKSIZE).min(BLKBITS);
assert!(blocks >= 16, "space too small"); assert!(blocks >= 16, "space too small");

@ -6,7 +6,7 @@ use core::fmt::{Debug, Formatter, Error};
use alloc::str; use alloc::str;
/// On-disk superblock /// On-disk superblock
#[repr(C, packed)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct SuperBlock { pub struct SuperBlock {
/// magic number, should be SFS_MAGIC /// magic number, should be SFS_MAGIC
@ -20,7 +20,7 @@ pub struct SuperBlock {
} }
/// inode (on disk) /// inode (on disk)
#[repr(C, packed)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct DiskINode { pub struct DiskINode {
/// size of the file (in bytes) /// size of the file (in bytes)
@ -41,13 +41,13 @@ pub struct DiskINode {
pub db_indirect: u32, pub db_indirect: u32,
} }
#[repr(C, packed)] #[repr(C)]
pub struct IndirectBlock { pub struct IndirectBlock {
pub entries: [u32; BLK_NENTRY], pub entries: [u32; BLK_NENTRY],
} }
/// file entry (on disk) /// file entry (on disk)
#[repr(C, packed)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]
pub struct DiskEntry { pub struct DiskEntry {
/// inode number /// inode number

@ -32,7 +32,7 @@ fn open_sample_file() {
#[test] #[test]
fn create_new_sfs() { fn create_new_sfs() {
let sfs = _create_new_sfs(); let sfs = _create_new_sfs();
let root = sfs.root_inode(); let _root = sfs.root_inode();
} }
// #[test] // #[test]

@ -1,7 +1,4 @@
use alloc::{vec::Vec, string::String, sync::{Arc, Weak}}; use alloc::{vec::Vec, string::String, sync::Arc};
use core::cell::RefCell;
use core::mem::size_of;
use core;
use core::fmt::Debug; use core::fmt::Debug;
use core::any::Any; use core::any::Any;
@ -57,7 +54,7 @@ impl INode {
let mut rest_path = path; let mut rest_path = path;
while rest_path != "" { while rest_path != "" {
assert_eq!(result.info()?.type_, FileType::Dir); assert_eq!(result.info()?.type_, FileType::Dir);
let mut name; let name;
match rest_path.find('/') { match rest_path.find('/') {
None => { None => {
name = rest_path; name = rest_path;

Loading…
Cancel
Save