bitmap.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * QNX4 file system, Linux implementation.
  3. *
  4. * Version : 0.2.1
  5. *
  6. * Using parts of the xiafs filesystem.
  7. *
  8. * History :
  9. *
  10. * 28-05-1998 by Richard Frowijn : first release.
  11. * 20-06-1998 by Frank Denis : basic optimisations.
  12. * 25-06-1998 by Frank Denis : qnx4_is_free, qnx4_set_bitmap, qnx4_bmap .
  13. * 28-06-1998 by Frank Denis : qnx4_free_inode (to be fixed) .
  14. */
  15. #include <linux/buffer_head.h>
  16. #include <linux/bitops.h>
  17. #include "qnx4.h"
  18. static void count_bits(register const char *bmPart, register int size,
  19. int *const tf)
  20. {
  21. char b;
  22. int tot = *tf;
  23. if (size > QNX4_BLOCK_SIZE) {
  24. size = QNX4_BLOCK_SIZE;
  25. }
  26. do {
  27. b = *bmPart++;
  28. tot += 8 - hweight8(b);
  29. size--;
  30. } while (size != 0);
  31. *tf = tot;
  32. }
  33. unsigned long qnx4_count_free_blocks(struct super_block *sb)
  34. {
  35. int start = le32_to_cpu(qnx4_sb(sb)->BitMap->di_first_xtnt.xtnt_blk) - 1;
  36. int total = 0;
  37. int total_free = 0;
  38. int offset = 0;
  39. int size = le32_to_cpu(qnx4_sb(sb)->BitMap->di_size);
  40. struct buffer_head *bh;
  41. while (total < size) {
  42. if ((bh = sb_bread(sb, start + offset)) == NULL) {
  43. printk(KERN_ERR "qnx4: I/O error in counting free blocks\n");
  44. break;
  45. }
  46. count_bits(bh->b_data, size - total, &total_free);
  47. brelse(bh);
  48. total += QNX4_BLOCK_SIZE;
  49. offset++;
  50. }
  51. return total_free;
  52. }