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
11 * in_group: determines if group 'grp' is in rfp->fp_sgroups[]
15 #include <minix/com.h>
16 #include <minix/endpoint.h>
26 /*===========================================================================*
28 *===========================================================================*/
29 inline int copy_name( size_t len
, char *dest
)
31 /* Go get path and put it in 'dest'.
33 if (len
> PATH_MAX
) { /* 'len' includes terminating-nul */
34 err_code
= ENAMETOOLONG
;
38 /* Check name length for validity. */
39 if (len
> SSIZE_MAX
) {
44 if (len
<= M3_STRING
) {
45 /* Just copy the path from the message */
46 strncpy(dest
, job_m_in
.pathname
, len
);
48 /* String is not contained in the message. */
53 if (dest
[len
- 1] != '\0') {
54 err_code
= ENAMETOOLONG
;
61 /*===========================================================================*
63 *===========================================================================*/
64 int fetch_name(vir_bytes path
, size_t len
, char *dest
)
66 /* Go get path and put it in 'dest'. */
69 if (len
> PATH_MAX
) { /* 'len' includes terminating-nul */
70 err_code
= ENAMETOOLONG
;
74 /* Check name length for validity. */
75 if (len
> SSIZE_MAX
) {
80 /* String is not contained in the message. Get it from user space. */
81 r
= sys_datacopy(who_e
, path
, VFS_PROC_NR
, (vir_bytes
) dest
, len
);
87 if (dest
[len
- 1] != '\0') {
88 err_code
= ENAMETOOLONG
;
96 /*===========================================================================*
98 *===========================================================================*/
101 /* Somebody has used an illegal system call number */
106 /*===========================================================================*
108 *===========================================================================*/
109 int isokendpt_f(char *file
, int line
, endpoint_t endpoint
, int *proc
,
114 *proc
= _ENDPOINT_P(endpoint
);
115 if (endpoint
== NONE
) {
116 printf("VFS %s:%d: endpoint is NONE\n", file
, line
);
118 } else if (*proc
< 0 || *proc
>= NR_PROCS
) {
119 printf("VFS %s:%d: proc (%d) from endpoint (%d) out of range\n",
120 file
, line
, *proc
, endpoint
);
122 } else if ((ke
= fproc
[*proc
].fp_endpoint
) != endpoint
) {
124 printf("VFS %s:%d: endpoint (%d) points to NONE slot (%d)\n",
125 file
, line
, endpoint
, *proc
);
126 assert(fproc
[*proc
].fp_pid
== PID_FREE
);
128 printf("VFS %s:%d: proc (%d) from endpoint (%d) doesn't match "
129 "known endpoint (%d)\n", file
, line
, *proc
, endpoint
,
130 fproc
[*proc
].fp_endpoint
);
131 assert(fproc
[*proc
].fp_pid
!= PID_FREE
);
137 panic("isokendpt_f failed");
139 return(failed
? EDEADEPT
: OK
);
143 /*===========================================================================*
145 *===========================================================================*/
148 /* This routine returns the time in seconds since 1.1.1970. MINIX is an
149 * astrophysically naive system that assumes the earth rotates at a constant
150 * rate and that such things as leap seconds do not exist.
157 r
= getuptime2(&uptime
, &boottime
);
159 panic("clock_time err: %d", r
);
161 return( (time_t) (boottime
+ (uptime
/system_hz
)));
164 /*===========================================================================*
166 *===========================================================================*/
167 int in_group(struct fproc
*rfp
, gid_t grp
)
171 for (i
= 0; i
< rfp
->fp_ngroups
; i
++)
172 if (rfp
->fp_sgroups
[i
] == grp
)