mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-28 15:28:55 +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:
parent
3f050c1972
commit
1d4af51250
Notes:
sideshowbarker
2024-07-19 18:36:57 +09:00
Author: https://github.com/awesomekling
Commit: 1d4af51250
11 changed files with 116 additions and 18 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue