. service tells you which device it couldn't stat
[minix3.git] / servers / mfs / utility.c
blob328844d69551abd2b845a786391e84608d29a4ce
2 #include "fs.h"
3 #include <sys/stat.h>
4 #include <string.h>
5 #include <minix/com.h>
6 #include <minix/callnr.h>
8 #include "buf.h"
9 #include "inode.h"
10 #include "super.h"
12 #include <minix/vfsif.h>
14 static int panicking;
16 /*===========================================================================*
17 * no_sys *
18 *===========================================================================*/
19 PUBLIC int no_sys()
21 /* Somebody has used an illegal system call number */
22 return(EINVAL);
25 /*===========================================================================*
26 * panic *
27 *===========================================================================*/
28 PUBLIC void panic(who, mess, num)
29 char *who; /* who caused the panic */
30 char *mess; /* panic message string */
31 int num; /* number to go with it */
33 /* Something awful has happened. Panics are caused when an internal
34 * inconsistency is detected, e.g., a programming error or illegal value of a
35 * defined constant.
37 if (panicking) return; /* do not panic during a sync */
38 panicking = TRUE; /* prevent another panic during the sync */
40 printf("FS panic (%s): %s ", who, mess);
41 if (num != NO_NUM) printf("%d",num);
42 (void) fs_sync(); /* flush everything to the disk */
43 sys_exit(SELF);
46 /*===========================================================================*
47 * conv2 *
48 *===========================================================================*/
49 PUBLIC unsigned conv2(norm, w)
50 int norm; /* TRUE if no swap, FALSE for byte swap */
51 int w; /* promotion of 16-bit word to be swapped */
53 /* Possibly swap a 16-bit word between 8086 and 68000 byte order. */
54 if (norm) return( (unsigned) w & 0xFFFF);
55 return( ((w&BYTE) << 8) | ( (w>>8) & BYTE));
58 /*===========================================================================*
59 * conv4 *
60 *===========================================================================*/
61 PUBLIC long conv4(norm, x)
62 int norm; /* TRUE if no swap, FALSE for byte swap */
63 long x; /* 32-bit long to be byte swapped */
65 /* Possibly swap a 32-bit long between 8086 and 68000 byte order. */
66 unsigned lo, hi;
67 long l;
69 if (norm) return(x); /* byte order was already ok */
70 lo = conv2(FALSE, (int) x & 0xFFFF); /* low-order half, byte swapped */
71 hi = conv2(FALSE, (int) (x>>16) & 0xFFFF); /* high-order half, swapped */
72 l = ( (long) lo <<16) | hi;
73 return(l);
76 /*===========================================================================*
77 * clock_time *
78 *===========================================================================*/
79 PUBLIC time_t clock_time()
81 /* This routine returns the time in seconds since 1.1.1970. MINIX is an
82 * astrophysically naive system that assumes the earth rotates at a constant
83 * rate and that such things as leap seconds do not exist.
86 register int k;
87 clock_t uptime;
89 if ( (k=getuptime(&uptime)) != OK) panic(__FILE__,"clock_time err", k);
90 return( (time_t) (boottime + (uptime/HZ)));
93 int mfs_min_f(char *file, int line, int v1, int v2)
95 if(v1 < 0 || v2 < 0) {
96 printf("mfs:%s:%d: strange string lengths: %d, %d\n",
97 file, line, v1, v2);
98 panic(file, "strange string lengths", NO_NUM);
100 if(v2 >= v1) return v1;
101 printf("mfs:%s:%d: truncated %d to %d\n",
102 file, line, v1, v2);
103 return v2;
106 void mfs_nul_f(char *file, int line, char *str, int len, int maxlen)
108 if(len < 1) {
109 printf("mfs:%s:%d: %d-length string?!\n", file, line, len);
110 panic(file, "strange string length", NO_NUM);
112 if(len < maxlen && str[len-1] != '\0') {
113 printf("mfs:%s:%d: string (length %d, maxlen %d) "
114 "not null-terminated\n",
115 file, line, len, maxlen);