summaryrefslogtreecommitdiff
path: root/cmd/btrfs-rec/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/btrfs-rec/main.go')
-rw-r--r--cmd/btrfs-rec/main.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/cmd/btrfs-rec/main.go b/cmd/btrfs-rec/main.go
index 49a9649..8d3193a 100644
--- a/cmd/btrfs-rec/main.go
+++ b/cmd/btrfs-rec/main.go
@@ -192,3 +192,25 @@ func runWithReadableFS(runE func(btrfs.ReadableFS, *cobra.Command, []string) err
return runE(rfs, cmd, args)
})
}
+
+func runWithReadableFSAndNodeList(nodeListFilename *string, runE func(btrfs.ReadableFS, []btrfsvol.LogicalAddr, *cobra.Command, []string) error) func(*cobra.Command, []string) error {
+ return runWithRawFS(func(fs *btrfs.FS, cmd *cobra.Command, args []string) error {
+ var nodeList []btrfsvol.LogicalAddr
+ var err error
+ if *nodeListFilename != "" {
+ nodeList, err = readJSONFile[[]btrfsvol.LogicalAddr](cmd.Context(), *nodeListFilename)
+ } else {
+ nodeList, err = btrfsutil.ListNodes(cmd.Context(), fs)
+ }
+ if err != nil {
+ return err
+ }
+
+ var rfs btrfs.ReadableFS = fs
+ if globalFlags.rebuild {
+ rfs = btrfsutil.NewOldRebuiltForrest(fs)
+ }
+
+ return runE(rfs, nodeList, cmd, args)
+ })
+}