From 464737fbe963254ea6e3d71e403cee3442936c98 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 7 Nov 2023 16:04:34 +0200 Subject: [PATCH] Kernel: Add method to TmpFS for looping over all (cached) inodes --- kernel/include/kernel/FS/TmpFS/FileSystem.h | 27 +++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/kernel/include/kernel/FS/TmpFS/FileSystem.h b/kernel/include/kernel/FS/TmpFS/FileSystem.h index e07008b1..36c423f8 100644 --- a/kernel/include/kernel/FS/TmpFS/FileSystem.h +++ b/kernel/include/kernel/FS/TmpFS/FileSystem.h @@ -26,6 +26,12 @@ namespace Kernel requires BAN::is_same_v; }; + template + concept for_each_inode_callback = requires(F func, BAN::RefPtr inode) + { + requires BAN::is_same_v; + }; + } @@ -58,6 +64,9 @@ namespace Kernel void free_block(size_t index); BAN::ErrorOr allocate_block(); + template + void for_each_inode(F callback); + private: struct PageInfo { @@ -149,4 +158,22 @@ namespace Kernel }); } + template + 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(); + } + } + } + } \ No newline at end of file