summaryrefslogtreecommitdiff
path: root/lib/btrfs/btrfsitem/item_freespacebitmap.go
blob: ebc00e4ff6de3489aa020d8a1d1c2ca8c0874a90 (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
// Copyright (C) 2022-2023  Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later

package btrfsitem

// key.objectid = object ID of the FreeSpaceInfo (logical_addr)
// key.offset = offset of the FreeSpaceInfo (size)
type FreeSpaceBitmap struct { // complex FREE_SPACE_BITMAP=200
	Bitmap []byte
}

func (o *FreeSpaceBitmap) Free() {
	bytePool.Put(o.Bitmap)
	*o = FreeSpaceBitmap{}
	freeSpaceBitmapPool.Put(o)
}

func (o FreeSpaceBitmap) Clone() FreeSpaceBitmap {
	o.Bitmap = cloneBytes(o.Bitmap)
	return o
}

func (o *FreeSpaceBitmap) UnmarshalBinary(dat []byte) (int, error) {
	o.Bitmap = cloneBytes(dat)
	return len(dat), nil
}

func (o FreeSpaceBitmap) MarshalBinary() ([]byte, error) {
	return append([]byte(nil), o.Bitmap...), nil
}