mirror of
https://github.com/mhx/dwarfs.git
synced 2025-08-04 02:06:22 -04:00
Deprecate (chunk|link)_inode_offset
These can be determined at run-time. This also magically fixes links on file systems created with pre 0.2.3 releases.
This commit is contained in:
parent
0f9bc1c716
commit
13aaf6737c
@ -101,9 +101,14 @@ class metadata_ : public metadata_v2::impl {
|
||||
: data_(data)
|
||||
, meta_(map_frozen<thrift::metadata::metadata>(schema, data_))
|
||||
, root_(meta_.entries()[meta_.entry_index()[0]], &meta_)
|
||||
, log_(lgr)
|
||||
, inode_offset_(inode_offset)
|
||||
, chunk_index_offset_(meta_.chunk_index_offset())
|
||||
, log_(lgr) {}
|
||||
, chunk_index_offset_(
|
||||
find_index_offset(meta_.entry_index().size(),
|
||||
[](uint16_t mode) { return S_ISREG(mode); }))
|
||||
, link_index_offset_(find_index_offset(
|
||||
chunk_index_offset_, [](uint16_t mode) { return S_ISLNK(mode); })) {
|
||||
}
|
||||
|
||||
void dump(std::ostream& os, int detail_level,
|
||||
std::function<void(const std::string&, uint32_t)> const& icb)
|
||||
@ -154,6 +159,19 @@ class metadata_ : public metadata_v2::impl {
|
||||
return make_entry_view(meta_.entry_index()[inode]);
|
||||
}
|
||||
|
||||
template <typename Func>
|
||||
size_t find_index_offset(size_t last, Func&& func) const {
|
||||
auto range = boost::irange(size_t(0), last);
|
||||
|
||||
auto it =
|
||||
std::upper_bound(range.begin(), range.end(), 0, [&](int, auto inode) {
|
||||
auto e = make_entry_view_from_inode(inode);
|
||||
return bool(func(e.mode()));
|
||||
});
|
||||
|
||||
return *it;
|
||||
}
|
||||
|
||||
directory_view make_directory_view(entry_view entry) const {
|
||||
return directory_view(entry, &meta_);
|
||||
}
|
||||
@ -205,15 +223,16 @@ class metadata_ : public metadata_v2::impl {
|
||||
|
||||
std::string_view link_value(entry_view entry) const {
|
||||
return meta_
|
||||
.links()[meta_.link_index()[entry.inode() - meta_.link_index_offset()]];
|
||||
.links()[meta_.link_index()[entry.inode() - link_index_offset_]];
|
||||
}
|
||||
|
||||
folly::ByteRange data_;
|
||||
MappedFrozen<thrift::metadata::metadata> meta_;
|
||||
entry_view root_;
|
||||
log_proxy<LoggerPolicy> log_;
|
||||
const int inode_offset_;
|
||||
const int chunk_index_offset_;
|
||||
log_proxy<LoggerPolicy> log_;
|
||||
const int link_index_offset_;
|
||||
};
|
||||
|
||||
template <typename LoggerPolicy>
|
||||
@ -534,7 +553,7 @@ template <typename LoggerPolicy>
|
||||
std::optional<chunk_range>
|
||||
metadata_<LoggerPolicy>::get_chunks(int inode) const {
|
||||
std::optional<chunk_range> rv;
|
||||
inode -= inode_offset_ + meta_.chunk_index_offset();
|
||||
inode -= inode_offset_ + chunk_index_offset_;
|
||||
if (inode >= 0 &&
|
||||
inode < (static_cast<int>(meta_.chunk_index().size()) - 1)) {
|
||||
uint32_t begin = meta_.chunk_index()[inode];
|
||||
|
@ -532,8 +532,6 @@ void scanner_<LoggerPolicy>::scan(filesystem_writer& fsw,
|
||||
mv2.names = ge_data.get_names();
|
||||
mv2.links = ge_data.get_links();
|
||||
mv2.timestamp_base = ge_data.get_timestamp_base();
|
||||
mv2.chunk_index_offset = first_file_inode;
|
||||
mv2.link_index_offset = first_link_inode;
|
||||
mv2.block_size = UINT32_C(1) << cfg_.block_size_bits;
|
||||
mv2.total_fs_size = prog.original_size;
|
||||
|
||||
|
@ -63,9 +63,9 @@ struct entry {
|
||||
*
|
||||
* - For directories, the inode can be used as an index into
|
||||
* metadata.directories.
|
||||
* - For links, (inode - metadata.link_index_offset) can be
|
||||
* - For links, (inode - link_index_offset) can be
|
||||
* used as an index into metadata.links.
|
||||
* - For files, (inode - metadata.chunk_index_offset) can be
|
||||
* - For files, (inode - chunk_index_offset) can be
|
||||
* used as in index into metadata.chunk_index.
|
||||
*/
|
||||
3: required UInt32 inode,
|
||||
@ -138,11 +138,16 @@ struct metadata {
|
||||
// timestamp base for all entry timestamps
|
||||
12: required UInt64 timestamp_base,
|
||||
|
||||
// inode offset for lookups into chunk_index
|
||||
13: required UInt32 chunk_index_offset;
|
||||
|
||||
// inode offset for lookups into link_index
|
||||
14: required UInt32 link_index_offset;
|
||||
/************************ DEPRECATED **********************
|
||||
*
|
||||
* These are redundant and can be determined at run-time
|
||||
* with a simple binary search. Compatibility is not
|
||||
* affected.
|
||||
*
|
||||
* 13: required UInt32 chunk_index_offset;
|
||||
* 14: required UInt32 link_index_offset;
|
||||
*
|
||||
*********************************************************/
|
||||
|
||||
// block size
|
||||
15: required UInt32 block_size;
|
||||
|
Loading…
x
Reference in New Issue
Block a user