diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-03-16 08:29:36 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-03-16 08:29:36 -0600 |
commit | c0f33186aa7a8903c5e7406024f13fad48cd14e3 (patch) | |
tree | c8361c8278b07839be9af2ccee3507d324a7a216 /lib/btrfs/btrfsprim/misc.go | |
parent | c2925f0f8a5d69369b43de0d2d201291fe5ed9d1 (diff) | |
parent | 17833fa13d5a7dcd79ad507fe4abf96b4a4a898b (diff) |
Merge branch 'lukeshu/errs'
Diffstat (limited to 'lib/btrfs/btrfsprim/misc.go')
-rw-r--r-- | lib/btrfs/btrfsprim/misc.go | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/lib/btrfs/btrfsprim/misc.go b/lib/btrfs/btrfsprim/misc.go index ca2e313..38290d6 100644 --- a/lib/btrfs/btrfsprim/misc.go +++ b/lib/btrfs/btrfsprim/misc.go @@ -5,84 +5,13 @@ package btrfsprim import ( - "fmt" - "math" "time" "git.lukeshu.com/btrfs-progs-ng/lib/binstruct" - "git.lukeshu.com/btrfs-progs-ng/lib/containers" ) type Generation uint64 -type Key struct { - ObjectID ObjID `bin:"off=0x0, siz=0x8"` // Each tree has its own set of Object IDs. - ItemType ItemType `bin:"off=0x8, siz=0x1"` - Offset uint64 `bin:"off=0x9, siz=0x8"` // The meaning depends on the item type. - binstruct.End `bin:"off=0x11"` -} - -// mimics print-tree.c:btrfs_print_key() -func (key Key) Format(tree ObjID) string { - switch tree { - case UUID_TREE_OBJECTID: - return fmt.Sprintf("(%v %v %#08x)", - key.ObjectID.Format(tree), - key.ItemType, - key.Offset) - case ROOT_TREE_OBJECTID, QUOTA_TREE_OBJECTID: - return fmt.Sprintf("(%v %v %v)", - key.ObjectID.Format(tree), - key.ItemType, - ObjID(key.Offset).Format(tree)) - default: - if key.Offset == math.MaxUint64 { - return fmt.Sprintf("(%v %v -1)", - key.ObjectID.Format(tree), - key.ItemType) - } else { - return fmt.Sprintf("(%v %v %v)", - key.ObjectID.Format(tree), - key.ItemType, - key.Offset) - } - } -} - -func (key Key) String() string { - return key.Format(0) -} - -var MaxKey = Key{ - ObjectID: math.MaxUint64, - ItemType: math.MaxUint8, - Offset: math.MaxUint64, -} - -func (key Key) Mm() Key { - switch { - case key.Offset > 0: - key.Offset-- - case key.ItemType > 0: - key.ItemType-- - case key.ObjectID > 0: - key.ObjectID-- - } - return key -} - -func (a Key) Compare(b Key) int { - if d := containers.NativeCompare(a.ObjectID, b.ObjectID); d != 0 { - return d - } - if d := containers.NativeCompare(a.ItemType, b.ItemType); d != 0 { - return d - } - return containers.NativeCompare(a.Offset, b.Offset) -} - -var _ containers.Ordered[Key] = Key{} - type Time struct { Sec int64 `bin:"off=0x0, siz=0x8"` // Number of seconds since 1970-01-01T00:00:00Z. NSec uint32 `bin:"off=0x8, siz=0x4"` // Number of nanoseconds since the beginning of the second. |