Ext2: read_dir implementation

This commit is contained in:
TheOddGarlic 2022-08-04 13:31:29 +03:00
parent 8c9521e893
commit e21b34a3e7
3 changed files with 23 additions and 4 deletions

View file

@ -5,10 +5,11 @@
*/
pub enum FsError {
EndOfFile,
InodeNotFound,
InvalidDevice,
IsDirectory,
EndOfFile,
NotADirectory,
UnsupportedOperation,
}
@ -28,7 +29,7 @@ impl Into<FsError> for ext2::error::Error {
by_inodes: _,
} => todo!(),
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::NotFound { name: _ } => todo!(),
}

View file

@ -57,8 +57,17 @@ where
todo!()
}
fn read_dir(&self, _node: &FsNode, _index: usize) -> Result<DirectoryEntry> {
todo!()
fn read_dir(&self, node: &FsNode, index: usize) -> Result<DirectoryEntry> {
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> {

View file

@ -156,3 +156,12 @@ pub struct DirectoryEntry {
name: String,
inode: usize,
}
impl DirectoryEntry {
fn new(name: String, inode: usize) -> Self {
Self {
name,
inode,
}
}
}