On Tue, Nov 06, 2007 at 02:33:53AM -0800, akpm@linux-foundation.org wrote:
[mmotm.git] / fs / qnx4 / bitmap.c
bloba17440bce018cb5d7bbc68cb0c56a8658e17dc45
1 /*
2 * QNX4 file system, Linux implementation.
4 * Version : 0.2.1
6 * Using parts of the xiafs filesystem.
8 * History :
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) .
16 #include <linux/buffer_head.h>
17 #include <linux/bitops.h>
18 #include "qnx4.h"
20 static void count_bits(register const char *bmPart, register int size,
21 int *const tf)
23 char b;
24 int tot = *tf;
26 if (size > QNX4_BLOCK_SIZE) {
27 size = QNX4_BLOCK_SIZE;
29 do {
30 b = *bmPart++;
31 if ((b & 1) == 0)
32 tot++;
33 if ((b & 2) == 0)
34 tot++;
35 if ((b & 4) == 0)
36 tot++;
37 if ((b & 8) == 0)
38 tot++;
39 if ((b & 16) == 0)
40 tot++;
41 if ((b & 32) == 0)
42 tot++;
43 if ((b & 64) == 0)
44 tot++;
45 if ((b & 128) == 0)
46 tot++;
47 size--;
48 } while (size != 0);
49 *tf = tot;
52 unsigned long qnx4_count_free_blocks(struct super_block *sb)
54 int start = le32_to_cpu(qnx4_sb(sb)->BitMap->di_first_xtnt.xtnt_blk) - 1;
55 int total = 0;
56 int total_free = 0;
57 int offset = 0;
58 int size = le32_to_cpu(qnx4_sb(sb)->BitMap->di_size);
59 struct buffer_head *bh;
61 while (total < size) {
62 if ((bh = sb_bread(sb, start + offset)) == NULL) {
63 printk(KERN_ERR "qnx4: I/O error in counting free blocks\n");
64 break;
66 count_bits(bh->b_data, size - total, &total_free);
67 brelse(bh);
68 total += QNX4_BLOCK_SIZE;
69 offset++;
72 return total_free;