summaryrefslogtreecommitdiff
path: root/lib/btrfs/btrfsitem/item_qgroupstatus.go
blob: b140371d3df8b929e6937cf1f23d03239a6c33dc (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright (C) 2023  Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later

package btrfsitem

import (
	"git.lukeshu.com/btrfs-progs-ng/lib/binstruct"
	"git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsprim"
	"git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsvol"
	"git.lukeshu.com/btrfs-progs-ng/lib/fmtutil"
)

type QGroupStatusFlags uint64

const (
	QGroupStatusFlagOn QGroupStatusFlags = 1 << iota
	QGroupStatusFlagRescan
	QGroupStatusFlagInconsistent
)

var qgroupStatusFlagNames = []string{
	"ON",
	"RESCAN",
	"INCONSISTENT",
}

func (f QGroupStatusFlags) Has(req QGroupStatusFlags) bool { return f&req == req }
func (f QGroupStatusFlags) String() string {
	return fmtutil.BitfieldString(f, qgroupStatusFlagNames, fmtutil.HexNone)
}

const QGroupStatusVersion uint64 = 1

// A QGroupStatus holds the qgroup state of a subvolume (I think that
// implies that the QGroupStatus goes in the subvolume tree that it is
// describing?).
//
// Key:
//
//	key.objectid = 0
//	key.offset   = 0
type QGroupStatus struct { // trivial QGROUP_STATUS=240
	Version        uint64               `bin:"off=0, siz=8"`
	Generation     btrfsprim.Generation `bin:"off=8, siz=8"`
	Flags          QGroupStatusFlags    `bin:"off=16, siz=8"`
	RescanProgress btrfsvol.LogicalAddr `bin:"off=24, siz=8"`
	binstruct.End  `bin:"off=32"`
}