summaryrefslogtreecommitdiff
path: root/lib/btrfsprogs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/btrfsprogs')
-rw-r--r--lib/btrfsprogs/btrfsinspect/csums.go7
-rw-r--r--lib/btrfsprogs/btrfsinspect/scandevices.go15
2 files changed, 13 insertions, 9 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/csums.go b/lib/btrfsprogs/btrfsinspect/csums.go
index 6335cb9..e690d24 100644
--- a/lib/btrfsprogs/btrfsinspect/csums.go
+++ b/lib/btrfsprogs/btrfsinspect/csums.go
@@ -103,12 +103,9 @@ type SumRun[Addr btrfsvol.IntAddr[Addr]] struct {
// How big a ShortSum is in this Run.
ChecksumSize int
// Base address where this run starts.
- Addr Addr
+ Addr Addr `json:",omitempty"`
// All of the ShortSums in this run, concatenated together.
- //
- // This is a 'string' rather than a 'ShortSum' to make it hard
- // to accidentally use it as a single sum.
- Sums string
+ Sums ShortSum
}
func (run SumRun[Addr]) NumSums() int {
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
}