0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include <linux/buffer_head.h>
0018 #include <linux/bitops.h>
0019 #include "qnx4.h"
0020
0021 unsigned long qnx4_count_free_blocks(struct super_block *sb)
0022 {
0023 int start = le32_to_cpu(qnx4_sb(sb)->BitMap->di_first_xtnt.xtnt_blk) - 1;
0024 int total = 0;
0025 int total_free = 0;
0026 int offset = 0;
0027 int size = le32_to_cpu(qnx4_sb(sb)->BitMap->di_size);
0028 struct buffer_head *bh;
0029
0030 while (total < size) {
0031 int bytes = min(size - total, QNX4_BLOCK_SIZE);
0032
0033 if ((bh = sb_bread(sb, start + offset)) == NULL) {
0034 printk(KERN_ERR "qnx4: I/O error in counting free blocks\n");
0035 break;
0036 }
0037 total_free += bytes * BITS_PER_BYTE -
0038 memweight(bh->b_data, bytes);
0039 brelse(bh);
0040 total += bytes;
0041 offset++;
0042 }
0043
0044 return total_free;
0045 }