summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/btrfs-clear-bad-nodes/main.go10
-rw-r--r--pkg/btrfs/io3_btree.go2
2 files changed, 10 insertions, 2 deletions
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()
diff --git a/pkg/btrfs/io3_btree.go b/pkg/btrfs/io3_btree.go
index 3c1535b..9ba3be1 100644
--- a/pkg/btrfs/io3_btree.go
+++ b/pkg/btrfs/io3_btree.go
@@ -152,7 +152,7 @@ func (fs *FS) treeWalk(path TreePath, cbs TreeWalkHandler) error {
}
}
node, err := fs.readNodeAtLevel(path[len(path)-1].NodeAddr, path[len(path)-1].NodeLevel)
- if node != nil {
+ if node != nil && err == nil {
path[len(path)-1].NodeLevel = node.Data.Head.Level
}
if cbs.Node != nil {