From 147cd93ed3a9ce6ebcd6f96857726461d66e99e9 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 e07008b1a7..36c423f825 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