xref: /minix3/minix/fs/mfs/utility.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc #include "fs.h"
2*433d6423SLionel Sambuc #include "buf.h"
3*433d6423SLionel Sambuc #include "inode.h"
4*433d6423SLionel Sambuc #include "super.h"
5*433d6423SLionel Sambuc 
6*433d6423SLionel Sambuc 
7*433d6423SLionel Sambuc /*===========================================================================*
8*433d6423SLionel Sambuc  *				no_sys					     *
9*433d6423SLionel Sambuc  *===========================================================================*/
10*433d6423SLionel Sambuc int no_sys()
11*433d6423SLionel Sambuc {
12*433d6423SLionel Sambuc /* Somebody has used an illegal system call number */
13*433d6423SLionel Sambuc   printf("no_sys: invalid call %d\n", req_nr);
14*433d6423SLionel Sambuc   return(EINVAL);
15*433d6423SLionel Sambuc }
16*433d6423SLionel Sambuc 
17*433d6423SLionel Sambuc 
18*433d6423SLionel Sambuc /*===========================================================================*
19*433d6423SLionel Sambuc  *				conv2					     *
20*433d6423SLionel Sambuc  *===========================================================================*/
21*433d6423SLionel Sambuc unsigned conv2(norm, w)
22*433d6423SLionel Sambuc int norm;			/* TRUE if no swap, FALSE for byte swap */
23*433d6423SLionel Sambuc int w;				/* promotion of 16-bit word to be swapped */
24*433d6423SLionel Sambuc {
25*433d6423SLionel Sambuc /* Possibly swap a 16-bit word between 8086 and 68000 byte order. */
26*433d6423SLionel Sambuc   if (norm) return( (unsigned) w & 0xFFFF);
27*433d6423SLionel Sambuc   return( ((w&BYTE) << 8) | ( (w>>8) & BYTE));
28*433d6423SLionel Sambuc }
29*433d6423SLionel Sambuc 
30*433d6423SLionel Sambuc 
31*433d6423SLionel Sambuc /*===========================================================================*
32*433d6423SLionel Sambuc  *				conv4					     *
33*433d6423SLionel Sambuc  *===========================================================================*/
34*433d6423SLionel Sambuc long conv4(norm, x)
35*433d6423SLionel Sambuc int norm;			/* TRUE if no swap, FALSE for byte swap */
36*433d6423SLionel Sambuc long x;				/* 32-bit long to be byte swapped */
37*433d6423SLionel Sambuc {
38*433d6423SLionel Sambuc /* Possibly swap a 32-bit long between 8086 and 68000 byte order. */
39*433d6423SLionel Sambuc   unsigned lo, hi;
40*433d6423SLionel Sambuc   long l;
41*433d6423SLionel Sambuc 
42*433d6423SLionel Sambuc   if (norm) return(x);			/* byte order was already ok */
43*433d6423SLionel Sambuc   lo = conv2(FALSE, (int) x & 0xFFFF);	/* low-order half, byte swapped */
44*433d6423SLionel Sambuc   hi = conv2(FALSE, (int) (x>>16) & 0xFFFF);	/* high-order half, swapped */
45*433d6423SLionel Sambuc   l = ( (long) lo <<16) | hi;
46*433d6423SLionel Sambuc   return(l);
47*433d6423SLionel Sambuc }
48*433d6423SLionel Sambuc 
49*433d6423SLionel Sambuc 
50*433d6423SLionel Sambuc /*===========================================================================*
51*433d6423SLionel Sambuc  *				clock_time				     *
52*433d6423SLionel Sambuc  *===========================================================================*/
53*433d6423SLionel Sambuc time_t clock_time()
54*433d6423SLionel Sambuc {
55*433d6423SLionel Sambuc /* This routine returns the time in seconds since 1.1.1970.  MINIX is an
56*433d6423SLionel Sambuc  * astrophysically naive system that assumes the earth rotates at a constant
57*433d6423SLionel Sambuc  * rate and that such things as leap seconds do not exist.
58*433d6423SLionel Sambuc  */
59*433d6423SLionel Sambuc 
60*433d6423SLionel Sambuc   register int k;
61*433d6423SLionel Sambuc   clock_t uptime;
62*433d6423SLionel Sambuc   clock_t realtime;
63*433d6423SLionel Sambuc   time_t boottime;
64*433d6423SLionel Sambuc 
65*433d6423SLionel Sambuc   if ( (k=getuptime(&uptime, &realtime, &boottime)) != OK)
66*433d6423SLionel Sambuc 		panic("clock_time: getuptme2 failed: %d", k);
67*433d6423SLionel Sambuc 
68*433d6423SLionel Sambuc   return( (time_t) (boottime + (realtime/sys_hz())));
69*433d6423SLionel Sambuc }
70*433d6423SLionel Sambuc 
71*433d6423SLionel Sambuc 
72*433d6423SLionel Sambuc /*===========================================================================*
73*433d6423SLionel Sambuc  *				mfs_min					     *
74*433d6423SLionel Sambuc  *===========================================================================*/
75*433d6423SLionel Sambuc int min(unsigned int l, unsigned int r)
76*433d6423SLionel Sambuc {
77*433d6423SLionel Sambuc 	if(r >= l) return(l);
78*433d6423SLionel Sambuc 
79*433d6423SLionel Sambuc 	return(r);
80*433d6423SLionel Sambuc }
81*433d6423SLionel Sambuc 
82*433d6423SLionel Sambuc 
83*433d6423SLionel Sambuc /*===========================================================================*
84*433d6423SLionel Sambuc  *				mfs_nul					     *
85*433d6423SLionel Sambuc  *===========================================================================*/
86*433d6423SLionel Sambuc void mfs_nul_f(char *file, int line, char *str, unsigned int len,
87*433d6423SLionel Sambuc unsigned int maxlen)
88*433d6423SLionel Sambuc {
89*433d6423SLionel Sambuc   if(len < maxlen && str[len-1] != '\0') {
90*433d6423SLionel Sambuc 	printf("MFS %s:%d string (length %d, maxlen %d) not null-terminated\n",
91*433d6423SLionel Sambuc 		file, line, len, maxlen);
92*433d6423SLionel Sambuc   }
93*433d6423SLionel Sambuc }
94*433d6423SLionel Sambuc 
95*433d6423SLionel Sambuc #define MYASSERT(c) if(!(c)) { printf("MFS:%s:%d: sanity check: %s failed\n", \
96*433d6423SLionel Sambuc   file, line, #c); panic("sanity check " #c " failed: %d", __LINE__); }
97*433d6423SLionel Sambuc 
98