summaryrefslogtreecommitdiff
path: root/lib/btrfs
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-03-17 02:28:54 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2023-03-17 02:52:07 -0400
commit1ea26f04701fa66e36b058f3efb3a6c7059cdc5c (patch)
tree9ba66e893d6f66096f6b06284d09c8eb3e50facc /lib/btrfs
parent0cfc5d80855ee0a28329305cda13e7bff935a297 (diff)
tree-wide: Turn on all revive linters (with exceptions)
Diffstat (limited to 'lib/btrfs')
-rw-r--r--lib/btrfs/btrfsprim/key.go9
-rw-r--r--lib/btrfs/btrfstree/btree_tree.go5
-rw-r--r--lib/btrfs/btrfstree/path.go27
-rw-r--r--lib/btrfs/btrfstree/types_node.go29
-rw-r--r--lib/btrfs/io4_fs.go16
5 files changed, 44 insertions, 42 deletions
diff --git a/lib/btrfs/btrfsprim/key.go b/lib/btrfs/btrfsprim/key.go
index 2930782..5580c52 100644
--- a/lib/btrfs/btrfsprim/key.go
+++ b/lib/btrfs/btrfsprim/key.go
@@ -42,12 +42,11 @@ func (key Key) Format(tree ObjID) string {
return fmt.Sprintf("(%v %v -1)",
key.ObjectID.Format(tree),
key.ItemType)
- } else {
- return fmt.Sprintf("(%v %v %v)",
- key.ObjectID.Format(tree),
- key.ItemType,
- key.Offset)
}
+ return fmt.Sprintf("(%v %v %v)",
+ key.ObjectID.Format(tree),
+ key.ItemType,
+ key.Offset)
}
}
diff --git a/lib/btrfs/btrfstree/btree_tree.go b/lib/btrfs/btrfstree/btree_tree.go
index df58c0c..1e3c789 100644
--- a/lib/btrfs/btrfstree/btree_tree.go
+++ b/lib/btrfs/btrfstree/btree_tree.go
@@ -188,7 +188,8 @@ func (fs TreeOperatorImpl) treeSearch(treeRoot TreeRoot, fn func(btrfsprim.Key,
return nil, nil, err
}
- if node.Data.Head.Level > 0 {
+ switch {
+ case node.Data.Head.Level > 0:
// interior node
// Search for the right-most node.Data.BodyInterior item for which
@@ -220,7 +221,7 @@ func (fs TreeOperatorImpl) treeSearch(treeRoot TreeRoot, fn func(btrfsprim.Key,
ToMaxKey: toMaxKey,
})
FreeNodeRef(node)
- } else {
+ default:
// leaf node
// Search for a member of node.Data.BodyLeaf for which
diff --git a/lib/btrfs/btrfstree/path.go b/lib/btrfs/btrfstree/path.go
index dc2fc1d..b9ab5bc 100644
--- a/lib/btrfs/btrfstree/path.go
+++ b/lib/btrfs/btrfstree/path.go
@@ -101,23 +101,22 @@ func (elem TreePathElem) writeNodeTo(w io.Writer) {
func (path TreePath) String() string {
if len(path) == 0 {
return "(empty-path)"
+ }
+ var ret strings.Builder
+ fmt.Fprintf(&ret, "%s->", path[0].FromTree.Format(btrfsprim.ROOT_TREE_OBJECTID))
+ if len(path) == 1 && path[0] == (TreePathElem{FromTree: path[0].FromTree, FromItemSlot: -1}) {
+ ret.WriteString("(empty-path)")
} else {
- var ret strings.Builder
- fmt.Fprintf(&ret, "%s->", path[0].FromTree.Format(btrfsprim.ROOT_TREE_OBJECTID))
- if len(path) == 1 && path[0] == (TreePathElem{FromTree: path[0].FromTree, FromItemSlot: -1}) {
- ret.WriteString("(empty-path)")
- } else {
- path[0].writeNodeTo(&ret)
- }
- for _, elem := range path[1:] {
- fmt.Fprintf(&ret, "[%v]", elem.FromItemSlot)
- if elem.ToNodeAddr != 0 {
- ret.WriteString("->")
- elem.writeNodeTo(&ret)
- }
+ path[0].writeNodeTo(&ret)
+ }
+ for _, elem := range path[1:] {
+ fmt.Fprintf(&ret, "[%v]", elem.FromItemSlot)
+ if elem.ToNodeAddr != 0 {
+ ret.WriteString("->")
+ elem.writeNodeTo(&ret)
}
- return ret.String()
}
+ return ret.String()
}
func (path TreePath) DeepCopy() TreePath {
diff --git a/lib/btrfs/btrfstree/types_node.go b/lib/btrfs/btrfstree/types_node.go
index c770fe8..8295ccb 100644
--- a/lib/btrfs/btrfstree/types_node.go
+++ b/lib/btrfs/btrfstree/types_node.go
@@ -113,20 +113,22 @@ type NodeHeader struct {
// .Head.NumItems.
func (node Node) MaxItems() uint32 {
bodyBytes := node.Size - uint32(nodeHeaderSize)
- if node.Head.Level > 0 {
+ switch {
+ case node.Head.Level > 0:
return bodyBytes / uint32(keyPointerSize)
- } else {
+ default:
return bodyBytes / uint32(itemHeaderSize)
}
}
func (node Node) MinItem() (btrfsprim.Key, bool) {
- if node.Head.Level > 0 {
+ switch {
+ case node.Head.Level > 0:
if len(node.BodyInterior) == 0 {
return btrfsprim.Key{}, false
}
return node.BodyInterior[0].Key, true
- } else {
+ default:
if len(node.BodyLeaf) == 0 {
return btrfsprim.Key{}, false
}
@@ -135,12 +137,13 @@ func (node Node) MinItem() (btrfsprim.Key, bool) {
}
func (node Node) MaxItem() (btrfsprim.Key, bool) {
- if node.Head.Level > 0 {
+ switch {
+ case node.Head.Level > 0:
if len(node.BodyInterior) == 0 {
return btrfsprim.Key{}, false
}
return node.BodyInterior[len(node.BodyInterior)-1].Key, true
- } else {
+ default:
if len(node.BodyLeaf) == 0 {
return btrfsprim.Key{}, false
}
@@ -221,15 +224,15 @@ func (node Node) MarshalBinary() ([]byte, error) {
buf := make([]byte, node.Size)
- if bs, err := binstruct.Marshal(node.Head); err != nil {
+ bs, err := binstruct.Marshal(node.Head)
+ if err != nil {
return buf, err
- } else {
- if len(bs) != nodeHeaderSize {
- return nil, fmt.Errorf("header is %v bytes but expected %v",
- len(bs), nodeHeaderSize)
- }
- copy(buf, bs)
}
+ if len(bs) != nodeHeaderSize {
+ return nil, fmt.Errorf("header is %v bytes but expected %v",
+ len(bs), nodeHeaderSize)
+ }
+ copy(buf, bs)
if node.Head.Level > 0 {
if err := node.marshalInteriorTo(buf[nodeHeaderSize:]); err != nil {
diff --git a/lib/btrfs/io4_fs.go b/lib/btrfs/io4_fs.go
index e146739..b1a1232 100644
--- a/lib/btrfs/io4_fs.go
+++ b/lib/btrfs/io4_fs.go
@@ -122,7 +122,7 @@ func (sv *Subvolume) LoadBareInode(inode btrfsprim.ObjID) (*BareInode, error) {
})
if err != nil {
val.Errs = append(val.Errs, err)
- return
+ return val
}
switch itemBody := item.Body.(type) {
@@ -135,7 +135,7 @@ func (sv *Subvolume) LoadBareInode(inode btrfsprim.ObjID) (*BareInode, error) {
panic(fmt.Errorf("should not happen: INODE_ITEM has unexpected item type: %T", itemBody))
}
- return
+ return val
})
if val.InodeItem == nil {
return nil, val.Errs
@@ -156,7 +156,7 @@ func (sv *Subvolume) LoadFullInode(inode btrfsprim.ObjID) (*FullInode, error) {
if err != nil {
val.Errs = append(val.Errs, err)
if len(items) == 0 {
- return
+ return val
}
}
for _, item := range items {
@@ -190,7 +190,7 @@ func (sv *Subvolume) LoadFullInode(inode btrfsprim.ObjID) (*FullInode, error) {
val.OtherItems = append(val.OtherItems, item)
}
}
- return
+ return val
})
if val.InodeItem == nil && val.OtherItems == nil {
return nil, val.Errs
@@ -205,12 +205,12 @@ func (sv *Subvolume) LoadDir(inode btrfsprim.ObjID) (*Dir, error) {
fullInode, err := sv.LoadFullInode(inode)
if err != nil {
val.Errs = append(val.Errs, err)
- return
+ return val
}
val.FullInode = *fullInode
val.SV = sv
val.populate()
- return
+ return val
})
if val.Inode == 0 {
return nil, val.Errs
@@ -342,12 +342,12 @@ func (sv *Subvolume) LoadFile(inode btrfsprim.ObjID) (*File, error) {
fullInode, err := sv.LoadFullInode(inode)
if err != nil {
val.Errs = append(val.Errs, err)
- return
+ return val
}
val.FullInode = *fullInode
val.SV = sv
val.populate()
- return
+ return val
})
if val.Inode == 0 {
return nil, val.Errs