summaryrefslogtreecommitdiff
path: root/lib/btrfs/btrfstree/btree.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/btrfs/btrfstree/btree.go')
-rw-r--r--lib/btrfs/btrfstree/btree.go70
1 files changed, 36 insertions, 34 deletions
diff --git a/lib/btrfs/btrfstree/btree.go b/lib/btrfs/btrfstree/btree.go
index e91fcc1..bc1bac2 100644
--- a/lib/btrfs/btrfstree/btree.go
+++ b/lib/btrfs/btrfstree/btree.go
@@ -22,30 +22,51 @@ type TreeSearcher interface {
Search(key btrfsprim.Key, size uint32) int
}
+type TreeWalkHandler struct {
+ BadSuperblock func(error)
+
+ // Callbacks for entire nodes.
+ //
+ // The return value from BadNode is whether to process the
+ // slots in this node or not; if no BadNode function is given,
+ // then it is not processed.
+ Node func(Path, *Node)
+ BadNode func(Path, *Node, error) bool
+
+ // Callbacks for slots in nodes.
+ //
+ // The return value from KeyPointer is whether to recurse or
+ // not; if no KeyPointer function is given, then it is
+ // recursed.
+ KeyPointer func(Path, KeyPointer) bool
+ Item func(Path, Item)
+ BadItem func(Path, Item)
+}
+
// TreeOperator is an interface for performing basic btree operations.
type TreeOperator interface {
// TreeWalk walks a tree, triggering callbacks for every node,
// key-pointer, and item; as well as for any errors encountered.
//
- // If the tree is valid, then everything is walked in key-order; but if
- // the tree is broken, then ordering is not guaranteed.
+ // If the tree is valid, then everything is walked in key-order; but
+ // if the tree is broken, then ordering is not guaranteed.
//
- // Canceling the Context causes TreeWalk to return early; no
- // values from the Context are used.
+ // Canceling the Context causes TreeWalk to return early; no values
+ // from the Context are used.
//
// The lifecycle of callbacks is:
//
- // 001 .PreNode()
- // 002 (read node)
- // 003 .Node() (or .BadNode())
- // for item in node.items:
- // if interior:
- // 004 .PreKeyPointer()
- // 005 (recurse)
- // 006 .PostKeyPointer()
- // else:
- // 004 .Item() (or .BadItem())
- // 007 .PostNode()
+ // 000 (read superblock) (maybe cbs.BadSuperblock())
+ //
+ // 001 (read node)
+ // 002 cbs.Node() or cbs.BadNode()
+ // if interior:
+ // for kp in node.items:
+ // 003a if cbs.PreKeyPointer == nil || cbs.PreKeyPointer() {
+ // 004b (recurse)
+ // else:
+ // for item in node.items:
+ // 003b cbs.Item() or cbs.BadItem()
TreeWalk(ctx context.Context, treeID btrfsprim.ObjID, errHandle func(*TreeError), cbs TreeWalkHandler)
TreeLookup(treeID btrfsprim.ObjID, key btrfsprim.Key) (Item, error)
@@ -62,25 +83,6 @@ type TreeOperator interface {
TreeSearchAll(treeID btrfsprim.ObjID, search TreeSearcher) ([]Item, error)
}
-type TreeWalkHandler struct {
- // Callbacks for entire nodes.
- //
- // If any of these return an error that is io/fs.SkipDir, the
- // node immediately stops getting processed; if PreNode, Node,
- // or BadNode return io/fs.SkipDir then key pointers and items
- // within the node are not processed.
- PreNode func(Path) error
- Node func(Path, *Node) error
- BadNode func(Path, *Node, error) error
- PostNode func(Path, *Node) error
- // Callbacks for items on interior nodes
- PreKeyPointer func(Path, KeyPointer) error
- PostKeyPointer func(Path, KeyPointer) error
- // Callbacks for items on leaf nodes
- Item func(Path, Item) error
- BadItem func(Path, Item) error
-}
-
type TreeError struct {
Path Path
Err error