22#define ELEM_BITS (sizeof (elem_type) * CHAR_BIT)
165 asm (
"orl %1, %0" :
"=m" (b->
bits[idx]) :
"r" (mask) :
"cc");
178 asm (
"andl %1, %0" :
"=m" (b->
bits[idx]) :
"r" (~mask) :
"cc");
193 asm (
"xorl %1, %0" :
"=m" (b->
bits[idx]) :
"r" (mask) :
"cc");
226 for (i = 0; i < cnt; i++)
242 for (i = 0; i < cnt; i++)
259 for (i = 0; i < cnt; i++)
303 size_t last = b->
bit_cnt - cnt;
305 for (i =
start; i <= last; i++)
333bitmap_file_size (
const struct bitmap *b)
static size_t elem_cnt(size_t bit_cnt)
Returns the number of elements required for BIT_CNT bits.
void bitmap_flip(struct bitmap *b, size_t bit_idx)
Atomically toggles the bit numbered IDX in B; that is, if it is true, makes it false,...
bool bitmap_none(const struct bitmap *b, size_t start, size_t cnt)
Returns true if no bits in B between START and START + CNT, exclusive, are set to true,...
static size_t byte_cnt(size_t bit_cnt)
Returns the number of bytes required for BIT_CNT bits.
size_t bitmap_size(const struct bitmap *b)
Bitmap size.
void bitmap_reset(struct bitmap *b, size_t bit_idx)
Atomically sets the bit numbered BIT_IDX in B to false.
void bitmap_set(struct bitmap *b, size_t idx, bool value)
Setting and testing single bits.
void bitmap_set_multiple(struct bitmap *b, size_t start, size_t cnt, bool value)
Sets the CNT bits starting at START in B to VALUE.
size_t bitmap_buf_size(size_t bit_cnt)
Returns the number of bytes required to accomodate a bitmap with BIT_CNT bits (for use with bitmap_cr...
size_t bitmap_scan(const struct bitmap *b, size_t start, size_t cnt, bool value)
Finding set or unset bits.
size_t bitmap_count(const struct bitmap *b, size_t start, size_t cnt, bool value)
Returns the number of bits in B between START and START + CNT, exclusive, that are set to VALUE.
bool bitmap_contains(const struct bitmap *b, size_t start, size_t cnt, bool value)
Returns true if any bits in B between START and START + CNT, exclusive, are set to VALUE,...
#define ELEM_BITS
Number of bits in an element.
size_t bitmap_scan_and_flip(struct bitmap *b, size_t start, size_t cnt, bool value)
Finds the first group of CNT consecutive bits in B at or after START that are all set to VALUE,...
bool bitmap_any(const struct bitmap *b, size_t start, size_t cnt)
Returns true if any bits in B between START and START + CNT, exclusive, are set to true,...
unsigned long elem_type
Element type.
bool bitmap_all(const struct bitmap *b, size_t start, size_t cnt)
Returns true if every bit in B between START and START + CNT, exclusive, is set to true,...
bool bitmap_test(const struct bitmap *b, size_t idx)
Returns the value of the bit numbered IDX in B.
static size_t elem_idx(size_t bit_idx)
Returns the index of the element that contains the bit numbered BIT_IDX.
void bitmap_dump(const struct bitmap *b)
File input and output.
static elem_type bit_mask(size_t bit_idx)
Returns an elem_type where only the bit corresponding to BIT_IDX is turned on.
void bitmap_set_all(struct bitmap *b, bool value)
Setting and testing multiple bits.
void bitmap_destroy(struct bitmap *b)
Destroys bitmap B, freeing its storage.
void bitmap_mark(struct bitmap *b, size_t bit_idx)
Atomically sets the bit numbered BIT_IDX in B to true.
struct bitmap * bitmap_create_in_buf(size_t bit_cnt, void *block, size_t block_size UNUSED)
Creates and returns a bitmap with BIT_CNT bits in the BLOCK_SIZE bytes of storage preallocated at BLO...
struct bitmap * bitmap_create(size_t bit_cnt)
Creation and destruction.
static elem_type last_mask(const struct bitmap *b)
Returns a bit mask in which the bits actually used in the last element of B's bits are set to 1 and t...
#define BITMAP_ERROR
Finding set or unset bits.
block_sector_t block_size(struct block *block)
Returns the number of sectors in BLOCK.
#define ASSERT(CONDITION)
This is outside the header guard so that debug.h may be included multiple times with different settin...
#define UNUSED
GCC lets us add "attributes" to functions, function parameters, etc.
off_t file_write_at(struct file *file, const void *buffer, off_t size, off_t file_ofs)
Writes SIZE bytes from BUFFER into FILE, starting at offset FILE_OFS in the file.
off_t file_read_at(struct file *file, void *buffer, off_t size, off_t file_ofs)
Reads SIZE bytes from FILE into BUFFER, starting at offset FILE_OFS in the file.
void hex_dump(uintptr_t ofs, const void *buf_, size_t size, bool ascii)
Dumps the SIZE bytes in BUF to the console as hex bytes arranged 16 per line.
void * malloc(size_t size)
Obtains and returns a new block of at least SIZE bytes.
void free(void *p)
Frees block P, which must have been previously allocated with malloc(), calloc(), or realloc().
int32_t off_t
An offset within a file.
#define DIV_ROUND_UP(X, STEP)
Yields X divided by STEP, rounded up.
From the outside, a bitmap is an array of bits.
size_t bit_cnt
Number of bits.
elem_type * bits
Elements that represent bits.