summaryrefslogtreecommitdiff
path: root/lib/btrfsprogs/btrfsinspect/scandevices.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-08-18 01:55:32 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-08-18 01:57:43 -0600
commit45494a8d80e4c78144b653044b55f8572e12e67d (patch)
tree417d22998e42bb79c5e40f0ca421d06b0d3dc43e /lib/btrfsprogs/btrfsinspect/scandevices.go
parentee0d8981e501c86774f3ec45466d3273464921e8 (diff)
Work on the scandevices output
Diffstat (limited to 'lib/btrfsprogs/btrfsinspect/scandevices.go')
-rw-r--r--lib/btrfsprogs/btrfsinspect/scandevices.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/scandevices.go b/lib/btrfsprogs/btrfsinspect/scandevices.go
index b0ec0ff..f4da3dc 100644
--- a/lib/btrfsprogs/btrfsinspect/scandevices.go
+++ b/lib/btrfsprogs/btrfsinspect/scandevices.go
@@ -8,6 +8,7 @@ import (
"context"
"errors"
"fmt"
+ "strings"
"sync"
"github.com/datawire/dlib/dgroup"
@@ -97,7 +98,8 @@ func ScanOneDevice(ctx context.Context, dev *btrfs.Device, sb btrfs.Superblock)
alg := sb.ChecksumType
csumSize := alg.Size()
numSums := int(devSize / btrfsitem.CSumBlockSize)
- sums := make([]byte, numSums*csumSize)
+ var sums strings.Builder
+ sums.Grow(numSums * csumSize)
lastProgress := -1
progress := func(pos btrfsvol.PhysicalAddr) {
@@ -126,9 +128,9 @@ func ScanOneDevice(ctx context.Context, dev *btrfs.Device, sb btrfs.Superblock)
if err != nil {
return result, err
}
- copy(sums[i*csumSize:], sum[:csumSize])
+ sums.Write(sum[:csumSize])
- checkForNode := pos >= minNextNode
+ checkForNode := pos >= minNextNode && pos+btrfsvol.PhysicalAddr(sb.NodeSize) <= devSize
if checkForNode {
for _, sbAddr := range btrfs.SuperblockAddrs {
if sbAddr <= pos && pos < sbAddr+sbSize {
@@ -142,7 +144,7 @@ func ScanOneDevice(ctx context.Context, dev *btrfs.Device, sb btrfs.Superblock)
nodeRef, err := btrfs.ReadNode[btrfsvol.PhysicalAddr](dev, sb, pos, nil)
if err != nil {
if !errors.Is(err, btrfs.ErrNotANode) {
- dlog.Infof(ctx, "... dev[%q] error: %v", dev.Name(), err)
+ dlog.Errorf(ctx, "... dev[%q] error: %v", dev.Name(), err)
}
} else {
result.FoundNodes[nodeRef.Data.Head.Addr] = append(result.FoundNodes[nodeRef.Data.Head.Addr], nodeRef.Addr)
@@ -209,5 +211,10 @@ func ScanOneDevice(ctx context.Context, dev *btrfs.Device, sb btrfs.Superblock)
}
progress(devSize)
+ result.Checksums = SumRun[btrfsvol.PhysicalAddr]{
+ ChecksumSize: csumSize,
+ Sums: ShortSum(sums.String()),
+ }
+
return result, nil
}