iPXE
bitmap.h
Go to the documentation of this file.
1#ifndef _IPXE_BITMAP_H
2#define _IPXE_BITMAP_H
3
4/** @file
5 *
6 * Bitmaps for multicast downloads
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <stdint.h>
14#include <stddef.h>
15#include <stdlib.h>
16
17/** A single block of bits within a bitmap */
18typedef unsigned long bitmap_block_t;
19
20/** Size of a block of bits (in bits) */
21#define BITMAP_BLKSIZE ( sizeof ( bitmap_block_t ) * 8 )
22
23/**
24 * Block index within bitmap
25 *
26 * @v bit Bit index
27 * @ret index Block index
28 */
29#define BITMAP_INDEX( bit ) ( (bit) / BITMAP_BLKSIZE )
30
31/**
32 * Block mask within bitmap
33 *
34 * @v bit Bit index
35 * @ret mask Block mask
36 */
37#define BITMAP_MASK( bit ) ( 1UL << ( (bit) % BITMAP_BLKSIZE ) )
38
39/**
40 * Number of blocks in the bitmap
41 *
42 * @v length Length of the bitmap, in bits
43 * @ret blocks Number of blocks
44 */
45#define BITMAP_BLOCKS( length ) ( ( (length) / BITMAP_BLKSIZE ) + \
46 ( !! ( (length) % BITMAP_BLKSIZE ) ) )
47
48/** A bitmap */
49struct bitmap {
50 /** Bitmap data */
52 /** Length of the bitmap, in bits */
53 unsigned int length;
54 /** Index of first gap in the bitmap */
55 unsigned int first_gap;
56};
57
58extern int bitmap_resize ( struct bitmap *bitmap, unsigned int new_length );
59extern int bitmap_test ( struct bitmap *bitmap, unsigned int bit );
60extern int bitmap_set ( struct bitmap *bitmap, unsigned int bit );
61
62/**
63 * Free bitmap resources
64 *
65 * @v bitmap Bitmap
66 */
67static inline void bitmap_free ( struct bitmap *bitmap ) {
68 free ( bitmap->blocks );
69}
70
71/**
72 * Get first gap within bitmap
73 *
74 * @v bitmap Bitmap
75 * @ret first_gap First gap
76 *
77 * The first gap is the first unset bit within the bitmap.
78 */
79static inline unsigned int bitmap_first_gap ( struct bitmap *bitmap ) {
80 return bitmap->first_gap;
81}
82
83/**
84 * Check to see if bitmap is full
85 *
86 * @v bitmap Bitmap
87 * @ret is_full Bitmap is full
88 *
89 * The bitmap is full if it has no gaps (i.e. no unset bits).
90 */
91static inline int bitmap_full ( struct bitmap *bitmap ) {
92 return ( bitmap->first_gap == bitmap->length );
93}
94
95#endif /* _IPXE_BITMAP_H */
static void bitmap_free(struct bitmap *bitmap)
Free bitmap resources.
Definition bitmap.h:67
static unsigned int bitmap_first_gap(struct bitmap *bitmap)
Get first gap within bitmap.
Definition bitmap.h:79
int bitmap_test(struct bitmap *bitmap, unsigned int bit)
Test bit in bitmap.
Definition bitmap.c:79
int bitmap_set(struct bitmap *bitmap, unsigned int bit)
Set bit in bitmap.
Definition bitmap.c:97
int bitmap_resize(struct bitmap *bitmap, unsigned int new_length)
Resize bitmap.
Definition bitmap.c:43
static int bitmap_full(struct bitmap *bitmap)
Check to see if bitmap is full.
Definition bitmap.h:91
unsigned long bitmap_block_t
A single block of bits within a bitmap.
Definition bitmap.h:18
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:921
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:951
static unsigned int unsigned int bit
Definition bigint.h:390
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
A bitmap.
Definition bitmap.h:49
unsigned int first_gap
Index of first gap in the bitmap.
Definition bitmap.h:55
unsigned int length
Length of the bitmap, in bits.
Definition bitmap.h:53
bitmap_block_t * blocks
Bitmap data.
Definition bitmap.h:51