summaryrefslogtreecommitdiff
path: root/cmd/btrfs-rec
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-07-13 02:03:59 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-07-13 02:03:59 -0600
commit8af2990bcad83ed8ee70a461c560b2dc610278ed (patch)
tree7a546a0f29d6c32f0b2547928a07599552888dd1 /cmd/btrfs-rec
parent7c23a1195257ed38fd5b37725f8181e37553419b (diff)
implement `btrfs-rec inspect spew-items`
Diffstat (limited to 'cmd/btrfs-rec')
-rw-r--r--cmd/btrfs-rec/inspect_spewitems.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/cmd/btrfs-rec/inspect_spewitems.go b/cmd/btrfs-rec/inspect_spewitems.go
new file mode 100644
index 0000000..f2a06ca
--- /dev/null
+++ b/cmd/btrfs-rec/inspect_spewitems.go
@@ -0,0 +1,55 @@
+// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+//
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+package main
+
+import (
+ "fmt"
+ "os"
+
+ "github.com/datawire/dlib/dlog"
+ "github.com/datawire/ocibuild/pkg/cliutil"
+ "github.com/davecgh/go-spew/spew"
+ "github.com/spf13/cobra"
+
+ "git.lukeshu.com/btrfs-progs-ng/lib/btrfs"
+ "git.lukeshu.com/btrfs-progs-ng/lib/btrfsprogs/btrfsutil"
+)
+
+func init() {
+ inspectors = append(inspectors, subcommand{
+ Command: cobra.Command{
+ Use: "spew-items",
+ Short: "Spew all items as parsed",
+ Args: cliutil.WrapPositionalArgs(cobra.NoArgs),
+ },
+ RunE: func(fs *btrfs.FS, cmd *cobra.Command, _ []string) error {
+ ctx := cmd.Context()
+
+ spew := spew.NewDefaultConfig()
+ spew.DisablePointerAddresses = true
+
+ btrfsutil.WalkAllTrees(ctx, fs, btrfsutil.WalkAllTreesHandler{
+ Err: func(err *btrfsutil.WalkError) {
+ dlog.Error(ctx, err)
+ },
+ TreeWalkHandler: btrfs.TreeWalkHandler{
+ Item: func(path btrfs.TreePath, item btrfs.Item) error {
+ fmt.Printf("%s = ", path)
+ spew.Dump(item)
+ os.Stdout.WriteString("\n")
+ return nil
+ },
+ BadItem: func(path btrfs.TreePath, item btrfs.Item) error {
+ fmt.Printf("%s = ", path)
+ spew.Dump(item)
+ os.Stdout.WriteString("\n")
+ return nil
+ },
+ },
+ })
+ return nil
+ },
+ })
+}