diff --git a/sys/victoriafalls/fs/ext2/ext2_driver.cpp b/sys/victoriafalls/fs/ext2/ext2_driver.cpp index 491ec80..9483838 100644 --- a/sys/victoriafalls/fs/ext2/ext2_driver.cpp +++ b/sys/victoriafalls/fs/ext2/ext2_driver.cpp @@ -56,7 +56,7 @@ glcr::ErrorOr> Ext2Driver::ReadDirectory( dbgln("Reading non directory."); return glcr::INVALID_ARGUMENT; } - ASSIGN_OR_RETURN(mmth::OwnedMemoryRegion dir, ReadInode(inode)); + ASSIGN_OR_RETURN(mmth::OwnedMemoryRegion dir, ReadInode(inode_number, inode)); glcr::Vector directory; @@ -90,10 +90,14 @@ glcr::ErrorOr Ext2Driver::ReadFile( dbgln("Reading non file."); return glcr::INVALID_ARGUMENT; } - return ReadInode(inode); + return ReadInode(inode_number, inode); } -glcr::ErrorOr Ext2Driver::ReadInode(Inode* inode) { +glcr::ErrorOr Ext2Driver::ReadInode(uint64_t inode_num, + Inode* inode) { + if (inode_cache_.Contains(inode_num)) { + return inode_cache_.at(inode_num).Duplicate(); + } // This calculation is cursed. uint64_t real_block_cnt = (inode->blocks - 1) / (ext2_reader_->BlockSize() / 512) + 1; @@ -150,5 +154,7 @@ glcr::ErrorOr Ext2Driver::ReadInode(Inode* inode) { } } - return ext2_reader_->ReadBlocks(blocks_to_read); + ASSIGN_OR_RETURN(auto inode_mem, ext2_reader_->ReadBlocks(blocks_to_read)); + RET_ERR(inode_cache_.Insert(glcr::Move(inode_num), inode_mem.Duplicate())); + return inode_mem; } diff --git a/sys/victoriafalls/fs/ext2/ext2_driver.h b/sys/victoriafalls/fs/ext2/ext2_driver.h index e70ab84..b3600cc 100644 --- a/sys/victoriafalls/fs/ext2/ext2_driver.h +++ b/sys/victoriafalls/fs/ext2/ext2_driver.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -24,10 +25,12 @@ class Ext2Driver { private: glcr::SharedPtr ext2_reader_; glcr::UniquePtr inode_table_; + glcr::HashMap inode_cache_; Ext2Driver(const glcr::SharedPtr& reader, glcr::UniquePtr inode_table) : ext2_reader_(reader), inode_table_(glcr::Move(inode_table)) {} - glcr::ErrorOr ReadInode(Inode* inode); + glcr::ErrorOr ReadInode(uint64_t inode_num, + Inode* inode); };