diff options
-rw-r--r-- | pkg/btrfs/btrfsitem/item_blockgroup.go | 15 | ||||
-rw-r--r-- | pkg/btrfs/btrfsitem/item_dir.go | 2 | ||||
-rw-r--r-- | pkg/btrfs/btrfsitem/item_extent.go | 2 | ||||
-rw-r--r-- | pkg/btrfs/btrfsitem/item_inode.go | 2 | ||||
-rw-r--r-- | pkg/btrfs/btrfsitem/item_root.go | 2 | ||||
-rw-r--r-- | pkg/btrfs/types_btree.go | 2 | ||||
-rw-r--r-- | pkg/btrfs/types_superblock.go | 2 | ||||
-rw-r--r-- | pkg/util/bitfield.go | 31 |
8 files changed, 45 insertions, 13 deletions
diff --git a/pkg/btrfs/btrfsitem/item_blockgroup.go b/pkg/btrfs/btrfsitem/item_blockgroup.go index 565aae8..a28d4bf 100644 --- a/pkg/btrfs/btrfsitem/item_blockgroup.go +++ b/pkg/btrfs/btrfsitem/item_blockgroup.go @@ -27,12 +27,15 @@ const ( 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", @@ -44,4 +47,14 @@ var blockGroupFlagNames = []string{ } func (f BlockGroupFlags) Has(req BlockGroupFlags) bool { return f&req == req } -func (f BlockGroupFlags) String() string { return util.BitfieldString(f, blockGroupFlagNames) } +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 +} diff --git a/pkg/btrfs/btrfsitem/item_dir.go b/pkg/btrfs/btrfsitem/item_dir.go index 44cfb75..afef12d 100644 --- a/pkg/btrfs/btrfsitem/item_dir.go +++ b/pkg/btrfs/btrfsitem/item_dir.go @@ -88,7 +88,7 @@ const ( func (ft FileType) String() string { names := map[FileType]string{ FT_UNKNOWN: "UNKNOWN", - FT_REG_FILE: "REG_FILE", + FT_REG_FILE: "FILE", // XXX FT_DIR: "DIR", FT_CHRDEV: "CHRDEV", FT_BLKDEV: "BLKDEV", diff --git a/pkg/btrfs/btrfsitem/item_extent.go b/pkg/btrfs/btrfsitem/item_extent.go index b0b208d..a86c2bd 100644 --- a/pkg/btrfs/btrfsitem/item_extent.go +++ b/pkg/btrfs/btrfsitem/item_extent.go @@ -87,7 +87,7 @@ var extentFlagNames = []string{ } func (f ExtentFlags) Has(req ExtentFlags) bool { return f&req == req } -func (f ExtentFlags) String() string { return util.BitfieldString(f, extentFlagNames) } +func (f ExtentFlags) String() string { return util.BitfieldString(f, extentFlagNames, util.HexNone) } type ExtentInlineRef struct { Type Type `bin:"off=0, siz=1"` diff --git a/pkg/btrfs/btrfsitem/item_inode.go b/pkg/btrfs/btrfsitem/item_inode.go index e7ae666..81ed658 100644 --- a/pkg/btrfs/btrfsitem/item_inode.go +++ b/pkg/btrfs/btrfsitem/item_inode.go @@ -60,4 +60,4 @@ var inodeFlagNames = []string{ } func (f InodeFlags) Has(req InodeFlags) bool { return f&req == req } -func (f InodeFlags) String() string { return util.BitfieldString(f, inodeFlagNames) } +func (f InodeFlags) String() string { return util.BitfieldString(f, inodeFlagNames, util.HexLower) } diff --git a/pkg/btrfs/btrfsitem/item_root.go b/pkg/btrfs/btrfsitem/item_root.go index 69d2d97..86fdabe 100644 --- a/pkg/btrfs/btrfsitem/item_root.go +++ b/pkg/btrfs/btrfsitem/item_root.go @@ -47,4 +47,4 @@ var rootFlagNames = []string{ } func (f RootFlags) Has(req RootFlags) bool { return f&req == req } -func (f RootFlags) String() string { return util.BitfieldString(f, rootFlagNames) } +func (f RootFlags) String() string { return util.BitfieldString(f, rootFlagNames, util.HexLower) } diff --git a/pkg/btrfs/types_btree.go b/pkg/btrfs/types_btree.go index 0be7b48..8ec1c9f 100644 --- a/pkg/btrfs/types_btree.go +++ b/pkg/btrfs/types_btree.go @@ -72,7 +72,7 @@ var nodeFlagNames = []string{ } func (f NodeFlags) Has(req NodeFlags) bool { return f&req == req } -func (f NodeFlags) String() string { return util.BitfieldString(f, nodeFlagNames) } +func (f NodeFlags) String() string { return util.BitfieldString(f, nodeFlagNames, util.HexLower) } type KeyPointer struct { Key Key `bin:"off=0x0, siz=0x11"` diff --git a/pkg/btrfs/types_superblock.go b/pkg/btrfs/types_superblock.go index 609ebc6..ec8b497 100644 --- a/pkg/btrfs/types_superblock.go +++ b/pkg/btrfs/types_superblock.go @@ -226,4 +226,4 @@ var incompatFlagNames = []string{ } func (f IncompatFlags) Has(req IncompatFlags) bool { return f&req == req } -func (f IncompatFlags) String() string { return util.BitfieldString(f, incompatFlagNames) } +func (f IncompatFlags) String() string { return util.BitfieldString(f, incompatFlagNames, util.HexLower) } diff --git a/pkg/util/bitfield.go b/pkg/util/bitfield.go index bf7812e..216837d 100644 --- a/pkg/util/bitfield.go +++ b/pkg/util/bitfield.go @@ -5,26 +5,45 @@ import ( "strings" ) -func BitfieldString[T ~uint8 | ~uint16 | ~uint32 | ~uint64](bitfield T, bitnames []string) string { +type BitfieldFormat uint8 + +const ( + HexNone = BitfieldFormat(iota) + HexLower + HexUpper +) + +func BitfieldString[T ~uint8 | ~uint16 | ~uint32 | ~uint64](bitfield T, bitnames []string, cfg BitfieldFormat) string { var out strings.Builder - fmt.Fprintf(&out, "0x%0x", uint64(bitfield)) + switch cfg { + case HexNone: + // do nothing + case HexLower: + fmt.Fprintf(&out, "0x%0x(", uint64(bitfield)) + case HexUpper: + fmt.Fprintf(&out, "0x%0X(", uint64(bitfield)) + } if bitfield == 0 { - out.WriteString("(none)") + out.WriteString("none") } else { rest := bitfield - sep := '(' + first := true for i := 0; rest != 0; i++ { if rest&(1<<i) != 0 { - out.WriteRune(sep) + if !first { + out.WriteRune('|') + } if i < len(bitnames) { out.WriteString(bitnames[i]) } else { fmt.Fprintf(&out, "(1<<%d)", i) } - sep = '|' + first = false } rest &^= 1 << i } + } + if cfg != HexNone { out.WriteRune(')') } return out.String() |