summaryrefslogtreecommitdiff
path: root/lib/btrfs/btrfsitem/item_rootref.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-02-03 13:04:17 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-02-12 16:16:53 -0700
commit21e92e5dea4d8efc65403eeaee91b32856b86cb6 (patch)
tree331fc7c8d8765fa11364d4fc28302e829a34e678 /lib/btrfs/btrfsitem/item_rootref.go
parent11ac4fae146e5f599f34a5fafa27e20fecf713a9 (diff)
btrfsitem: Add `Free` and `CloneItem` methods to Items
Diffstat (limited to 'lib/btrfs/btrfsitem/item_rootref.go')
-rw-r--r--lib/btrfs/btrfsitem/item_rootref.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/btrfs/btrfsitem/item_rootref.go b/lib/btrfs/btrfsitem/item_rootref.go
index b33883d..4179890 100644
--- a/lib/btrfs/btrfsitem/item_rootref.go
+++ b/lib/btrfs/btrfsitem/item_rootref.go
@@ -1,4 +1,4 @@
-// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later
@@ -19,7 +19,7 @@ import (
// ROOT_REF | ROOT_BACKREF
// key.objectid = ID of the parent subvolume | ID of the child subvolume
// key.offset = ID of the child subvolume | ID of the parent subvolume
-type RootRef struct { // ROOT_REF=156 ROOT_BACKREF=144
+type RootRef struct { // complex ROOT_REF=156 ROOT_BACKREF=144
DirID btrfsprim.ObjID `bin:"off=0x00, siz=0x8"` // inode of the parent directory of the dir entry
Sequence int64 `bin:"off=0x08, siz=0x8"` // index of that dir entry within the parent
NameLen uint16 `bin:"off=0x10, siz=0x2"` // [ignored-when-writing]
@@ -27,6 +27,17 @@ type RootRef struct { // ROOT_REF=156 ROOT_BACKREF=144
Name []byte `bin:"-"`
}
+func (o *RootRef) Free() {
+ bytePool.Put(o.Name)
+ *o = RootRef{}
+ rootRefPool.Put(o)
+}
+
+func (o RootRef) Clone() RootRef {
+ o.Name = cloneBytes(o.Name)
+ return o
+}
+
func (o *RootRef) UnmarshalBinary(dat []byte) (int, error) {
if err := binutil.NeedNBytes(dat, 0x12); err != nil {
return 0, err
@@ -42,7 +53,7 @@ func (o *RootRef) UnmarshalBinary(dat []byte) (int, error) {
if err := binutil.NeedNBytes(dat, 0x12+int(o.NameLen)); err != nil {
return 0, err
}
- o.Name = dat[n : n+int(o.NameLen)]
+ o.Name = cloneBytes(dat[n : n+int(o.NameLen)])
n += int(o.NameLen)
return n, nil
}