summaryrefslogtreecommitdiff
path: root/lib/btrfs/btrfsitem/item_dir.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/btrfs/btrfsitem/item_dir.go')
-rw-r--r--lib/btrfs/btrfsitem/item_dir.go21
1 files changed, 17 insertions, 4 deletions
diff --git a/lib/btrfs/btrfsitem/item_dir.go b/lib/btrfs/btrfsitem/item_dir.go
index 584e44d..0049072 100644
--- a/lib/btrfs/btrfsitem/item_dir.go
+++ b/lib/btrfs/btrfsitem/item_dir.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
@@ -23,7 +23,7 @@ func NameHash(dat []byte) uint64 {
// key.offset =
// - for DIR_ITEM and XATTR_ITEM = NameHash(name)
// - for DIR_INDEX = index id in the directory (starting at 2, because "." and "..")
-type DirEntry struct { // DIR_ITEM=84 DIR_INDEX=96 XATTR_ITEM=24
+type DirEntry struct { // complex DIR_ITEM=84 DIR_INDEX=96 XATTR_ITEM=24
Location btrfsprim.Key `bin:"off=0x0, siz=0x11"`
TransID int64 `bin:"off=0x11, siz=8"`
DataLen uint16 `bin:"off=0x19, siz=2"` // [ignored-when-writing]
@@ -34,6 +34,19 @@ type DirEntry struct { // DIR_ITEM=84 DIR_INDEX=96 XATTR_ITEM=24
Name []byte `bin:"-"`
}
+func (o *DirEntry) Free() {
+ bytePool.Put(o.Data)
+ bytePool.Put(o.Name)
+ *o = DirEntry{}
+ dirEntryPool.Put(o)
+}
+
+func (o DirEntry) Clone() DirEntry {
+ o.Data = cloneBytes(o.Data)
+ o.Name = cloneBytes(o.Name)
+ return o
+}
+
func (o *DirEntry) UnmarshalBinary(dat []byte) (int, error) {
if err := binutil.NeedNBytes(dat, 0x1e); err != nil {
return 0, err
@@ -49,9 +62,9 @@ func (o *DirEntry) UnmarshalBinary(dat []byte) (int, error) {
if err := binutil.NeedNBytes(dat, 0x1e+int(o.DataLen)+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)
- o.Data = dat[n : n+int(o.DataLen)]
+ o.Data = cloneBytes(dat[n : n+int(o.DataLen)])
n += int(o.DataLen)
return n, nil
}