Add a VFS::absolutePath(InodeIdentifier).

This is pretty inefficient for ext2fs. We walk the entire block group
containing the inode, searching through every directory for an entry
referencing this inode.

It might be a good idea to cache this information somehow. I'm not sure
how often we'll be searching for it.

Obviously there are multiple caching layers missing in the file system.
This commit is contained in:
Andreas Kling 2018-10-28 12:20:25 +01:00
parent 3f050c1972
commit 1d4af51250
Notes: sideshowbarker 2024-07-19 18:36:57 +09:00
11 changed files with 116 additions and 18 deletions

View file

@ -943,3 +943,35 @@ InodeIdentifier Ext2FileSystem::createInode(InodeIdentifier parentInode, const S
return { id(), inode };
}
InodeIdentifier Ext2FileSystem::findParentOfInode(InodeIdentifier inode) const
{
ASSERT(inode.fileSystemID() == id());
unsigned groupIndex = groupIndexFromInode(inode.index());
unsigned firstInodeInGroup = inodesPerGroup() * (groupIndex - 1);
Vector<InodeIdentifier> directoriesInGroup;
for (unsigned i = 0; i < inodesPerGroup(); ++i) {
auto e2inode = lookupExt2Inode(firstInodeInGroup + i);
if (!e2inode)
continue;
if (isDirectory(e2inode->i_mode)) {
directoriesInGroup.append({ id(), firstInodeInGroup + i });
}
}
InodeIdentifier foundParent;
for (auto& directory : directoriesInGroup) {
enumerateDirectoryInode(directory, [inode, directory, &foundParent] (auto& entry) {
if (entry.inode == inode) {
foundParent = directory;
return false;
}
return true;
});
if (foundParent.isValid())
break;
}
return foundParent;
}