untested single layer lookup named find

master
Ben Pig Chu 6 years ago
parent c744a3aea2
commit e640f78134

@ -396,6 +396,17 @@ impl vfs::INode for INode {
_ => unimplemented!(), _ => unimplemented!(),
} }
} }
fn find(&self, name: &str) -> vfs::Result<Ptr<vfs::INode>> {
let fs = self.fs.upgrade().unwrap();
let info = self.info().unwrap();
assert_eq!(info.type_, vfs::FileType::Dir);
let inode_id = self.get_file_inode_id(name);
if inode_id.is_none() {
return Err(());
}
let inode = fs.get_inode(inode_id.unwrap());
Ok(inode)
}
fn get_entry(&self,id: usize) -> vfs::Result<String> { fn get_entry(&self,id: usize) -> vfs::Result<String> {
assert_eq!(self.disk_inode.type_, FileType::Dir); assert_eq!(self.disk_inode.type_, FileType::Dir);
assert!(id<self.disk_inode.blocks as usize); assert!(id<self.disk_inode.blocks as usize);

@ -28,6 +28,8 @@ pub trait INode: Debug + Any {
/// user of the vfs api should call borrow_mut by itself /// user of the vfs api should call borrow_mut by itself
fn link(&mut self, name: &str, other:&mut INode) -> Result<()>; fn link(&mut self, name: &str, other:&mut INode) -> Result<()>;
fn lookup(&self, path: &str) -> Result<INodePtr>; fn lookup(&self, path: &str) -> Result<INodePtr>;
/// lookup with only one layer
fn find(&self, name: &str) -> Result<INodePtr>;
fn list(&self) -> Result<Vec<String>>; fn list(&self) -> Result<Vec<String>>;
/// like list()[id] /// like list()[id]
/// only get one item in list, often faster than list /// only get one item in list, often faster than list

Loading…
Cancel
Save