summaryrefslogtreecommitdiff
path: root/cmd/btrfs-rec/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/btrfs-rec/util.go')
-rw-r--r--cmd/btrfs-rec/util.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/cmd/btrfs-rec/util.go b/cmd/btrfs-rec/util.go
index 3d751a6..2e4bb84 100644
--- a/cmd/btrfs-rec/util.go
+++ b/cmd/btrfs-rec/util.go
@@ -13,6 +13,10 @@ import (
"git.lukeshu.com/go/lowmemjson"
"github.com/datawire/dlib/dlog"
+ "git.lukeshu.com/btrfs-progs-ng/cmd/btrfs-rec/inspect/rebuildmappings"
+ "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsvol"
+ "git.lukeshu.com/btrfs-progs-ng/lib/containers"
+ "git.lukeshu.com/btrfs-progs-ng/lib/maps"
"git.lukeshu.com/btrfs-progs-ng/lib/streamio"
)
@@ -47,3 +51,24 @@ func writeJSONFile(w io.Writer, obj any, cfg lowmemjson.ReEncoderConfig) (err er
}()
return lowmemjson.NewEncoder(lowmemjson.NewReEncoder(buffer, cfg)).Encode(obj)
}
+
+func readNodeList(ctx context.Context, filename string) ([]btrfsvol.LogicalAddr, error) {
+ if filename == "" {
+ return nil, nil
+ }
+ results, err := readJSONFile[rebuildmappings.ScanDevicesResult](ctx, filename)
+ if err != nil {
+ return nil, err
+ }
+ var cnt int
+ for _, devResults := range results {
+ cnt += len(devResults.FoundNodes)
+ }
+ set := make(containers.Set[btrfsvol.LogicalAddr], cnt)
+ for _, devResults := range results {
+ for laddr := range devResults.FoundNodes {
+ set.Insert(laddr)
+ }
+ }
+ return maps.SortedKeys(set), nil
+}