From 5858c1c53deea79db2ff14983dbcba1de4416252 Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Sat, 28 Nov 2020 01:40:29 +0100 Subject: [PATCH] metadata_v2: clean up inode_manager --- include/dwarfs/fstypes.h | 65 ---------------------------------- include/dwarfs/inode.h | 3 +- include/dwarfs/inode_manager.h | 11 ++---- src/dwarfs/inode_manager.cpp | 52 +++++---------------------- src/dwarfs/scanner.cpp | 16 ++++----- 5 files changed, 20 insertions(+), 127 deletions(-) diff --git a/include/dwarfs/fstypes.h b/include/dwarfs/fstypes.h index 80dbc3f8..4554f3fe 100644 --- a/include/dwarfs/fstypes.h +++ b/include/dwarfs/fstypes.h @@ -132,71 +132,6 @@ struct directory { } u; }; -struct meta_config { - uint8_t block_size_bits; - dir_entry_type de_type; - uint16_t unused; - uint32_t inode_count; - uint64_t orig_fs_size; - uint32_t chunk_index_offset; - uint32_t inode_index_offset; -}; - -using chunk_type = uint64_t; - -template -struct chunk_access { - static_assert(BlockSizeBits < 32, "invalid value for BlockSizeBits"); - - static const unsigned block_bits = 64 - 2 * BlockSizeBits; - static const unsigned block_shift = 64 - block_bits; - static const chunk_type block_mask = - (static_cast(1) << block_bits) - 1; - static const unsigned offset_shift = BlockSizeBits; - static const chunk_type offset_mask = - (static_cast(1) << BlockSizeBits) - 1; - static const unsigned size_shift = 0; - static const chunk_type size_mask = - (static_cast(1) << BlockSizeBits) - 1; - static const chunk_type max_size = size_mask + 1; - - static void set(chunk_type& chunk, size_t block, size_t offset, size_t size) { - if (block > block_mask) { - std::cerr << "block out of range: " << block << " > " << block_mask - << " [" << block_bits << "]"; - throw std::runtime_error("block out of range"); - } - - if (offset > offset_mask) { - std::cerr << "offset out of range: " << offset << " > " << offset_mask - << " [" << block_bits << "]"; - throw std::runtime_error("offset out of range"); - } - - if (size > max_size or size == 0) { - std::cerr << "size out of range: " << size << " > " << size_mask << " [" - << block_bits << "]"; - throw std::runtime_error("size out of range"); - } - - chunk = (static_cast(block) << block_shift) | - (static_cast(offset) << offset_shift) | - (static_cast(size - 1) << size_shift); - } - - static size_t block(chunk_type chunk) { - return (chunk >> block_shift) & block_mask; - }; - - static size_t offset(chunk_type chunk) { - return (chunk >> offset_shift) & offset_mask; - }; - - static size_t size(chunk_type chunk) { - return ((chunk >> size_shift) & size_mask) + 1; - }; -}; - std::string get_compression_name(compression_type type); std::string get_section_name(section_type type); diff --git a/include/dwarfs/inode.h b/include/dwarfs/inode.h index 06899890..14ab3e22 100644 --- a/include/dwarfs/inode.h +++ b/include/dwarfs/inode.h @@ -41,8 +41,7 @@ class inode : public file_interface { virtual uint32_t similarity_hash() const = 0; virtual const file_interface* any() const = 0; // TODO virtual void add_chunk(size_t block, size_t offset, size_t size) = 0; - virtual const std::vector& chunks() const = 0; virtual void - append_chunks(std::vector& vec) const = 0; + append_chunks_to(std::vector& vec) const = 0; }; } // namespace dwarfs diff --git a/include/dwarfs/inode_manager.h b/include/dwarfs/inode_manager.h index f882c893..5971fb72 100644 --- a/include/dwarfs/inode_manager.h +++ b/include/dwarfs/inode_manager.h @@ -34,23 +34,16 @@ class script; class inode_manager { public: - static std::shared_ptr create(unsigned block_size_bits); + static std::unique_ptr create(); virtual ~inode_manager() = default; - virtual std::shared_ptr create() = 0; + virtual std::shared_ptr create_inode() = 0; virtual size_t count() const = 0; - virtual size_t block_size() const = 0; - virtual unsigned block_size_bits() const = 0; - virtual size_t chunk_size() const = 0; virtual void order_inodes() = 0; virtual void order_inodes(std::shared_ptr