summaryrefslogtreecommitdiff
path: root/lib/btrfs/btrfstree
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-08-29 19:25:47 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-08-30 21:29:00 -0600
commitb6a7ab5f6c1fe993271242021c3ed4050733fdf2 (patch)
tree2a0a099e0adc5bf58c586a76d9dd49c725d4dba7 /lib/btrfs/btrfstree
parent8aea2c35c9475293c89293a148134c0e6d5c4e7b (diff)
wip
Diffstat (limited to 'lib/btrfs/btrfstree')
-rw-r--r--lib/btrfs/btrfstree/readnode.go27
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/btrfs/btrfstree/readnode.go b/lib/btrfs/btrfstree/readnode.go
index bb80d20..b1c34e4 100644
--- a/lib/btrfs/btrfstree/readnode.go
+++ b/lib/btrfs/btrfstree/readnode.go
@@ -13,14 +13,26 @@ import (
"git.lukeshu.com/btrfs-progs-ng/lib/diskio"
)
+type NodeFile interface {
+ diskio.File[btrfsvol.LogicalAddr]
+ Superblock() (*Superblock, error)
+
+ // ParentTree, given a tree ID, returns that tree's parent
+ // tree, if it has one.
+ //
+ // - non-zero, true : the parent tree ID
+ //
+ // - 0, true : the tree does not have a parent
+ //
+ // - any, false : the tree's parent information could not be
+ // looked up
+ ParentTree(btrfsprim.ObjID) (btrfsprim.ObjID, bool)
+}
+
// FSReadNode is a utility function to help with implementing the
// 'NodeSource' interface.
func FSReadNode(
- fs interface {
- diskio.File[btrfsvol.LogicalAddr]
- Superblock() (*Superblock, error)
- ParentTree(btrfsprim.ObjID) (btrfsprim.ObjID, bool)
- },
+ fs NodeFile,
path TreePath,
) (*diskio.Ref[btrfsvol.LogicalAddr, Node], error) {
sb, err := fs.Superblock()
@@ -39,6 +51,11 @@ func FSReadNode(
var ok bool
exp, ok = fs.ParentTree(exp)
if !ok {
+ // Failed lookup up parent info; fail open.
+ return nil
+ }
+ if exp == 0 {
+ // End of the line.
return fmt.Errorf("expected owner in %v but claims to have owner=%v",
treeParents, owner)
}