mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-12 13:59:46 -04:00
metadata_v2: cleanup directory_view
This commit is contained in:
parent
87d547aaae
commit
6896b53c28
@ -33,38 +33,43 @@
|
|||||||
|
|
||||||
namespace dwarfs {
|
namespace dwarfs {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class metadata_;
|
||||||
|
|
||||||
class entry_view
|
class entry_view
|
||||||
: public ::apache::thrift::frozen::View<thrift::metadata::entry> {
|
: public ::apache::thrift::frozen::View<thrift::metadata::entry> {
|
||||||
using EntryView = ::apache::thrift::frozen::View<thrift::metadata::entry>;
|
using EntryView = ::apache::thrift::frozen::View<thrift::metadata::entry>;
|
||||||
using Meta =
|
using Meta =
|
||||||
::apache::thrift::frozen::MappedFrozen<thrift::metadata::metadata>;
|
::apache::thrift::frozen::MappedFrozen<thrift::metadata::metadata>;
|
||||||
|
|
||||||
public:
|
template <typename T>
|
||||||
entry_view(EntryView ev, Meta const* meta)
|
friend class metadata_;
|
||||||
: EntryView(ev)
|
|
||||||
, meta_(meta) {}
|
|
||||||
|
|
||||||
|
public:
|
||||||
std::string_view name() const;
|
std::string_view name() const;
|
||||||
uint16_t mode() const;
|
uint16_t mode() const;
|
||||||
uint16_t getuid() const;
|
uint16_t getuid() const;
|
||||||
uint16_t getgid() const;
|
uint16_t getgid() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
entry_view(EntryView ev, Meta const* meta)
|
||||||
|
: EntryView(ev)
|
||||||
|
, meta_(meta) {}
|
||||||
|
|
||||||
Meta const* meta_;
|
Meta const* meta_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class directory_view
|
class directory_view {
|
||||||
: public ::apache::thrift::frozen::View<thrift::metadata::entry> {
|
|
||||||
using EntryView = ::apache::thrift::frozen::View<thrift::metadata::entry>;
|
using EntryView = ::apache::thrift::frozen::View<thrift::metadata::entry>;
|
||||||
using DirView = ::apache::thrift::frozen::View<thrift::metadata::directory>;
|
using DirView = ::apache::thrift::frozen::View<thrift::metadata::directory>;
|
||||||
using Meta =
|
using Meta =
|
||||||
::apache::thrift::frozen::MappedFrozen<thrift::metadata::metadata>;
|
::apache::thrift::frozen::MappedFrozen<thrift::metadata::metadata>;
|
||||||
|
|
||||||
public:
|
template <typename T>
|
||||||
directory_view(EntryView ev, Meta const* meta)
|
friend class metadata_;
|
||||||
: EntryView(ev)
|
|
||||||
, meta_(meta) {}
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
uint32_t inode() const { return entry_.inode(); }
|
||||||
uint32_t parent_inode() const;
|
uint32_t parent_inode() const;
|
||||||
uint32_t first_entry() const;
|
uint32_t first_entry() const;
|
||||||
uint32_t entry_count() const;
|
uint32_t entry_count() const;
|
||||||
@ -72,10 +77,15 @@ class directory_view
|
|||||||
boost::integer_range<uint32_t> entry_range() const;
|
boost::integer_range<uint32_t> entry_range() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
directory_view(EntryView ev, Meta const* meta)
|
||||||
|
: entry_(ev)
|
||||||
|
, meta_(meta) {}
|
||||||
|
|
||||||
DirView getdir() const;
|
DirView getdir() const;
|
||||||
DirView getdir(uint32_t ino) const;
|
DirView getdir(uint32_t ino) const;
|
||||||
uint32_t entry_count(DirView self) const;
|
uint32_t entry_count(DirView self) const;
|
||||||
|
|
||||||
|
EntryView entry_;
|
||||||
Meta const* meta_;
|
Meta const* meta_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -85,6 +95,9 @@ class chunk_range {
|
|||||||
using Meta =
|
using Meta =
|
||||||
::apache::thrift::frozen::MappedFrozen<thrift::metadata::metadata>;
|
::apache::thrift::frozen::MappedFrozen<thrift::metadata::metadata>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
friend class metadata_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
class iterator
|
class iterator
|
||||||
: public boost::iterator_facade<iterator, chunk_view const,
|
: public boost::iterator_facade<iterator, chunk_view const,
|
||||||
@ -92,16 +105,17 @@ class chunk_range {
|
|||||||
public:
|
public:
|
||||||
iterator() = default;
|
iterator() = default;
|
||||||
|
|
||||||
iterator(Meta const* meta, uint32_t it)
|
|
||||||
: meta_(meta)
|
|
||||||
, it_(it) {}
|
|
||||||
|
|
||||||
iterator(iterator const& other)
|
iterator(iterator const& other)
|
||||||
: meta_(other.meta_)
|
: meta_(other.meta_)
|
||||||
, it_(other.it_) {}
|
, it_(other.it_) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class boost::iterator_core_access;
|
friend class boost::iterator_core_access;
|
||||||
|
friend class chunk_range;
|
||||||
|
|
||||||
|
iterator(Meta const* meta, uint32_t it)
|
||||||
|
: meta_(meta)
|
||||||
|
, it_(it) {}
|
||||||
|
|
||||||
bool equal(iterator const& other) const {
|
bool equal(iterator const& other) const {
|
||||||
return meta_ == other.meta_ && it_ == other.it_;
|
return meta_ == other.meta_ && it_ == other.it_;
|
||||||
@ -128,11 +142,6 @@ class chunk_range {
|
|||||||
mutable chunk_view view_;
|
mutable chunk_view view_;
|
||||||
};
|
};
|
||||||
|
|
||||||
chunk_range(Meta const* meta, uint32_t begin, uint32_t end)
|
|
||||||
: meta_(meta)
|
|
||||||
, begin_(begin)
|
|
||||||
, end_(end) {}
|
|
||||||
|
|
||||||
iterator begin() const { return iterator(meta_, begin_); }
|
iterator begin() const { return iterator(meta_, begin_); }
|
||||||
|
|
||||||
iterator end() const { return iterator(meta_, end_); }
|
iterator end() const { return iterator(meta_, end_); }
|
||||||
@ -142,6 +151,11 @@ class chunk_range {
|
|||||||
bool empty() const { return end_ == begin_; }
|
bool empty() const { return end_ == begin_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
chunk_range(Meta const* meta, uint32_t begin, uint32_t end)
|
||||||
|
: meta_(meta)
|
||||||
|
, begin_(begin)
|
||||||
|
, end_(end) {}
|
||||||
|
|
||||||
Meta const* meta_;
|
Meta const* meta_;
|
||||||
uint32_t begin_{0};
|
uint32_t begin_{0};
|
||||||
uint32_t end_{0};
|
uint32_t end_{0};
|
||||||
|
@ -40,7 +40,7 @@ uint16_t entry_view::getgid() const { return meta_->gids()[group_index()]; }
|
|||||||
|
|
||||||
::apache::thrift::frozen::View<thrift::metadata::directory>
|
::apache::thrift::frozen::View<thrift::metadata::directory>
|
||||||
directory_view::getdir() const {
|
directory_view::getdir() const {
|
||||||
return getdir(inode());
|
return getdir(entry_.inode());
|
||||||
}
|
}
|
||||||
|
|
||||||
::apache::thrift::frozen::View<thrift::metadata::directory>
|
::apache::thrift::frozen::View<thrift::metadata::directory>
|
||||||
@ -52,7 +52,7 @@ uint32_t directory_view::entry_count() const { return entry_count(getdir()); }
|
|||||||
|
|
||||||
uint32_t directory_view::entry_count(
|
uint32_t directory_view::entry_count(
|
||||||
::apache::thrift::frozen::View<thrift::metadata::directory> self) const {
|
::apache::thrift::frozen::View<thrift::metadata::directory> self) const {
|
||||||
auto next = getdir(inode() + 1);
|
auto next = getdir(entry_.inode() + 1);
|
||||||
return next.first_entry() - self.first_entry();
|
return next.first_entry() - self.first_entry();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,6 +84,8 @@ void analyze_frozen(std::ostream& os,
|
|||||||
|
|
||||||
const uint16_t READ_ONLY_MASK = ~(S_IWUSR | S_IWGRP | S_IWOTH);
|
const uint16_t READ_ONLY_MASK = ~(S_IWUSR | S_IWGRP | S_IWOTH);
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
template <typename LoggerPolicy>
|
template <typename LoggerPolicy>
|
||||||
class metadata_ : public metadata_v2::impl {
|
class metadata_ : public metadata_v2::impl {
|
||||||
public:
|
public:
|
||||||
@ -536,8 +538,6 @@ metadata_<LoggerPolicy>::get_chunks(int inode) const {
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
void metadata_v2::get_stat_defaults(struct ::stat* defaults) {
|
void metadata_v2::get_stat_defaults(struct ::stat* defaults) {
|
||||||
::memset(defaults, 0, sizeof(struct ::stat));
|
::memset(defaults, 0, sizeof(struct ::stat));
|
||||||
defaults->st_uid = ::geteuid();
|
defaults->st_uid = ::geteuid();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user