summaryrefslogtreecommitdiff
path: root/lib/btrfs/types_node.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-07-27 22:53:32 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-07-27 23:51:27 -0600
commita424326c8918f3c4b63fb07a35b2d8fea05d7733 (patch)
tree29f4b8010ed7fe883c2e55648a664ad93ae4c11c /lib/btrfs/types_node.go
parent3aed2695a3edfba7c5d95ab86b8854cc1b6dc6a8 (diff)
implement `rebuild-nodes`
Diffstat (limited to 'lib/btrfs/types_node.go')
-rw-r--r--lib/btrfs/types_node.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/btrfs/types_node.go b/lib/btrfs/types_node.go
index 840236d..3a83ee7 100644
--- a/lib/btrfs/types_node.go
+++ b/lib/btrfs/types_node.go
@@ -103,6 +103,34 @@ func (node Node) MaxItems() uint32 {
}
}
+func (node Node) MinItem() (Key, bool) {
+ if node.Head.Level > 0 {
+ if len(node.BodyInternal) == 0 {
+ return Key{}, false
+ }
+ return node.BodyInternal[0].Key, true
+ } else {
+ if len(node.BodyLeaf) == 0 {
+ return Key{}, false
+ }
+ return node.BodyLeaf[0].Key, true
+ }
+}
+
+func (node Node) MaxItem() (Key, bool) {
+ if node.Head.Level > 0 {
+ if len(node.BodyInternal) == 0 {
+ return Key{}, false
+ }
+ return node.BodyInternal[len(node.BodyInternal)-1].Key, true
+ } else {
+ if len(node.BodyLeaf) == 0 {
+ return Key{}, false
+ }
+ return node.BodyLeaf[len(node.BodyLeaf)-1].Key, true
+ }
+}
+
func (node Node) CalculateChecksum() (btrfssum.CSum, error) {
data, err := binstruct.Marshal(node)
if err != nil {