diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-06 23:56:11 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-06 23:56:11 -0600 |
commit | 69f0420fdb3701fd6ed6a682835e3ba282b7bdbb (patch) | |
tree | 2a48cfd35792fb3dca803f2982a9cb0f7a03c03c /cmd/btrfs-fsck/pass1.go | |
parent | 07b7c8a2a12a09c49659efbe522ad1c3f7161aed (diff) |
fixup
Diffstat (limited to 'cmd/btrfs-fsck/pass1.go')
-rw-r--r-- | cmd/btrfs-fsck/pass1.go | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/cmd/btrfs-fsck/pass1.go b/cmd/btrfs-fsck/pass1.go index 97129cd..378c88d 100644 --- a/cmd/btrfs-fsck/pass1.go +++ b/cmd/btrfs-fsck/pass1.go @@ -170,16 +170,16 @@ func pass1ReconstructChunksOneDev( LAddr btrfs.LogicalAddr Size uint64 } - var stripes []stripe + var stripes []*stripe for _, paddr := range sortedPaddrs { var lastStripe *stripe if len(stripes) > 0 { - lastStripe = &stripes[len(stripes)-1] + lastStripe = stripes[len(stripes)-1] } if lastStripe != nil && (lastStripe.PAddr+btrfs.PhysicalAddr(lastStripe.Size)) == paddr { lastStripe.Size += uint64(superblock.Data.NodeSize) } else { - stripes = append(stripes, stripe{ + stripes = append(stripes, &stripe{ PAddr: paddr, LAddr: lostAndFoundNodes[paddr], Size: uint64(superblock.Data.NodeSize), @@ -242,6 +242,7 @@ func pass1WriteReconstructedChunks( }, }, } + for _, dev := range fs.Devices { superblock, _ := dev.Superblock() reconstructedNode.Data.BodyLeaf = append(reconstructedNode.Data.BodyLeaf, btrfs.Item{ @@ -255,7 +256,20 @@ func pass1WriteReconstructedChunks( Body: superblock.Data.DevItem, }) } - for laddr, chunk := range fsReconstructedChunks { + + sortedLAddrs := make([]btrfs.LogicalAddr, 0, len(fsReconstructedChunks)) + for laddr := range fsReconstructedChunks { + sortedLAddrs = append(sortedLAddrs, laddr) + } + sort.Slice(sortedLAddrs, func(i, j int) bool { + return sortedLAddrs[i] < sortedLAddrs[j] + }) + for i, laddr := range sortedLAddrs { + chunk := fsReconstructedChunks[laddr] + for j, stripe := range chunk.Stripes { + fmt.Printf("Pass 1: chunk[%d].stripe[%d] = { laddr=0x%0x ⇒ { dev_id=%v, paddr=0x%0x }, size=0x%0x }\n", + i, j, laddr, stripe.DeviceID, stripe.Offset, chunk.Size) + } reconstructedNode.Data.BodyLeaf = append(reconstructedNode.Data.BodyLeaf, btrfs.Item{ Head: btrfs.ItemHeader{ Key: btrfs.Key{ @@ -280,11 +294,13 @@ func pass1WriteReconstructedChunks( }, }) } + var err error reconstructedNode.Data.Head.Checksum, err = reconstructedNode.Data.CalculateChecksum() if err != nil { fmt.Printf("Pass 1: ... new node checksum: error: %v\n", err) } + if err := reconstructedNode.Write(); err != nil { fmt.Printf("Pass 1: ... write new node: error: %v\n", err) } |