From 48a0289cd33314a3fa652f5eb1c8695e9f25fd6a Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 12 Jun 2022 00:29:13 -0600 Subject: Have WalkTree include path information --- cmd/btrfs-fsck/pass1.go | 3 ++- cmd/btrfs-fsck/pass2.go | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'cmd/btrfs-fsck') 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{}{} -- cgit v1.2.3-2-g168b