bitmap - /* * Manager for arrays of bits. * See bitmap.h...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* * Manager for arrays of bits. * See bitmap.h for more information. */ #include <types.h> #include <lib.h> #include <kern/errno.h> #include <bitmap.h> /* * It would be a lot more efficient on most platforms to use u_int32_t * or unsigned long as the base type for holding bits. But we don't, * because if one uses any data type more than a single byte wide, * bitmap data saved on disk becomes endian-dependent, which is a * severe nuisance. */ #define BITS_PER_WORD (CHAR_BIT) #define WORD_TYPE unsigned char #define WORD_ALLBITS (0xff) struct bitmap { u_int32_t nbits; WORD_TYPE *v; }; struct bitmap * bitmap_create(u_int32_t nbits) { struct bitmap *b; u_int32_t words; words = DIVROUNDUP(nbits, BITS_PER_WORD); b = kmalloc(sizeof(struct bitmap)); if (b == NULL) { return NULL; } b->v = kmalloc(words*sizeof(WORD_TYPE)); if (b->v == NULL) { kfree(b); return NULL; } bzero(b->v, words*sizeof(WORD_TYPE)); b->nbits = nbits; /* Mark any leftover bits at the end in use */ if (nbits / BITS_PER_WORD < words) {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/10/2009 for the course CS 536 taught by Professor Lums during the Spring '09 term at Indiana.

Page1 / 3

bitmap - /* * Manager for arrays of bits. * See bitmap.h...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online