Fixed extern declaration from pointer to array
[minix.git] / servers / vfs / utility.c
blob1e23caf7f3c33289903c52c7120548faac901fe7
1 /* This file contains a few general purpose utility routines.
3 * The entry points into this file are
4 * clock_time: ask the clock task for the real time
5 * copy: copy a block of data
6 * fetch_name: go get a path name from user space
7 * no_sys: reject a system call that FS does not handle
8 * panic: something awful has occurred; MINIX cannot continue
9 * conv2: do byte swapping on a 16-bit int
10 * conv4: do byte swapping on a 32-bit long
13 #include "fs.h"
14 #include <minix/com.h>
15 #include <minix/endpoint.h>
16 #include <unistd.h>
17 #include <stdlib.h>
18 #include <assert.h>
19 #include "file.h"
20 #include "fproc.h"
21 #include "param.h"
22 #include "vmnt.h"
24 /*===========================================================================*
25 * fetch_name *
26 *===========================================================================*/
27 PUBLIC int fetch_name(path, len, flag)
28 char *path; /* pointer to the path in user space */
29 int len; /* path length, including 0 byte */
30 int flag; /* M3 means path may be in message */
32 /* Go get path and put it in 'user_fullpath'.
33 * If 'flag' = M3 and 'len' <= M3_STRING, the path is present in 'message'.
34 * If it is not, go copy it from user space.
36 register char *rpu, *rpm;
37 int r, count;
39 if (len > PATH_MAX) {
40 err_code = ENAMETOOLONG;
41 return(EGENERIC);
44 if(len >= sizeof(user_fullpath))
45 panic(__FILE__, "fetch_name: len too much for user_fullpath", len);
47 /* Check name length for validity. */
48 if (len <= 0) {
49 err_code = EINVAL;
50 return(EGENERIC);
53 if (flag == M3 && len <= M3_STRING) {
54 /* Just copy the path from the message to 'user_fullpath'. */
55 rpu = &user_fullpath[0];
56 rpm = m_in.pathname; /* contained in input message */
57 count = len;
58 do { *rpu++ = *rpm++; } while (--count);
59 r = OK;
60 } else {
61 /* String is not contained in the message. Get it from user space. */
62 r = sys_datacopy(who_e, (vir_bytes) path,
63 FS_PROC_NR, (vir_bytes) user_fullpath, (phys_bytes) len);
66 if (user_fullpath[len - 1] != '\0') {
67 err_code = ENAMETOOLONG;
68 return(EGENERIC);
71 return(r);
75 /*===========================================================================*
76 * no_sys *
77 *===========================================================================*/
78 PUBLIC int no_sys()
80 /* Somebody has used an illegal system call number */
81 printf("VFS no_sys: call %d from %d (pid %d)\n", call_nr, who_e, who_p);
82 return(ENOSYS);
86 /*===========================================================================*
87 * isokendpt_f *
88 *===========================================================================*/
89 PUBLIC int isokendpt_f(char *file, int line, int endpoint, int *proc, int fatal)
91 int failed = 0;
92 endpoint_t ke;
93 *proc = _ENDPOINT_P(endpoint);
94 if(endpoint == NONE) {
95 printf("vfs:%s: endpoint is NONE\n", file, line, endpoint);
96 failed = 1;
97 } else if(*proc < 0 || *proc >= NR_PROCS) {
98 printf("vfs:%s:%d: proc (%d) from endpoint (%d) out of range\n",
99 file, line, *proc, endpoint);
100 failed = 1;
101 } else if((ke=fproc[*proc].fp_endpoint) != endpoint) {
102 if(ke == NONE) {
103 printf("vfs:%s:%d: endpoint (%d) points to NONE slot (%d)\n",
104 file, line, endpoint, *proc);
105 assert(fproc[*proc].fp_pid == PID_FREE);
106 } else {
107 printf("vfs:%s:%d: proc (%d) from endpoint (%d) doesn't match "
108 "known endpoint (%d)\n", file, line, *proc, endpoint,
109 fproc[*proc].fp_endpoint);
110 assert(fproc[*proc].fp_pid != PID_FREE);
112 failed = 1;
115 if(failed && fatal)
116 panic(__FILE__, "isokendpt_f failed", NO_NUM);
118 return(failed ? EDEADSRCDST : OK);
122 /*===========================================================================*
123 * clock_time *
124 *===========================================================================*/
125 PUBLIC time_t clock_time()
127 /* This routine returns the time in seconds since 1.1.1970. MINIX is an
128 * astrophysically naive system that assumes the earth rotates at a constant
129 * rate and that such things as leap seconds do not exist.
132 register int r;
133 clock_t uptime;
134 time_t boottime;
136 r = getuptime2(&uptime, &boottime);
137 if (r != OK)
138 panic(__FILE__,"clock_time err", r);
140 return( (time_t) (boottime + (uptime/system_hz)));