From 5040303f5067ac266b274a44888e0b49c06da816 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Sun, 23 Oct 2022 14:01:38 -0400 Subject: [PATCH] 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 --- include/crucible/fs.h | 10 +++++----- lib/fs.cc | 35 ++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/include/crucible/fs.h b/include/crucible/fs.h index f6db988..2869d1e 100644 --- a/include/crucible/fs.h +++ b/include/crucible/fs.h @@ -55,15 +55,15 @@ namespace crucible { ostream & operator<<(ostream &os, const BtrfsInodeOffsetRoot &p); - struct BtrfsDataContainer : public btrfs_data_container { + struct BtrfsDataContainer { BtrfsDataContainer(size_t size = 64 * 1024); void *prepare(size_t size); size_t get_size() const; - decltype(bytes_left) get_bytes_left() const; - decltype(bytes_missing) get_bytes_missing() const; - decltype(elem_cnt) get_elem_cnt() const; - decltype(elem_missed) get_elem_missed() const; + decltype(btrfs_data_container::bytes_left) get_bytes_left() const; + decltype(btrfs_data_container::bytes_missing) get_bytes_missing() const; + decltype(btrfs_data_container::elem_cnt) get_elem_cnt() const; + decltype(btrfs_data_container::elem_missed) get_elem_missed() const; ByteVector m_data; }; diff --git a/lib/fs.cc b/lib/fs.cc index a30b771..4f4167f 100644 --- a/lib/fs.cc +++ b/lib/fs.cc @@ -197,18 +197,15 @@ namespace crucible { void * BtrfsDataContainer::prepare(size_t container_size) { - if (m_data.size() < container_size) { - m_data = ByteVector(container_size); - } - const auto p = m_data.get(); const size_t min_size = offsetof(btrfs_data_container, val); if (container_size < min_size) { THROW_ERROR(out_of_range, "container size " << container_size << " smaller than minimum " << min_size); } - p->bytes_left = 0; - p->bytes_missing = 0; - p->elem_cnt = 0; - p->elem_missed = 0; + if (m_data.size() < container_size) { + m_data = ByteVector(container_size); + } + const auto p = m_data.get(); + *p = (btrfs_data_container) { }; return p; } @@ -221,25 +218,29 @@ namespace crucible { decltype(btrfs_data_container::bytes_left) BtrfsDataContainer::get_bytes_left() const { - return bytes_left; + const auto p = m_data.get(); + return p->bytes_left; } decltype(btrfs_data_container::bytes_missing) BtrfsDataContainer::get_bytes_missing() const { - return bytes_missing; + const auto p = m_data.get(); + return p->bytes_missing; } decltype(btrfs_data_container::elem_cnt) BtrfsDataContainer::get_elem_cnt() const { - return elem_cnt; + const auto p = m_data.get(); + return p->elem_cnt; } decltype(btrfs_data_container::elem_missed) BtrfsDataContainer::get_elem_missed() const { - return elem_missed; + const auto p = m_data.get(); + return p->elem_missed; } ostream & @@ -373,8 +374,8 @@ namespace crucible { bili_version = BTRFS_IOC_LOGICAL_INO_V2; } - btrfs_data_container *bdc = reinterpret_cast(p->inodes); - BtrfsInodeOffsetRoot *input_iter = reinterpret_cast(bdc->val); + btrfs_data_container *const bdc = reinterpret_cast(p->inodes); + BtrfsInodeOffsetRoot *const input_iter = reinterpret_cast(bdc->val); // elem_cnt counts uint64_t, but BtrfsInodeOffsetRoot is 3x uint64_t THROW_CHECK1(runtime_error, bdc->elem_cnt, bdc->elem_cnt % 3 == 0); @@ -423,14 +424,14 @@ namespace crucible { return false; } - btrfs_data_container *bdc = reinterpret_cast(p->fspath); + btrfs_data_container *const bdc = reinterpret_cast(p->fspath); m_paths.reserve(bdc->elem_cnt); const uint64_t *up = reinterpret_cast(bdc->val); - const char *cp = reinterpret_cast(bdc->val); + const char *const cp = reinterpret_cast(bdc->val); for (auto count = bdc->elem_cnt; count > 0; --count) { - const char *path = cp + *up++; + const char *const path = cp + *up++; if (static_cast(path - cp) > container.get_size()) { THROW_ERROR(out_of_range, "offset " << (path - cp) << " > size " << container.get_size() << " in " << __PRETTY_FUNCTION__); }