#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) ( 1 << ( (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) | |
| 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. | |
Definition in file bitmap.h.
| #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.
| bit | Bit index |
| index | Block index |
Definition at line 28 of file bitmap.h.
Referenced by bitmap_resize(), bitmap_set(), and bitmap_test().
| #define BITMAP_MASK | ( | bit | ) | ( 1 << ( (bit) % BITMAP_BLKSIZE ) ) |
Block mask within bitmap.
| bit | Bit index |
| mask | Block mask |
Definition at line 36 of file bitmap.h.
Referenced by bitmap_set(), and bitmap_test().
| typedef unsigned long bitmap_block_t |
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
| int bitmap_resize | ( | struct bitmap * | bitmap, | |
| unsigned int | new_length | |||
| ) |
Resize bitmap.
| rc | Return status code |
Definition at line 37 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().
00037 { 00038 unsigned int old_num_blocks; 00039 unsigned int new_num_blocks; 00040 size_t new_size; 00041 bitmap_block_t *new_blocks; 00042 00043 old_num_blocks = BITMAP_INDEX ( bitmap->length + BITMAP_BLKSIZE - 1 ); 00044 new_num_blocks = BITMAP_INDEX ( new_length + BITMAP_BLKSIZE - 1 ); 00045 00046 if ( old_num_blocks != new_num_blocks ) { 00047 new_size = ( new_num_blocks * sizeof ( bitmap->blocks[0] ) ); 00048 new_blocks = realloc ( bitmap->blocks, new_size ); 00049 if ( ! new_blocks ) { 00050 DBGC ( bitmap, "Bitmap %p could not resize to %d " 00051 "bits\n", bitmap, new_length ); 00052 return -ENOMEM; 00053 } 00054 bitmap->blocks = new_blocks; 00055 } 00056 bitmap->length = new_length; 00057 00058 while ( old_num_blocks < new_num_blocks ) { 00059 bitmap->blocks[old_num_blocks++] = 0; 00060 } 00061 00062 DBGC ( bitmap, "Bitmap %p resized to %d bits\n", bitmap, new_length ); 00063 return 0; 00064 }
| int bitmap_test | ( | struct bitmap * | bitmap, | |
| unsigned int | bit | |||
| ) |
Test bit in bitmap.
| bitmap | Bitmap | |
| bit | Bit index |
| is_set | Bit is set |
Definition at line 73 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().
00073 { 00074 unsigned int index = BITMAP_INDEX ( bit ); 00075 bitmap_block_t mask = BITMAP_MASK ( bit ); 00076 00077 if ( bit >= bitmap->length ) 00078 return 0; 00079 return ( bitmap->blocks[index] & mask ); 00080 }
| void bitmap_set | ( | struct bitmap * | bitmap, | |
| unsigned int | bit | |||
| ) |
Set bit in bitmap.
| bitmap | Bitmap | |
| bit | Bit index |
Definition at line 88 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().
00088 { 00089 unsigned int index = BITMAP_INDEX ( bit ); 00090 bitmap_block_t mask = BITMAP_MASK ( bit ); 00091 00092 DBGC ( bitmap, "Bitmap %p setting bit %d\n", bitmap, bit ); 00093 00094 /* Update bitmap */ 00095 bitmap->blocks[index] |= mask; 00096 00097 /* Update first gap counter */ 00098 while ( bitmap_test ( bitmap, bitmap->first_gap ) ) { 00099 bitmap->first_gap++; 00100 } 00101 }
| static void bitmap_free | ( | struct bitmap * | bitmap | ) | [inline, static] |
Free bitmap resources.
| bitmap | Bitmap |
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().
| static unsigned int bitmap_first_gap | ( | struct bitmap * | bitmap | ) | [inline, static] |
Get first gap within bitmap.
| bitmap | Bitmap |
| first_gap | First gap |
Definition at line 69 of file bitmap.h.
References bitmap::first_gap.
Referenced by slam_tx_nack(), tftp_rx_data(), and tftp_send_ack().
00069 { 00070 return bitmap->first_gap; 00071 }
| static int bitmap_full | ( | struct bitmap * | bitmap | ) | [inline, static] |
Check to see if bitmap is full.
| bitmap | Bitmap |
| is_full | Bitmap is full |
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().
1.5.7.1