From 2ad8ae4cdf002cb77a4788ac6c5adde895035d87 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Fri, 4 Apr 2025 22:52:16 +0200 Subject: [PATCH] feat(filesystem_v2): add `cache_all_blocks` method --- include/dwarfs/reader/filesystem_v2.h | 3 +++ include/dwarfs/reader/internal/inode_reader_v2.h | 3 +++ src/reader/filesystem_v2.cpp | 2 ++ src/reader/internal/inode_reader_v2.cpp | 6 ++++++ 4 files changed, 14 insertions(+) diff --git a/include/dwarfs/reader/filesystem_v2.h b/include/dwarfs/reader/filesystem_v2.h index ff284cd4..bfb3439d 100644 --- a/include/dwarfs/reader/filesystem_v2.h +++ b/include/dwarfs/reader/filesystem_v2.h @@ -361,6 +361,8 @@ class filesystem_v2 { return impl_->cache_blocks_by_category(category); } + void cache_all_blocks() const { impl_->cache_all_blocks(); } + class impl { public: virtual ~impl() = default; @@ -457,6 +459,7 @@ class filesystem_v2 { virtual std::optional get_block_category(size_t block_number) const = 0; virtual void cache_blocks_by_category(std::string_view category) const = 0; + virtual void cache_all_blocks() const = 0; }; private: diff --git a/include/dwarfs/reader/internal/inode_reader_v2.h b/include/dwarfs/reader/internal/inode_reader_v2.h index 75e47bfa..145c95c5 100644 --- a/include/dwarfs/reader/internal/inode_reader_v2.h +++ b/include/dwarfs/reader/internal/inode_reader_v2.h @@ -105,6 +105,8 @@ class inode_reader_v2 { impl_->cache_blocks(blocks); } + void cache_all_blocks() const { impl_->cache_all_blocks(); } + class impl { public: virtual ~impl() = default; @@ -127,6 +129,7 @@ class inode_reader_v2 { virtual void set_cache_tidy_config(cache_tidy_config const& cfg) = 0; virtual size_t num_blocks() const = 0; virtual void cache_blocks(std::span blocks) const = 0; + virtual void cache_all_blocks() const = 0; }; private: diff --git a/src/reader/filesystem_v2.cpp b/src/reader/filesystem_v2.cpp index a2f7e620..242a671d 100644 --- a/src/reader/filesystem_v2.cpp +++ b/src/reader/filesystem_v2.cpp @@ -316,6 +316,8 @@ class filesystem_ final : public filesystem_v2::impl { ir_.cache_blocks(meta_.get_block_numbers_by_category(category)); } + void cache_all_blocks() const override { ir_.cache_all_blocks(); } + private: filesystem_info const* get_info(fsinfo_options const& opts) const; void check_section(fs_section const& section) const; diff --git a/src/reader/internal/inode_reader_v2.cpp b/src/reader/internal/inode_reader_v2.cpp index 6b352a68..cef08ddb 100644 --- a/src/reader/internal/inode_reader_v2.cpp +++ b/src/reader/internal/inode_reader_v2.cpp @@ -158,6 +158,12 @@ class inode_reader_ final : public inode_reader_v2::impl { } } + void cache_all_blocks() const override { + for (size_t i = 0; i < cache_.block_count(); ++i) { + cache_.get(i, 0, 1); + } + } + private: using offset_cache_type = basic_offset_cache