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
14 #include <minix/com.h>
15 #include <minix/endpoint.h>
24 /*===========================================================================*
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
;
40 err_code
= ENAMETOOLONG
;
44 if(len
>= sizeof(user_fullpath
))
45 panic(__FILE__
, "fetch_name: len too much for user_fullpath", len
);
47 /* Check name length for validity. */
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 */
58 do { *rpu
++ = *rpm
++; } while (--count
);
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
;
75 /*===========================================================================*
77 *===========================================================================*/
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
);
86 /*===========================================================================*
88 *===========================================================================*/
89 PUBLIC
int isokendpt_f(char *file
, int line
, int endpoint
, int *proc
, int fatal
)
93 *proc
= _ENDPOINT_P(endpoint
);
94 if(endpoint
== NONE
) {
95 printf("vfs:%s: endpoint is NONE\n", file
, line
, endpoint
);
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
);
101 } else if((ke
=fproc
[*proc
].fp_endpoint
) != endpoint
) {
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
);
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
);
116 panic(__FILE__
, "isokendpt_f failed", NO_NUM
);
118 return(failed
? EDEADSRCDST
: OK
);
122 /*===========================================================================*
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.
136 r
= getuptime2(&uptime
, &boottime
);
138 panic(__FILE__
,"clock_time err", r
);
140 return( (time_t) (boottime
+ (uptime
/system_hz
)));