fix get_entry

master
WangRunji 6 years ago
parent d071071342
commit f3d4811305

@ -47,7 +47,7 @@ impl VfsFuse {
perm: info.mode, perm: info.mode,
nlink: info.nlinks as u32, nlink: info.nlinks as u32,
uid: 501, // info.uid as u32, uid: 501, // info.uid as u32,
gid: 20, // info.gid as u32, gid: 20, // info.gid as u32,
rdev: 0, rdev: 0,
flags: 0, flags: 0,
} }
@ -294,10 +294,12 @@ impl Filesystem for VfsFuse {
mut reply: ReplyDirectory, mut reply: ReplyDirectory,
) { ) {
let inode = try_vfs!(reply, self.get_inode(ino)); let inode = try_vfs!(reply, self.get_inode(ino));
let info = try_vfs!(reply, inode.metadata()); for i in offset as usize.. {
let count = info.size; let name = match inode.get_entry(i) {
for i in offset as usize..count { Ok(name) => name,
let name = inode.get_entry(i).unwrap(); Err(vfs::FsError::EntryNotFound) => break,
e @ _ => try_vfs!(reply, e),
};
let inode = try_vfs!(reply, inode.find(name.as_str())); let inode = try_vfs!(reply, inode.find(name.as_str()));
let info = try_vfs!(reply, inode.metadata()); let info = try_vfs!(reply, inode.metadata());
let kind = Self::trans_type(info.type_); let kind = Self::trans_type(info.type_);

@ -1,9 +1,9 @@
use crate::dev::DevError;
use alloc::{string::String, sync::Arc, vec::Vec}; use alloc::{string::String, sync::Arc, vec::Vec};
use core::any::Any; use core::any::Any;
use core::fmt; use core::fmt;
use core::result; use core::result;
use core::str; use core::str;
use crate::dev::DevError;
/// Abstract file system object such as file or directory. /// Abstract file system object such as file or directory.
pub trait INode: Any + Sync + Send { pub trait INode: Any + Sync + Send {
@ -73,7 +73,11 @@ impl INode {
if info.type_ != FileType::Dir { if info.type_ != FileType::Dir {
return Err(FsError::NotDir); return Err(FsError::NotDir);
} }
(0..info.size).map(|i| self.get_entry(i)).collect() Ok((0..)
.map(|i| self.get_entry(i))
.take_while(|result| result.is_ok())
.filter_map(|result| result.ok())
.collect())
} }
/// Lookup path from current INode, and do not follow symlinks /// Lookup path from current INode, and do not follow symlinks
@ -116,8 +120,7 @@ impl INode {
follow_times -= 1; follow_times -= 1;
let mut content = [0u8; 256]; let mut content = [0u8; 256];
let len = inode.read_at(0, &mut content)?; let len = inode.read_at(0, &mut content)?;
let path = str::from_utf8(&content[..len]) let path = str::from_utf8(&content[..len]).map_err(|_| FsError::NotDir)?;
.map_err(|_| FsError::NotDir)?;
// result remains unchanged // result remains unchanged
rest_path = { rest_path = {
let mut new_path = String::from(path); let mut new_path = String::from(path);

Loading…
Cancel
Save