Ext2: read_dir implementation
This commit is contained in:
parent
8c9521e893
commit
e21b34a3e7
|
@ -5,10 +5,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pub enum FsError {
|
pub enum FsError {
|
||||||
|
EndOfFile,
|
||||||
InodeNotFound,
|
InodeNotFound,
|
||||||
InvalidDevice,
|
InvalidDevice,
|
||||||
IsDirectory,
|
IsDirectory,
|
||||||
EndOfFile,
|
NotADirectory,
|
||||||
UnsupportedOperation,
|
UnsupportedOperation,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +29,7 @@ impl Into<FsError> for ext2::error::Error {
|
||||||
by_inodes: _,
|
by_inodes: _,
|
||||||
} => todo!(),
|
} => todo!(),
|
||||||
ext2::error::Error::InodeNotFound { inode: _ } => FsError::InodeNotFound,
|
ext2::error::Error::InodeNotFound { inode: _ } => FsError::InodeNotFound,
|
||||||
ext2::error::Error::NotADirectory { inode: _, name: _ } => todo!(),
|
ext2::error::Error::NotADirectory { inode: _, name: _ } => FsError::NotADirectory,
|
||||||
ext2::error::Error::NotAbsolute { name: _ } => todo!(),
|
ext2::error::Error::NotAbsolute { name: _ } => todo!(),
|
||||||
ext2::error::Error::NotFound { name: _ } => todo!(),
|
ext2::error::Error::NotFound { name: _ } => todo!(),
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,8 +57,17 @@ where
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_dir(&self, _node: &FsNode, _index: usize) -> Result<DirectoryEntry> {
|
fn read_dir(&self, node: &FsNode, index: usize) -> Result<DirectoryEntry> {
|
||||||
todo!()
|
let inode = self
|
||||||
|
.fs
|
||||||
|
.inode_nth(node.inode as usize)
|
||||||
|
.ok_or_else(|| FsError::InodeNotFound)?;
|
||||||
|
let mut dir = inode.directory().ok_or_else(|| FsError::NotADirectory)?;
|
||||||
|
let entry = dir.nth(index)
|
||||||
|
.ok_or_else(|| FsError::InodeNotFound)?
|
||||||
|
.map_err(|e| e.into())?;
|
||||||
|
|
||||||
|
Ok(DirectoryEntry::new(entry.file_name_string(), entry.inode))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_dir(&self, _node: &FsNode, _name: &str) -> Result<FsNode> {
|
fn find_dir(&self, _node: &FsNode, _name: &str) -> Result<FsNode> {
|
||||||
|
|
|
@ -156,3 +156,12 @@ pub struct DirectoryEntry {
|
||||||
name: String,
|
name: String,
|
||||||
inode: usize,
|
inode: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl DirectoryEntry {
|
||||||
|
fn new(name: String, inode: usize) -> Self {
|
||||||
|
Self {
|
||||||
|
name,
|
||||||
|
inode,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue