summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-03-29 22:14:49 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2023-03-30 00:11:50 -0600
commit755ac780df4f653879cb376d27cad7ff8e8d7b0f (patch)
treedbb9cc24a2ed4c800bf489101aad13e86fd703e4 /lib
parent9317e6ec41ebafe1a6950a2996dcd8c4e35650fd (diff)
btrfstree: Maximum node level is 8
Diffstat (limited to 'lib')
-rw-r--r--lib/btrfs/btrfstree/node_exp.go4
-rw-r--r--lib/btrfs/btrfstree/types_node.go5
2 files changed, 8 insertions, 1 deletions
diff --git a/lib/btrfs/btrfstree/node_exp.go b/lib/btrfs/btrfstree/node_exp.go
index 5311ea0..dec6dbb 100644
--- a/lib/btrfs/btrfstree/node_exp.go
+++ b/lib/btrfs/btrfstree/node_exp.go
@@ -35,6 +35,10 @@ func (exp NodeExpectations) Check(node *Node) error {
errs = append(errs, fmt.Errorf("expected level=%v but claims to be level=%v",
exp.Level.Val, node.Head.Level))
}
+ if node.Head.Level > MaxLevel {
+ errs = append(errs, fmt.Errorf("maximum level=%v but claims to be level=%v",
+ MaxLevel, node.Head.Level))
+ }
if exp.Generation.OK && node.Head.Generation != exp.Generation.Val {
errs = append(errs, fmt.Errorf("expected generation=%v but claims to be generation=%v",
exp.Generation.Val, node.Head.Generation))
diff --git a/lib/btrfs/btrfstree/types_node.go b/lib/btrfs/btrfstree/types_node.go
index ed9ba58..28b93cf 100644
--- a/lib/btrfs/btrfstree/types_node.go
+++ b/lib/btrfs/btrfstree/types_node.go
@@ -103,10 +103,13 @@ type NodeHeader struct {
Generation btrfsprim.Generation `bin:"off=0x50, siz=0x8"`
Owner btrfsprim.ObjID `bin:"off=0x58, siz=0x8"` // The ID of the tree that contains this node
NumItems uint32 `bin:"off=0x60, siz=0x4"` // [ignored-when-writing]
- Level uint8 `bin:"off=0x64, siz=0x1"` // 0 for leaf nodes, >=1 for interior nodes
+ Level uint8 `bin:"off=0x64, siz=0x1"` // 0 for leaf nodes, >=1 for interior nodes (max 8)
binstruct.End `bin:"off=0x65"`
}
+// MaxLevel is the maximum valid NodeHeader.Level.
+const MaxLevel = 8
+
// MaxItems returns the maximum possible valid value of
// .Head.NumItems.
func (node Node) MaxItems() uint32 {