Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * QNX4 file system, Linux implementation.
0004  *
0005  * Version : 0.2.1
0006  *
0007  * Using parts of the xiafs filesystem.
0008  *
0009  * History :
0010  *
0011  * 28-05-1998 by Richard Frowijn : first release.
0012  * 20-06-1998 by Frank Denis : basic optimisations.
0013  * 25-06-1998 by Frank Denis : qnx4_is_free, qnx4_set_bitmap, qnx4_bmap .
0014  * 28-06-1998 by Frank Denis : qnx4_free_inode (to be fixed) .
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 }