diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-05 23:57:05 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-06-05 23:57:05 -0600 |
commit | 6a5b5b59345c6e57ba496c7d517902c339d2f0b8 (patch) | |
tree | e3428175ffd07791fad1406401fe1856e95e8555 /pkg/btrfs | |
parent | 5c02065e573ce42d9d83099b524566878ba61bdb (diff) |
wip gather stripes
Diffstat (limited to 'pkg/btrfs')
-rw-r--r-- | pkg/btrfs/btrfsitem/item_chunk.go | 16 | ||||
-rw-r--r-- | pkg/btrfs/io2_fs.go | 4 |
2 files changed, 12 insertions, 8 deletions
diff --git a/pkg/btrfs/btrfsitem/item_chunk.go b/pkg/btrfs/btrfsitem/item_chunk.go index 4389a46..8ffc83b 100644 --- a/pkg/btrfs/btrfsitem/item_chunk.go +++ b/pkg/btrfs/btrfsitem/item_chunk.go @@ -7,8 +7,13 @@ import ( "lukeshu.com/btrfs-tools/pkg/btrfs/internal" ) +// Maps logical address to physical. type Chunk struct { // CHUNK_ITEM=228 - // Maps logical address to physical. + Head ChunkHeader + Stripes []ChunkStripe +} + +type ChunkHeader struct { Size uint64 `bin:"off=0x0, siz=0x8"` // size of chunk (bytes) Owner internal.ObjID `bin:"off=0x8, siz=0x8"` // root referencing this chunk (2) StripeLen uint64 `bin:"off=0x10, siz=0x8"` // stripe length @@ -19,7 +24,6 @@ type Chunk struct { // CHUNK_ITEM=228 NumStripes uint16 `bin:"off=0x2c, siz=0x2"` // number of stripes SubStripes uint16 `bin:"off=0x2e, siz=0x2"` // sub stripes binstruct.End `bin:"off=0x30"` - Stripes []ChunkStripe `bin:"-"` } type ChunkStripe struct { @@ -30,12 +34,12 @@ type ChunkStripe struct { } func (chunk *Chunk) UnmarshalBinary(dat []byte) (int, error) { - n, err := binstruct.UnmarshalWithoutInterface(dat, chunk) + n, err := binstruct.Unmarshal(dat, &chunk.Head) if err != nil { return n, err } chunk.Stripes = nil - for i := 0; i < int(chunk.NumStripes); i++ { + for i := 0; i < int(chunk.Head.NumStripes); i++ { var stripe ChunkStripe _n, err := binstruct.Unmarshal(dat[n:], &stripe) n += _n @@ -48,8 +52,8 @@ func (chunk *Chunk) UnmarshalBinary(dat []byte) (int, error) { } func (chunk Chunk) MarshalBinary() ([]byte, error) { - chunk.NumStripes = uint16(len(chunk.Stripes)) - ret, err := binstruct.MarshalWithoutInterface(chunk) + chunk.Head.NumStripes = uint16(len(chunk.Stripes)) + ret, err := binstruct.Marshal(chunk.Head) if err != nil { return ret, err } diff --git a/pkg/btrfs/io2_fs.go b/pkg/btrfs/io2_fs.go index ca67a9c..035019c 100644 --- a/pkg/btrfs/io2_fs.go +++ b/pkg/btrfs/io2_fs.go @@ -175,9 +175,9 @@ func (fs *FS) Resolve(laddr LogicalAddr) (paddrs map[QualifiedPhysicalAddr]struc maxlen = math.MaxUint64 for _, chunk := range fs.chunks { - if chunk.Key.Offset <= uint64(laddr) && uint64(laddr) < chunk.Key.Offset+uint64(chunk.Chunk.Size) { + if chunk.Key.Offset <= uint64(laddr) && uint64(laddr) < chunk.Key.Offset+uint64(chunk.Chunk.Head.Size) { offsetWithinChunk := uint64(laddr) - chunk.Key.Offset - maxlen = util.Min(maxlen, chunk.Chunk.Size-offsetWithinChunk) + maxlen = util.Min(maxlen, chunk.Chunk.Head.Size-offsetWithinChunk) for _, stripe := range chunk.Chunk.Stripes { paddrs[QualifiedPhysicalAddr{ Dev: stripe.DeviceUUID, |