diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-15 00:00:28 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-15 00:01:45 -0600 |
commit | af6b87672fa55a2436609ac63bd19931d3fe7725 (patch) | |
tree | 6b1b21dfbe6d7b585bd8dc50d9cc62774a57be4e /cmd/btrfs-fsck/pass2.go | |
parent | 7a55b5b74708242adfffb9a9d8381b02fe11ed38 (diff) |
do a better job of scanning for mapping stuff in a device
Diffstat (limited to 'cmd/btrfs-fsck/pass2.go')
-rw-r--r-- | cmd/btrfs-fsck/pass2.go | 84 |
1 files changed, 2 insertions, 82 deletions
diff --git a/cmd/btrfs-fsck/pass2.go b/cmd/btrfs-fsck/pass2.go index b38fbcc..0e74fc2 100644 --- a/cmd/btrfs-fsck/pass2.go +++ b/cmd/btrfs-fsck/pass2.go @@ -6,95 +6,15 @@ import ( "sort" "lukeshu.com/btrfs-tools/pkg/btrfs" - "lukeshu.com/btrfs-tools/pkg/btrfs/btrfsitem" + "lukeshu.com/btrfs-tools/pkg/btrfsmisc" "lukeshu.com/btrfs-tools/pkg/util" ) -func walkFS(fs *btrfs.FS, cbs btrfs.WalkTreeHandler, errCb func(error)) { - var treeName string - origErrCb := errCb - errCb = func(err error) { - origErrCb(fmt.Errorf("%v: %w", treeName, err)) - } - - var foundTrees []struct { - Name string - Root btrfs.LogicalAddr - } - origItem := cbs.Item - 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("%v: ROOT_ITEM_KEY is a %T, not a btrfsitem.Root", path, item.Body)) - } else { - foundTrees = append(foundTrees, struct { - Name string - Root btrfs.LogicalAddr - }{ - Name: fmt.Sprintf("tree %v (via %v %v)", - item.Head.Key.ObjectID.Format(0), treeName, path), - Root: root.ByteNr, - }) - } - } - if origItem != nil { - return origItem(path, item) - } - return nil - } - - origNode := cbs.Node - cbs.Node = func(path btrfs.WalkTreePath, node *util.Ref[btrfs.LogicalAddr, btrfs.Node], err error) error { - if err != nil { - errCb(fmt.Errorf("%v: %w", path, err)) - } - if node != nil && origNode != nil { - return origNode(path, node, nil) - } - return nil - } - - treeName = "superblock" - superblock, err := fs.Superblock() - if err != nil { - errCb(err) - return - } - - treeName = "root tree" - if err := fs.WalkTree(superblock.Data.RootTree, cbs); err != nil { - errCb(err) - } - - treeName = "chunk tree" - if err := fs.WalkTree(superblock.Data.ChunkTree, cbs); err != nil { - errCb(err) - } - - treeName = "log tree" - if err := fs.WalkTree(superblock.Data.LogTree, cbs); err != nil { - errCb(err) - } - - treeName = "block group tree" - if err := fs.WalkTree(superblock.Data.BlockGroupRoot, cbs); err != nil { - errCb(err) - } - - for _, tree := range foundTrees { - treeName = tree.Name - if err := fs.WalkTree(tree.Root, cbs); err != nil { - errCb(err) - } - } -} - func pass2(fs *btrfs.FS, foundNodes map[btrfs.LogicalAddr]struct{}) { fmt.Printf("\nPass 2: orphaned nodes\n") visitedNodes := make(map[btrfs.LogicalAddr]struct{}) - walkFS(fs, btrfs.WalkTreeHandler{ + btrfsmisc.WalkFS(fs, btrfs.WalkTreeHandler{ Node: func(path btrfs.WalkTreePath, node *util.Ref[btrfs.LogicalAddr, btrfs.Node], err error) error { visitedNodes[node.Addr] = struct{}{} return nil |