tar: use utime() to restore timestamps
[minix.git] / servers / mfs / utility.c
blob3a2ecd5619a06439bbb4b15fca791d5fd2ac8112
1 #include "fs.h"
2 #include "buf.h"
3 #include "inode.h"
4 #include "super.h"
7 /*===========================================================================*
8 * no_sys *
9 *===========================================================================*/
10 int no_sys()
12 /* Somebody has used an illegal system call number */
13 printf("no_sys: invalid call %d\n", req_nr);
14 return(EINVAL);
18 /*===========================================================================*
19 * conv2 *
20 *===========================================================================*/
21 unsigned conv2(norm, w)
22 int norm; /* TRUE if no swap, FALSE for byte swap */
23 int w; /* promotion of 16-bit word to be swapped */
25 /* Possibly swap a 16-bit word between 8086 and 68000 byte order. */
26 if (norm) return( (unsigned) w & 0xFFFF);
27 return( ((w&BYTE) << 8) | ( (w>>8) & BYTE));
31 /*===========================================================================*
32 * conv4 *
33 *===========================================================================*/
34 long conv4(norm, x)
35 int norm; /* TRUE if no swap, FALSE for byte swap */
36 long x; /* 32-bit long to be byte swapped */
38 /* Possibly swap a 32-bit long between 8086 and 68000 byte order. */
39 unsigned lo, hi;
40 long l;
42 if (norm) return(x); /* byte order was already ok */
43 lo = conv2(FALSE, (int) x & 0xFFFF); /* low-order half, byte swapped */
44 hi = conv2(FALSE, (int) (x>>16) & 0xFFFF); /* high-order half, swapped */
45 l = ( (long) lo <<16) | hi;
46 return(l);
50 /*===========================================================================*
51 * clock_time *
52 *===========================================================================*/
53 time_t clock_time()
55 /* This routine returns the time in seconds since 1.1.1970. MINIX is an
56 * astrophysically naive system that assumes the earth rotates at a constant
57 * rate and that such things as leap seconds do not exist.
60 register int k;
61 clock_t uptime;
62 time_t boottime;
64 if ( (k=getuptime2(&uptime, &boottime)) != OK)
65 panic("clock_time: getuptme2 failed: %d", k);
67 return( (time_t) (boottime + (uptime/sys_hz())));
71 /*===========================================================================*
72 * mfs_min *
73 *===========================================================================*/
74 int min(unsigned int l, unsigned int r)
76 if(r >= l) return(l);
78 return(r);
82 /*===========================================================================*
83 * mfs_nul *
84 *===========================================================================*/
85 void mfs_nul_f(char *file, int line, char *str, unsigned int len,
86 unsigned int maxlen)
88 if(len < maxlen && str[len-1] != '\0') {
89 printf("MFS %s:%d string (length %d, maxlen %d) not null-terminated\n",
90 file, line, len, maxlen);
94 #define MYASSERT(c) if(!(c)) { printf("MFS:%s:%d: sanity check: %s failed\n", \
95 file, line, #c); panic("sanity check " #c " failed: %d", __LINE__); }
98 /*===========================================================================*
99 * sanity_check *
100 *===========================================================================*/
101 void sanitycheck(char *file, int line)
103 MYASSERT(SELF_E > 0);
104 if(superblock.s_dev != NO_DEV) {
105 MYASSERT(superblock.s_dev == fs_dev);
106 MYASSERT(superblock.s_block_size == lmfs_fs_block_size());
107 } else {
108 MYASSERT(_MIN_BLOCK_SIZE == lmfs_fs_block_size());