1*b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * QNX4 file system, Linux implementation. 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Version : 0.2.1 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * Using parts of the xiafs filesystem. 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * History : 101da177e4SLinus Torvalds * 111da177e4SLinus Torvalds * 28-05-1998 by Richard Frowijn : first release. 121da177e4SLinus Torvalds * 20-06-1998 by Frank Denis : basic optimisations. 131da177e4SLinus Torvalds * 25-06-1998 by Frank Denis : qnx4_is_free, qnx4_set_bitmap, qnx4_bmap . 141da177e4SLinus Torvalds * 28-06-1998 by Frank Denis : qnx4_free_inode (to be fixed) . 151da177e4SLinus Torvalds */ 161da177e4SLinus Torvalds 171da177e4SLinus Torvalds #include <linux/buffer_head.h> 181da177e4SLinus Torvalds #include <linux/bitops.h> 19964f5369SAl Viro #include "qnx4.h" 201da177e4SLinus Torvalds qnx4_count_free_blocks(struct super_block * sb)211da177e4SLinus Torvaldsunsigned long qnx4_count_free_blocks(struct super_block *sb) 221da177e4SLinus Torvalds { 231da177e4SLinus Torvalds int start = le32_to_cpu(qnx4_sb(sb)->BitMap->di_first_xtnt.xtnt_blk) - 1; 241da177e4SLinus Torvalds int total = 0; 251da177e4SLinus Torvalds int total_free = 0; 261da177e4SLinus Torvalds int offset = 0; 271da177e4SLinus Torvalds int size = le32_to_cpu(qnx4_sb(sb)->BitMap->di_size); 281da177e4SLinus Torvalds struct buffer_head *bh; 291da177e4SLinus Torvalds 301da177e4SLinus Torvalds while (total < size) { 319b58f6d4SAkinobu Mita int bytes = min(size - total, QNX4_BLOCK_SIZE); 329b58f6d4SAkinobu Mita 331da177e4SLinus Torvalds if ((bh = sb_bread(sb, start + offset)) == NULL) { 34891ddb95SAnders Larsen printk(KERN_ERR "qnx4: I/O error in counting free blocks\n"); 351da177e4SLinus Torvalds break; 361da177e4SLinus Torvalds } 379b58f6d4SAkinobu Mita total_free += bytes * BITS_PER_BYTE - 389b58f6d4SAkinobu Mita memweight(bh->b_data, bytes); 391da177e4SLinus Torvalds brelse(bh); 409b58f6d4SAkinobu Mita total += bytes; 411da177e4SLinus Torvalds offset++; 421da177e4SLinus Torvalds } 431da177e4SLinus Torvalds 441da177e4SLinus Torvalds return total_free; 451da177e4SLinus Torvalds } 46