void *Create_Bit_Set(uint_t totalBits) { ulong_t numBytes; void *bitSet; numBytes = FIND_NUM_BYTES(totalBits); bitSet = malloc(numBytes); if (bitSet != 0) memset(bitSet, '\0', numBytes); return bitSet; }
int Find_First_Free_Bit(void *bitSet, ulong_t totalBits) { uint_t numBytes = FIND_NUM_BYTES(totalBits); ulong_t offset; unsigned char *bits = (unsigned char *) bitSet; for (offset = 0; offset < numBytes; ++offset) { if (bits[offset] != 0xff) { uint_t bit; for (bit = 0; bit < 8; ++bit) { if ((bits[offset] & (1 << (7-bit))) == 0) return (offset * 8) + bit; } } } return -1; }
int Find_First_Free_Bit(void *bitSet, ulong_t totalBits) { uint_t numBytes = FIND_NUM_BYTES(totalBits); ulong_t offset; uchar_t *bits = (uchar_t *) bitSet; for(offset = 0; offset < numBytes; ++offset) { if(bits[offset] != 0xff) { uint_t bit; for(bit = 0; bit < 8; ++bit) { if((bits[offset] & (1 << bit)) == 0) return (offset * 8) + bit; } #ifdef GEEKOS /* kassert only defined properly when running in geekos. */ KASSERT(false); #endif } } return -1; }