master
Harry Cheng 5 years ago
parent 1e623ab4f1
commit 306ff01031

@ -1,5 +1,4 @@
#![cfg_attr(not(any(test, feature = "std")), no_std)] #![cfg_attr(not(any(test, feature = "std")), no_std)]
#![feature(alloc)]
extern crate alloc; extern crate alloc;

@ -1,4 +1,3 @@
#[macro_use]
extern crate log; extern crate log;
#[cfg(feature = "use_fuse")] #[cfg(feature = "use_fuse")]

@ -1,5 +1,4 @@
#![cfg_attr(not(any(test, feature = "std")), no_std)] #![cfg_attr(not(any(test, feature = "std")), no_std)]
#![feature(alloc)]
extern crate alloc; extern crate alloc;
#[macro_use] #[macro_use]
@ -210,7 +209,8 @@ impl MNode {
/// If `child` is a child of `self`, return its name. /// If `child` is a child of `self`, return its name.
pub fn find_name_by_child(&self, child: &Arc<MNode>) -> Result<String> { pub fn find_name_by_child(&self, child: &Arc<MNode>) -> Result<String> {
for index in 0.. { 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() { match name.as_ref() {
"." | ".." => {} "." | ".." => {}
_ => { _ => {
@ -311,7 +311,7 @@ impl INode for MNode {
Ok(self.find(false, name)?) Ok(self.find(false, name)?)
} }
fn get_entry(&self, id: usize) -> Result<String> { fn get_entry(&self, id: usize) -> Result<(usize, String)> {
self.inode.get_entry(id) self.inode.get_entry(id)
} }

@ -1,8 +1,6 @@
#![cfg_attr(not(any(test, feature = "std")), no_std)] #![cfg_attr(not(any(test, feature = "std")), no_std)]
#![feature(alloc)]
extern crate alloc; extern crate alloc;
#[macro_use]
extern crate log; extern crate log;
use alloc::{ use alloc::{
@ -288,18 +286,18 @@ impl INode for LockedINode {
} }
} }
fn get_entry(&self, id: usize) -> Result<String> { fn get_entry(&self, id: usize) -> Result<(usize, String)> {
let file = self.0.read(); let file = self.0.read();
if file.extra.type_ != FileType::Dir { if file.extra.type_ != FileType::Dir {
return Err(FsError::NotDir); return Err(FsError::NotDir);
} }
match id { match id {
0 => Ok(String::from(".")), 0 => Ok((0, String::from("."))),
1 => Ok(String::from("..")), 1 => Ok((1, String::from(".."))),
i => { i => {
if let Some(s) = file.children.keys().nth(i - 2) { if let Some(s) = file.children.keys().nth(i - 2) {
Ok(s.to_string()) Ok((id, s.to_string()))
} else { } else {
Err(FsError::EntryNotFound) Err(FsError::EntryNotFound)
} }

@ -49,7 +49,7 @@ impl super::Storage for StdStorage {
impl From<std::io::Error> for DeviceError { impl From<std::io::Error> for DeviceError {
fn from(e: std::io::Error) -> Self { fn from(e: std::io::Error) -> Self {
panic!("{:?}", e); panic!("{:?}", e);
DeviceError // DeviceError
} }
} }

@ -1,5 +1,4 @@
#![cfg_attr(not(any(test, feature = "std")), no_std)] #![cfg_attr(not(any(test, feature = "std")), no_std)]
#![feature(alloc)]
extern crate alloc; extern crate alloc;
@ -15,7 +14,6 @@ use core::fmt::{Debug, Error, Formatter};
use core::mem::uninitialized; use core::mem::uninitialized;
use bitvec::BitVec; use bitvec::BitVec;
use log::*;
use rcore_fs::dev::TimeProvider; use rcore_fs::dev::TimeProvider;
use rcore_fs::dirty::Dirty; use rcore_fs::dirty::Dirty;
use rcore_fs::vfs::{self, FileSystem, FsError, INode, Timespec}; 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)?; let inode_id = self.get_file_inode_id(name).ok_or(FsError::EntryNotFound)?;
Ok(self.fs.get_inode(inode_id)) Ok(self.fs.get_inode(inode_id))
} }
fn get_entry(&self, id: usize) -> vfs::Result<String> { fn get_entry(&self, id: usize) -> vfs::Result<(usize, String)> {
if self.disk_inode.read().type_ != FileType::Dir { if self.disk_inode.read().type_ != FileType::Dir {
return Err(FsError::NotDir); return Err(FsError::NotDir);
} }
@ -419,7 +417,7 @@ impl vfs::INode for INodeImpl {
return Err(FsError::EntryNotFound); return Err(FsError::EntryNotFound);
}; };
let entry = self.file.read_direntry(id)?; 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<()> { fn io_control(&self, _cmd: u32, _data: usize) -> vfs::Result<()> {
Err(FsError::NotSupported) Err(FsError::NotSupported)

@ -1,5 +1,4 @@
#![cfg_attr(not(any(test, feature = "std")), no_std)] #![cfg_attr(not(any(test, feature = "std")), no_std)]
#![feature(alloc)]
#![feature(const_str_len)] #![feature(const_str_len)]
extern crate alloc; 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)?; let inode_id = self.get_file_inode_id(name).ok_or(FsError::EntryNotFound)?;
Ok(self.fs.get_inode(inode_id)) Ok(self.fs.get_inode(inode_id))
} }
fn get_entry(&self, id: usize) -> vfs::Result<String> { fn get_entry(&self, id: usize) -> vfs::Result<(usize, String)> {
if self.disk_inode.read().type_ != FileType::Dir { if self.disk_inode.read().type_ != FileType::Dir {
return Err(FsError::NotDir); return Err(FsError::NotDir);
} }
@ -679,7 +678,7 @@ impl vfs::INode for INodeImpl {
return Err(FsError::EntryNotFound); return Err(FsError::EntryNotFound);
}; };
let entry = self.read_direntry(id)?; 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<()> { fn io_control(&self, _cmd: u32, _data: usize) -> vfs::Result<()> {
if self.metadata().unwrap().type_ != vfs::FileType::CharDevice { if self.metadata().unwrap().type_ != vfs::FileType::CharDevice {
@ -868,7 +867,9 @@ impl SimpleFileSystem {
/// Get inode by id. Load if not in memory. /// Get inode by id. Load if not in memory.
/// ** Must ensure it's a valid INode ** /// ** Must ensure it's a valid INode **
fn get_inode(&self, id: INodeId) -> Arc<INodeImpl> { fn get_inode(&self, id: INodeId) -> Arc<INodeImpl> {
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. // In the BTreeSet and not weak.
if let Some(inode) = self.inodes.read().get(&id) { if let Some(inode) = self.inodes.read().get(&id) {

@ -36,7 +36,7 @@ impl File {
self.inode.metadata() self.inode.metadata()
} }
pub fn get_entry(&self, id: usize) -> Result<String> { pub fn get_entry(&self, id: usize) -> Result<(usize, String)> {
self.inode.get_entry(id) self.inode.get_entry(id)
} }
} }

@ -61,7 +61,7 @@ pub trait INode: Any + Sync + Send {
fn find(&self, name: &str) -> Result<Arc<dyn INode>>; fn find(&self, name: &str) -> Result<Arc<dyn INode>>;
/// Get the name of directory entry /// Get the name of directory entry
fn get_entry(&self, id: usize) -> Result<String>; fn get_entry(&self, id: usize) -> Result<(usize, String)>;
/// Control device /// Control device
fn io_control(&self, cmd: u32, data: usize) -> Result<()>; fn io_control(&self, cmd: u32, data: usize) -> Result<()>;
@ -89,7 +89,7 @@ impl dyn INode {
Ok((0..) Ok((0..)
.map(|i| self.get_entry(i)) .map(|i| self.get_entry(i))
.take_while(|result| result.is_ok()) .take_while(|result| result.is_ok())
.filter_map(|result| result.ok()) .filter_map(|result| result.ok().map(|s| s.1))
.collect()) .collect())
} }

@ -1 +1 @@
nightly nightly-2019-07-14

Loading…
Cancel
Save