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