summaryrefslogtreecommitdiff
path: root/pkg/btrfs/internal
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/btrfs/internal')
-rw-r--r--pkg/btrfs/internal/addr.go12
-rw-r--r--pkg/btrfs/internal/uuid.go9
2 files changed, 21 insertions, 0 deletions
diff --git a/pkg/btrfs/internal/addr.go b/pkg/btrfs/internal/addr.go
index a3f41ed..09618a8 100644
--- a/pkg/btrfs/internal/addr.go
+++ b/pkg/btrfs/internal/addr.go
@@ -31,3 +31,15 @@ func (a LogicalAddr) Sub(b LogicalAddr) AddrDelta { return AddrDelta(a - b) }
func (a PhysicalAddr) Add(b AddrDelta) PhysicalAddr { return a + PhysicalAddr(b) }
func (a LogicalAddr) Add(b AddrDelta) LogicalAddr { return a + LogicalAddr(b) }
+
+type QualifiedPhysicalAddr struct {
+ Dev UUID
+ Addr PhysicalAddr
+}
+
+func (a QualifiedPhysicalAddr) Cmp(b QualifiedPhysicalAddr) int {
+ if d := a.Dev.Cmp(b.Dev); d != 0 {
+ return d
+ }
+ return int(a.Addr - b.Addr)
+}
diff --git a/pkg/btrfs/internal/uuid.go b/pkg/btrfs/internal/uuid.go
index cb2c800..ebfd247 100644
--- a/pkg/btrfs/internal/uuid.go
+++ b/pkg/btrfs/internal/uuid.go
@@ -21,6 +21,15 @@ func (uuid UUID) String() string {
}, "-")
}
+func (a UUID) Cmp(b UUID) int {
+ for i := range a {
+ if d := int(a[i]) - int(b[i]); d != 0 {
+ return d
+ }
+ }
+ return 0
+}
+
func (uuid UUID) Format(f fmt.State, verb rune) {
util.FormatByteArrayStringer(uuid, uuid[:], f, verb)
}