diff options
Diffstat (limited to 'pkg/btrfs/btrfsitem/item_uuid.go')
-rw-r--r-- | pkg/btrfs/btrfsitem/item_uuid.go | 39 |
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 +} |