mirror of
https://github.com/RGBCube/serenity
synced 2025-05-15 09:44:58 +00:00
Kernel: Make Inode::lookup() return a RefPtr<Inode>
Previously this API would return an InodeIdentifier, which meant that there was a race in path resolution where an inode could be unlinked in between finding the InodeIdentifier for a path component, and actually resolving that to an Inode object. Attaching a test that would quickly trip an assertion before. Test: Kernel/path-resolution-race.cpp
This commit is contained in:
parent
5aa37f6f5c
commit
c44b4d61f3
11 changed files with 50 additions and 36 deletions
|
@ -1493,14 +1493,14 @@ void Ext2FSInode::populate_lookup_cache() const
|
|||
m_lookup_cache = move(children);
|
||||
}
|
||||
|
||||
InodeIdentifier Ext2FSInode::lookup(StringView name)
|
||||
RefPtr<Inode> Ext2FSInode::lookup(StringView name)
|
||||
{
|
||||
ASSERT(is_directory());
|
||||
populate_lookup_cache();
|
||||
LOCKER(m_lock);
|
||||
auto it = m_lookup_cache.find(name.hash(), [&](auto& entry) { return entry.key == name; });
|
||||
if (it != m_lookup_cache.end())
|
||||
return { fsid(), (*it).value };
|
||||
return fs().get_inode({ fsid(), (*it).value });
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue