diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-05-24 21:53:28 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-05-24 21:53:28 -0600 |
commit | 23ab1f8be6a1f4b5ce01e05f8ed3f6b5dae30d0b (patch) | |
tree | 854801aa60dd204cd390c40f7cafb326e981014f /cmd | |
parent | b0dd4d1f0c8262e3680570d529d00c9ebead1a91 (diff) |
stuff
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/btrfs-dbg/main.go | 16 | ||||
-rw-r--r-- | cmd/btrfs-dump-tree/main.go | 67 |
2 files changed, 77 insertions, 6 deletions
diff --git a/cmd/btrfs-dbg/main.go b/cmd/btrfs-dbg/main.go index 6d60a73..1b3b993 100644 --- a/cmd/btrfs-dbg/main.go +++ b/cmd/btrfs-dbg/main.go @@ -27,14 +27,18 @@ func Main(imgfilename string) (err error) { if err != nil { return err } - img := &btrfs.Img{ - File: fh, - } defer func() { - maybeSetErr(img.Close()) + maybeSetErr(fh.Close()) }() + fs := &btrfs.FS{ + Devices: []*btrfs.Device{ + { + File: fh, + }, + }, + } - superblocks, err := img.Superblocks() + superblocks, err := fs.Devices[0].Superblocks() if err != nil { return err } @@ -55,7 +59,7 @@ func Main(imgfilename string) (err error) { } spew.Dump(syschunks) - if err := img.ScanForNodes(superblocks[0].Data); err != nil { + if err := btrfs.ScanForNodes(fs.Devices[0], superblocks[0].Data); err != nil { return err } diff --git a/cmd/btrfs-dump-tree/main.go b/cmd/btrfs-dump-tree/main.go new file mode 100644 index 0000000..1b3b993 --- /dev/null +++ b/cmd/btrfs-dump-tree/main.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "os" + + "github.com/davecgh/go-spew/spew" + + "lukeshu.com/btrfs-tools/pkg/btrfs" +) + +func main() { + if err := Main(os.Args[1]); err != nil { + fmt.Fprintf(os.Stderr, "%s: error: %v\n", os.Args[0], err) + os.Exit(1) + } +} + +func Main(imgfilename string) (err error) { + maybeSetErr := func(_err error) { + if _err != nil && err == nil { + err = _err + } + } + + fh, err := os.Open(imgfilename) + if err != nil { + return err + } + defer func() { + maybeSetErr(fh.Close()) + }() + fs := &btrfs.FS{ + Devices: []*btrfs.Device{ + { + File: fh, + }, + }, + } + + superblocks, err := fs.Devices[0].Superblocks() + if err != nil { + return err + } + + spew := spew.NewDefaultConfig() + spew.DisablePointerAddresses = true + + sum, err := superblocks[0].Data.CalculateChecksum() + if err != nil { + return err + } + fmt.Printf("superblock checksum: %x\n", sum) + spew.Dump(superblocks[0].Data) + + syschunks, err := superblocks[0].Data.ParseSysChunkArray() + if err != nil { + return err + } + spew.Dump(syschunks) + + if err := btrfs.ScanForNodes(fs.Devices[0], superblocks[0].Data); err != nil { + return err + } + + return nil +} |