]> git.hungrycats.org Git - bees/commitdiff
btrfs-tree: add a method to get root backref items to BtrfsRootFetcher
authorZygo Blaxell <bees@furryterror.org>
Mon, 3 Feb 2025 03:24:37 +0000 (22:24 -0500)
committerZygo Blaxell <bees@furryterror.org>
Fri, 7 Feb 2025 03:42:15 +0000 (22:42 -0500)
This complements the already existing support for reading the fields of
a root backref.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
include/crucible/btrfs-tree.h
lib/btrfs-tree.cc

index dddb55d757b17aba56cf9d82b6f697fb94ba9b48..7e2914f21b903f73654e7091abd09c9966a34a25 100644 (file)
@@ -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
index dd3bee0926aefaa95b8d27358af9085cb27fcf7c..2027e8b743da139de6a182004e89a3a2fe3f370b 100644 (file)
@@ -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;
        }