diff options
Diffstat (limited to 'cmd/btrfs-fsck/pass0.go')
-rw-r--r-- | cmd/btrfs-fsck/pass0.go | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/cmd/btrfs-fsck/pass0.go b/cmd/btrfs-fsck/pass0.go index 2a8e20a..c0c872b 100644 --- a/cmd/btrfs-fsck/pass0.go +++ b/cmd/btrfs-fsck/pass0.go @@ -8,19 +8,27 @@ import ( "lukeshu.com/btrfs-tools/pkg/util" ) -func pass0(imgfiles ...*os.File) (*btrfs.FS, *util.Ref[btrfs.PhysicalAddr, btrfs.Superblock], error) { +func pass0(filenames ...string) (*btrfs.FS, *util.Ref[btrfs.PhysicalAddr, btrfs.Superblock], error) { fmt.Printf("\nPass 0: init and superblocks...\n") fs := new(btrfs.FS) - for _, imgfile := range imgfiles { - fmt.Printf("Pass 0: ... adding device %q...\n", imgfile.Name()) - if err := fs.AddDevice(&btrfs.Device{File: imgfile}); err != nil { - fmt.Printf("Pass 0: ... add device %q: error: %v\n", imgfile.Name(), err) + for _, filename := range filenames { + fmt.Printf("Pass 0: ... adding device %q...\n", filename) + + fh, err := os.OpenFile(filename, os.O_RDWR, 0) + if err != nil { + _ = fs.Close() + return nil, nil, fmt.Errorf("device %q: %w", filename, err) + } + + if err := fs.AddDevice(&btrfs.Device{File: fh}); err != nil { + fmt.Printf("Pass 0: ... add device %q: error: %v\n", filename, err) } } sb, err := fs.Superblock() if err != nil { + _ = fs.Close() return nil, nil, err } |