iPXE
Functions
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)
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 ( GPL2_OR_LATER_OR_UBDL  )
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 42 of file bitmap.c.

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

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

                                                                     {
        unsigned int old_num_blocks;
        unsigned int new_num_blocks;
        size_t new_size;
        bitmap_block_t *new_blocks;

        old_num_blocks = BITMAP_INDEX ( bitmap->length + BITMAP_BLKSIZE - 1 );
        new_num_blocks = BITMAP_INDEX ( new_length + BITMAP_BLKSIZE - 1 );

        if ( old_num_blocks != new_num_blocks ) {
                new_size = ( new_num_blocks * sizeof ( bitmap->blocks[0] ) );
                new_blocks = realloc ( bitmap->blocks, new_size );
                if ( ! new_blocks ) {
                        DBGC ( bitmap, "Bitmap %p could not resize to %d "
                               "bits\n", bitmap, new_length );
                        return -ENOMEM;
                }
                bitmap->blocks = new_blocks;
        }
        bitmap->length = new_length;

        while ( old_num_blocks < new_num_blocks ) {
                bitmap->blocks[old_num_blocks++] = 0;
        }

        DBGC ( bitmap, "Bitmap %p resized to %d bits\n", bitmap, new_length );
        return 0;
}
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 78 of file bitmap.c.

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

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

                                                            {
        unsigned int index = BITMAP_INDEX ( bit );
        bitmap_block_t mask = BITMAP_MASK ( bit );

        if ( bit >= bitmap->length )
                return 0;
        return ( ( bitmap->blocks[index] & mask ) != 0 );
}
void bitmap_set ( struct bitmap bitmap,
unsigned int  bit 
)

Set bit in bitmap.

Parameters:
bitmapBitmap
bitBit index

Definition at line 93 of file bitmap.c.

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

Referenced by slam_mc_socket_deliver(), and tftp_rx_data().

                                                            {
        unsigned int index = BITMAP_INDEX ( bit );
        bitmap_block_t mask = BITMAP_MASK ( bit );

        DBGC ( bitmap, "Bitmap %p setting bit %d\n", bitmap, bit );

        /* Update bitmap */
        bitmap->blocks[index] |= mask;

        /* Update first gap counter */
        while ( bitmap_test ( bitmap, bitmap->first_gap ) ) {
                bitmap->first_gap++;
        }
}