summaryrefslogtreecommitdiff
path: root/pkg/btrfs/btrfsitem/item_chunk.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-06-26 22:19:29 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-06-26 22:19:41 -0600
commit8463b2bff37978124e5210a59590f1ac33e453c0 (patch)
tree37fc4c13f1fdaedf20ee48a53653414fbb3d9ed7 /pkg/btrfs/btrfsitem/item_chunk.go
parent64c04fc690ec5a276e11500691173962bbe4d99e (diff)
use devid instead of devuuid, add a Mapping struct
Diffstat (limited to 'pkg/btrfs/btrfsitem/item_chunk.go')
-rw-r--r--pkg/btrfs/btrfsitem/item_chunk.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/pkg/btrfs/btrfsitem/item_chunk.go b/pkg/btrfs/btrfsitem/item_chunk.go
index a77ae33..efd9d31 100644
--- a/pkg/btrfs/btrfsitem/item_chunk.go
+++ b/pkg/btrfs/btrfsitem/item_chunk.go
@@ -32,12 +32,28 @@ type ChunkHeader struct {
}
type ChunkStripe struct {
- DeviceID internal.ObjID `bin:"off=0x0, siz=0x8"`
+ DeviceID btrfsvol.DeviceID `bin:"off=0x0, siz=0x8"`
Offset btrfsvol.PhysicalAddr `bin:"off=0x8, siz=0x8"`
DeviceUUID util.UUID `bin:"off=0x10, siz=0x10"`
binstruct.End `bin:"off=0x20"`
}
+func (chunk Chunk) Mappings(key internal.Key) []btrfsvol.Mapping {
+ ret := make([]btrfsvol.Mapping, 0, len(chunk.Stripes))
+ for _, stripe := range chunk.Stripes {
+ ret = append(ret, btrfsvol.Mapping{
+ LAddr: btrfsvol.LogicalAddr(key.Offset),
+ PAddr: btrfsvol.QualifiedPhysicalAddr{
+ Dev: stripe.DeviceID,
+ Addr: stripe.Offset,
+ },
+ Size: chunk.Head.Size,
+ Flags: &chunk.Head.Type,
+ })
+ }
+ return ret
+}
+
func (chunk *Chunk) UnmarshalBinary(dat []byte) (int, error) {
n, err := binstruct.Unmarshal(dat, &chunk.Head)
if err != nil {