summaryrefslogtreecommitdiff
path: root/lib/btrfs/btrfsitem/item_devextent.go
blob: cade165456c1a14c0c8f77f9177f8dc016efbd97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright (C) 2022-2023  Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later

package btrfsitem

import (
	"git.lukeshu.com/btrfs-progs-ng/lib/binstruct"
	"git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsprim"
	"git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsvol"
)

// key.objectid = device_id
// key.offset = physical_addr
type DevExtent struct { // trivial DEV_EXTENT=204
	ChunkTree     btrfsprim.ObjID      `bin:"off=0, siz=8"`  // always CHUNK_TREE_OBJECTID
	ChunkObjectID btrfsprim.ObjID      `bin:"off=8, siz=8"`  // which chunk within .ChunkTree owns this extent, always FIRST_CHUNK_TREE_OBJECTID
	ChunkOffset   btrfsvol.LogicalAddr `bin:"off=16, siz=8"` // offset of the CHUNK_ITEM that owns this extent, within the .ChunkObjectID
	Length        btrfsvol.AddrDelta   `bin:"off=24, siz=8"`
	ChunkTreeUUID btrfsprim.UUID       `bin:"off=32, siz=16"`
	binstruct.End `bin:"off=48"`
}

func (devext DevExtent) Mapping(key btrfsprim.Key) btrfsvol.Mapping {
	return btrfsvol.Mapping{
		LAddr: devext.ChunkOffset,
		PAddr: btrfsvol.QualifiedPhysicalAddr{
			Dev:  btrfsvol.DeviceID(key.ObjectID),
			Addr: btrfsvol.PhysicalAddr(key.Offset),
		},
		Size:       devext.Length,
		SizeLocked: true,
	}
}