1 /* fslib.c - routines needed by fs and fs utilities */ 2 3 #include <minix/config.h> /* for unused stuff in <minix/type.h> :-( */ 4 #include <limits.h> 5 #include <dirent.h> 6 #include <assert.h> 7 #include <stdlib.h> /* for abort() */ 8 #include <sys/types.h> 9 #include <minix/const.h> 10 #include <minix/type.h> /* for unshort :-( */ 11 #include <minix/minlib.h> 12 #include <minix/ipc.h> 13 #include "mfs/const.h" /* depends of -I flag in Makefile */ 14 #include "mfs/type.h" /* ditto */ 15 #include "mfs/inode.h" /* ditto */ 16 #include "mfs/super.h" 17 #include <minix/fslib.h> 18 19 /* The next routine is copied from fsck.c and mkfs.c... (Re)define some 20 * things for consistency. Some things should be done better. 21 */ 22 23 /* Convert from bit count to a block count. The usual expression 24 * 25 * (nr_bits + (1 << BITMAPSHIFT) - 1) >> BITMAPSHIFT 26 * 27 * doesn't work because of overflow. 28 * 29 * Other overflow bugs, such as the expression for N_ILIST overflowing when 30 * s_inodes is just over V*_INODES_PER_BLOCK less than the maximum+1, are not 31 * fixed yet, because that number of inodes is silly. 32 */ 33 /* The above comment doesn't all apply now bit_t is long. Overflow is now 34 * unlikely, but negative bit counts are now possible (though unlikely) 35 * and give silly results. 36 */ bitmapsize(nr_bits,block_size)37int bitmapsize(nr_bits, block_size) 38 bit_t nr_bits; 39 int block_size; 40 { 41 int nr_blocks; 42 43 nr_blocks = (int) (nr_bits / FS_BITS_PER_BLOCK(block_size)); 44 if (((bit_t) nr_blocks * FS_BITS_PER_BLOCK(block_size)) < nr_bits) ++nr_blocks; 45 return(nr_blocks); 46 } 47