custom message type for VM_INFO
[minix3.git] / lib / libminlib / fslib.c
blob07901d13cd68516b4f0bdcf1e84eb23aed0b7006
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 <sys/types.h>
7 #include <minix/const.h>
8 #include <minix/type.h> /* for unshort :-( */
9 #include <minix/sysutil.h>
10 #include <minix/minlib.h>
11 #include "mfs/const.h" /* depends of -I flag in Makefile */
12 #include "mfs/type.h" /* ditto */
13 #include "mfs/inode.h" /* ditto */
14 #include "mfs/super.h"
15 #include <minix/fslib.h>
16 #include <sys/stat.h>
18 /* The next routine is copied from fsck.c and mkfs.c... (Re)define some
19 * things for consistency. Some things should be done better.
22 /* Convert from bit count to a block count. The usual expression
24 * (nr_bits + (1 << BITMAPSHIFT) - 1) >> BITMAPSHIFT
26 * doesn't work because of overflow.
28 * Other overflow bugs, such as the expression for N_ILIST overflowing when
29 * s_inodes is just over V*_INODES_PER_BLOCK less than the maximum+1, are not
30 * fixed yet, because that number of inodes is silly.
32 /* The above comment doesn't all apply now bit_t is long. Overflow is now
33 * unlikely, but negative bit counts are now possible (though unlikely)
34 * and give silly results.
35 */
36 int bitmapsize(nr_bits, block_size)
37 bit_t nr_bits;
38 int block_size;
40 int nr_blocks;
42 nr_blocks = (int) (nr_bits / FS_BITS_PER_BLOCK(block_size));
43 if (((bit_t) nr_blocks * FS_BITS_PER_BLOCK(block_size)) < nr_bits) ++nr_blocks;
44 return(nr_blocks);
47 uint8_t fs_mode_to_type(mode_t mode)
49 if(S_ISREG(mode)) return DT_REG;
50 else if(S_ISDIR(mode)) return DT_DIR;
51 else if(S_ISLNK(mode)) return DT_LNK;
52 else if(S_ISCHR(mode)) return DT_CHR;
53 else if(S_ISBLK(mode)) return DT_BLK;
54 else if(S_ISFIFO(mode)) return DT_FIFO;
55 else if(S_ISSOCK(mode)) return DT_SOCK;
57 panic("unknown type, mode 0x%x", mode);