diff --git a/rcore-fs-fuse/src/fuse.rs b/rcore-fs-fuse/src/fuse.rs index c15c500..a57efd2 100644 --- a/rcore-fs-fuse/src/fuse.rs +++ b/rcore-fs-fuse/src/fuse.rs @@ -47,7 +47,7 @@ impl VfsFuse { perm: info.mode, nlink: info.nlinks as u32, uid: 501, // info.uid as u32, - gid: 20, // info.gid as u32, + gid: 20, // info.gid as u32, rdev: 0, flags: 0, } @@ -294,10 +294,12 @@ impl Filesystem for VfsFuse { mut reply: ReplyDirectory, ) { let inode = try_vfs!(reply, self.get_inode(ino)); - let info = try_vfs!(reply, inode.metadata()); - let count = info.size; - for i in offset as usize..count { - let name = inode.get_entry(i).unwrap(); + for i in offset as usize.. { + let name = match inode.get_entry(i) { + Ok(name) => name, + Err(vfs::FsError::EntryNotFound) => break, + e @ _ => try_vfs!(reply, e), + }; let inode = try_vfs!(reply, inode.find(name.as_str())); let info = try_vfs!(reply, inode.metadata()); let kind = Self::trans_type(info.type_); diff --git a/rcore-fs/src/vfs.rs b/rcore-fs/src/vfs.rs index 8d27c63..eb9b113 100644 --- a/rcore-fs/src/vfs.rs +++ b/rcore-fs/src/vfs.rs @@ -1,9 +1,9 @@ +use crate::dev::DevError; use alloc::{string::String, sync::Arc, vec::Vec}; use core::any::Any; use core::fmt; use core::result; use core::str; -use crate::dev::DevError; /// Abstract file system object such as file or directory. pub trait INode: Any + Sync + Send { @@ -73,7 +73,11 @@ impl INode { if info.type_ != FileType::Dir { 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 @@ -116,8 +120,7 @@ impl INode { follow_times -= 1; let mut content = [0u8; 256]; let len = inode.read_at(0, &mut content)?; - let path = str::from_utf8(&content[..len]) - .map_err(|_| FsError::NotDir)?; + let path = str::from_utf8(&content[..len]).map_err(|_| FsError::NotDir)?; // result remains unchanged rest_path = { let mut new_path = String::from(path);