summaryrefslogtreecommitdiff
path: root/lib/btrfs/btrfsitem
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-02-03 11:32:52 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-02-12 16:16:53 -0700
commit677755c799c1b6b942349c7d9de836335c7bbf55 (patch)
tree9709e8bb3040d3afa31388b448077a04523a979f /lib/btrfs/btrfsitem
parent81e8155ff1c16dbf70206fbf239f99cf37c49432 (diff)
btrfsitem: Have all Item implementations be pointers to structs
Diffstat (limited to 'lib/btrfs/btrfsitem')
-rw-r--r--lib/btrfs/btrfsitem/item_extent.go10
-rw-r--r--lib/btrfs/btrfsitem/item_freespacebitmap.go10
-rw-r--r--lib/btrfs/btrfsitem/item_inoderef.go12
-rw-r--r--lib/btrfs/btrfsitem/items.go18
-rw-r--r--lib/btrfs/btrfsitem/items_gen.go48
5 files changed, 51 insertions, 47 deletions
diff --git a/lib/btrfs/btrfsitem/item_extent.go b/lib/btrfs/btrfsitem/item_extent.go
index 66aae1d..72371a9 100644
--- a/lib/btrfs/btrfsitem/item_extent.go
+++ b/lib/btrfs/btrfsitem/item_extent.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
@@ -114,8 +114,8 @@ func (o *ExtentInlineRef) UnmarshalBinary(dat []byte) (int, error) {
return n, err
}
case EXTENT_DATA_REF_KEY:
- var dref ExtentDataRef
- _n, err := binstruct.Unmarshal(dat[n:], &dref)
+ dref := new(ExtentDataRef)
+ _n, err := binstruct.Unmarshal(dat[n:], dref)
n += _n
o.Body = dref
if err != nil {
@@ -127,8 +127,8 @@ func (o *ExtentInlineRef) UnmarshalBinary(dat []byte) (int, error) {
if err != nil {
return n, err
}
- var sref SharedDataRef
- _n, err = binstruct.Unmarshal(dat[n:], &sref)
+ sref := new(SharedDataRef)
+ _n, err = binstruct.Unmarshal(dat[n:], sref)
n += _n
o.Body = sref
if err != nil {
diff --git a/lib/btrfs/btrfsitem/item_freespacebitmap.go b/lib/btrfs/btrfsitem/item_freespacebitmap.go
index ad46204..742d126 100644
--- a/lib/btrfs/btrfsitem/item_freespacebitmap.go
+++ b/lib/btrfs/btrfsitem/item_freespacebitmap.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
@@ -6,13 +6,15 @@ package btrfsitem
// key.objectid = object ID of the FreeSpaceInfo (logical_addr)
// key.offset = offset of the FreeSpaceInfo (size)
-type FreeSpaceBitmap []byte // FREE_SPACE_BITMAP=200
+type FreeSpaceBitmap struct { // FREE_SPACE_BITMAP=200
+ Bitmap []byte
+}
func (o *FreeSpaceBitmap) UnmarshalBinary(dat []byte) (int, error) {
- *o = dat
+ o.Bitmap = dat
return len(dat), nil
}
func (o FreeSpaceBitmap) MarshalBinary() ([]byte, error) {
- return []byte(o), nil
+ return o.Bitmap, nil
}
diff --git a/lib/btrfs/btrfsitem/item_inoderef.go b/lib/btrfs/btrfsitem/item_inoderef.go
index 083f19e..c90fe44 100644
--- a/lib/btrfs/btrfsitem/item_inoderef.go
+++ b/lib/btrfs/btrfsitem/item_inoderef.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
@@ -16,10 +16,12 @@ import (
//
// Might have multiple entries if the same file has multiple hardlinks
// in the same directory.
-type InodeRefs []InodeRef // INODE_REF=12
+type InodeRefs struct { // INODE_REF=12
+ Refs []InodeRef
+}
func (o *InodeRefs) UnmarshalBinary(dat []byte) (int, error) {
- *o = nil
+ o.Refs = nil
n := 0
for n < len(dat) {
var ref InodeRef
@@ -28,14 +30,14 @@ func (o *InodeRefs) UnmarshalBinary(dat []byte) (int, error) {
if err != nil {
return n, err
}
- *o = append(*o, ref)
+ o.Refs = append(o.Refs, ref)
}
return n, nil
}
func (o InodeRefs) MarshalBinary() ([]byte, error) {
var dat []byte
- for _, ref := range o {
+ for _, ref := range o.Refs {
_dat, err := binstruct.Marshal(ref)
dat = append(dat, _dat...)
if err != nil {
diff --git a/lib/btrfs/btrfsitem/items.go b/lib/btrfs/btrfsitem/items.go
index 67f96fa..9964e2d 100644
--- a/lib/btrfs/btrfsitem/items.go
+++ b/lib/btrfs/btrfsitem/items.go
@@ -25,7 +25,7 @@ type Error struct {
Err error
}
-func (Error) isItem() {}
+func (*Error) isItem() {}
func (o Error) MarshalBinary() ([]byte, error) {
return o.Dat, nil
@@ -43,7 +43,7 @@ func UnmarshalItem(key btrfsprim.Key, csumType btrfssum.CSumType, dat []byte) It
var ok bool
gotyp, ok = untypedObjID2gotype[key.ObjectID]
if !ok {
- return Error{
+ return &Error{
Dat: dat,
Err: fmt.Errorf("btrfsitem.UnmarshalItem({ItemType:%v, ObjectID:%v}, dat): unknown object ID for untyped item",
key.ItemType, key.ObjectID),
@@ -53,31 +53,31 @@ func UnmarshalItem(key btrfsprim.Key, csumType btrfssum.CSumType, dat []byte) It
var ok bool
gotyp, ok = keytype2gotype[key.ItemType]
if !ok {
- return Error{
+ return &Error{
Dat: dat,
Err: fmt.Errorf("btrfsitem.UnmarshalItem({ItemType:%v}, dat): unknown item type", key.ItemType),
}
}
}
- retPtr := reflect.New(gotyp)
- if csums, ok := retPtr.Interface().(*ExtentCSum); ok {
+ ptr := reflect.New(gotyp)
+ if csums, ok := ptr.Interface().(*ExtentCSum); ok {
csums.ChecksumSize = csumType.Size()
csums.Addr = btrfsvol.LogicalAddr(key.Offset)
}
- n, err := binstruct.Unmarshal(dat, retPtr.Interface())
+ n, err := binstruct.Unmarshal(dat, ptr.Interface())
if err != nil {
- return Error{
+ return &Error{
Dat: dat,
Err: fmt.Errorf("btrfsitem.UnmarshalItem({ItemType:%v}, dat): %w", key.ItemType, err),
}
}
if n < len(dat) {
- return Error{
+ return &Error{
Dat: dat,
Err: fmt.Errorf("btrfsitem.UnmarshalItem({ItemType:%v}, dat): left over data: got %v bytes but only consumed %v",
key.ItemType, len(dat), n),
}
}
//nolint:forcetypeassert // items_gen.go has all types in keytype2gotype implement the Item interface.
- return retPtr.Elem().Interface().(Item)
+ return ptr.Interface().(Item)
}
diff --git a/lib/btrfs/btrfsitem/items_gen.go b/lib/btrfs/btrfsitem/items_gen.go
index 9daef81..21c6795 100644
--- a/lib/btrfs/btrfsitem/items_gen.go
+++ b/lib/btrfs/btrfsitem/items_gen.go
@@ -80,27 +80,27 @@ var untypedObjID2gotype = map[btrfsprim.ObjID]reflect.Type{
btrfsprim.FREE_SPACE_OBJECTID: reflect.TypeOf(FreeSpaceHeader{}),
}
-func (BlockGroup) isItem() {}
-func (Chunk) isItem() {}
-func (Dev) isItem() {}
-func (DevExtent) isItem() {}
-func (DevStats) isItem() {}
-func (DirEntry) isItem() {}
-func (Empty) isItem() {}
-func (Extent) isItem() {}
-func (ExtentCSum) isItem() {}
-func (ExtentDataRef) isItem() {}
-func (FileExtent) isItem() {}
-func (FreeSpaceBitmap) isItem() {}
-func (FreeSpaceHeader) isItem() {}
-func (FreeSpaceInfo) isItem() {}
-func (Inode) isItem() {}
-func (InodeRefs) isItem() {}
-func (Metadata) isItem() {}
-func (QGroupInfo) isItem() {}
-func (QGroupLimit) isItem() {}
-func (QGroupStatus) isItem() {}
-func (Root) isItem() {}
-func (RootRef) isItem() {}
-func (SharedDataRef) isItem() {}
-func (UUIDMap) isItem() {}
+func (*BlockGroup) isItem() {}
+func (*Chunk) isItem() {}
+func (*Dev) isItem() {}
+func (*DevExtent) isItem() {}
+func (*DevStats) isItem() {}
+func (*DirEntry) isItem() {}
+func (*Empty) isItem() {}
+func (*Extent) isItem() {}
+func (*ExtentCSum) isItem() {}
+func (*ExtentDataRef) isItem() {}
+func (*FileExtent) isItem() {}
+func (*FreeSpaceBitmap) isItem() {}
+func (*FreeSpaceHeader) isItem() {}
+func (*FreeSpaceInfo) isItem() {}
+func (*Inode) isItem() {}
+func (*InodeRefs) isItem() {}
+func (*Metadata) isItem() {}
+func (*QGroupInfo) isItem() {}
+func (*QGroupLimit) isItem() {}
+func (*QGroupStatus) isItem() {}
+func (*Root) isItem() {}
+func (*RootRef) isItem() {}
+func (*SharedDataRef) isItem() {}
+func (*UUIDMap) isItem() {}