1 /* fslib.c - routines needed by fs and fs utilities */
3 #include <minix/config.h> /* for unused stuff in <minix/type.h> :-( */
7 #include <stdlib.h> /* for abort() */
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>
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.
23 /* Convert from bit count to a block count. The usual expression
25 * (nr_bits + (1 << BITMAPSHIFT) - 1) >> BITMAPSHIFT
27 * doesn't work because of overflow.
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.
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.
37 int bitmapsize(nr_bits
, block_size
)
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
;