diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-07 01:33:40 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-07 01:33:40 -0600 |
commit | 8d6bd496c2ed027739a3edf02fe1785009f5a89f (patch) | |
tree | 9e97a23fd84425c6659ea9584d28468cb4720956 /cmd/btrfs-fsck/pass1.go | |
parent | 69f0420fdb3701fd6ed6a682835e3ba282b7bdbb (diff) |
fast
Diffstat (limited to 'cmd/btrfs-fsck/pass1.go')
-rw-r--r-- | cmd/btrfs-fsck/pass1.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/cmd/btrfs-fsck/pass1.go b/cmd/btrfs-fsck/pass1.go index 378c88d..f880ac9 100644 --- a/cmd/btrfs-fsck/pass1.go +++ b/cmd/btrfs-fsck/pass1.go @@ -1,7 +1,11 @@ package main import ( + "encoding/json" + "errors" "fmt" + iofs "io/fs" + "os" "sort" "lukeshu.com/btrfs-tools/pkg/btrfs" @@ -86,6 +90,46 @@ func pass1ScanOneDev( lostAndFoundChunks []btrfs.SysChunk, err error, ) { + type rec struct { + DevFoundNodes map[btrfs.LogicalAddr][]btrfs.PhysicalAddr + DevLostAndFoundChunks []btrfs.SysChunk + } + var obj rec + + const jsonFilename = "/home/lukeshu/btrfs/pass1.json" + + bs, err := os.ReadFile(jsonFilename) + if err != nil { + if errors.Is(err, iofs.ErrNotExist) { + obj.DevFoundNodes, obj.DevLostAndFoundChunks, err = pass1ScanOneDev_x(dev, superblock, visitedChunkNodes) + if err != nil { + panic(err) + } + bs, err := json.Marshal(obj) + if err != nil { + panic(err) + } + if err := os.WriteFile(jsonFilename, bs, 0600); err != nil { + panic(err) + } + } + return nil, nil, err + } + if err := json.Unmarshal(bs, &obj); err != nil { + return nil, nil, err + } + return obj.DevFoundNodes, obj.DevLostAndFoundChunks, nil +} + +func pass1ScanOneDev_x( + dev *btrfs.Device, + superblock btrfs.Superblock, + visitedChunkNodes map[btrfs.LogicalAddr]struct{}, +) ( + foundNodes map[btrfs.LogicalAddr][]btrfs.PhysicalAddr, + lostAndFoundChunks []btrfs.SysChunk, + err error, +) { foundNodes = make(map[btrfs.LogicalAddr][]btrfs.PhysicalAddr) devSize, _ := dev.Size() |