mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-09 20:41:04 -04:00
add fragment_chunkable
This commit is contained in:
parent
7b24687c56
commit
f54ac8d50e
@ -373,6 +373,7 @@ list(
|
||||
src/dwarfs/filesystem_extractor.cpp
|
||||
src/dwarfs/filesystem_v2.cpp
|
||||
src/dwarfs/filesystem_writer.cpp
|
||||
src/dwarfs/fragment_chunkable.cpp
|
||||
src/dwarfs/fragment_order_parser.cpp
|
||||
src/dwarfs/fstypes.cpp
|
||||
src/dwarfs/fs_section.cpp
|
||||
|
56
include/dwarfs/fragment_chunkable.h
Normal file
56
include/dwarfs/fragment_chunkable.h
Normal file
@ -0,0 +1,56 @@
|
||||
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||
/**
|
||||
* \author Marcus Holland-Moritz (github@mhxnet.de)
|
||||
* \copyright Copyright (c) Marcus Holland-Moritz
|
||||
*
|
||||
* This file is part of dwarfs.
|
||||
*
|
||||
* dwarfs is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* dwarfs is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with dwarfs. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "dwarfs/chunkable.h"
|
||||
|
||||
namespace dwarfs {
|
||||
|
||||
class categorizer_manager;
|
||||
class inode;
|
||||
class mmif;
|
||||
class single_inode_fragment;
|
||||
|
||||
class fragment_chunkable : public chunkable {
|
||||
public:
|
||||
fragment_chunkable(inode const& ino, single_inode_fragment& frag,
|
||||
file_off_t offset, mmif& mm,
|
||||
categorizer_manager const& catmgr);
|
||||
~fragment_chunkable();
|
||||
|
||||
size_t size() const override;
|
||||
std::string description() const override;
|
||||
std::span<uint8_t const> span() const override;
|
||||
void add_chunk(size_t block, size_t offset, size_t size) override;
|
||||
void release_until(size_t offset) override;
|
||||
|
||||
private:
|
||||
inode const& ino_;
|
||||
single_inode_fragment& frag_;
|
||||
file_off_t offset_;
|
||||
mmif& mm_;
|
||||
categorizer_manager const& catmgr_;
|
||||
};
|
||||
|
||||
} // namespace dwarfs
|
@ -45,6 +45,14 @@ class single_inode_fragment {
|
||||
file_off_t length() const { return length_; }
|
||||
file_off_t size() const { return length_; }
|
||||
|
||||
void add_chunk(size_t block, size_t offset, size_t size) {
|
||||
thrift::metadata::chunk c;
|
||||
c.block() = block;
|
||||
c.offset() = offset;
|
||||
c.size() = size;
|
||||
chunks_.push_back(c);
|
||||
}
|
||||
|
||||
std::span<thrift::metadata::chunk const> chunks() const { return chunks_; }
|
||||
|
||||
void extend(file_off_t length) { length_ += length; }
|
||||
|
65
src/dwarfs/fragment_chunkable.cpp
Normal file
65
src/dwarfs/fragment_chunkable.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
/* vim:set ts=2 sw=2 sts=2 et: */
|
||||
/**
|
||||
* \author Marcus Holland-Moritz (github@mhxnet.de)
|
||||
* \copyright Copyright (c) Marcus Holland-Moritz
|
||||
*
|
||||
* This file is part of dwarfs.
|
||||
*
|
||||
* dwarfs is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* dwarfs is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with dwarfs. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "dwarfs/categorizer.h"
|
||||
#include "dwarfs/entry.h"
|
||||
#include "dwarfs/fragment_chunkable.h"
|
||||
#include "dwarfs/inode.h"
|
||||
#include "dwarfs/inode_fragments.h"
|
||||
#include "dwarfs/mmif.h"
|
||||
|
||||
namespace dwarfs {
|
||||
|
||||
fragment_chunkable::fragment_chunkable(inode const& ino,
|
||||
single_inode_fragment& frag,
|
||||
file_off_t offset, mmif& mm,
|
||||
categorizer_manager const& catmgr)
|
||||
: ino_{ino}
|
||||
, frag_{frag}
|
||||
, offset_{offset}
|
||||
, mm_{mm}
|
||||
, catmgr_{catmgr} {}
|
||||
|
||||
fragment_chunkable::~fragment_chunkable() = default;
|
||||
|
||||
size_t fragment_chunkable::size() const { return frag_.size(); }
|
||||
|
||||
std::string fragment_chunkable::description() const {
|
||||
return fmt::format("{} fragment at offset {} of inode {} [{}] - size: {}",
|
||||
catmgr_.category_name(frag_.category().value()), offset_,
|
||||
ino_.num(), ino_.any()->name(), size());
|
||||
}
|
||||
|
||||
std::span<uint8_t const> fragment_chunkable::span() const {
|
||||
return mm_.span(offset_, frag_.size());
|
||||
}
|
||||
|
||||
void fragment_chunkable::add_chunk(size_t block, size_t offset, size_t size) {
|
||||
frag_.add_chunk(block, offset, size);
|
||||
}
|
||||
|
||||
void fragment_chunkable::release_until(size_t offset) {
|
||||
mm_.release_until(offset_ + offset);
|
||||
}
|
||||
|
||||
} // namespace dwarfs
|
Loading…
x
Reference in New Issue
Block a user