diff options
-rw-r--r-- | cmd/btrfs-rec/inspect_lstrees.go | 13 | ||||
-rw-r--r-- | cmd/btrfs-rec/main.go | 22 |
2 files changed, 23 insertions, 12 deletions
diff --git a/cmd/btrfs-rec/inspect_lstrees.go b/cmd/btrfs-rec/inspect_lstrees.go index 24622b4..cb7bef8 100644 --- a/cmd/btrfs-rec/inspect_lstrees.go +++ b/cmd/btrfs-rec/inspect_lstrees.go @@ -33,20 +33,9 @@ func init() { "If no --node-list is given, then a slow sector-by-sector scan " + "will be used to find all lost+found nodes.", Args: cliutil.WrapPositionalArgs(cobra.NoArgs), - RunE: runWithRawFS(func(fs *btrfs.FS, cmd *cobra.Command, _ []string) error { + RunE: runWithReadableFSAndNodeList(&nodeListFilename, func(fs btrfs.ReadableFS, nodeList []btrfsvol.LogicalAddr, cmd *cobra.Command, _ []string) error { ctx := cmd.Context() - var nodeList []btrfsvol.LogicalAddr - var err error - if nodeListFilename != "" { - nodeList, err = readJSONFile[[]btrfsvol.LogicalAddr](ctx, nodeListFilename) - } else { - nodeList, err = btrfsutil.ListNodes(ctx, fs) - } - if err != nil { - return err - } - var treeErrCnt int var treeItemCnt map[btrfsitem.Type]int flush := func() { 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) + }) +} |