From 306ff01031977dc894bd09e645a964ee2c6d5ab9 Mon Sep 17 00:00:00 2001 From: Harry Cheng Date: Tue, 30 Jul 2019 20:30:39 +0800 Subject: [PATCH] Cleanup --- rcore-fs-ext2/src/lib.rs | 1 - rcore-fs-fuse/src/lib.rs | 1 - rcore-fs-mountfs/src/lib.rs | 6 +++--- rcore-fs-ramfs/src/lib.rs | 10 ++++------ rcore-fs-sefs/src/dev/std_impl.rs | 2 +- rcore-fs-sefs/src/lib.rs | 6 ++---- rcore-fs-sfs/src/lib.rs | 9 +++++---- rcore-fs/src/file.rs | 2 +- rcore-fs/src/vfs.rs | 4 ++-- rust-toolchain | 2 +- 10 files changed, 19 insertions(+), 24 deletions(-) diff --git a/rcore-fs-ext2/src/lib.rs b/rcore-fs-ext2/src/lib.rs index 0fb8963..ef7f119 100644 --- a/rcore-fs-ext2/src/lib.rs +++ b/rcore-fs-ext2/src/lib.rs @@ -1,5 +1,4 @@ #![cfg_attr(not(any(test, feature = "std")), no_std)] -#![feature(alloc)] extern crate alloc; diff --git a/rcore-fs-fuse/src/lib.rs b/rcore-fs-fuse/src/lib.rs index 31772d4..7ad34e8 100644 --- a/rcore-fs-fuse/src/lib.rs +++ b/rcore-fs-fuse/src/lib.rs @@ -1,4 +1,3 @@ -#[macro_use] extern crate log; #[cfg(feature = "use_fuse")] diff --git a/rcore-fs-mountfs/src/lib.rs b/rcore-fs-mountfs/src/lib.rs index 4b8debd..fcec8b2 100644 --- a/rcore-fs-mountfs/src/lib.rs +++ b/rcore-fs-mountfs/src/lib.rs @@ -1,5 +1,4 @@ #![cfg_attr(not(any(test, feature = "std")), no_std)] -#![feature(alloc)] extern crate alloc; #[macro_use] @@ -210,7 +209,8 @@ impl MNode { /// If `child` is a child of `self`, return its name. pub fn find_name_by_child(&self, child: &Arc) -> Result { for index in 0.. { - let name = self.inode.get_entry(index)?; + let entry = self.inode.get_entry(index)?; + let name = entry.1; match name.as_ref() { "." | ".." => {} _ => { @@ -311,7 +311,7 @@ impl INode for MNode { Ok(self.find(false, name)?) } - fn get_entry(&self, id: usize) -> Result { + fn get_entry(&self, id: usize) -> Result<(usize, String)> { self.inode.get_entry(id) } diff --git a/rcore-fs-ramfs/src/lib.rs b/rcore-fs-ramfs/src/lib.rs index e7e90ab..5ce1fb8 100644 --- a/rcore-fs-ramfs/src/lib.rs +++ b/rcore-fs-ramfs/src/lib.rs @@ -1,8 +1,6 @@ #![cfg_attr(not(any(test, feature = "std")), no_std)] -#![feature(alloc)] extern crate alloc; -#[macro_use] extern crate log; use alloc::{ @@ -288,18 +286,18 @@ impl INode for LockedINode { } } - fn get_entry(&self, id: usize) -> Result { + fn get_entry(&self, id: usize) -> Result<(usize, String)> { let file = self.0.read(); if file.extra.type_ != FileType::Dir { return Err(FsError::NotDir); } match id { - 0 => Ok(String::from(".")), - 1 => Ok(String::from("..")), + 0 => Ok((0, String::from("."))), + 1 => Ok((1, String::from(".."))), i => { if let Some(s) = file.children.keys().nth(i - 2) { - Ok(s.to_string()) + Ok((id, s.to_string())) } else { Err(FsError::EntryNotFound) } diff --git a/rcore-fs-sefs/src/dev/std_impl.rs b/rcore-fs-sefs/src/dev/std_impl.rs index e6beaba..2b961f1 100644 --- a/rcore-fs-sefs/src/dev/std_impl.rs +++ b/rcore-fs-sefs/src/dev/std_impl.rs @@ -49,7 +49,7 @@ impl super::Storage for StdStorage { impl From for DeviceError { fn from(e: std::io::Error) -> Self { panic!("{:?}", e); - DeviceError + // DeviceError } } diff --git a/rcore-fs-sefs/src/lib.rs b/rcore-fs-sefs/src/lib.rs index 9210889..5c1c6ed 100644 --- a/rcore-fs-sefs/src/lib.rs +++ b/rcore-fs-sefs/src/lib.rs @@ -1,5 +1,4 @@ #![cfg_attr(not(any(test, feature = "std")), no_std)] -#![feature(alloc)] extern crate alloc; @@ -15,7 +14,6 @@ use core::fmt::{Debug, Error, Formatter}; use core::mem::uninitialized; use bitvec::BitVec; -use log::*; use rcore_fs::dev::TimeProvider; use rcore_fs::dirty::Dirty; use rcore_fs::vfs::{self, FileSystem, FsError, INode, Timespec}; @@ -411,7 +409,7 @@ impl vfs::INode for INodeImpl { let inode_id = self.get_file_inode_id(name).ok_or(FsError::EntryNotFound)?; Ok(self.fs.get_inode(inode_id)) } - fn get_entry(&self, id: usize) -> vfs::Result { + fn get_entry(&self, id: usize) -> vfs::Result<(usize, String)> { if self.disk_inode.read().type_ != FileType::Dir { return Err(FsError::NotDir); } @@ -419,7 +417,7 @@ impl vfs::INode for INodeImpl { return Err(FsError::EntryNotFound); }; let entry = self.file.read_direntry(id)?; - Ok(String::from(entry.name.as_ref())) + Ok((entry.id as usize, String::from(entry.name.as_ref()))) } fn io_control(&self, _cmd: u32, _data: usize) -> vfs::Result<()> { Err(FsError::NotSupported) diff --git a/rcore-fs-sfs/src/lib.rs b/rcore-fs-sfs/src/lib.rs index 3ce9c9c..ad8e824 100644 --- a/rcore-fs-sfs/src/lib.rs +++ b/rcore-fs-sfs/src/lib.rs @@ -1,5 +1,4 @@ #![cfg_attr(not(any(test, feature = "std")), no_std)] -#![feature(alloc)] #![feature(const_str_len)] extern crate alloc; @@ -671,7 +670,7 @@ impl vfs::INode for INodeImpl { let inode_id = self.get_file_inode_id(name).ok_or(FsError::EntryNotFound)?; Ok(self.fs.get_inode(inode_id)) } - fn get_entry(&self, id: usize) -> vfs::Result { + fn get_entry(&self, id: usize) -> vfs::Result<(usize, String)> { if self.disk_inode.read().type_ != FileType::Dir { return Err(FsError::NotDir); } @@ -679,7 +678,7 @@ impl vfs::INode for INodeImpl { return Err(FsError::EntryNotFound); }; let entry = self.read_direntry(id)?; - Ok(String::from(entry.name.as_ref())) + Ok((entry.id as usize, String::from(entry.name.as_ref()))) } fn io_control(&self, _cmd: u32, _data: usize) -> vfs::Result<()> { if self.metadata().unwrap().type_ != vfs::FileType::CharDevice { @@ -868,7 +867,9 @@ impl SimpleFileSystem { /// Get inode by id. Load if not in memory. /// ** Must ensure it's a valid INode ** fn get_inode(&self, id: INodeId) -> Arc { - assert!(!self.free_map.read()[id]); + if self.free_map.read()[id] { + panic!("INode id {} not found in SFS", id); + } // In the BTreeSet and not weak. if let Some(inode) = self.inodes.read().get(&id) { diff --git a/rcore-fs/src/file.rs b/rcore-fs/src/file.rs index e5acf84..d6cf221 100644 --- a/rcore-fs/src/file.rs +++ b/rcore-fs/src/file.rs @@ -36,7 +36,7 @@ impl File { self.inode.metadata() } - pub fn get_entry(&self, id: usize) -> Result { + pub fn get_entry(&self, id: usize) -> Result<(usize, String)> { self.inode.get_entry(id) } } diff --git a/rcore-fs/src/vfs.rs b/rcore-fs/src/vfs.rs index 55b7f4f..9d5fc6b 100644 --- a/rcore-fs/src/vfs.rs +++ b/rcore-fs/src/vfs.rs @@ -61,7 +61,7 @@ pub trait INode: Any + Sync + Send { fn find(&self, name: &str) -> Result>; /// Get the name of directory entry - fn get_entry(&self, id: usize) -> Result; + fn get_entry(&self, id: usize) -> Result<(usize, String)>; /// Control device fn io_control(&self, cmd: u32, data: usize) -> Result<()>; @@ -89,7 +89,7 @@ impl dyn INode { Ok((0..) .map(|i| self.get_entry(i)) .take_while(|result| result.is_ok()) - .filter_map(|result| result.ok()) + .filter_map(|result| result.ok().map(|s| s.1)) .collect()) } diff --git a/rust-toolchain b/rust-toolchain index bf867e0..e00fad6 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly +nightly-2019-07-14