iPXE
bitmap.c File Reference

Bitmaps for multicast downloads. More...

#include <errno.h>
#include <ipxe/bitmap.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
int bitmap_resize (struct bitmap *bitmap, unsigned int new_length)
 Resize bitmap.
int bitmap_test (struct bitmap *bitmap, unsigned int bit)
 Test bit in bitmap.
void bitmap_set (struct bitmap *bitmap, unsigned int bit)
 Set bit in bitmap.

Detailed Description

Bitmaps for multicast downloads.

Definition in file bitmap.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ bitmap_resize()

int bitmap_resize ( struct bitmap * bitmap,
unsigned int new_length )

Resize bitmap.

Parameters
bitmapBitmap
new_lengthNew length of bitmap, in bits
Return values
rcReturn status code

Definition at line 43 of file bitmap.c.

43 {
44 unsigned int old_num_blocks;
45 unsigned int new_num_blocks;
46 size_t new_size;
47 bitmap_block_t *new_blocks;
48
49 old_num_blocks = BITMAP_INDEX ( bitmap->length + BITMAP_BLKSIZE - 1 );
50 new_num_blocks = BITMAP_INDEX ( new_length + BITMAP_BLKSIZE - 1 );
51
52 if ( old_num_blocks != new_num_blocks ) {
53 new_size = ( new_num_blocks * sizeof ( bitmap->blocks[0] ) );
54 new_blocks = realloc ( bitmap->blocks, new_size );
55 if ( ! new_blocks ) {
56 DBGC ( bitmap, "Bitmap %p could not resize to %d "
57 "bits\n", bitmap, new_length );
58 return -ENOMEM;
59 }
60 bitmap->blocks = new_blocks;
61 }
62 bitmap->length = new_length;
63
64 while ( old_num_blocks < new_num_blocks ) {
65 bitmap->blocks[old_num_blocks++] = 0;
66 }
67
68 DBGC ( bitmap, "Bitmap %p resized to %d bits\n", bitmap, new_length );
69 return 0;
70}
#define BITMAP_INDEX(bit)
Block index within bitmap.
Definition bitmap.h:29
#define BITMAP_BLKSIZE
Size of a block of bits (in bits)
Definition bitmap.h:21
unsigned long bitmap_block_t
A single block of bits within a bitmap.
Definition bitmap.h:18
#define DBGC(...)
Definition compiler.h:505
#define ENOMEM
Not enough space.
Definition errno.h:535
void * realloc(void *old_ptr, size_t new_size)
Reallocate memory.
Definition malloc.c:607
A bitmap.
Definition bitmap.h:40
unsigned int length
Length of the bitmap, in bits.
Definition bitmap.h:44
bitmap_block_t * blocks
Bitmap data.
Definition bitmap.h:42

References BITMAP_BLKSIZE, BITMAP_INDEX, bitmap::blocks, DBGC, ENOMEM, bitmap::length, and realloc().

Referenced by slam_open(), slam_pull_header(), and tftp_presize().

◆ bitmap_test()

int bitmap_test ( struct bitmap * bitmap,
unsigned int bit )

Test bit in bitmap.

Parameters
bitmapBitmap
bitBit index
Return values
is_setBit is set

Definition at line 79 of file bitmap.c.

79 {
80 unsigned int index = BITMAP_INDEX ( bit );
82
83 if ( bit >= bitmap->length )
84 return 0;
85 return ( ( bitmap->blocks[index] & mask ) != 0 );
86}
long index
Definition bigint.h:65
#define BITMAP_MASK(bit)
Block mask within bitmap.
Definition bitmap.h:37
static unsigned int unsigned int bit
Definition bigint.h:392

References bit, BITMAP_INDEX, BITMAP_MASK, bitmap::blocks, index, and bitmap::length.

Referenced by bitmap_set(), slam_mc_socket_deliver(), and slam_tx_nack().

◆ bitmap_set()

void bitmap_set ( struct bitmap * bitmap,
unsigned int bit )

Set bit in bitmap.

Parameters
bitmapBitmap
bitBit index

Definition at line 94 of file bitmap.c.

94 {
95 unsigned int index = BITMAP_INDEX ( bit );
97
98 DBGC ( bitmap, "Bitmap %p setting bit %d\n", bitmap, bit );
99
100 /* Update bitmap */
101 bitmap->blocks[index] |= mask;
102
103 /* Update first gap counter */
104 while ( bitmap_test ( bitmap, bitmap->first_gap ) ) {
105 bitmap->first_gap++;
106 }
107}
int bitmap_test(struct bitmap *bitmap, unsigned int bit)
Test bit in bitmap.
Definition bitmap.c:79
unsigned int first_gap
Index of first gap in the bitmap.
Definition bitmap.h:46

References bit, BITMAP_INDEX, BITMAP_MASK, bitmap_test(), bitmap::blocks, DBGC, bitmap::first_gap, and index.

Referenced by slam_mc_socket_deliver(), and tftp_rx_data().