diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-07-01 00:00:19 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-07-01 00:00:19 -0600 |
commit | aee0fa4cf09ef5af90e28441d673ce440e4c2c16 (patch) | |
tree | 5a87486e5bd4f0af400d633d3040edd5ed03bf5c /cmd/btrfs-dbg | |
parent | df3e7ef9c5fd0ceb2e89d5afd4e981652f9a8bdd (diff) |
add open/close utility functions
Diffstat (limited to 'cmd/btrfs-dbg')
-rw-r--r-- | cmd/btrfs-dbg/main.go | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/cmd/btrfs-dbg/main.go b/cmd/btrfs-dbg/main.go index 3f30915..4b4a7a2 100644 --- a/cmd/btrfs-dbg/main.go +++ b/cmd/btrfs-dbg/main.go @@ -25,20 +25,13 @@ func Main(imgfilename string) (err error) { } } - fh, err := os.Open(imgfilename) + fs, err := btrfsmisc.Open(os.O_RDONLY, imgfilename) if err != nil { return err } defer func() { - maybeSetErr(fh.Close()) + maybeSetErr(fs.Close()) }() - dev := &btrfs.Device{ - File: fh, - } - fs := new(btrfs.FS) - if err := fs.AddDevice(dev); err != nil { - return err - } superblocks, err := fs.Superblocks() if err != nil { @@ -61,17 +54,19 @@ func Main(imgfilename string) (err error) { } spew.Dump(syschunks) - if err := btrfsmisc.ScanForNodes(dev, superblocks[0].Data, func(nodeRef *util.Ref[btrfs.PhysicalAddr, btrfs.Node], err error) { - if err != nil { - fmt.Println(err) - } else { - fmt.Printf("node@%v: physical_addr=%v logical_addr=%v generation=%v owner=%v level=%v\n", - nodeRef.Addr, - nodeRef.Addr, nodeRef.Data.Head.Addr, - nodeRef.Data.Head.Generation, nodeRef.Data.Head.Owner, nodeRef.Data.Head.Level) + for _, dev := range fs.LV.PhysicalVolumes() { + if err := btrfsmisc.ScanForNodes(dev, superblocks[0].Data, func(nodeRef *util.Ref[btrfs.PhysicalAddr, btrfs.Node], err error) { + if err != nil { + fmt.Println(err) + } else { + fmt.Printf("node@%v: physical_addr=%v logical_addr=%v generation=%v owner=%v level=%v\n", + nodeRef.Addr, + nodeRef.Addr, nodeRef.Data.Head.Addr, + nodeRef.Data.Head.Generation, nodeRef.Data.Head.Owner, nodeRef.Data.Head.Level) + } + }, nil); err != nil { + return err } - }, nil); err != nil { - return err } return nil |