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 
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11 FILE_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 */
18 typedef 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 /** A bitmap */
40 struct bitmap {
41  /** Bitmap data */
43  /** Length of the bitmap, in bits */
44  unsigned int length;
45  /** Index of first gap in the bitmap */
46  unsigned int first_gap;
47 };
48 
49 extern int bitmap_resize ( struct bitmap *bitmap, unsigned int new_length );
50 extern int bitmap_test ( struct bitmap *bitmap, unsigned int bit );
51 extern void bitmap_set ( struct bitmap *bitmap, unsigned int bit );
52 
53 /**
54  * Free bitmap resources
55  *
56  * @v bitmap Bitmap
57  */
58 static inline void bitmap_free ( struct bitmap *bitmap ) {
59  free ( bitmap->blocks );
60 }
61 
62 /**
63  * Get first gap within bitmap
64  *
65  * @v bitmap Bitmap
66  * @ret first_gap First gap
67  *
68  * The first gap is the first unset bit within the bitmap.
69  */
70 static inline unsigned int bitmap_first_gap ( struct bitmap *bitmap ) {
71  return bitmap->first_gap;
72 }
73 
74 /**
75  * Check to see if bitmap is full
76  *
77  * @v bitmap Bitmap
78  * @ret is_full Bitmap is full
79  *
80  * The bitmap is full if it has no gaps (i.e. no unset bits).
81  */
82 static inline int bitmap_full ( struct bitmap *bitmap ) {
83  return ( bitmap->first_gap == bitmap->length );
84 }
85 
86 #endif /* _IPXE_BITMAP_H */
int bitmap_resize(struct bitmap *bitmap, unsigned int new_length)
Resize bitmap.
Definition: bitmap.c:43
static void bitmap_free(struct bitmap *bitmap)
Free bitmap resources.
Definition: bitmap.h:58
FILE_SECBOOT(PERMITTED)
unsigned int length
Length of the bitmap, in bits.
Definition: bitmap.h:44
unsigned long bitmap_block_t
A single block of bits within a bitmap.
Definition: bitmap.h:18
static unsigned int unsigned int bit
Definition: bigint.h:392
bitmap_block_t * blocks
Bitmap data.
Definition: bitmap.h:42
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
A bitmap.
Definition: bitmap.h:40
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:55
unsigned int first_gap
Index of first gap in the bitmap.
Definition: bitmap.h:46
int bitmap_test(struct bitmap *bitmap, unsigned int bit)
Test bit in bitmap.
Definition: bitmap.c:79
static unsigned int bitmap_first_gap(struct bitmap *bitmap)
Get first gap within bitmap.
Definition: bitmap.h:70
void bitmap_set(struct bitmap *bitmap, unsigned int bit)
Set bit in bitmap.
Definition: bitmap.c:94
static int bitmap_full(struct bitmap *bitmap)
Check to see if bitmap is full.
Definition: bitmap.h:82