use crate::{
block_read::BlockRead,
dir,
error::{Error, Result},
inode::Dinode,
path::Path,
superblock::Superblock,
};
pub(crate) fn resolve<R: BlockRead>(
reader: &mut R,
sb: &Superblock,
path: Path<'_>,
) -> Result<u64> {
let mut ino = sb.rootino;
for comp in path.components() {
if comp == b".." {
return Err(Error::NotFound {
component: "parent_dir_unsupported",
});
}
let dir_inode = Dinode::read(reader, sb, ino)?;
if !dir_inode.is_dir() {
return Err(Error::NotFound {
component: "not_a_directory",
});
}
let entries = dir::read_dir(reader, sb, &dir_inode)?;
let next = entries
.iter()
.find(|e| e.name == comp)
.ok_or(Error::NotFound {
component: "no_such_entry",
})?;
ino = next.inumber;
}
Ok(ino)
}