diff options
Diffstat (limited to 'pkg/btrfsmisc/open.go')
-rw-r--r-- | pkg/btrfsmisc/open.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/pkg/btrfsmisc/open.go b/pkg/btrfsmisc/open.go new file mode 100644 index 0000000..bf72670 --- /dev/null +++ b/pkg/btrfsmisc/open.go @@ -0,0 +1,24 @@ +package btrfsmisc + +import ( + "fmt" + "os" + + "lukeshu.com/btrfs-tools/pkg/btrfs" +) + +func Open(flag int, filenames ...string) (*btrfs.FS, error) { + fs := new(btrfs.FS) + for _, filename := range filenames { + fh, err := os.OpenFile(filename, flag, 0) + if err != nil { + _ = fs.Close() + return nil, fmt.Errorf("file %q: %w", filename, err) + } + if err := fs.AddDevice(&btrfs.Device{File: fh}); err != nil { + _ = fs.Close() + return nil, fmt.Errorf("file %q: %w", filename, err) + } + } + return fs, nil +} |