From 21e92e5dea4d8efc65403eeaee91b32856b86cb6 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 3 Feb 2023 13:04:17 -0700 Subject: btrfsitem: Add `Free` and `CloneItem` methods to Items --- lib/btrfs/btrfsitem/item_rootref.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'lib/btrfs/btrfsitem/item_rootref.go') 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 +// Copyright (C) 2022-2023 Luke Shumaker // // 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 } -- cgit v1.2.3-2-g168b