summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/btrfs-rec/inspect/rebuildmappings/scan.go5
-rw-r--r--cmd/btrfs-rec/inspect_rebuildmappings.go17
2 files changed, 16 insertions, 6 deletions
diff --git a/cmd/btrfs-rec/inspect/rebuildmappings/scan.go b/cmd/btrfs-rec/inspect/rebuildmappings/scan.go
index 9454ca0..d689136 100644
--- a/cmd/btrfs-rec/inspect/rebuildmappings/scan.go
+++ b/cmd/btrfs-rec/inspect/rebuildmappings/scan.go
@@ -25,6 +25,11 @@ import (
// Result types ////////////////////////////////////////////////////////////////
+type ScanResult struct {
+ Mappings []btrfsvol.Mapping
+ Devices ScanDevicesResult
+}
+
type ScanDevicesResult = map[btrfsvol.DeviceID]ScanOneDeviceResult
type ScanOneDeviceResult struct {
diff --git a/cmd/btrfs-rec/inspect_rebuildmappings.go b/cmd/btrfs-rec/inspect_rebuildmappings.go
index ae2e415..e883b93 100644
--- a/cmd/btrfs-rec/inspect_rebuildmappings.go
+++ b/cmd/btrfs-rec/inspect_rebuildmappings.go
@@ -70,11 +70,16 @@ func init() {
RunE: runWithRawFS(func(fs *btrfs.FS, cmd *cobra.Command, _ []string) (err error) {
ctx := cmd.Context()
- scanResults, err := rebuildmappings.ScanDevices(ctx, fs)
+ devResults, err := rebuildmappings.ScanDevices(ctx, fs)
if err != nil {
return err
}
+ scanResults := rebuildmappings.ScanResult{
+ Mappings: fs.LV.Mappings(),
+ Devices: devResults,
+ }
+
dlog.Info(ctx, "Writing scan results to stdout...")
if err := writeJSONFile(os.Stdout, scanResults, lowmemjson.ReEncoderConfig{
Indent: "\t",
@@ -97,13 +102,13 @@ func init() {
ctx := cmd.Context()
dlog.Infof(ctx, "Reading %q...", args[0])
- scanResults, err := readJSONFile[rebuildmappings.ScanDevicesResult](ctx, args[0])
+ scanResults, err := readJSONFile[rebuildmappings.ScanResult](ctx, args[0])
if err != nil {
return err
}
dlog.Infof(ctx, "... done reading %q", args[0])
- if err := rebuildmappings.RebuildMappings(ctx, fs, scanResults); err != nil {
+ if err := rebuildmappings.RebuildMappings(ctx, fs, scanResults.Devices); err != nil {
return err
}
@@ -132,17 +137,17 @@ func init() {
RunE: run(func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
- scanResults, err := readJSONFile[rebuildmappings.ScanDevicesResult](ctx, args[0])
+ scanResults, err := readJSONFile[rebuildmappings.ScanResult](ctx, args[0])
if err != nil {
return err
}
var cnt int
- for _, devResults := range scanResults {
+ for _, devResults := range scanResults.Devices {
cnt += len(devResults.FoundNodes)
}
set := make(containers.Set[btrfsvol.LogicalAddr], cnt)
- for _, devResults := range scanResults {
+ for _, devResults := range scanResults.Devices {
for laddr := range devResults.FoundNodes {
set.Insert(laddr)
}