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/btrfs-dump-tree | |
parent | b0dd4d1f0c8262e3680570d529d00c9ebead1a91 (diff) |
stuff
Diffstat (limited to 'cmd/btrfs-dump-tree')
-rw-r--r-- | cmd/btrfs-dump-tree/main.go | 67 |
1 files changed, 67 insertions, 0 deletions
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 +} |