add swifi to the build/install.
[minix.git] / servers / mfs / utility.c
blobd8a75c5f9cb07d8c1a260d578838c44d72d877d3
1 #include "fs.h"
2 #include <sys/stat.h>
3 #include <string.h>
4 #include <minix/com.h>
5 #include <minix/callnr.h>
6 #include <stdlib.h>
7 #include "buf.h"
8 #include "inode.h"
9 #include "super.h"
10 #include <minix/vfsif.h>
13 /*===========================================================================*
14 * no_sys *
15 *===========================================================================*/
16 PUBLIC int no_sys()
18 /* Somebody has used an illegal system call number */
19 printf("no_sys: invalid call %d\n", req_nr);
20 return(EINVAL);
24 /*===========================================================================*
25 * conv2 *
26 *===========================================================================*/
27 PUBLIC unsigned conv2(norm, w)
28 int norm; /* TRUE if no swap, FALSE for byte swap */
29 int w; /* promotion of 16-bit word to be swapped */
31 /* Possibly swap a 16-bit word between 8086 and 68000 byte order. */
32 if (norm) return( (unsigned) w & 0xFFFF);
33 return( ((w&BYTE) << 8) | ( (w>>8) & BYTE));
37 /*===========================================================================*
38 * conv4 *
39 *===========================================================================*/
40 PUBLIC long conv4(norm, x)
41 int norm; /* TRUE if no swap, FALSE for byte swap */
42 long x; /* 32-bit long to be byte swapped */
44 /* Possibly swap a 32-bit long between 8086 and 68000 byte order. */
45 unsigned lo, hi;
46 long l;
48 if (norm) return(x); /* byte order was already ok */
49 lo = conv2(FALSE, (int) x & 0xFFFF); /* low-order half, byte swapped */
50 hi = conv2(FALSE, (int) (x>>16) & 0xFFFF); /* high-order half, swapped */
51 l = ( (long) lo <<16) | hi;
52 return(l);
56 /*===========================================================================*
57 * clock_time *
58 *===========================================================================*/
59 PUBLIC time_t clock_time()
61 /* This routine returns the time in seconds since 1.1.1970. MINIX is an
62 * astrophysically naive system that assumes the earth rotates at a constant
63 * rate and that such things as leap seconds do not exist.
66 register int k;
67 clock_t uptime;
69 if (use_getuptime2) {
70 if ( (k=getuptime2(&uptime,&boottime)) != OK)
71 panic(__FILE__,"clock_time: getuptme2 failed", k);
72 } else {
73 if ( (k=getuptime(&uptime)) != OK)
74 panic(__FILE__,"clock_time err", k);
77 return( (time_t) (boottime + (uptime/sys_hz())));
81 /*===========================================================================*
82 * mfs_min *
83 *===========================================================================*/
84 PUBLIC int mfs_min_f(char *file, int line, int v1, int v2)
86 if(v1 < 0 || v2 < 0) {
87 printf("mfs:%s:%d: strange string lengths: %d, %d\n",
88 file, line, v1, v2);
89 panic(file, "strange string lengths", NO_NUM);
91 if(v2 >= v1) return v1;
93 return v2;
97 /*===========================================================================*
98 * mfs_nul *
99 *===========================================================================*/
100 PUBLIC void mfs_nul_f(char *file, int line, char *str, int len, int maxlen)
102 if(len < 1) {
103 printf("mfs:%s:%d: %d-length string?!\n", file, line, len);
104 panic(file, "strange string length", NO_NUM);
106 if(len < maxlen && str[len-1] != '\0') {
107 printf("mfs:%s:%d: string (length %d, maxlen %d) "
108 "not null-terminated\n",
109 file, line, len, maxlen);
113 #define MYASSERT(c) if(!(c)) { printf("MFS:%s:%d: sanity check: %s failed\n", \
114 file, line, #c); panic("MFS", "sanity check " #c " failed", __LINE__); }
117 /*===========================================================================*
118 * sanity_check *
119 *===========================================================================*/
120 PUBLIC void sanitycheck(char *file, int line)
122 MYASSERT(SELF_E > 0);
123 if(superblock.s_dev != NO_DEV) {
124 MYASSERT(superblock.s_dev == fs_dev);
125 MYASSERT(superblock.s_block_size == fs_block_size);
126 } else {
127 MYASSERT(_MIN_BLOCK_SIZE == fs_block_size);