get_entry(), as a different design from list()

master
Ben Pig Chu 6 years ago
parent 4a97d89b8f
commit c744a3aea2

@ -396,6 +396,14 @@ impl vfs::INode for INode {
_ => unimplemented!(),
}
}
fn get_entry(&self,id: usize) -> vfs::Result<String> {
assert_eq!(self.disk_inode.type_, FileType::Dir);
assert!(id<self.disk_inode.blocks as usize);
use vfs::INode;
let mut entry: DiskEntry = unsafe { uninitialized() };
self._read_at(id as usize * BLKSIZE, entry.as_buf_mut()).unwrap();
Ok(String::from(entry.name.as_ref()))
}
fn list(&self) -> vfs::Result<Vec<String>> {
assert_eq!(self.disk_inode.type_, FileType::Dir);

@ -62,6 +62,9 @@ fn print_root() {
let files = root.borrow().list().unwrap();
println!("{:?}", files);
assert_eq!(files[3],root.borrow().get_entry(3).unwrap());
sfs.sync().unwrap();
}
#[test]

@ -29,6 +29,9 @@ pub trait INode: Debug + Any {
fn link(&mut self, name: &str, other:&mut INode) -> Result<()>;
fn lookup(&self, path: &str) -> Result<INodePtr>;
fn list(&self) -> Result<Vec<String>>;
/// like list()[id]
/// only get one item in list, often faster than list
fn get_entry(&self,id: usize) -> Result<String>;
// fn io_ctrl(&mut self, op: u32, data: &[u8]) -> Result<()>;
fn fs(&self) -> Weak<FileSystem>;
/// this is used to implement dynamics cast

Loading…
Cancel
Save