iPXE
Data Structures | Defines | Typedefs | Functions
bitmap.h File Reference

Bitmaps for multicast downloads. More...

#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>

Go to the source code of this file.

Data Structures

struct  bitmap
 A bitmap. More...

Defines

#define BITMAP_BLKSIZE   ( sizeof ( bitmap_block_t ) * 8 )
 Size of a block of bits (in bits)
#define BITMAP_INDEX(bit)   ( (bit) / BITMAP_BLKSIZE )
 Block index within bitmap.
#define BITMAP_MASK(bit)   ( 1UL << ( (bit) % BITMAP_BLKSIZE ) )
 Block mask within bitmap.

Typedefs

typedef unsigned long bitmap_block_t
 A single block of bits within a bitmap.

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.
static void bitmap_free (struct bitmap *bitmap)
 Free bitmap resources.
static unsigned int bitmap_first_gap (struct bitmap *bitmap)
 Get first gap within bitmap.
static int bitmap_full (struct bitmap *bitmap)
 Check to see if bitmap is full.

Detailed Description

Bitmaps for multicast downloads.

Definition in file bitmap.h.


Define Documentation

#define BITMAP_BLKSIZE   ( sizeof ( bitmap_block_t ) * 8 )

Size of a block of bits (in bits)

Definition at line 20 of file bitmap.h.

Referenced by bitmap_resize().

#define BITMAP_INDEX (   bit)    ( (bit) / BITMAP_BLKSIZE )

Block index within bitmap.

Parameters:
bitBit index
Return values:
indexBlock index

Definition at line 28 of file bitmap.h.

Referenced by bitmap_resize(), bitmap_set(), and bitmap_test().

#define BITMAP_MASK (   bit)    ( 1UL << ( (bit) % BITMAP_BLKSIZE ) )

Block mask within bitmap.

Parameters:
bitBit index
Return values:
maskBlock mask

Definition at line 36 of file bitmap.h.

Referenced by bitmap_set(), and bitmap_test().


Typedef Documentation

typedef unsigned long bitmap_block_t

A single block of bits within a bitmap.

Definition at line 17 of file bitmap.h.


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++;
        }
}
static void bitmap_free ( struct bitmap bitmap) [inline, static]

Free bitmap resources.

Parameters:
bitmapBitmap

Definition at line 57 of file bitmap.h.

References bitmap::blocks, and free.

Referenced by slam_free(), slam_pull_header(), tftp_free(), and tftp_timer_expired().

                                                         {
        free ( bitmap->blocks );
}
static unsigned int bitmap_first_gap ( struct bitmap bitmap) [inline, static]

Get first gap within bitmap.

Parameters:
bitmapBitmap
Return values:
first_gapFirst gap

The first gap is the first unset bit within the bitmap.

Definition at line 69 of file bitmap.h.

References bitmap::first_gap.

Referenced by slam_tx_nack(), tftp_rx_data(), and tftp_send_ack().

                                                                      {
        return bitmap->first_gap;
}
static int bitmap_full ( struct bitmap bitmap) [inline, static]

Check to see if bitmap is full.

Parameters:
bitmapBitmap
Return values:
is_fullBitmap is full

The bitmap is full if it has no gaps (i.e. no unset bits).

Definition at line 81 of file bitmap.h.

References bitmap::first_gap, and bitmap::length.

Referenced by slam_mc_socket_deliver(), and tftp_rx_data().

                                                        {
        return ( bitmap->first_gap == bitmap->length );
}