summaryrefslogtreecommitdiff
path: root/lib/btrfsprogs/btrfsinspect/rebuildnodes/util.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-09-17 00:02:22 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-09-17 15:34:03 -0600
commit4649251d68744b9ba9ebbf62cf65f849aac0bfdc (patch)
treeb4b649335da81cce7911f1ba6764fc61257c4016 /lib/btrfsprogs/btrfsinspect/rebuildnodes/util.go
parent8d9e7a0ab86225515feb34e33f91801ccc1615c9 (diff)
split files
Diffstat (limited to 'lib/btrfsprogs/btrfsinspect/rebuildnodes/util.go')
-rw-r--r--lib/btrfsprogs/btrfsinspect/rebuildnodes/util.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/util.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/util.go
new file mode 100644
index 0000000..f9e4e95
--- /dev/null
+++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/util.go
@@ -0,0 +1,51 @@
+// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+//
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+package rebuildnodes
+
+import (
+ "fmt"
+ "math"
+
+ "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsprim"
+ "git.lukeshu.com/btrfs-progs-ng/lib/btrfsprogs/btrfsinspect"
+)
+
+func ptrTo[T any](x T) *T {
+ return &x
+}
+
+func maybeSet[K, V comparable](name string, m map[K]V, k K, v V) error {
+ if other, conflict := m[k]; conflict && other != v {
+ return fmt.Errorf("conflict: %s %v can't have both %v and %v", name, k, other, v)
+ }
+ m[k] = v
+ return nil
+}
+
+var maxKey = btrfsprim.Key{
+ ObjectID: math.MaxUint64,
+ ItemType: math.MaxUint8,
+ Offset: math.MaxUint64,
+}
+
+func keyMm(key btrfsprim.Key) btrfsprim.Key {
+ switch {
+ case key.Offset > 0:
+ key.Offset--
+ case key.ItemType > 0:
+ key.ItemType--
+ case key.ObjectID > 0:
+ key.ObjectID--
+ }
+ return key
+}
+
+func countNodes(nodeScanResults btrfsinspect.ScanDevicesResult) int {
+ var cnt int
+ for _, devResults := range nodeScanResults {
+ cnt += len(devResults.FoundNodes)
+ }
+ return cnt
+}