summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/btrfs-rec/inpsect_dbg.go73
-rwxr-xr-xscripts/main.sh3
2 files changed, 76 insertions, 0 deletions
diff --git a/cmd/btrfs-rec/inpsect_dbg.go b/cmd/btrfs-rec/inpsect_dbg.go
new file mode 100644
index 0000000..a0dd92e
--- /dev/null
+++ b/cmd/btrfs-rec/inpsect_dbg.go
@@ -0,0 +1,73 @@
+// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+//
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+package main
+
+import (
+ "bufio"
+ "fmt"
+ "os"
+
+ "github.com/datawire/dlib/dlog"
+ "github.com/datawire/ocibuild/pkg/cliutil"
+ "github.com/spf13/cobra"
+
+ "git.lukeshu.com/btrfs-progs-ng/lib/btrfs"
+ "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsitem"
+ "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsvol"
+ "git.lukeshu.com/btrfs-progs-ng/lib/btrfsprogs/btrfsinspect/scanforextents"
+ "git.lukeshu.com/btrfs-progs-ng/lib/btrfsprogs/btrfsutil"
+)
+
+func init() {
+ inspectors = append(inspectors, subcommand{
+ Command: cobra.Command{
+ Use: "dbg DUMPSUMS.gob",
+ Args: cliutil.WrapPositionalArgs(cobra.ExactArgs(1)),
+ },
+ RunE: func(fs *btrfs.FS, cmd *cobra.Command, args []string) error {
+ ctx := cmd.Context()
+
+ dlog.Infof(ctx, "Reading %q...", args[0])
+ sums, err := scanforextents.ReadAllSums(args[0])
+ if err != nil {
+ return err
+ }
+ dlog.Infof(ctx, "... done reading %q", args[0])
+
+ out := bufio.NewWriter(os.Stdout)
+
+ dlog.Info(ctx, "Walking sum tree...")
+ btrfsutil.NewBrokenTrees(ctx, fs).TreeWalk(ctx, btrfs.CSUM_TREE_OBJECTID,
+ func(err *btrfs.TreeError) {
+ dlog.Error(ctx, err)
+ },
+ btrfs.TreeWalkHandler{
+ Item: func(path btrfs.TreePath, item btrfs.Item) error {
+ if item.Key.ItemType != btrfsitem.EXTENT_CSUM_KEY {
+ return nil
+ }
+ body := item.Body.(btrfsitem.ExtentCSum)
+
+ for i, sum := range body.Sums {
+ laddr := btrfsvol.LogicalAddr(item.Key.Offset) + (btrfsvol.LogicalAddr(i) * scanforextents.CSumBlockSize)
+ fmt.Fprintf(out, "walk: %v=%q\n",
+ laddr, scanforextents.ShortSum(sum[:body.ChecksumSize]))
+ }
+ return nil
+ },
+ },
+ )
+
+ dlog.Info(ctx, "Dumping gob...")
+ _ = sums.WalkLogical(ctx, func(laddr btrfsvol.LogicalAddr, sum scanforextents.ShortSum) error {
+ fmt.Fprintf(out, "gob: %v=%q\n",
+ laddr, sum)
+ return nil
+ })
+
+ return out.Flush()
+ },
+ })
+}
diff --git a/scripts/main.sh b/scripts/main.sh
index 08d747b..bc8b01d 100755
--- a/scripts/main.sh
+++ b/scripts/main.sh
@@ -27,6 +27,9 @@ gen $b.gen/1.mappings.json \
gen $b.gen/2.csums.gob \
./btrfs-rec --pv=$b.img --mappings=$b.gen/1.mappings.json \
inspect dump-sums
+# gen $b.gen/3.dbg.txt \
+# ./btrfs-rec --pv=$b.img --mappings=$b.gen/1.mappings.json \
+# inspect dbg $b.gen/2.csums.gob
gen $b.gen/3.mappings.json \
./btrfs-rec --pv=$b.img --mappings=$b.gen/1.mappings.json \
inspect scan-for-extents $b.gen/0.scan-for-nodes.json $b.gen/2.csums.gob