summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-03-02 16:02:42 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-03-23 11:57:55 -0600
commitb8185f8e741bd81e0d6f6416e46e11f6f7570995 (patch)
tree623581e503f056267091ef94f0c9c7f4d30924ff /cmd
parent6ebccb12a4234e6202afb4aa362aa97d125e089e (diff)
btrfstree: Fuss with the TreeWalk API
Diffstat (limited to 'cmd')
-rw-r--r--cmd/btrfs-rec/inspect/dumptrees/print_tree.go15
-rw-r--r--cmd/btrfs-rec/inspect_lstrees.go14
-rw-r--r--cmd/btrfs-rec/inspect_spewitems.go6
3 files changed, 16 insertions, 19 deletions
diff --git a/cmd/btrfs-rec/inspect/dumptrees/print_tree.go b/cmd/btrfs-rec/inspect/dumptrees/print_tree.go
index 60303e9..7703078 100644
--- a/cmd/btrfs-rec/inspect/dumptrees/print_tree.go
+++ b/cmd/btrfs-rec/inspect/dumptrees/print_tree.go
@@ -53,9 +53,9 @@ func DumpTrees(ctx context.Context, out io.Writer, fs *btrfs.FS) {
dlog.Error(ctx, err)
},
btrfstree.TreeWalkHandler{
- Item: func(_ btrfstree.Path, item btrfstree.Item) error {
+ Item: func(_ btrfstree.Path, item btrfstree.Item) {
if item.Key.ItemType != btrfsitem.ROOT_ITEM_KEY {
- return nil
+ return
}
treeName, ok := map[btrfsprim.ObjID]string{
btrfsprim.ROOT_TREE_OBJECTID: "root",
@@ -82,7 +82,6 @@ func DumpTrees(ctx context.Context, out io.Writer, fs *btrfs.FS) {
}
textui.Fprintf(out, "%v tree key %v \n", treeName, item.Key.Format(btrfsprim.ROOT_TREE_OBJECTID))
printTree(ctx, out, fs, item.Key.ObjectID)
- return nil
},
},
)
@@ -99,20 +98,19 @@ var nodeHeaderSize = binstruct.StaticSize(btrfstree.NodeHeader{})
func printTree(ctx context.Context, out io.Writer, fs *btrfs.FS, treeID btrfsprim.ObjID) {
var itemOffset uint32
handlers := btrfstree.TreeWalkHandler{
- Node: func(path btrfstree.Path, node *btrfstree.Node) error {
+ Node: func(path btrfstree.Path, node *btrfstree.Node) {
printHeaderInfo(out, node)
itemOffset = node.Size - uint32(nodeHeaderSize)
- return nil
},
- PreKeyPointer: func(path btrfstree.Path, item btrfstree.KeyPointer) error {
+ KeyPointer: func(path btrfstree.Path, item btrfstree.KeyPointer) bool {
treeID := path[0].FromTree
textui.Fprintf(out, "\tkey %v block %v gen %v\n",
item.Key.Format(treeID),
item.BlockPtr,
item.Generation)
- return nil
+ return true
},
- Item: func(path btrfstree.Path, item btrfstree.Item) error {
+ Item: func(path btrfstree.Path, item btrfstree.Item) {
treeID := path[0].FromTree
i := path.Node(-1).FromItemSlot
bs, _ := binstruct.Marshal(item.Body)
@@ -359,7 +357,6 @@ func printTree(ctx context.Context, out io.Writer, fs *btrfs.FS, treeID btrfspri
default:
textui.Fprintf(out, "\t\t(error) unhandled item type: %T\n", body)
}
- return nil
},
}
handlers.BadItem = handlers.Item
diff --git a/cmd/btrfs-rec/inspect_lstrees.go b/cmd/btrfs-rec/inspect_lstrees.go
index cad1a37..1449a21 100644
--- a/cmd/btrfs-rec/inspect_lstrees.go
+++ b/cmd/btrfs-rec/inspect_lstrees.go
@@ -75,19 +75,21 @@ func init() {
treeErrCnt++
},
TreeWalkHandler: btrfstree.TreeWalkHandler{
- Node: func(path btrfstree.Path, node *btrfstree.Node) error {
+ Node: func(path btrfstree.Path, node *btrfstree.Node) {
visitedNodes.Insert(path.Node(-1).ToNodeAddr)
- return nil
},
- Item: func(_ btrfstree.Path, item btrfstree.Item) error {
+ BadNode: func(path btrfstree.Path, node *btrfstree.Node, err error) bool {
+ visitedNodes.Insert(path.Node(-1).ToNodeAddr)
+ treeErrCnt++
+ return false
+ },
+ Item: func(_ btrfstree.Path, item btrfstree.Item) {
typ := item.Key.ItemType
treeItemCnt[typ]++
- return nil
},
- BadItem: func(_ btrfstree.Path, item btrfstree.Item) error {
+ BadItem: func(_ btrfstree.Path, item btrfstree.Item) {
typ := item.Key.ItemType
treeItemCnt[typ]++
- return nil
},
},
PostTree: func(_ string, _ btrfsprim.ObjID) {
diff --git a/cmd/btrfs-rec/inspect_spewitems.go b/cmd/btrfs-rec/inspect_spewitems.go
index b83e989..c3a1e6b 100644
--- a/cmd/btrfs-rec/inspect_spewitems.go
+++ b/cmd/btrfs-rec/inspect_spewitems.go
@@ -34,17 +34,15 @@ func init() {
dlog.Error(ctx, err)
},
TreeWalkHandler: btrfstree.TreeWalkHandler{
- Item: func(path btrfstree.Path, item btrfstree.Item) error {
+ Item: func(path btrfstree.Path, item btrfstree.Item) {
textui.Fprintf(os.Stdout, "%s = ", path)
spew.Dump(item)
_, _ = os.Stdout.WriteString("\n")
- return nil
},
- BadItem: func(path btrfstree.Path, item btrfstree.Item) error {
+ BadItem: func(path btrfstree.Path, item btrfstree.Item) {
textui.Fprintf(os.Stdout, "%s = ", path)
spew.Dump(item)
_, _ = os.Stdout.WriteString("\n")
- return nil
},
},
})