From 8463b2bff37978124e5210a59590f1ac33e453c0 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 26 Jun 2022 22:19:29 -0600 Subject: use devid instead of devuuid, add a Mapping struct --- pkg/btrfs/btrfsitem/item_chunk.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'pkg/btrfs/btrfsitem/item_chunk.go') 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 { -- cgit v1.2.3-2-g168b