42 lines · c
1#include <linux/bitmap.h>2 3void __bitmap_set(unsigned long *map, unsigned int start, int len)4{5 unsigned long *p = map + BIT_WORD(start);6 const unsigned int size = start + len;7 int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG);8 unsigned long mask_to_set = BITMAP_FIRST_WORD_MASK(start);9 10 while (len - bits_to_set >= 0) {11 *p |= mask_to_set;12 len -= bits_to_set;13 bits_to_set = BITS_PER_LONG;14 mask_to_set = ~0UL;15 p++;16 }17 if (len) {18 mask_to_set &= BITMAP_LAST_WORD_MASK(size);19 *p |= mask_to_set;20 }21}22 23void __bitmap_clear(unsigned long *map, unsigned int start, int len)24{25 unsigned long *p = map + BIT_WORD(start);26 const unsigned int size = start + len;27 int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG);28 unsigned long mask_to_clear = BITMAP_FIRST_WORD_MASK(start);29 30 while (len - bits_to_clear >= 0) {31 *p &= ~mask_to_clear;32 len -= bits_to_clear;33 bits_to_clear = BITS_PER_LONG;34 mask_to_clear = ~0UL;35 p++;36 }37 if (len) {38 mask_to_clear &= BITMAP_LAST_WORD_MASK(size);39 *p &= ~mask_to_clear;40 }41}42