summaryrefslogtreecommitdiff
path: root/cmd/btrfs-fsck/pass0.go
blob: fc087e5f6ba660deaf9d1929a336d6ee4d2149dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright (C) 2022  Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later

package main

import (
	"context"
	"fmt"
	"os"

	"git.lukeshu.com/btrfs-progs-ng/lib/btrfs"
	"git.lukeshu.com/btrfs-progs-ng/lib/btrfsprogs/btrfsutil"
)

func pass0(ctx context.Context, filenames ...string) (*btrfs.FS, *btrfs.Superblock, error) {
	fmt.Printf("\nPass 0: init and superblocks...\n")

	fs, err := btrfsutil.Open(ctx, os.O_RDWR, filenames...)
	if err != nil {
		return nil, nil, err
	}

	sb, err := fs.Superblock()
	if err != nil {
		_ = fs.Close()
		return nil, nil, err
	}

	return fs, sb, nil
}