summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--lib/btrfs/internal/uuid.go26
-rw-r--r--lib/btrfsprogs/btrfsinspect/csums.go7
-rw-r--r--lib/btrfsprogs/btrfsinspect/scandevices.go15
5 files changed, 38 insertions, 16 deletions
diff --git a/go.mod b/go.mod
index 9daf22b..fdafd8b 100644
--- a/go.mod
+++ b/go.mod
@@ -7,7 +7,7 @@ module git.lukeshu.com/btrfs-progs-ng
go 1.19
require (
- git.lukeshu.com/go/lowmemjson v0.0.0-20220818015700-3bd2e0e93647
+ git.lukeshu.com/go/lowmemjson v0.0.0-20220818070739-fb063e2955de
github.com/datawire/dlib v1.3.0
github.com/datawire/ocibuild v0.0.3-0.20220423003204-fc6a4e9f90dc
github.com/davecgh/go-spew v1.1.1
diff --git a/go.sum b/go.sum
index 0fda7e5..b6bc81f 100644
--- a/go.sum
+++ b/go.sum
@@ -1,5 +1,5 @@
-git.lukeshu.com/go/lowmemjson v0.0.0-20220818015700-3bd2e0e93647 h1:/gQH3jRZbslWRF5qMvB+jjgvOQCbbS0cDkHy6VSw8v8=
-git.lukeshu.com/go/lowmemjson v0.0.0-20220818015700-3bd2e0e93647/go.mod h1:7StdaFpmZNKYJmQ67fGbzcIcnrGjmD54f/2WbeHLaBw=
+git.lukeshu.com/go/lowmemjson v0.0.0-20220818070739-fb063e2955de h1:JfGT4m2u1ME94YQaxqXOSwEQswBxywen/mUqyu60YCw=
+git.lukeshu.com/go/lowmemjson v0.0.0-20220818070739-fb063e2955de/go.mod h1:7StdaFpmZNKYJmQ67fGbzcIcnrGjmD54f/2WbeHLaBw=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/datawire/dlib v1.3.0 h1:KkmyXU1kwm3oPBk1ypR70YbcOlEXWzEbx5RE0iRXTGk=
github.com/datawire/dlib v1.3.0/go.mod h1:NiGDmetmbkBvtznpWSx6C0vA0s0LK9aHna3LJDqjruk=
diff --git a/lib/btrfs/internal/uuid.go b/lib/btrfs/internal/uuid.go
index 3749b1a..96807b6 100644
--- a/lib/btrfs/internal/uuid.go
+++ b/lib/btrfs/internal/uuid.go
@@ -5,6 +5,7 @@
package internal
import (
+ "encoding"
"encoding/hex"
"fmt"
"strings"
@@ -14,6 +15,13 @@ import (
type UUID [16]byte
+var (
+ _ fmt.Stringer = UUID{}
+ _ fmt.Formatter = UUID{}
+ _ encoding.TextMarshaler = UUID{}
+ _ encoding.TextUnmarshaler = (*UUID)(nil)
+)
+
func (uuid UUID) String() string {
str := hex.EncodeToString(uuid[:])
return strings.Join([]string{
@@ -25,6 +33,20 @@ func (uuid UUID) String() string {
}, "-")
}
+func (uuid UUID) MarshalText() ([]byte, error) {
+ return []byte(uuid.String()), nil
+}
+
+func (uuid *UUID) UnmarshalText(text []byte) error {
+ var err error
+ *uuid, err = ParseUUID(string(text))
+ return err
+}
+
+func (uuid UUID) Format(f fmt.State, verb rune) {
+ fmtutil.FormatByteArrayStringer(uuid, uuid[:], f, verb)
+}
+
func (a UUID) Cmp(b UUID) int {
for i := range a {
if d := int(a[i]) - int(b[i]); d != 0 {
@@ -34,10 +56,6 @@ func (a UUID) Cmp(b UUID) int {
return 0
}
-func (uuid UUID) Format(f fmt.State, verb rune) {
- fmtutil.FormatByteArrayStringer(uuid, uuid[:], f, verb)
-}
-
func ParseUUID(str string) (UUID, error) {
var ret UUID
j := 0
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
}