etc/services - sync with NetBSD-8
[minix.git] / minix / lib / libc / gen / fslib.c
blob58f01e78cdba9babf3fff3d34d8b609c8a5588c6
1 /* fslib.c - routines needed by fs and fs utilities */
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>
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.
36 */
37 int bitmapsize(nr_bits, block_size)
38 bit_t nr_bits;
39 int block_size;
41 int nr_blocks;
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);