From c93e585d97cf6129cba277c812d100e7eac0d249 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 7 Jul 2022 13:17:40 -0600 Subject: sorta fix the Level on root nodes --- cmd/btrfs-clear-bad-nodes/main.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'cmd') diff --git a/cmd/btrfs-clear-bad-nodes/main.go b/cmd/btrfs-clear-bad-nodes/main.go index ddd8cd3..44f6697 100644 --- a/cmd/btrfs-clear-bad-nodes/main.go +++ b/cmd/btrfs-clear-bad-nodes/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "math" "os" "lukeshu.com/btrfs-tools/pkg/btrfs" @@ -58,8 +59,15 @@ func Main(imgfilenames ...string) (err error) { } origErr := err if !uuidsInited { + // TODO(lukeshu): Is there a better way to get the chunk + // tree UUID. return fmt.Errorf("cannot repair node@%v: not (yet?) sure what the chunk tree UUID is", node.Addr) } + nodeLevel := path[len(path)-1].NodeLevel + if nodeLevel == math.MaxUint8 { + // TODO(lukeshu): Use level from the superblock or whatever. + nodeLevel = 0 + } node.Data = btrfs.Node{ Size: node.Data.Size, ChecksumType: node.Data.ChecksumType, @@ -73,7 +81,7 @@ func Main(imgfilenames ...string) (err error) { Generation: 0, Owner: treeID, NumItems: 0, - Level: path[len(path)-1].NodeLevel, + Level: nodeLevel, }, } node.Data.Head.Checksum, err = node.Data.CalculateChecksum() -- cgit v1.2.3-2-g168b