From ffe2a767d3d7a1313cba5de95cfee3984b981dc1 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Wed, 11 Jan 2017 20:58:01 -0500 Subject: [PATCH] crucible: extentwalker: add compressed() and bytenr() methods Also use C++11 syntax for construction. Signed-off-by: Zygo Blaxell --- include/crucible/extentwalker.h | 18 ++++++++++-------- lib/extentwalker.cc | 23 ++++++++++++----------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/include/crucible/extentwalker.h b/include/crucible/extentwalker.h index 6f12182..2c1cb0f 100644 --- a/include/crucible/extentwalker.h +++ b/include/crucible/extentwalker.h @@ -8,15 +8,15 @@ namespace crucible { // FIXME: ExtentCursor is probably a better name struct Extent { - off_t m_begin; - off_t m_end; - uint64_t m_physical; - uint64_t m_flags; + off_t m_begin = 0; + off_t m_end = 0; + uint64_t m_physical = 0; + uint64_t m_flags = 0; // Btrfs extent reference details - off_t m_physical_len; - off_t m_logical_len; - off_t m_offset; + off_t m_physical_len = 0; + off_t m_logical_len = 0; + off_t m_offset = 0; // fiemap flags are uint32_t, so bits 32..63 are OK for us @@ -38,10 +38,12 @@ namespace crucible { off_t physical_len() const { return m_physical_len; } off_t logical_len() const { return m_logical_len; } off_t offset() const { return m_offset; } + bool compressed() const; + uint64_t bytenr() const; bool operator==(const Extent &that) const; bool operator!=(const Extent &that) const { return !(*this == that); } - Extent(); + Extent() = default; Extent(const Extent &e) = default; }; diff --git a/lib/extentwalker.cc b/lib/extentwalker.cc index 999f097..626255a 100644 --- a/lib/extentwalker.cc +++ b/lib/extentwalker.cc @@ -79,17 +79,6 @@ namespace crucible { << "] }"; } - Extent::Extent() : - m_begin(0), - m_end(0), - m_physical(0), - m_flags(0), - m_physical_len(0), - m_logical_len(0), - m_offset(0) - { - } - Extent::operator bool() const { THROW_CHECK2(invalid_argument, m_begin, m_end, m_end >= m_begin); @@ -109,6 +98,18 @@ namespace crucible { return m_begin == that.m_begin && m_end == that.m_end && m_physical == that.m_physical && m_flags == that.m_flags; } + bool + Extent::compressed() const + { + return m_flags & FIEMAP_EXTENT_ENCODED; + } + + uint64_t + Extent::bytenr() const + { + return compressed() ? m_physical : m_physical - m_offset; + } + ExtentWalker::ExtentWalker(Fd fd) : m_fd(fd), m_current(m_extents.begin())