1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-15 09:44:58 +00:00

Kernel/Ext2FS: Cache the root inode in a member variable

We often get queried for the root inode, and it will always be cached
in memory anyway, so let's make Ext2FS::root_inode() fast by keeping
the root inode in a dedicated member variable.
This commit is contained in:
Andreas Kling 2021-07-18 01:29:54 +02:00
parent 9457d83986
commit 58c6d30f6a
4 changed files with 13 additions and 4 deletions

View file

@ -145,12 +145,18 @@ bool Ext2FS::initialize()
}
}
m_root_inode = static_ptr_cast<Ext2FSInode>(get_inode({ fsid(), EXT2_ROOT_INO }));
if (!m_root_inode) {
dbgln("Ext2FS: failed to acquire root inode");
return false;
}
return true;
}
NonnullRefPtr<Inode> Ext2FS::root_inode() const
{
return *get_inode({ fsid(), EXT2_ROOT_INO });
return *m_root_inode;
}
bool Ext2FS::find_block_containing_inode(InodeIndex inode, BlockIndex& block_index, unsigned& offset) const
@ -1778,7 +1784,7 @@ unsigned Ext2FS::free_inode_count() const
return super_block().s_free_inodes_count;
}
KResult Ext2FS::prepare_to_unmount() const
KResult Ext2FS::prepare_to_unmount()
{
MutexLocker locker(m_lock);
@ -1788,6 +1794,7 @@ KResult Ext2FS::prepare_to_unmount() const
}
m_inode_cache.clear();
m_root_inode = nullptr;
return KSuccess;
}
}