summaryrefslogtreecommitdiff
path: root/lib/btrfs/btrfsvol/blockgroupflags.go
blob: 1a194d7f869291cf99cdbde697d81fdd7c1a440c (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
50
51
package btrfsvol

import (
	"git.lukeshu.com/btrfs-progs-ng/lib/util"
)

type BlockGroupFlags uint64

const (
	BLOCK_GROUP_DATA = BlockGroupFlags(1 << iota)
	BLOCK_GROUP_SYSTEM
	BLOCK_GROUP_METADATA
	BLOCK_GROUP_RAID0
	BLOCK_GROUP_RAID1
	BLOCK_GROUP_DUP
	BLOCK_GROUP_RAID10
	BLOCK_GROUP_RAID5
	BLOCK_GROUP_RAID6
	BLOCK_GROUP_RAID1C3
	BLOCK_GROUP_RAID1C4

	BLOCK_GROUP_RAID_MASK = (BLOCK_GROUP_RAID1 | BLOCK_GROUP_DUP | BLOCK_GROUP_RAID10 | BLOCK_GROUP_RAID5 | BLOCK_GROUP_RAID6 | BLOCK_GROUP_RAID1C3 | BLOCK_GROUP_RAID1C4)
)

var blockGroupFlagNames = []string{
	"DATA",
	"SYSTEM",
	"METADATA",

	"RAID0",
	"RAID1",
	"DUP",
	"RAID10",
	"RAID5",
	"RAID6",
	"RAID1C3",
	"RAID1C4",
}

func (f BlockGroupFlags) Has(req BlockGroupFlags) bool { return f&req == req }
func (f BlockGroupFlags) String() string {
	ret := util.BitfieldString(f, blockGroupFlagNames, util.HexNone)
	if f&BLOCK_GROUP_RAID_MASK == 0 {
		if ret == "" {
			ret = "single"
		} else {
			ret += "|single"
		}
	}
	return ret
}