diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-06 21:24:40 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-06 21:24:40 -0600 |
commit | 31f242bf094494054be15d9d56c85019287c520e (patch) | |
tree | 12c3cd571a3ce2310d19f19a0e4d034d8b03dcb8 /cmd/btrfs-fsck | |
parent | 7151acadd5efd7e2ad18b07f9e51cf4e203b9c8b (diff) |
wip: walkFS
Diffstat (limited to 'cmd/btrfs-fsck')
-rw-r--r-- | cmd/btrfs-fsck/main.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/cmd/btrfs-fsck/main.go b/cmd/btrfs-fsck/main.go index 8086904..1147acf 100644 --- a/cmd/btrfs-fsck/main.go +++ b/cmd/btrfs-fsck/main.go @@ -291,3 +291,40 @@ func Main(imgfilename string) (err error) { */ return nil } + +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) + if !ok { + errCb(fmt.Errorf("ROOT_ITEM_KEY is a %T, not a btrfsitem.Root", body)) + } else if err := fs.WalkTree(root.ByteNr, cbs); err != nil { + errCb(err) + } + } + if origItem != nil { + return origItem(key, body) + } + return nil + } + + superblock, err := fs.Superblock() + if err != nil { + errCb(err) + return + } + + if err := fs.WalkTree(superblock.Data.RootTree, cbs); err != nil { + errCb(err) + } + if err := fs.WalkTree(superblock.Data.ChunkTree, cbs); err != nil { + errCb(err) + } + if err := fs.WalkTree(superblock.Data.LogTree, cbs); err != nil { + errCb(err) + } + if err := fs.WalkTree(superblock.Data.BlockGroupRoot, cbs); err != nil { + errCb(err) + } +} |