bitmap.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * QNX4 file system, Linux implementation.
  4. *
  5. * Version : 0.2.1
  6. *
  7. * Using parts of the xiafs filesystem.
  8. *
  9. * History :
  10. *
  11. * 28-05-1998 by Richard Frowijn : first release.
  12. * 20-06-1998 by Frank Denis : basic optimisations.
  13. * 25-06-1998 by Frank Denis : qnx4_is_free, qnx4_set_bitmap, qnx4_bmap .
  14. * 28-06-1998 by Frank Denis : qnx4_free_inode (to be fixed) .
  15. */
  16. #include <linux/buffer_head.h>
  17. #include <linux/bitops.h>
  18. #include "qnx4.h"
  19. unsigned long qnx4_count_free_blocks(struct super_block *sb)
  20. {
  21. int start = le32_to_cpu(qnx4_sb(sb)->BitMap->di_first_xtnt.xtnt_blk) - 1;
  22. int total = 0;
  23. int total_free = 0;
  24. int offset = 0;
  25. int size = le32_to_cpu(qnx4_sb(sb)->BitMap->di_size);
  26. struct buffer_head *bh;
  27. while (total < size) {
  28. int bytes = min(size - total, QNX4_BLOCK_SIZE);
  29. if ((bh = sb_bread(sb, start + offset)) == NULL) {
  30. printk(KERN_ERR "qnx4: I/O error in counting free blocks\n");
  31. break;
  32. }
  33. total_free += bytes * BITS_PER_BYTE -
  34. memweight(bh->b_data, bytes);
  35. brelse(bh);
  36. total += bytes;
  37. offset++;
  38. }
  39. return total_free;
  40. }