diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-07-25 12:32:13 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-07-25 12:37:54 -0600 |
commit | 4afd0a5b438f0eda8af3be8018bc024daeb738c3 (patch) | |
tree | 71e21a668ddc0ceee42c619f5845a361d0f6886d /lib/btrfsutil | |
parent | a2e7457d7fc339caac4e1f55d0eeadd732af60b1 (diff) |
Inline btrfsutil.Open() into main.go
Diffstat (limited to 'lib/btrfsutil')
-rw-r--r-- | lib/btrfsutil/open.go | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/lib/btrfsutil/open.go b/lib/btrfsutil/open.go deleted file mode 100644 index 91bb943..0000000 --- a/lib/btrfsutil/open.go +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com> -// -// SPDX-License-Identifier: GPL-2.0-or-later - -package btrfsutil - -import ( - "context" - "fmt" - "os" - - "github.com/datawire/dlib/dlog" - - "git.lukeshu.com/btrfs-progs-ng/lib/btrfs" - "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsvol" - "git.lukeshu.com/btrfs-progs-ng/lib/diskio" - "git.lukeshu.com/btrfs-progs-ng/lib/textui" -) - -func Open(ctx context.Context, flag int, filenames ...string) (*btrfs.FS, error) { - fs := new(btrfs.FS) - for i, filename := range filenames { - dlog.Debugf(ctx, "Adding device file %d/%d %q...", i, len(filenames), filename) - osFile, err := os.OpenFile(filename, flag, 0) - if err != nil { - _ = fs.Close() - return nil, fmt.Errorf("device file %q: %w", filename, err) - } - typedFile := &diskio.OSFile[btrfsvol.PhysicalAddr]{ - File: osFile, - } - bufFile := diskio.NewBufferedFile[btrfsvol.PhysicalAddr]( - ctx, - typedFile, - //nolint:gomnd // False positive: gomnd.ignored-functions=[textui.Tunable] doesn't support type params. - textui.Tunable[btrfsvol.PhysicalAddr](16*1024), // block size: 16KiB - textui.Tunable(1024), // number of blocks to buffer; total of 16MiB - ) - devFile := &btrfs.Device{ - File: bufFile, - } - if err := fs.AddDevice(ctx, devFile); err != nil { - return nil, fmt.Errorf("device file %q: %w", filename, err) - } - } - if err := fs.InitChunks(ctx); err != nil { - dlog.Errorf(ctx, "error: InitChunks: %v", err) - } - return fs, nil -} |