From dd08f6379f35de2488ccc44752bbccf9fc39df71 Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Sun, 2 Feb 2025 22:24:37 -0500 Subject: [PATCH] btrfs-tree: add a method to get root backref items to BtrfsRootFetcher This complements the already existing support for reading the fields of a root backref. Signed-off-by: Zygo Blaxell --- include/crucible/btrfs-tree.h | 1 + lib/btrfs-tree.cc | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/crucible/btrfs-tree.h b/include/crucible/btrfs-tree.h index dddb55d..7e2914f 100644 --- a/include/crucible/btrfs-tree.h +++ b/include/crucible/btrfs-tree.h @@ -198,6 +198,7 @@ namespace crucible { public: BtrfsRootFetcher(const Fd &fd); BtrfsTreeItem root(uint64_t subvol); + BtrfsTreeItem root_backref(uint64_t subvol); }; /// Fetch data extent items from extent tree, skipping metadata-only block groups diff --git a/lib/btrfs-tree.cc b/lib/btrfs-tree.cc index dd3bee0..2027e8b 100644 --- a/lib/btrfs-tree.cc +++ b/lib/btrfs-tree.cc @@ -696,17 +696,31 @@ namespace crucible { BtrfsTreeObjectFetcher(fd) { tree(BTRFS_ROOT_TREE_OBJECTID); - type(BTRFS_ROOT_ITEM_KEY); scale_size(1); } BtrfsTreeItem - BtrfsRootFetcher::root(uint64_t subvol) + BtrfsRootFetcher::root(const uint64_t subvol) { + const auto my_type = BTRFS_ROOT_ITEM_KEY; + type(my_type); const auto item = at(subvol); if (!!item) { THROW_CHECK2(runtime_error, item.objectid(), subvol, subvol == item.objectid()); - THROW_CHECK2(runtime_error, item.type(), BTRFS_ROOT_ITEM_KEY, item.type() == BTRFS_ROOT_ITEM_KEY); + THROW_CHECK2(runtime_error, item.type(), my_type, item.type() == my_type); + } + return item; + } + + BtrfsTreeItem + BtrfsRootFetcher::root_backref(const uint64_t subvol) + { + const auto my_type = BTRFS_ROOT_BACKREF_KEY; + type(my_type); + const auto item = at(subvol); + if (!!item) { + THROW_CHECK2(runtime_error, item.objectid(), subvol, subvol == item.objectid()); + THROW_CHECK2(runtime_error, item.type(), my_type, item.type() == my_type); } return item; }