1
0
mirror of https://github.com/Zygo/bees.git synced 2025-05-17 21:35:45 +02:00

fs: get rid of base class btrfs_data_container

This fixes another build failure of the form:

	error: flexible array member btrfs_... not at end of struct crucible::Btrfs...

Fixes: https://github.com/Zygo/bees/issues/236
Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
Zygo Blaxell 2022-10-23 14:01:38 -04:00
parent 3654738f56
commit 5040303f50
2 changed files with 23 additions and 22 deletions

View File

@ -55,15 +55,15 @@ namespace crucible {
ostream & operator<<(ostream &os, const BtrfsInodeOffsetRoot &p); ostream & operator<<(ostream &os, const BtrfsInodeOffsetRoot &p);
struct BtrfsDataContainer : public btrfs_data_container { struct BtrfsDataContainer {
BtrfsDataContainer(size_t size = 64 * 1024); BtrfsDataContainer(size_t size = 64 * 1024);
void *prepare(size_t size); void *prepare(size_t size);
size_t get_size() const; size_t get_size() const;
decltype(bytes_left) get_bytes_left() const; decltype(btrfs_data_container::bytes_left) get_bytes_left() const;
decltype(bytes_missing) get_bytes_missing() const; decltype(btrfs_data_container::bytes_missing) get_bytes_missing() const;
decltype(elem_cnt) get_elem_cnt() const; decltype(btrfs_data_container::elem_cnt) get_elem_cnt() const;
decltype(elem_missed) get_elem_missed() const; decltype(btrfs_data_container::elem_missed) get_elem_missed() const;
ByteVector m_data; ByteVector m_data;
}; };

View File

@ -197,18 +197,15 @@ namespace crucible {
void * void *
BtrfsDataContainer::prepare(size_t container_size) BtrfsDataContainer::prepare(size_t container_size)
{ {
if (m_data.size() < container_size) {
m_data = ByteVector(container_size);
}
const auto p = m_data.get<btrfs_data_container>();
const size_t min_size = offsetof(btrfs_data_container, val); const size_t min_size = offsetof(btrfs_data_container, val);
if (container_size < min_size) { if (container_size < min_size) {
THROW_ERROR(out_of_range, "container size " << container_size << " smaller than minimum " << min_size); THROW_ERROR(out_of_range, "container size " << container_size << " smaller than minimum " << min_size);
} }
p->bytes_left = 0; if (m_data.size() < container_size) {
p->bytes_missing = 0; m_data = ByteVector(container_size);
p->elem_cnt = 0; }
p->elem_missed = 0; const auto p = m_data.get<btrfs_data_container>();
*p = (btrfs_data_container) { };
return p; return p;
} }
@ -221,25 +218,29 @@ namespace crucible {
decltype(btrfs_data_container::bytes_left) decltype(btrfs_data_container::bytes_left)
BtrfsDataContainer::get_bytes_left() const BtrfsDataContainer::get_bytes_left() const
{ {
return bytes_left; const auto p = m_data.get<btrfs_data_container>();
return p->bytes_left;
} }
decltype(btrfs_data_container::bytes_missing) decltype(btrfs_data_container::bytes_missing)
BtrfsDataContainer::get_bytes_missing() const BtrfsDataContainer::get_bytes_missing() const
{ {
return bytes_missing; const auto p = m_data.get<btrfs_data_container>();
return p->bytes_missing;
} }
decltype(btrfs_data_container::elem_cnt) decltype(btrfs_data_container::elem_cnt)
BtrfsDataContainer::get_elem_cnt() const BtrfsDataContainer::get_elem_cnt() const
{ {
return elem_cnt; const auto p = m_data.get<btrfs_data_container>();
return p->elem_cnt;
} }
decltype(btrfs_data_container::elem_missed) decltype(btrfs_data_container::elem_missed)
BtrfsDataContainer::get_elem_missed() const BtrfsDataContainer::get_elem_missed() const
{ {
return elem_missed; const auto p = m_data.get<btrfs_data_container>();
return p->elem_missed;
} }
ostream & ostream &
@ -373,8 +374,8 @@ namespace crucible {
bili_version = BTRFS_IOC_LOGICAL_INO_V2; bili_version = BTRFS_IOC_LOGICAL_INO_V2;
} }
btrfs_data_container *bdc = reinterpret_cast<btrfs_data_container *>(p->inodes); btrfs_data_container *const bdc = reinterpret_cast<btrfs_data_container *>(p->inodes);
BtrfsInodeOffsetRoot *input_iter = reinterpret_cast<BtrfsInodeOffsetRoot *>(bdc->val); BtrfsInodeOffsetRoot *const input_iter = reinterpret_cast<BtrfsInodeOffsetRoot *>(bdc->val);
// elem_cnt counts uint64_t, but BtrfsInodeOffsetRoot is 3x uint64_t // elem_cnt counts uint64_t, but BtrfsInodeOffsetRoot is 3x uint64_t
THROW_CHECK1(runtime_error, bdc->elem_cnt, bdc->elem_cnt % 3 == 0); THROW_CHECK1(runtime_error, bdc->elem_cnt, bdc->elem_cnt % 3 == 0);
@ -423,14 +424,14 @@ namespace crucible {
return false; return false;
} }
btrfs_data_container *bdc = reinterpret_cast<btrfs_data_container *>(p->fspath); btrfs_data_container *const bdc = reinterpret_cast<btrfs_data_container *>(p->fspath);
m_paths.reserve(bdc->elem_cnt); m_paths.reserve(bdc->elem_cnt);
const uint64_t *up = reinterpret_cast<const uint64_t *>(bdc->val); const uint64_t *up = reinterpret_cast<const uint64_t *>(bdc->val);
const char *cp = reinterpret_cast<const char *>(bdc->val); const char *const cp = reinterpret_cast<const char *>(bdc->val);
for (auto count = bdc->elem_cnt; count > 0; --count) { for (auto count = bdc->elem_cnt; count > 0; --count) {
const char *path = cp + *up++; const char *const path = cp + *up++;
if (static_cast<size_t>(path - cp) > container.get_size()) { if (static_cast<size_t>(path - cp) > container.get_size()) {
THROW_ERROR(out_of_range, "offset " << (path - cp) << " > size " << container.get_size() << " in " << __PRETTY_FUNCTION__); THROW_ERROR(out_of_range, "offset " << (path - cp) << " > size " << container.get_size() << " in " << __PRETTY_FUNCTION__);
} }