diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-03-10 19:31:50 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-03-30 17:20:54 -0600 |
commit | 8c2de0e63ac106b910173ed17f394b725103596f (patch) | |
tree | a1c8b09c01b761c4b294a701c091bb047a100397 | |
parent | b983da08439f041e9b93fa61aa2db5704be60022 (diff) |
cmd/btrfs-rec: Add a runWithReadableFS helper for rebuilt forrests
-rw-r--r-- | cmd/btrfs-rec/inspect/mount/mount.go | 17 | ||||
-rw-r--r-- | cmd/btrfs-rec/inspect_dumptrees.go | 2 | ||||
-rw-r--r-- | cmd/btrfs-rec/inspect_lsfiles.go | 5 | ||||
-rw-r--r-- | cmd/btrfs-rec/inspect_mount.go | 2 | ||||
-rw-r--r-- | cmd/btrfs-rec/inspect_spewitems.go | 2 | ||||
-rw-r--r-- | cmd/btrfs-rec/main.go | 6 |
6 files changed, 14 insertions, 20 deletions
diff --git a/cmd/btrfs-rec/inspect/mount/mount.go b/cmd/btrfs-rec/inspect/mount/mount.go index 28363ed..214cc8d 100644 --- a/cmd/btrfs-rec/inspect/mount/mount.go +++ b/cmd/btrfs-rec/inspect/mount/mount.go @@ -29,23 +29,12 @@ import ( "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsitem" "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsprim" "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfstree" - "git.lukeshu.com/btrfs-progs-ng/lib/btrfsutil" "git.lukeshu.com/btrfs-progs-ng/lib/containers" "git.lukeshu.com/btrfs-progs-ng/lib/maps" "git.lukeshu.com/btrfs-progs-ng/lib/slices" ) -func MountRO(ctx context.Context, fs *btrfs.FS, mountpoint string, noChecksums bool) error { - pvs := fs.LV.PhysicalVolumes() - if len(pvs) < 1 { - return errors.New("no devices") - } - - deviceName := pvs[maps.SortedKeys(pvs)[0]].Name() - if abs, err := filepath.Abs(deviceName); err == nil { - deviceName = abs - } - +func MountRO(ctx context.Context, fs btrfs.ReadableFS, mountpoint string, noChecksums bool) error { sb, err := fs.Superblock() if err != nil { return err @@ -54,11 +43,11 @@ func MountRO(ctx context.Context, fs *btrfs.FS, mountpoint string, noChecksums b rootSubvol := &subvolume{ Subvolume: btrfs.NewSubvolume( ctx, - btrfsutil.NewOldRebuiltForrest(fs), + fs, btrfsprim.FS_TREE_OBJECTID, noChecksums, ), - DeviceName: deviceName, + DeviceName: fs.Name(), Mountpoint: mountpoint, sb: sb, diff --git a/cmd/btrfs-rec/inspect_dumptrees.go b/cmd/btrfs-rec/inspect_dumptrees.go index fd152d3..431a302 100644 --- a/cmd/btrfs-rec/inspect_dumptrees.go +++ b/cmd/btrfs-rec/inspect_dumptrees.go @@ -20,7 +20,7 @@ func init() { Use: "dump-trees", Short: "A clone of `btrfs inspect-internal dump-tree`", Args: cliutil.WrapPositionalArgs(cobra.NoArgs), - RunE: runWithRawFS(func(fs *btrfs.FS, cmd *cobra.Command, _ []string) error { + RunE: runWithReadableFS(func(fs btrfs.ReadableFS, cmd *cobra.Command, _ []string) error { const version = "6.1.3" out := os.Stdout textui.Fprintf(out, "btrfs-progs v%v\n", version) diff --git a/cmd/btrfs-rec/inspect_lsfiles.go b/cmd/btrfs-rec/inspect_lsfiles.go index abc73bc..e66f09f 100644 --- a/cmd/btrfs-rec/inspect_lsfiles.go +++ b/cmd/btrfs-rec/inspect_lsfiles.go @@ -13,7 +13,6 @@ import ( "git.lukeshu.com/btrfs-progs-ng/cmd/btrfs-rec/inspect/lsfiles" "git.lukeshu.com/btrfs-progs-ng/lib/btrfs" - "git.lukeshu.com/btrfs-progs-ng/lib/btrfsutil" ) func init() { @@ -21,7 +20,7 @@ func init() { Use: "ls-files", Short: "A listing of all files in the filesystem", Args: cliutil.WrapPositionalArgs(cobra.NoArgs), - RunE: runWithRawFS(func(fs *btrfs.FS, cmd *cobra.Command, _ []string) (err error) { + RunE: runWithReadableFS(func(fs btrfs.ReadableFS, cmd *cobra.Command, _ []string) (err error) { out := bufio.NewWriter(os.Stdout) defer func() { if _err := out.Flush(); _err != nil && err == nil { @@ -32,7 +31,7 @@ func init() { return lsfiles.LsFiles( cmd.Context(), out, - btrfsutil.NewOldRebuiltForrest(fs)) + fs) }), }) } diff --git a/cmd/btrfs-rec/inspect_mount.go b/cmd/btrfs-rec/inspect_mount.go index 4582f9f..54cfebf 100644 --- a/cmd/btrfs-rec/inspect_mount.go +++ b/cmd/btrfs-rec/inspect_mount.go @@ -18,7 +18,7 @@ func init() { Use: "mount MOUNTPOINT", Short: "Mount the filesystem read-only", Args: cliutil.WrapPositionalArgs(cobra.ExactArgs(1)), - RunE: runWithRawFS(func(fs *btrfs.FS, cmd *cobra.Command, args []string) error { + RunE: runWithReadableFS(func(fs btrfs.ReadableFS, cmd *cobra.Command, args []string) error { return mount.MountRO(cmd.Context(), fs, args[0], skipFileSums) }), } diff --git a/cmd/btrfs-rec/inspect_spewitems.go b/cmd/btrfs-rec/inspect_spewitems.go index 94d34d9..40a929f 100644 --- a/cmd/btrfs-rec/inspect_spewitems.go +++ b/cmd/btrfs-rec/inspect_spewitems.go @@ -24,7 +24,7 @@ func init() { Use: "spew-items", Short: "Spew all items as parsed", Args: cliutil.WrapPositionalArgs(cobra.NoArgs), - RunE: runWithRawFS(func(fs *btrfs.FS, cmd *cobra.Command, _ []string) error { + RunE: runWithReadableFS(func(fs btrfs.ReadableFS, cmd *cobra.Command, _ []string) error { ctx := cmd.Context() spew := spew.NewDefaultConfig() diff --git a/cmd/btrfs-rec/main.go b/cmd/btrfs-rec/main.go index e433654..d221c3d 100644 --- a/cmd/btrfs-rec/main.go +++ b/cmd/btrfs-rec/main.go @@ -175,3 +175,9 @@ func runWithRawFS(runE func(*btrfs.FS, *cobra.Command, []string) error) func(*co return runE(fs, cmd, args) }) } + +func runWithReadableFS(runE func(btrfs.ReadableFS, *cobra.Command, []string) error) func(*cobra.Command, []string) error { + return runWithRawFS(func(fs *btrfs.FS, cmd *cobra.Command, args []string) error { + return runE(btrfsutil.NewOldRebuiltForrest(fs), cmd, args) + }) +} |