summaryrefslogtreecommitdiff
path: root/cmd/btrfs-fsck/main.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-06-06 00:21:59 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-06-06 00:21:59 -0600
commit20c21bf5ebc085f6f318e9199a1fee5f44c6ea61 (patch)
treebabb8b3e8dcd2d0155d752d9af99209b3598c66b /cmd/btrfs-fsck/main.go
parent6a5b5b59345c6e57ba496c7d517902c339d2f0b8 (diff)
wip
Diffstat (limited to 'cmd/btrfs-fsck/main.go')
-rw-r--r--cmd/btrfs-fsck/main.go100
1 files changed, 55 insertions, 45 deletions
diff --git a/cmd/btrfs-fsck/main.go b/cmd/btrfs-fsck/main.go
index 2e47588..5f958a6 100644
--- a/cmd/btrfs-fsck/main.go
+++ b/cmd/btrfs-fsck/main.go
@@ -5,6 +5,7 @@ import (
"os"
"sort"
+ "lukeshu.com/btrfs-tools/pkg/binstruct"
"lukeshu.com/btrfs-tools/pkg/btrfs"
"lukeshu.com/btrfs-tools/pkg/btrfs/btrfsitem"
"lukeshu.com/btrfs-tools/pkg/btrfsmisc"
@@ -172,55 +173,64 @@ func Main(imgfilename string) (err error) {
// store that node at the root node of the chunk tree. This
// isn't true in general, but it's true of my particular
// filesystem.
- /*
- reconstructedNode := &util.Ref[btrfs.LogicalAddr, btrfs.Node]{
- File: fs,
- Addr: superblock.Data.ChunkTree,
- Data: btrfs.Node{
- Size: superblock.Data.NodeSize,
- Head: btrfs.NodeHeader{
- MetadataUUID: superblock.Data.EffectiveMetadataUUID(),
- Addr: superblock.Data.ChunkTree,
- Flags: btrfs.NodeWritten,
- //BackrefRef: ???,
- //ChunkTreeUUID: ???,
- Generation: superblock.Data.ChunkRootGeneration,
- Owner: btrfs.CHUNK_TREE_OBJECTID,
- Level: 0,
- },
+ reconstructedNode := &util.Ref[btrfs.LogicalAddr, btrfs.Node]{
+ File: fs,
+ Addr: superblock.Data.ChunkTree,
+ Data: btrfs.Node{
+ Size: superblock.Data.NodeSize,
+ Head: btrfs.NodeHeader{
+ MetadataUUID: superblock.Data.EffectiveMetadataUUID(),
+ Addr: superblock.Data.ChunkTree,
+ Flags: btrfs.NodeWritten,
+ //BackrefRef: ???,
+ //ChunkTreeUUID: ???,
+ Generation: superblock.Data.ChunkRootGeneration,
+ Owner: btrfs.CHUNK_TREE_OBJECTID,
+ Level: 0,
},
- }
- itemOff := superblock.Data.NodeSize - binstruct.StaticSize(btrfs.ItemHeader{})
- for laddr, stripes := range reconstructedChunks {
- stripeSize := stripes[0].Size
- for i, stripe := range stripes {
- if stripes.Size != stripeSize {
- panic("mismatch")
- }
+ },
+ }
+ itemOff := uint32(uint64(superblock.Data.NodeSize) - uint64(binstruct.StaticSize(btrfs.ItemHeader{})))
+ for laddr, stripes := range reconstructedChunks {
+ stripeSize := stripes[0].Size
+ for _, stripe := range stripes {
+ if stripe.Size != stripeSize {
+ panic("mismatch")
}
- itemSize := binstruct.StaticSize(btrfsitem.ChunkHeader) + (len(stripes) * binstruct.StaticSize(btrfsitem.ChunkStripe))
- itemOff -= itemSize
- reconstructedNode.Data.BodyLeaf = append(reconstructedNode.Data.BodyLeaf, btrfs.Item{
- Head: btrfs.ItemHeader{
- Key: TODO,
- DataOffset: itemOff,
- DataSize: itemSize,
+ }
+ itemSize := uint32(binstruct.StaticSize(btrfsitem.ChunkHeader{}) + (len(stripes) * binstruct.StaticSize(btrfsitem.ChunkStripe{})))
+ itemOff -= itemSize
+ reconstructedNode.Data.BodyLeaf = append(reconstructedNode.Data.BodyLeaf, btrfs.Item{
+ Head: btrfs.ItemHeader{
+ Key: btrfs.Key{
+ ObjectID: TODO,
+ ItemType: TODO,
+ Offset: uint64(laddr),
},
- Body: btrfsitem.Chunk{
- Head: btrfsitem.ChunkHeader{
- Size: stripeSize,
- Owner: 2,
- StripeLen:
- Stripes: stripes,
+ DataOffset: itemOff,
+ DataSize: itemSize,
+ },
+ Body: btrfsitem.Chunk{
+ Head: btrfsitem.ChunkHeader{
+ Size: stripeSize,
+ Owner: btrfs.EXTENT_TREE_OBJECTID,
+ StripeLen: 65536, // ???
+ Type: TODO,
+ IOOptimalAlign: TODO,
+ IOOptimalWidth: TODO,
+ IOMinSize: TODO,
+ NumStripes: uint16(len(stripes)),
+ SubStripes: 1,
},
- })
- }
- reconstructedNode.Data.Head.NumItems = len(reconstructedNode.Data.BodyLeaf)
- reconstructedNode.Data.Head.Checksum, err = reconstructedNode.Data.CalculateChecksum()
- if err != nil {
- fmt.Printf("Pass 1: ... new node checksum: error: %v\n", err)
- }
- */
+ Stripes: stripes,
+ },
+ })
+ }
+ reconstructedNode.Data.Head.NumItems = uint32(len(reconstructedNode.Data.BodyLeaf))
+ reconstructedNode.Data.Head.Checksum, err = reconstructedNode.Data.CalculateChecksum()
+ if err != nil {
+ fmt.Printf("Pass 1: ... new node checksum: error: %v\n", err)
+ }
fmt.Printf("\nPass 2: ?????????????????????????\n") ////////////////////////////////////////
/*