bitmap.c 1.0 KB

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