summaryrefslogtreecommitdiff
path: root/pkg/btrfs/btrfsitem/item_uuid.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-06-01 01:27:19 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-06-01 01:27:19 -0600
commit3825cf60fd652f22acc438d50028701d27a7402d (patch)
tree24b86afb8513891274dfaa8b982c4c94c1a65a5d /pkg/btrfs/btrfsitem/item_uuid.go
parent2348cdbe2a3417990a2088f9e4e91adf0c45617d (diff)
wow
Diffstat (limited to 'pkg/btrfs/btrfsitem/item_uuid.go')
-rw-r--r--pkg/btrfs/btrfsitem/item_uuid.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/pkg/btrfs/btrfsitem/item_uuid.go b/pkg/btrfs/btrfsitem/item_uuid.go
new file mode 100644
index 0000000..315dd70
--- /dev/null
+++ b/pkg/btrfs/btrfsitem/item_uuid.go
@@ -0,0 +1,39 @@
+package btrfsitem
+
+import (
+ "lukeshu.com/btrfs-tools/pkg/binstruct"
+ "lukeshu.com/btrfs-tools/pkg/btrfs/btrfstyp"
+)
+
+// The Key for this item is a UUID, and the item is a list of
+// subvolume IDs (ObjectIDs) that that UUID maps to.
+type UUIDMap struct { // UUID_SUBVOL=251 UUID_RECEIVED_SUBVOL=252
+ SubvolIDs []btrfstyp.ObjID
+}
+
+func (o *UUIDMap) UnmarshalBinary(dat []byte) (int, error) {
+ o.SubvolIDs = nil
+ var n int
+ for len(dat) > n {
+ var subvolID btrfstyp.ObjID
+ _n, err := binstruct.Unmarshal(dat[n:], &subvolID)
+ n += _n
+ if err != nil {
+ return n, err
+ }
+ o.SubvolIDs = append(o.SubvolIDs, subvolID)
+ }
+ return n, nil
+}
+
+func (o UUIDMap) MarshalBinary() ([]byte, error) {
+ var ret []byte
+ for _, subvolID := range o.SubvolIDs {
+ bs, err := binstruct.Marshal(subvolID)
+ ret = append(ret, bs...)
+ if err != nil {
+ return ret, err
+ }
+ }
+ return ret, nil
+}