master
WangRunji 6 years ago
parent d1112a3768
commit c12928502d

@ -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<T: BlockedDevice> 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<T: BlockedDevice> 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);

@ -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]

@ -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<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.
/// 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<Device>, space: usize) -> Arc<Self> {
pub fn create(device: Box<Device>, space: usize) -> Arc<Self> {
let blocks = (space / BLKSIZE).min(BLKBITS);
assert!(blocks >= 16, "space too small");

@ -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

@ -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]

@ -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;

Loading…
Cancel
Save