diff options
Diffstat (limited to 'lib/btrfs/btrfstree')
-rw-r--r-- | lib/btrfs/btrfstree/node_exp.go | 4 | ||||
-rw-r--r-- | lib/btrfs/btrfstree/types_node.go | 5 |
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 { |