summaryrefslogtreecommitdiff
path: root/cmd/btrfs-fsck
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-06-12 00:29:13 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-06-12 00:29:13 -0600
commit48a0289cd33314a3fa652f5eb1c8695e9f25fd6a (patch)
tree8508296ecbd0de2e2c3b484669b14bb6b3040609 /cmd/btrfs-fsck
parent515dfcbef2002aacf49b92aa16843eb8d7232db3 (diff)
Have WalkTree include path information
Diffstat (limited to 'cmd/btrfs-fsck')
-rw-r--r--cmd/btrfs-fsck/pass1.go3
-rw-r--r--cmd/btrfs-fsck/pass2.go16
2 files changed, 10 insertions, 9 deletions
diff --git a/cmd/btrfs-fsck/pass1.go b/cmd/btrfs-fsck/pass1.go
index 37fca0c..bd2b6d9 100644
--- a/cmd/btrfs-fsck/pass1.go
+++ b/cmd/btrfs-fsck/pass1.go
@@ -25,8 +25,9 @@ func pass1(fs *btrfs.FS, superblock *util.Ref[btrfs.PhysicalAddr, btrfs.Superblo
fmt.Printf("Pass 1: ... walking chunk tree\n")
visitedChunkNodes := make(map[btrfs.LogicalAddr]struct{})
if err := fs.WalkTree(superblock.Data.ChunkTree, btrfs.WalkTreeHandler{
- Node: func(node *util.Ref[btrfs.LogicalAddr, btrfs.Node], err error) error {
+ Node: func(path btrfs.WalkTreePath, node *util.Ref[btrfs.LogicalAddr, btrfs.Node], err error) error {
if err != nil {
+ err = fmt.Errorf("%v: %w", path, err)
fmt.Printf("Pass 1: ... walk chunk tree: error: %v\n", err)
}
if node != nil {
diff --git a/cmd/btrfs-fsck/pass2.go b/cmd/btrfs-fsck/pass2.go
index c1ec61b..7c4a090 100644
--- a/cmd/btrfs-fsck/pass2.go
+++ b/cmd/btrfs-fsck/pass2.go
@@ -10,17 +10,17 @@ import (
func walkFS(fs *btrfs.FS, cbs btrfs.WalkTreeHandler, errCb func(error)) {
origItem := cbs.Item
- cbs.Item = func(key btrfs.Key, body btrfsitem.Item) error {
- if key.ItemType == btrfsitem.ROOT_ITEM_KEY {
- root, ok := body.(btrfsitem.Root)
+ cbs.Item = func(path btrfs.WalkTreePath, item btrfs.Item) error {
+ if item.Head.Key.ItemType == btrfsitem.ROOT_ITEM_KEY {
+ root, ok := item.Body.(btrfsitem.Root)
if !ok {
- errCb(fmt.Errorf("ROOT_ITEM_KEY is a %T, not a btrfsitem.Root", body))
+ errCb(fmt.Errorf("%v: ROOT_ITEM_KEY is a %T, not a btrfsitem.Root", path, item.Body))
} else if err := fs.WalkTree(root.ByteNr, cbs); err != nil {
- errCb(fmt.Errorf("tree %v: %w", key.ObjectID.Format(0), err))
+ errCb(fmt.Errorf("%v: tree %v: %w", path, item.Head.Key.ObjectID.Format(0), err))
}
}
if origItem != nil {
- return origItem(key, body)
+ return origItem(path, item)
}
return nil
}
@@ -50,9 +50,9 @@ func pass2(fs *btrfs.FS, foundNodes map[btrfs.LogicalAddr]struct{}) {
visitedNodes := make(map[btrfs.LogicalAddr]struct{})
walkFS(fs, btrfs.WalkTreeHandler{
- Node: func(node *util.Ref[btrfs.LogicalAddr, btrfs.Node], err error) error {
+ Node: func(path btrfs.WalkTreePath, node *util.Ref[btrfs.LogicalAddr, btrfs.Node], err error) error {
if err != nil {
- fmt.Printf("Pass 2: node error: %v\n", err)
+ fmt.Printf("Pass 2: node error: %v: %v\n", path, err)
}
if node != nil {
visitedNodes[node.Addr] = struct{}{}