Kernel: Add method to TmpFS for looping over all (cached) inodes

This commit is contained in:
Bananymous 2023-11-07 16:04:34 +02:00
parent 07b5920f3f
commit 147cd93ed3
1 changed files with 27 additions and 0 deletions

View File

@ -26,6 +26,12 @@ namespace Kernel
requires BAN::is_same_v<decltype(func(buffer)), void>;
};
template<typename F>
concept for_each_inode_callback = requires(F func, BAN::RefPtr<TmpInode> inode)
{
requires BAN::is_same_v<decltype(func(inode)), BAN::Iteration>;
};
}
@ -58,6 +64,9 @@ namespace Kernel
void free_block(size_t index);
BAN::ErrorOr<size_t> allocate_block();
template<TmpFuncs::for_each_inode_callback F>
void for_each_inode(F callback);
private:
struct PageInfo
{
@ -149,4 +158,22 @@ namespace Kernel
});
}
template<TmpFuncs::for_each_inode_callback F>
void TmpFileSystem::for_each_inode(F callback)
{
LockGuard _(m_lock);
for (auto& [_, inode] : m_inode_cache)
{
switch (callback(inode))
{
case BAN::Iteration::Continue:
break;
case BAN::Iteration::Break:
return;
default:
ASSERT_NOT_REACHED();
}
}
}
}