blob: d50b44c8376ee7f36f01af566e17f992be933cd1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
package main
import (
"fmt"
"os"
"github.com/davecgh/go-spew/spew"
"lukeshu.com/btrfs-tools/pkg/btrfs"
"lukeshu.com/btrfs-tools/pkg/btrfsmisc"
)
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 := btrfsmisc.ScanForNodes(fs.Devices[0], superblocks[0].Data); err != nil {
return err
}
return nil
}
|