summaryrefslogtreecommitdiff
path: root/lib/btrfs/btrfsitem/item_fileextent.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_fileextent.go
parent11ac4fae146e5f599f34a5fafa27e20fecf713a9 (diff)
btrfsitem: Add `Free` and `CloneItem` methods to Items
Diffstat (limited to 'lib/btrfs/btrfsitem/item_fileextent.go')
-rw-r--r--lib/btrfs/btrfsitem/item_fileextent.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/lib/btrfs/btrfsitem/item_fileextent.go b/lib/btrfs/btrfsitem/item_fileextent.go
index 83e5d34..30a14ef 100644
--- a/lib/btrfs/btrfsitem/item_fileextent.go
+++ b/lib/btrfs/btrfsitem/item_fileextent.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
@@ -14,7 +14,7 @@ import (
// key.objectid = inode
// key.offset = offset within file
-type FileExtent struct { // EXTENT_DATA=108
+type FileExtent struct { // complex EXTENT_DATA=108
Generation btrfsprim.Generation `bin:"off=0x0, siz=0x8"` // transaction ID that created this extent
RAMBytes int64 `bin:"off=0x8, siz=0x8"` // upper bound of what compressed data will decompress to
@@ -46,6 +46,17 @@ type FileExtentExtent struct {
binstruct.End `bin:"off=0x20"`
}
+func (o *FileExtent) Free() {
+ bytePool.Put(o.BodyInline)
+ *o = FileExtent{}
+ fileExtentPool.Put(o)
+}
+
+func (o FileExtent) Clone() FileExtent {
+ o.BodyInline = cloneBytes(o.BodyInline)
+ return o
+}
+
func (o *FileExtent) UnmarshalBinary(dat []byte) (int, error) {
n, err := binstruct.UnmarshalWithoutInterface(dat, o)
if err != nil {
@@ -53,7 +64,7 @@ func (o *FileExtent) UnmarshalBinary(dat []byte) (int, error) {
}
switch o.Type {
case FILE_EXTENT_INLINE:
- o.BodyInline = dat[n:]
+ o.BodyInline = cloneBytes(dat[n:])
n += len(o.BodyInline)
case FILE_EXTENT_REG, FILE_EXTENT_PREALLOC:
_n, err := binstruct.Unmarshal(dat[n:], &o.BodyExtent)