mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-25 02:40:49 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user