sunos_misc.c revision 1.81 1 1.81 bouyer /* $NetBSD: sunos_misc.c,v 1.81 1997/08/04 09:48:10 bouyer Exp $ */
2 1.30 cgd
3 1.1 deraadt /*
4 1.1 deraadt * Copyright (c) 1992, 1993
5 1.1 deraadt * The Regents of the University of California. All rights reserved.
6 1.1 deraadt *
7 1.1 deraadt * This software was developed by the Computer Systems Engineering group
8 1.1 deraadt * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 1.1 deraadt * contributed to Berkeley.
10 1.1 deraadt *
11 1.1 deraadt * All advertising materials mentioning features or use of this software
12 1.1 deraadt * must display the following acknowledgement:
13 1.1 deraadt * This product includes software developed by the University of
14 1.1 deraadt * California, Lawrence Berkeley Laboratory.
15 1.1 deraadt *
16 1.1 deraadt * Redistribution and use in source and binary forms, with or without
17 1.1 deraadt * modification, are permitted provided that the following conditions
18 1.1 deraadt * are met:
19 1.1 deraadt * 1. Redistributions of source code must retain the above copyright
20 1.1 deraadt * notice, this list of conditions and the following disclaimer.
21 1.1 deraadt * 2. Redistributions in binary form must reproduce the above copyright
22 1.1 deraadt * notice, this list of conditions and the following disclaimer in the
23 1.1 deraadt * documentation and/or other materials provided with the distribution.
24 1.1 deraadt * 3. All advertising materials mentioning features or use of this software
25 1.1 deraadt * must display the following acknowledgement:
26 1.1 deraadt * This product includes software developed by the University of
27 1.1 deraadt * California, Berkeley and its contributors.
28 1.1 deraadt * 4. Neither the name of the University nor the names of its contributors
29 1.1 deraadt * may be used to endorse or promote products derived from this software
30 1.1 deraadt * without specific prior written permission.
31 1.1 deraadt *
32 1.1 deraadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 1.1 deraadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 1.1 deraadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 1.1 deraadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 1.1 deraadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1 deraadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1 deraadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1 deraadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 1.1 deraadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 1.1 deraadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 1.1 deraadt * SUCH DAMAGE.
43 1.1 deraadt *
44 1.33 deraadt * @(#)sunos_misc.c 8.1 (Berkeley) 6/18/93
45 1.1 deraadt *
46 1.33 deraadt * Header: sunos_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
47 1.1 deraadt */
48 1.1 deraadt
49 1.1 deraadt /*
50 1.1 deraadt * SunOS compatibility module.
51 1.1 deraadt *
52 1.1 deraadt * SunOS system calls that are implemented differently in BSD are
53 1.1 deraadt * handled here.
54 1.1 deraadt */
55 1.1 deraadt
56 1.1 deraadt #include <sys/param.h>
57 1.1 deraadt #include <sys/systm.h>
58 1.10 deraadt #include <sys/namei.h>
59 1.1 deraadt #include <sys/proc.h>
60 1.63 gwr #include <sys/dirent.h>
61 1.1 deraadt #include <sys/file.h>
62 1.10 deraadt #include <sys/stat.h>
63 1.1 deraadt #include <sys/filedesc.h>
64 1.1 deraadt #include <sys/ioctl.h>
65 1.8 deraadt #include <sys/kernel.h>
66 1.44 christos #include <sys/reboot.h>
67 1.1 deraadt #include <sys/malloc.h>
68 1.1 deraadt #include <sys/mbuf.h>
69 1.1 deraadt #include <sys/mman.h>
70 1.1 deraadt #include <sys/mount.h>
71 1.35 deraadt #include <sys/ptrace.h>
72 1.1 deraadt #include <sys/resource.h>
73 1.1 deraadt #include <sys/resourcevar.h>
74 1.1 deraadt #include <sys/signal.h>
75 1.1 deraadt #include <sys/signalvar.h>
76 1.1 deraadt #include <sys/socket.h>
77 1.60 pk #include <sys/tty.h>
78 1.1 deraadt #include <sys/vnode.h>
79 1.1 deraadt #include <sys/uio.h>
80 1.1 deraadt #include <sys/wait.h>
81 1.8 deraadt #include <sys/utsname.h>
82 1.12 deraadt #include <sys/unistd.h>
83 1.33 deraadt #include <sys/syscallargs.h>
84 1.64 christos #include <sys/conf.h>
85 1.64 christos #include <sys/socketvar.h>
86 1.73 christos #include <sys/exec.h>
87 1.55 mycroft
88 1.33 deraadt #include <compat/sunos/sunos.h>
89 1.33 deraadt #include <compat/sunos/sunos_syscallargs.h>
90 1.48 pk #include <compat/sunos/sunos_util.h>
91 1.56 mycroft #include <compat/sunos/sunos_dirent.h>
92 1.1 deraadt
93 1.10 deraadt #include <netinet/in.h>
94 1.10 deraadt
95 1.7 deraadt #include <miscfs/specfs/specdev.h>
96 1.1 deraadt
97 1.27 pk #include <nfs/rpcv2.h>
98 1.61 pk #include <nfs/nfsproto.h>
99 1.27 pk #include <nfs/nfs.h>
100 1.27 pk
101 1.1 deraadt #include <vm/vm.h>
102 1.79 mrg #include <vm/vm_swap.h>
103 1.1 deraadt
104 1.64 christos static int sunstatfs __P((struct statfs *, caddr_t));
105 1.70 christos
106 1.70 christos int
107 1.70 christos sunos_sys_stime(p, v, retval)
108 1.70 christos struct proc *p;
109 1.70 christos void *v;
110 1.70 christos register_t *retval;
111 1.70 christos {
112 1.70 christos struct sunos_sys_stime_args *uap = v;
113 1.70 christos struct sys_settimeofday_args ap;
114 1.70 christos caddr_t sg = stackgap_init(p->p_emul);
115 1.75 cjs struct timeval tv, *sgtvp;
116 1.70 christos int error;
117 1.70 christos
118 1.70 christos error = copyin(SCARG(uap, tp), &tv.tv_sec, sizeof(tv.tv_sec));
119 1.70 christos if (error)
120 1.70 christos return error;
121 1.70 christos tv.tv_usec = 0;
122 1.70 christos
123 1.75 cjs SCARG(&ap, tv) = sgtvp = stackgap_alloc(&sg, sizeof(struct timeval));
124 1.70 christos SCARG(&ap, tzp) = NULL;
125 1.70 christos
126 1.75 cjs error = copyout(&tv, sgtvp, sizeof(struct timeval));
127 1.70 christos if (error)
128 1.70 christos return error;
129 1.70 christos
130 1.70 christos return sys_settimeofday(p, &ap, retval);
131 1.70 christos }
132 1.70 christos
133 1.33 deraadt int
134 1.55 mycroft sunos_sys_wait4(p, v, retval)
135 1.1 deraadt struct proc *p;
136 1.54 thorpej void *v;
137 1.32 cgd register_t *retval;
138 1.1 deraadt {
139 1.55 mycroft struct sunos_sys_wait4_args *uap = v;
140 1.33 deraadt if (SCARG(uap, pid) == 0)
141 1.33 deraadt SCARG(uap, pid) = WAIT_ANY;
142 1.55 mycroft return (sys_wait4(p, uap, retval));
143 1.1 deraadt }
144 1.1 deraadt
145 1.33 deraadt int
146 1.55 mycroft sunos_sys_creat(p, v, retval)
147 1.1 deraadt struct proc *p;
148 1.54 thorpej void *v;
149 1.32 cgd register_t *retval;
150 1.1 deraadt {
151 1.55 mycroft struct sunos_sys_creat_args *uap = v;
152 1.55 mycroft struct sys_open_args ouap;
153 1.1 deraadt
154 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
155 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
156 1.48 pk
157 1.33 deraadt SCARG(&ouap, path) = SCARG(uap, path);
158 1.33 deraadt SCARG(&ouap, flags) = O_WRONLY | O_CREAT | O_TRUNC;
159 1.33 deraadt SCARG(&ouap, mode) = SCARG(uap, mode);
160 1.55 mycroft
161 1.55 mycroft return (sys_open(p, &ouap, retval));
162 1.1 deraadt }
163 1.1 deraadt
164 1.33 deraadt int
165 1.55 mycroft sunos_sys_access(p, v, retval)
166 1.48 pk struct proc *p;
167 1.54 thorpej void *v;
168 1.48 pk register_t *retval;
169 1.48 pk {
170 1.55 mycroft struct sunos_sys_access_args *uap = v;
171 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
172 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
173 1.48 pk
174 1.55 mycroft return (sys_access(p, uap, retval));
175 1.48 pk }
176 1.48 pk
177 1.48 pk int
178 1.55 mycroft sunos_sys_stat(p, v, retval)
179 1.48 pk struct proc *p;
180 1.54 thorpej void *v;
181 1.48 pk register_t *retval;
182 1.48 pk {
183 1.55 mycroft struct sunos_sys_stat_args *uap = v;
184 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
185 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
186 1.48 pk
187 1.55 mycroft return (compat_43_sys_stat(p, uap, retval));
188 1.48 pk }
189 1.48 pk
190 1.48 pk int
191 1.55 mycroft sunos_sys_lstat(p, v, retval)
192 1.48 pk struct proc *p;
193 1.54 thorpej void *v;
194 1.48 pk register_t *retval;
195 1.48 pk {
196 1.55 mycroft struct sunos_sys_lstat_args *uap = v;
197 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
198 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
199 1.48 pk
200 1.55 mycroft return (compat_43_sys_lstat(p, uap, retval));
201 1.48 pk }
202 1.48 pk
203 1.48 pk int
204 1.55 mycroft sunos_sys_execv(p, v, retval)
205 1.1 deraadt struct proc *p;
206 1.54 thorpej void *v;
207 1.32 cgd register_t *retval;
208 1.1 deraadt {
209 1.71 mycroft struct sunos_sys_execv_args /* {
210 1.71 mycroft syscallarg(char *) path;
211 1.71 mycroft syscallarg(char **) argv;
212 1.71 mycroft } */ *uap = v;
213 1.71 mycroft struct sys_execve_args ap;
214 1.71 mycroft caddr_t sg;
215 1.1 deraadt
216 1.71 mycroft sg = stackgap_init(p->p_emul);
217 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
218 1.48 pk
219 1.71 mycroft SCARG(&ap, path) = SCARG(uap, path);
220 1.71 mycroft SCARG(&ap, argp) = SCARG(uap, argp);
221 1.71 mycroft SCARG(&ap, envp) = NULL;
222 1.69 thorpej
223 1.71 mycroft return (sys_execve(p, &ap, retval));
224 1.69 thorpej }
225 1.69 thorpej
226 1.69 thorpej int
227 1.69 thorpej sunos_sys_execve(p, v, retval)
228 1.69 thorpej struct proc *p;
229 1.69 thorpej void *v;
230 1.69 thorpej register_t *retval;
231 1.69 thorpej {
232 1.71 mycroft struct sunos_sys_execve_args /* {
233 1.71 mycroft syscallarg(char *) path;
234 1.71 mycroft syscallarg(char **) argv;
235 1.71 mycroft syscallarg(char **) envp;
236 1.71 mycroft } */ *uap = v;
237 1.71 mycroft struct sys_execve_args ap;
238 1.71 mycroft caddr_t sg;
239 1.71 mycroft
240 1.71 mycroft sg = stackgap_init(p->p_emul);
241 1.71 mycroft SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
242 1.71 mycroft
243 1.71 mycroft SCARG(&ap, path) = SCARG(uap, path);
244 1.71 mycroft SCARG(&ap, argp) = SCARG(uap, argp);
245 1.71 mycroft SCARG(&ap, envp) = SCARG(uap, envp);
246 1.55 mycroft
247 1.71 mycroft return (sys_execve(p, &ap, retval));
248 1.1 deraadt }
249 1.1 deraadt
250 1.33 deraadt int
251 1.55 mycroft sunos_sys_omsync(p, v, retval)
252 1.1 deraadt struct proc *p;
253 1.54 thorpej void *v;
254 1.32 cgd register_t *retval;
255 1.1 deraadt {
256 1.55 mycroft struct sunos_sys_omsync_args *uap = v;
257 1.55 mycroft struct sys_msync_args ouap;
258 1.1 deraadt
259 1.33 deraadt if (SCARG(uap, flags))
260 1.1 deraadt return (EINVAL);
261 1.33 deraadt SCARG(&ouap, addr) = SCARG(uap, addr);
262 1.33 deraadt SCARG(&ouap, len) = SCARG(uap, len);
263 1.55 mycroft
264 1.55 mycroft return (sys_msync(p, &ouap, retval));
265 1.1 deraadt }
266 1.1 deraadt
267 1.33 deraadt int
268 1.55 mycroft sunos_sys_unmount(p, v, retval)
269 1.33 deraadt struct proc *p;
270 1.54 thorpej void *v;
271 1.32 cgd register_t *retval;
272 1.1 deraadt {
273 1.55 mycroft struct sunos_sys_unmount_args *uap = v;
274 1.55 mycroft struct sys_unmount_args ouap;
275 1.54 thorpej
276 1.55 mycroft SCARG(&ouap, path) = SCARG(uap, path);
277 1.55 mycroft SCARG(&ouap, flags) = 0;
278 1.55 mycroft
279 1.55 mycroft return (sys_unmount(p, &ouap, retval));
280 1.33 deraadt }
281 1.1 deraadt
282 1.61 pk /*
283 1.61 pk * Conversion table for SunOS NFS mount flags.
284 1.61 pk */
285 1.61 pk static struct {
286 1.61 pk int sun_flg;
287 1.61 pk int bsd_flg;
288 1.61 pk } sunnfs_flgtab[] = {
289 1.61 pk { SUNNFS_SOFT, NFSMNT_SOFT },
290 1.61 pk { SUNNFS_WSIZE, NFSMNT_WSIZE },
291 1.61 pk { SUNNFS_RSIZE, NFSMNT_RSIZE },
292 1.61 pk { SUNNFS_TIMEO, NFSMNT_TIMEO },
293 1.61 pk { SUNNFS_RETRANS, NFSMNT_RETRANS },
294 1.61 pk { SUNNFS_HOSTNAME, 0 }, /* Ignored */
295 1.61 pk { SUNNFS_INT, NFSMNT_INT },
296 1.61 pk { SUNNFS_NOAC, 0 }, /* Ignored */
297 1.61 pk { SUNNFS_ACREGMIN, 0 }, /* Ignored */
298 1.61 pk { SUNNFS_ACREGMAX, 0 }, /* Ignored */
299 1.61 pk { SUNNFS_ACDIRMIN, 0 }, /* Ignored */
300 1.61 pk { SUNNFS_ACDIRMAX, 0 }, /* Ignored */
301 1.61 pk { SUNNFS_SECURE, 0 }, /* Ignored */
302 1.61 pk { SUNNFS_NOCTO, 0 }, /* Ignored */
303 1.61 pk { SUNNFS_POSIX, 0 } /* Ignored */
304 1.61 pk };
305 1.61 pk
306 1.33 deraadt int
307 1.55 mycroft sunos_sys_mount(p, v, retval)
308 1.1 deraadt struct proc *p;
309 1.54 thorpej void *v;
310 1.32 cgd register_t *retval;
311 1.1 deraadt {
312 1.55 mycroft struct sunos_sys_mount_args *uap = v;
313 1.33 deraadt int oflags = SCARG(uap, flags), nflags, error;
314 1.16 deraadt char fsname[MFSNAMELEN];
315 1.74 christos caddr_t sg = stackgap_init(p->p_emul);
316 1.16 deraadt
317 1.1 deraadt if (oflags & (SUNM_NOSUB | SUNM_SYS5))
318 1.1 deraadt return (EINVAL);
319 1.16 deraadt if ((oflags & SUNM_NEWTYPE) == 0)
320 1.16 deraadt return (EINVAL);
321 1.1 deraadt nflags = 0;
322 1.1 deraadt if (oflags & SUNM_RDONLY)
323 1.1 deraadt nflags |= MNT_RDONLY;
324 1.1 deraadt if (oflags & SUNM_NOSUID)
325 1.1 deraadt nflags |= MNT_NOSUID;
326 1.1 deraadt if (oflags & SUNM_REMOUNT)
327 1.1 deraadt nflags |= MNT_UPDATE;
328 1.33 deraadt SCARG(uap, flags) = nflags;
329 1.10 deraadt
330 1.64 christos error = copyinstr((caddr_t)SCARG(uap, type), fsname,
331 1.64 christos sizeof fsname, (size_t *)0);
332 1.64 christos if (error)
333 1.16 deraadt return (error);
334 1.16 deraadt
335 1.49 cgd if (strncmp(fsname, "4.2", sizeof fsname) == 0) {
336 1.74 christos SCARG(uap, type) = stackgap_alloc(&sg, sizeof("ffs"));
337 1.64 christos error = copyout("ffs", SCARG(uap, type), sizeof("ffs"));
338 1.64 christos if (error)
339 1.16 deraadt return (error);
340 1.49 cgd } else if (strncmp(fsname, "nfs", sizeof fsname) == 0) {
341 1.33 deraadt struct sunos_nfs_args sna;
342 1.10 deraadt struct sockaddr_in sain;
343 1.10 deraadt struct nfs_args na;
344 1.10 deraadt struct sockaddr sa;
345 1.61 pk int n;
346 1.10 deraadt
347 1.64 christos error = copyin(SCARG(uap, data), &sna, sizeof sna);
348 1.64 christos if (error)
349 1.10 deraadt return (error);
350 1.64 christos error = copyin(sna.addr, &sain, sizeof sain);
351 1.64 christos if (error)
352 1.10 deraadt return (error);
353 1.10 deraadt bcopy(&sain, &sa, sizeof sa);
354 1.10 deraadt sa.sa_len = sizeof(sain);
355 1.74 christos SCARG(uap, data) = stackgap_alloc(&sg, sizeof(na));
356 1.61 pk na.version = NFS_ARGSVERSION;
357 1.74 christos na.addr = stackgap_alloc(&sg, sizeof(struct sockaddr));
358 1.29 pk na.addrlen = sizeof(struct sockaddr);
359 1.10 deraadt na.sotype = SOCK_DGRAM;
360 1.10 deraadt na.proto = IPPROTO_UDP;
361 1.61 pk na.fh = (void *)sna.fh;
362 1.61 pk na.fhsize = NFSX_V2FH;
363 1.61 pk na.flags = 0;
364 1.61 pk n = sizeof(sunnfs_flgtab) / sizeof(sunnfs_flgtab[0]);
365 1.61 pk while (--n >= 0)
366 1.61 pk if (sna.flags & sunnfs_flgtab[n].sun_flg)
367 1.61 pk na.flags |= sunnfs_flgtab[n].bsd_flg;
368 1.10 deraadt na.wsize = sna.wsize;
369 1.10 deraadt na.rsize = sna.rsize;
370 1.62 pk if (na.flags & NFSMNT_RSIZE) {
371 1.62 pk na.flags |= NFSMNT_READDIRSIZE;
372 1.62 pk na.readdirsize = na.rsize;
373 1.62 pk }
374 1.10 deraadt na.timeo = sna.timeo;
375 1.10 deraadt na.retrans = sna.retrans;
376 1.10 deraadt na.hostname = sna.hostname;
377 1.10 deraadt
378 1.64 christos error = copyout(&sa, na.addr, sizeof sa);
379 1.64 christos if (error)
380 1.10 deraadt return (error);
381 1.64 christos error = copyout(&na, SCARG(uap, data), sizeof na);
382 1.64 christos if (error)
383 1.10 deraadt return (error);
384 1.10 deraadt }
385 1.55 mycroft return (sys_mount(p, (struct sys_mount_args *)uap, retval));
386 1.1 deraadt }
387 1.1 deraadt
388 1.76 thorpej #if defined(NFS)
389 1.33 deraadt int
390 1.55 mycroft async_daemon(p, v, retval)
391 1.27 pk struct proc *p;
392 1.55 mycroft void *v;
393 1.32 cgd register_t *retval;
394 1.27 pk {
395 1.55 mycroft struct sys_nfssvc_args ouap;
396 1.27 pk
397 1.33 deraadt SCARG(&ouap, flag) = NFSSVC_BIOD;
398 1.33 deraadt SCARG(&ouap, argp) = NULL;
399 1.55 mycroft
400 1.55 mycroft return (sys_nfssvc(p, &ouap, retval));
401 1.27 pk }
402 1.76 thorpej #endif /* NFS */
403 1.27 pk
404 1.33 deraadt int
405 1.55 mycroft sunos_sys_sigpending(p, v, retval)
406 1.1 deraadt struct proc *p;
407 1.54 thorpej void *v;
408 1.32 cgd register_t *retval;
409 1.1 deraadt {
410 1.55 mycroft struct sunos_sys_sigpending_args *uap = v;
411 1.21 deraadt int mask = p->p_siglist & p->p_sigmask;
412 1.1 deraadt
413 1.33 deraadt return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int)));
414 1.1 deraadt }
415 1.1 deraadt
416 1.1 deraadt /*
417 1.1 deraadt * Read Sun-style directory entries. We suck them into kernel space so
418 1.1 deraadt * that they can be massaged before being copied out to user code. Like
419 1.1 deraadt * SunOS, we squish out `empty' entries.
420 1.1 deraadt *
421 1.1 deraadt * This is quite ugly, but what do you expect from compatibility code?
422 1.1 deraadt */
423 1.33 deraadt int
424 1.55 mycroft sunos_sys_getdents(p, v, retval)
425 1.1 deraadt struct proc *p;
426 1.54 thorpej void *v;
427 1.32 cgd register_t *retval;
428 1.1 deraadt {
429 1.56 mycroft struct sunos_sys_getdents_args *uap = v;
430 1.56 mycroft struct dirent *bdp;
431 1.56 mycroft struct vnode *vp;
432 1.56 mycroft caddr_t inp, buf; /* BSD-format */
433 1.56 mycroft int len, reclen; /* BSD-format */
434 1.56 mycroft caddr_t outp; /* Sun-format */
435 1.56 mycroft int resid, sunos_reclen;/* Sun-format */
436 1.1 deraadt struct file *fp;
437 1.1 deraadt struct uio auio;
438 1.1 deraadt struct iovec aiov;
439 1.56 mycroft struct sunos_dirent idb;
440 1.1 deraadt off_t off; /* true file offset */
441 1.1 deraadt int buflen, error, eofflag;
442 1.56 mycroft u_long *cookiebuf, *cookie;
443 1.56 mycroft int ncookies;
444 1.1 deraadt
445 1.33 deraadt if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
446 1.1 deraadt return (error);
447 1.56 mycroft
448 1.1 deraadt if ((fp->f_flag & FREAD) == 0)
449 1.1 deraadt return (EBADF);
450 1.56 mycroft
451 1.1 deraadt vp = (struct vnode *)fp->f_data;
452 1.56 mycroft
453 1.1 deraadt if (vp->v_type != VDIR) /* XXX vnode readdir op should do this */
454 1.1 deraadt return (EINVAL);
455 1.56 mycroft
456 1.33 deraadt buflen = min(MAXBSIZE, SCARG(uap, nbytes));
457 1.1 deraadt buf = malloc(buflen, M_TEMP, M_WAITOK);
458 1.56 mycroft ncookies = buflen / 16;
459 1.56 mycroft cookiebuf = malloc(ncookies * sizeof(*cookiebuf), M_TEMP, M_WAITOK);
460 1.1 deraadt VOP_LOCK(vp);
461 1.1 deraadt off = fp->f_offset;
462 1.1 deraadt again:
463 1.1 deraadt aiov.iov_base = buf;
464 1.1 deraadt aiov.iov_len = buflen;
465 1.1 deraadt auio.uio_iov = &aiov;
466 1.1 deraadt auio.uio_iovcnt = 1;
467 1.1 deraadt auio.uio_rw = UIO_READ;
468 1.1 deraadt auio.uio_segflg = UIO_SYSSPACE;
469 1.1 deraadt auio.uio_procp = p;
470 1.1 deraadt auio.uio_resid = buflen;
471 1.1 deraadt auio.uio_offset = off;
472 1.1 deraadt /*
473 1.1 deraadt * First we read into the malloc'ed buffer, then
474 1.1 deraadt * we massage it into user space, one record at a time.
475 1.1 deraadt */
476 1.56 mycroft error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, cookiebuf,
477 1.56 mycroft ncookies);
478 1.59 ghudson if (error)
479 1.59 ghudson goto out;
480 1.56 mycroft
481 1.1 deraadt inp = buf;
482 1.33 deraadt outp = SCARG(uap, buf);
483 1.33 deraadt resid = SCARG(uap, nbytes);
484 1.1 deraadt if ((len = buflen - auio.uio_resid) == 0)
485 1.1 deraadt goto eof;
486 1.56 mycroft
487 1.56 mycroft for (cookie = cookiebuf; len > 0; len -= reclen) {
488 1.56 mycroft bdp = (struct dirent *)inp;
489 1.56 mycroft reclen = bdp->d_reclen;
490 1.1 deraadt if (reclen & 3)
491 1.33 deraadt panic("sunos_getdents");
492 1.56 mycroft if (bdp->d_fileno == 0) {
493 1.1 deraadt inp += reclen; /* it is a hole; squish it out */
494 1.81 bouyer off = *cookie++;
495 1.1 deraadt continue;
496 1.1 deraadt }
497 1.56 mycroft sunos_reclen = SUNOS_RECLEN(&idb, bdp->d_namlen);
498 1.56 mycroft if (reclen > len || resid < sunos_reclen) {
499 1.1 deraadt /* entry too big for buffer, so just stop */
500 1.1 deraadt outp++;
501 1.1 deraadt break;
502 1.1 deraadt }
503 1.81 bouyer off = *cookie++; /* each entry points to next */
504 1.1 deraadt /*
505 1.1 deraadt * Massage in place to make a Sun-shaped dirent (otherwise
506 1.1 deraadt * we have to worry about touching user memory outside of
507 1.1 deraadt * the copyout() call).
508 1.1 deraadt */
509 1.56 mycroft idb.d_fileno = bdp->d_fileno;
510 1.56 mycroft idb.d_off = off;
511 1.56 mycroft idb.d_reclen = sunos_reclen;
512 1.56 mycroft idb.d_namlen = bdp->d_namlen;
513 1.56 mycroft strcpy(idb.d_name, bdp->d_name);
514 1.56 mycroft if ((error = copyout((caddr_t)&idb, outp, sunos_reclen)) != 0)
515 1.1 deraadt goto out;
516 1.1 deraadt /* advance past this real entry */
517 1.1 deraadt inp += reclen;
518 1.1 deraadt /* advance output past Sun-shaped entry */
519 1.56 mycroft outp += sunos_reclen;
520 1.56 mycroft resid -= sunos_reclen;
521 1.1 deraadt }
522 1.56 mycroft
523 1.1 deraadt /* if we squished out the whole block, try again */
524 1.33 deraadt if (outp == SCARG(uap, buf))
525 1.1 deraadt goto again;
526 1.1 deraadt fp->f_offset = off; /* update the vnode offset */
527 1.56 mycroft
528 1.1 deraadt eof:
529 1.33 deraadt *retval = SCARG(uap, nbytes) - resid;
530 1.1 deraadt out:
531 1.1 deraadt VOP_UNLOCK(vp);
532 1.56 mycroft free(cookiebuf, M_TEMP);
533 1.1 deraadt free(buf, M_TEMP);
534 1.1 deraadt return (error);
535 1.1 deraadt }
536 1.1 deraadt
537 1.33 deraadt #define SUNOS__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */
538 1.4 deraadt
539 1.33 deraadt int
540 1.55 mycroft sunos_sys_mmap(p, v, retval)
541 1.1 deraadt register struct proc *p;
542 1.54 thorpej void *v;
543 1.32 cgd register_t *retval;
544 1.1 deraadt {
545 1.55 mycroft register struct sunos_sys_mmap_args *uap = v;
546 1.55 mycroft struct sys_mmap_args ouap;
547 1.1 deraadt register struct filedesc *fdp;
548 1.1 deraadt register struct file *fp;
549 1.1 deraadt register struct vnode *vp;
550 1.1 deraadt
551 1.1 deraadt /*
552 1.14 cgd * Verify the arguments.
553 1.1 deraadt */
554 1.33 deraadt if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
555 1.14 cgd return (EINVAL); /* XXX still needed? */
556 1.4 deraadt
557 1.33 deraadt if ((SCARG(uap, flags) & SUNOS__MAP_NEW) == 0)
558 1.1 deraadt return (EINVAL);
559 1.1 deraadt
560 1.34 deraadt SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUNOS__MAP_NEW;
561 1.34 deraadt SCARG(&ouap, addr) = SCARG(uap, addr);
562 1.34 deraadt
563 1.34 deraadt if ((SCARG(&ouap, flags) & MAP_FIXED) == 0 &&
564 1.34 deraadt SCARG(&ouap, addr) != 0 &&
565 1.34 deraadt SCARG(&ouap, addr) < (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ))
566 1.34 deraadt SCARG(&ouap, addr) = (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ);
567 1.34 deraadt
568 1.34 deraadt SCARG(&ouap, len) = SCARG(uap, len);
569 1.34 deraadt SCARG(&ouap, prot) = SCARG(uap, prot);
570 1.34 deraadt SCARG(&ouap, fd) = SCARG(uap, fd);
571 1.34 deraadt SCARG(&ouap, pos) = SCARG(uap, pos);
572 1.10 deraadt
573 1.1 deraadt /*
574 1.1 deraadt * Special case: if fd refers to /dev/zero, map as MAP_ANON. (XXX)
575 1.1 deraadt */
576 1.1 deraadt fdp = p->p_fd;
577 1.34 deraadt if ((unsigned)SCARG(&ouap, fd) < fdp->fd_nfiles && /*XXX*/
578 1.34 deraadt (fp = fdp->fd_ofiles[SCARG(&ouap, fd)]) != NULL && /*XXX*/
579 1.1 deraadt fp->f_type == DTYPE_VNODE && /*XXX*/
580 1.1 deraadt (vp = (struct vnode *)fp->f_data)->v_type == VCHR && /*XXX*/
581 1.23 deraadt iszerodev(vp->v_rdev)) { /*XXX*/
582 1.34 deraadt SCARG(&ouap, flags) |= MAP_ANON;
583 1.34 deraadt SCARG(&ouap, fd) = -1;
584 1.14 cgd }
585 1.4 deraadt
586 1.55 mycroft return (sys_mmap(p, &ouap, retval));
587 1.1 deraadt }
588 1.1 deraadt
589 1.1 deraadt #define MC_SYNC 1
590 1.1 deraadt #define MC_LOCK 2
591 1.1 deraadt #define MC_UNLOCK 3
592 1.1 deraadt #define MC_ADVISE 4
593 1.1 deraadt #define MC_LOCKAS 5
594 1.1 deraadt #define MC_UNLOCKAS 6
595 1.1 deraadt
596 1.33 deraadt int
597 1.55 mycroft sunos_sys_mctl(p, v, retval)
598 1.1 deraadt register struct proc *p;
599 1.54 thorpej void *v;
600 1.32 cgd register_t *retval;
601 1.1 deraadt {
602 1.55 mycroft register struct sunos_sys_mctl_args *uap = v;
603 1.1 deraadt
604 1.33 deraadt switch (SCARG(uap, func)) {
605 1.1 deraadt case MC_ADVISE: /* ignore for now */
606 1.1 deraadt return (0);
607 1.1 deraadt case MC_SYNC: /* translate to msync */
608 1.55 mycroft return (sys_msync(p, uap, retval));
609 1.1 deraadt default:
610 1.1 deraadt return (EINVAL);
611 1.1 deraadt }
612 1.1 deraadt }
613 1.1 deraadt
614 1.33 deraadt int
615 1.55 mycroft sunos_sys_setsockopt(p, v, retval)
616 1.1 deraadt struct proc *p;
617 1.54 thorpej void *v;
618 1.32 cgd register_t *retval;
619 1.1 deraadt {
620 1.55 mycroft register struct sunos_sys_setsockopt_args *uap = v;
621 1.1 deraadt struct file *fp;
622 1.1 deraadt struct mbuf *m = NULL;
623 1.1 deraadt int error;
624 1.1 deraadt
625 1.64 christos if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
626 1.1 deraadt return (error);
627 1.1 deraadt #define SO_DONTLINGER (~SO_LINGER)
628 1.33 deraadt if (SCARG(uap, name) == SO_DONTLINGER) {
629 1.1 deraadt m = m_get(M_WAIT, MT_SOOPTS);
630 1.1 deraadt mtod(m, struct linger *)->l_onoff = 0;
631 1.1 deraadt m->m_len = sizeof(struct linger);
632 1.33 deraadt return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
633 1.1 deraadt SO_LINGER, m));
634 1.1 deraadt }
635 1.37 pk if (SCARG(uap, level) == IPPROTO_IP) {
636 1.37 pk #define SUNOS_IP_MULTICAST_IF 2
637 1.37 pk #define SUNOS_IP_MULTICAST_TTL 3
638 1.37 pk #define SUNOS_IP_MULTICAST_LOOP 4
639 1.37 pk #define SUNOS_IP_ADD_MEMBERSHIP 5
640 1.37 pk #define SUNOS_IP_DROP_MEMBERSHIP 6
641 1.37 pk static int ipoptxlat[] = {
642 1.37 pk IP_MULTICAST_IF,
643 1.37 pk IP_MULTICAST_TTL,
644 1.37 pk IP_MULTICAST_LOOP,
645 1.37 pk IP_ADD_MEMBERSHIP,
646 1.37 pk IP_DROP_MEMBERSHIP
647 1.37 pk };
648 1.37 pk if (SCARG(uap, name) >= SUNOS_IP_MULTICAST_IF &&
649 1.37 pk SCARG(uap, name) <= SUNOS_IP_DROP_MEMBERSHIP) {
650 1.37 pk SCARG(uap, name) =
651 1.37 pk ipoptxlat[SCARG(uap, name) - SUNOS_IP_MULTICAST_IF];
652 1.37 pk }
653 1.37 pk }
654 1.33 deraadt if (SCARG(uap, valsize) > MLEN)
655 1.1 deraadt return (EINVAL);
656 1.33 deraadt if (SCARG(uap, val)) {
657 1.1 deraadt m = m_get(M_WAIT, MT_SOOPTS);
658 1.64 christos error = copyin(SCARG(uap, val), mtod(m, caddr_t),
659 1.64 christos (u_int)SCARG(uap, valsize));
660 1.64 christos if (error) {
661 1.1 deraadt (void) m_free(m);
662 1.1 deraadt return (error);
663 1.1 deraadt }
664 1.33 deraadt m->m_len = SCARG(uap, valsize);
665 1.1 deraadt }
666 1.33 deraadt return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
667 1.33 deraadt SCARG(uap, name), m));
668 1.1 deraadt }
669 1.1 deraadt
670 1.33 deraadt int
671 1.55 mycroft sunos_sys_fchroot(p, v, retval)
672 1.1 deraadt register struct proc *p;
673 1.54 thorpej void *v;
674 1.32 cgd register_t *retval;
675 1.1 deraadt {
676 1.55 mycroft register struct sunos_sys_fchroot_args *uap = v;
677 1.1 deraadt register struct filedesc *fdp = p->p_fd;
678 1.1 deraadt register struct vnode *vp;
679 1.1 deraadt struct file *fp;
680 1.1 deraadt int error;
681 1.1 deraadt
682 1.1 deraadt if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
683 1.1 deraadt return (error);
684 1.33 deraadt if ((error = getvnode(fdp, SCARG(uap, fd), &fp)) != 0)
685 1.1 deraadt return (error);
686 1.1 deraadt vp = (struct vnode *)fp->f_data;
687 1.1 deraadt VOP_LOCK(vp);
688 1.1 deraadt if (vp->v_type != VDIR)
689 1.1 deraadt error = ENOTDIR;
690 1.1 deraadt else
691 1.78 mycroft error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p);
692 1.1 deraadt VOP_UNLOCK(vp);
693 1.1 deraadt if (error)
694 1.1 deraadt return (error);
695 1.1 deraadt VREF(vp);
696 1.1 deraadt if (fdp->fd_rdir != NULL)
697 1.1 deraadt vrele(fdp->fd_rdir);
698 1.1 deraadt fdp->fd_rdir = vp;
699 1.1 deraadt return (0);
700 1.3 deraadt }
701 1.3 deraadt
702 1.3 deraadt /*
703 1.3 deraadt * XXX: This needs cleaning up.
704 1.3 deraadt */
705 1.33 deraadt int
706 1.55 mycroft sunos_sys_auditsys(p, v, retval)
707 1.40 deraadt struct proc *p;
708 1.55 mycroft void *v;
709 1.40 deraadt register_t *retval;
710 1.3 deraadt {
711 1.3 deraadt return 0;
712 1.8 deraadt }
713 1.8 deraadt
714 1.33 deraadt int
715 1.55 mycroft sunos_sys_uname(p, v, retval)
716 1.8 deraadt struct proc *p;
717 1.54 thorpej void *v;
718 1.32 cgd register_t *retval;
719 1.8 deraadt {
720 1.55 mycroft struct sunos_sys_uname_args *uap = v;
721 1.33 deraadt struct sunos_utsname sut;
722 1.22 deraadt extern char ostype[], machine[], osrelease[];
723 1.8 deraadt
724 1.22 deraadt bzero(&sut, sizeof(sut));
725 1.8 deraadt
726 1.22 deraadt bcopy(ostype, sut.sysname, sizeof(sut.sysname) - 1);
727 1.22 deraadt bcopy(hostname, sut.nodename, sizeof(sut.nodename));
728 1.22 deraadt sut.nodename[sizeof(sut.nodename)-1] = '\0';
729 1.22 deraadt bcopy(osrelease, sut.release, sizeof(sut.release) - 1);
730 1.22 deraadt bcopy("1", sut.version, sizeof(sut.version) - 1);
731 1.22 deraadt bcopy(machine, sut.machine, sizeof(sut.machine) - 1);
732 1.8 deraadt
733 1.33 deraadt return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
734 1.33 deraadt sizeof(struct sunos_utsname));
735 1.8 deraadt }
736 1.8 deraadt
737 1.8 deraadt int
738 1.55 mycroft sunos_sys_setpgrp(p, v, retval)
739 1.8 deraadt struct proc *p;
740 1.54 thorpej void *v;
741 1.32 cgd register_t *retval;
742 1.8 deraadt {
743 1.55 mycroft struct sunos_sys_setpgrp_args *uap = v;
744 1.54 thorpej
745 1.8 deraadt /*
746 1.8 deraadt * difference to our setpgid call is to include backwards
747 1.8 deraadt * compatibility to pre-setsid() binaries. Do setsid()
748 1.8 deraadt * instead of setpgid() in those cases where the process
749 1.8 deraadt * tries to create a new session the old way.
750 1.8 deraadt */
751 1.55 mycroft if (!SCARG(uap, pgid) &&
752 1.55 mycroft (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
753 1.55 mycroft return sys_setsid(p, uap, retval);
754 1.8 deraadt else
755 1.55 mycroft return sys_setpgid(p, uap, retval);
756 1.8 deraadt }
757 1.8 deraadt
758 1.33 deraadt int
759 1.55 mycroft sunos_sys_open(p, v, retval)
760 1.8 deraadt struct proc *p;
761 1.54 thorpej void *v;
762 1.32 cgd register_t *retval;
763 1.8 deraadt {
764 1.55 mycroft struct sunos_sys_open_args *uap = v;
765 1.8 deraadt int l, r;
766 1.39 pk int noctty;
767 1.8 deraadt int ret;
768 1.8 deraadt
769 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
770 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
771 1.48 pk
772 1.8 deraadt /* convert mode into NetBSD mode */
773 1.39 pk l = SCARG(uap, flags);
774 1.39 pk noctty = l & 0x8000;
775 1.8 deraadt r = (l & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
776 1.8 deraadt r |= ((l & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
777 1.8 deraadt r |= ((l & 0x0080) ? O_SHLOCK : 0);
778 1.8 deraadt r |= ((l & 0x0100) ? O_EXLOCK : 0);
779 1.8 deraadt r |= ((l & 0x2000) ? O_FSYNC : 0);
780 1.8 deraadt
781 1.39 pk SCARG(uap, flags) = r;
782 1.55 mycroft ret = sys_open(p, (struct sys_open_args *)uap, retval);
783 1.8 deraadt
784 1.20 cgd if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
785 1.8 deraadt struct filedesc *fdp = p->p_fd;
786 1.8 deraadt struct file *fp = fdp->fd_ofiles[*retval];
787 1.8 deraadt
788 1.8 deraadt /* ignore any error, just give it a try */
789 1.8 deraadt if (fp->f_type == DTYPE_VNODE)
790 1.55 mycroft (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, p);
791 1.8 deraadt }
792 1.8 deraadt return ret;
793 1.10 deraadt }
794 1.10 deraadt
795 1.11 chopps #if defined (NFSSERVER)
796 1.33 deraadt int
797 1.55 mycroft sunos_sys_nfssvc(p, v, retval)
798 1.10 deraadt struct proc *p;
799 1.54 thorpej void *v;
800 1.32 cgd register_t *retval;
801 1.10 deraadt {
802 1.64 christos #if 0
803 1.55 mycroft struct sunos_sys_nfssvc_args *uap = v;
804 1.51 briggs struct emul *e = p->p_emul;
805 1.55 mycroft struct sys_nfssvc_args outuap;
806 1.10 deraadt struct sockaddr sa;
807 1.10 deraadt int error;
808 1.74 christos caddr_t sg = stackgap_init(p->p_emul);
809 1.10 deraadt
810 1.10 deraadt bzero(&outuap, sizeof outuap);
811 1.33 deraadt SCARG(&outuap, fd) = SCARG(uap, fd);
812 1.74 christos SCARG(&outuap, mskval) = stackgap_alloc(&sg, sizeof(sa));
813 1.74 christos SCARG(&outuap, msklen) = sizeof(sa);
814 1.74 christos SCARG(&outuap, mtchval) = stackgap_alloc(&sg, sizeof(sa));
815 1.74 christos SCARG(&outuap, mtchlen) = sizeof(sa);
816 1.10 deraadt
817 1.10 deraadt bzero(&sa, sizeof sa);
818 1.33 deraadt if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
819 1.10 deraadt return (error);
820 1.33 deraadt if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
821 1.10 deraadt return (error);
822 1.10 deraadt
823 1.10 deraadt return nfssvc(p, &outuap, retval);
824 1.33 deraadt #else
825 1.33 deraadt return (ENOSYS);
826 1.33 deraadt #endif
827 1.10 deraadt }
828 1.11 chopps #endif /* NFSSERVER */
829 1.10 deraadt
830 1.33 deraadt int
831 1.55 mycroft sunos_sys_ustat(p, v, retval)
832 1.10 deraadt struct proc *p;
833 1.54 thorpej void *v;
834 1.32 cgd register_t *retval;
835 1.10 deraadt {
836 1.55 mycroft struct sunos_sys_ustat_args *uap = v;
837 1.33 deraadt struct sunos_ustat us;
838 1.10 deraadt int error;
839 1.10 deraadt
840 1.10 deraadt bzero(&us, sizeof us);
841 1.10 deraadt
842 1.10 deraadt /*
843 1.10 deraadt * XXX: should set f_tfree and f_tinode at least
844 1.33 deraadt * How do we translate dev -> fstat? (and then to sunos_ustat)
845 1.10 deraadt */
846 1.10 deraadt
847 1.64 christos if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0)
848 1.10 deraadt return (error);
849 1.10 deraadt return 0;
850 1.10 deraadt }
851 1.10 deraadt
852 1.33 deraadt int
853 1.55 mycroft sunos_sys_quotactl(p, v, retval)
854 1.10 deraadt struct proc *p;
855 1.54 thorpej void *v;
856 1.32 cgd register_t *retval;
857 1.10 deraadt {
858 1.54 thorpej
859 1.10 deraadt return EINVAL;
860 1.10 deraadt }
861 1.10 deraadt
862 1.33 deraadt int
863 1.55 mycroft sunos_sys_vhangup(p, v, retval)
864 1.10 deraadt struct proc *p;
865 1.55 mycroft void *v;
866 1.32 cgd register_t *retval;
867 1.10 deraadt {
868 1.60 pk struct session *sp = p->p_session;
869 1.60 pk
870 1.60 pk if (sp->s_ttyvp == 0)
871 1.60 pk return 0;
872 1.60 pk
873 1.60 pk if (sp->s_ttyp && sp->s_ttyp->t_session == sp && sp->s_ttyp->t_pgrp)
874 1.60 pk pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1);
875 1.60 pk
876 1.60 pk (void) ttywait(sp->s_ttyp);
877 1.60 pk if (sp->s_ttyvp)
878 1.60 pk vgoneall(sp->s_ttyvp);
879 1.60 pk if (sp->s_ttyvp)
880 1.60 pk vrele(sp->s_ttyvp);
881 1.60 pk sp->s_ttyvp = NULL;
882 1.55 mycroft
883 1.10 deraadt return 0;
884 1.10 deraadt }
885 1.10 deraadt
886 1.64 christos static int
887 1.10 deraadt sunstatfs(sp, buf)
888 1.10 deraadt struct statfs *sp;
889 1.10 deraadt caddr_t buf;
890 1.10 deraadt {
891 1.33 deraadt struct sunos_statfs ssfs;
892 1.10 deraadt
893 1.10 deraadt bzero(&ssfs, sizeof ssfs);
894 1.10 deraadt ssfs.f_type = 0;
895 1.16 deraadt ssfs.f_bsize = sp->f_bsize;
896 1.10 deraadt ssfs.f_blocks = sp->f_blocks;
897 1.10 deraadt ssfs.f_bfree = sp->f_bfree;
898 1.10 deraadt ssfs.f_bavail = sp->f_bavail;
899 1.10 deraadt ssfs.f_files = sp->f_files;
900 1.10 deraadt ssfs.f_ffree = sp->f_ffree;
901 1.10 deraadt ssfs.f_fsid = sp->f_fsid;
902 1.10 deraadt return copyout((caddr_t)&ssfs, buf, sizeof ssfs);
903 1.10 deraadt }
904 1.10 deraadt
905 1.33 deraadt int
906 1.55 mycroft sunos_sys_statfs(p, v, retval)
907 1.10 deraadt struct proc *p;
908 1.54 thorpej void *v;
909 1.32 cgd register_t *retval;
910 1.10 deraadt {
911 1.55 mycroft struct sunos_sys_statfs_args *uap = v;
912 1.10 deraadt register struct mount *mp;
913 1.10 deraadt register struct statfs *sp;
914 1.10 deraadt int error;
915 1.10 deraadt struct nameidata nd;
916 1.10 deraadt
917 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
918 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
919 1.48 pk
920 1.33 deraadt NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
921 1.64 christos if ((error = namei(&nd)) != 0)
922 1.10 deraadt return (error);
923 1.27 pk mp = nd.ni_vp->v_mount;
924 1.10 deraadt sp = &mp->mnt_stat;
925 1.27 pk vrele(nd.ni_vp);
926 1.64 christos if ((error = VFS_STATFS(mp, sp, p)) != 0)
927 1.10 deraadt return (error);
928 1.10 deraadt sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
929 1.33 deraadt return sunstatfs(sp, (caddr_t)SCARG(uap, buf));
930 1.10 deraadt }
931 1.10 deraadt
932 1.33 deraadt int
933 1.55 mycroft sunos_sys_fstatfs(p, v, retval)
934 1.10 deraadt struct proc *p;
935 1.54 thorpej void *v;
936 1.32 cgd register_t *retval;
937 1.10 deraadt {
938 1.55 mycroft struct sunos_sys_fstatfs_args *uap = v;
939 1.10 deraadt struct file *fp;
940 1.10 deraadt struct mount *mp;
941 1.10 deraadt register struct statfs *sp;
942 1.10 deraadt int error;
943 1.10 deraadt
944 1.64 christos if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
945 1.10 deraadt return (error);
946 1.10 deraadt mp = ((struct vnode *)fp->f_data)->v_mount;
947 1.10 deraadt sp = &mp->mnt_stat;
948 1.64 christos if ((error = VFS_STATFS(mp, sp, p)) != 0)
949 1.10 deraadt return (error);
950 1.10 deraadt sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
951 1.33 deraadt return sunstatfs(sp, (caddr_t)SCARG(uap, buf));
952 1.10 deraadt }
953 1.10 deraadt
954 1.33 deraadt int
955 1.55 mycroft sunos_sys_exportfs(p, v, retval)
956 1.10 deraadt struct proc *p;
957 1.54 thorpej void *v;
958 1.32 cgd register_t *retval;
959 1.10 deraadt {
960 1.10 deraadt /*
961 1.10 deraadt * XXX: should perhaps translate into a mount(2)
962 1.10 deraadt * with MOUNT_EXPORT?
963 1.10 deraadt */
964 1.10 deraadt return 0;
965 1.10 deraadt }
966 1.10 deraadt
967 1.33 deraadt int
968 1.55 mycroft sunos_sys_mknod(p, v, retval)
969 1.10 deraadt struct proc *p;
970 1.54 thorpej void *v;
971 1.32 cgd register_t *retval;
972 1.10 deraadt {
973 1.55 mycroft struct sunos_sys_mknod_args *uap = v;
974 1.55 mycroft
975 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
976 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
977 1.48 pk
978 1.33 deraadt if (S_ISFIFO(SCARG(uap, mode)))
979 1.55 mycroft return sys_mkfifo(p, uap, retval);
980 1.10 deraadt
981 1.55 mycroft return sys_mknod(p, (struct sys_mknod_args *)uap, retval);
982 1.12 deraadt }
983 1.12 deraadt
984 1.33 deraadt #define SUNOS_SC_ARG_MAX 1
985 1.33 deraadt #define SUNOS_SC_CHILD_MAX 2
986 1.33 deraadt #define SUNOS_SC_CLK_TCK 3
987 1.33 deraadt #define SUNOS_SC_NGROUPS_MAX 4
988 1.33 deraadt #define SUNOS_SC_OPEN_MAX 5
989 1.33 deraadt #define SUNOS_SC_JOB_CONTROL 6
990 1.33 deraadt #define SUNOS_SC_SAVED_IDS 7
991 1.33 deraadt #define SUNOS_SC_VERSION 8
992 1.12 deraadt
993 1.33 deraadt int
994 1.55 mycroft sunos_sys_sysconf(p, v, retval)
995 1.12 deraadt struct proc *p;
996 1.54 thorpej void *v;
997 1.32 cgd register_t *retval;
998 1.12 deraadt {
999 1.55 mycroft struct sunos_sys_sysconf_args *uap = v;
1000 1.24 deraadt extern int maxfiles;
1001 1.12 deraadt
1002 1.33 deraadt switch(SCARG(uap, name)) {
1003 1.33 deraadt case SUNOS_SC_ARG_MAX:
1004 1.12 deraadt *retval = ARG_MAX;
1005 1.13 deraadt break;
1006 1.33 deraadt case SUNOS_SC_CHILD_MAX:
1007 1.12 deraadt *retval = maxproc;
1008 1.13 deraadt break;
1009 1.33 deraadt case SUNOS_SC_CLK_TCK:
1010 1.12 deraadt *retval = 60; /* should this be `hz', ie. 100? */
1011 1.13 deraadt break;
1012 1.33 deraadt case SUNOS_SC_NGROUPS_MAX:
1013 1.12 deraadt *retval = NGROUPS_MAX;
1014 1.13 deraadt break;
1015 1.33 deraadt case SUNOS_SC_OPEN_MAX:
1016 1.24 deraadt *retval = maxfiles;
1017 1.13 deraadt break;
1018 1.33 deraadt case SUNOS_SC_JOB_CONTROL:
1019 1.12 deraadt *retval = 1;
1020 1.13 deraadt break;
1021 1.33 deraadt case SUNOS_SC_SAVED_IDS:
1022 1.12 deraadt #ifdef _POSIX_SAVED_IDS
1023 1.12 deraadt *retval = 1;
1024 1.12 deraadt #else
1025 1.12 deraadt *retval = 0;
1026 1.12 deraadt #endif
1027 1.13 deraadt break;
1028 1.33 deraadt case SUNOS_SC_VERSION:
1029 1.12 deraadt *retval = 198808;
1030 1.13 deraadt break;
1031 1.12 deraadt default:
1032 1.12 deraadt return EINVAL;
1033 1.12 deraadt }
1034 1.12 deraadt return 0;
1035 1.17 pk }
1036 1.17 pk
1037 1.33 deraadt #define SUNOS_RLIMIT_NOFILE 6 /* Other RLIMIT_* are the same */
1038 1.33 deraadt #define SUNOS_RLIM_NLIMITS 7
1039 1.17 pk
1040 1.33 deraadt int
1041 1.55 mycroft sunos_sys_getrlimit(p, v, retval)
1042 1.17 pk struct proc *p;
1043 1.54 thorpej void *v;
1044 1.32 cgd register_t *retval;
1045 1.17 pk {
1046 1.55 mycroft struct sunos_sys_getrlimit_args *uap = v;
1047 1.54 thorpej
1048 1.33 deraadt if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
1049 1.17 pk return EINVAL;
1050 1.17 pk
1051 1.33 deraadt if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
1052 1.33 deraadt SCARG(uap, which) = RLIMIT_NOFILE;
1053 1.17 pk
1054 1.55 mycroft return compat_43_sys_getrlimit(p, uap, retval);
1055 1.17 pk }
1056 1.17 pk
1057 1.33 deraadt int
1058 1.55 mycroft sunos_sys_setrlimit(p, v, retval)
1059 1.17 pk struct proc *p;
1060 1.54 thorpej void *v;
1061 1.32 cgd register_t *retval;
1062 1.17 pk {
1063 1.55 mycroft struct sunos_sys_getrlimit_args *uap = v;
1064 1.54 thorpej
1065 1.33 deraadt if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
1066 1.17 pk return EINVAL;
1067 1.17 pk
1068 1.33 deraadt if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
1069 1.33 deraadt SCARG(uap, which) = RLIMIT_NOFILE;
1070 1.17 pk
1071 1.55 mycroft return compat_43_sys_setrlimit(p, uap, retval);
1072 1.35 deraadt }
1073 1.36 deraadt
1074 1.36 deraadt /* for the m68k machines */
1075 1.36 deraadt #ifndef PT_GETFPREGS
1076 1.36 deraadt #define PT_GETFPREGS -1
1077 1.36 deraadt #endif
1078 1.36 deraadt #ifndef PT_SETFPREGS
1079 1.36 deraadt #define PT_SETFPREGS -1
1080 1.36 deraadt #endif
1081 1.35 deraadt
1082 1.35 deraadt static int sreq2breq[] = {
1083 1.35 deraadt PT_TRACE_ME, PT_READ_I, PT_READ_D, -1,
1084 1.35 deraadt PT_WRITE_I, PT_WRITE_D, -1, PT_CONTINUE,
1085 1.35 deraadt PT_KILL, -1, PT_ATTACH, PT_DETACH,
1086 1.35 deraadt PT_GETREGS, PT_SETREGS, PT_GETFPREGS, PT_SETFPREGS
1087 1.35 deraadt };
1088 1.35 deraadt static int nreqs = sizeof(sreq2breq) / sizeof(sreq2breq[0]);
1089 1.35 deraadt
1090 1.64 christos int
1091 1.55 mycroft sunos_sys_ptrace(p, v, retval)
1092 1.35 deraadt struct proc *p;
1093 1.54 thorpej void *v;
1094 1.55 mycroft register_t *retval;
1095 1.35 deraadt {
1096 1.55 mycroft struct sunos_sys_ptrace_args *uap = v;
1097 1.55 mycroft struct sys_ptrace_args pa;
1098 1.35 deraadt int req;
1099 1.35 deraadt
1100 1.35 deraadt req = SCARG(uap, req);
1101 1.35 deraadt
1102 1.35 deraadt if (req < 0 || req >= nreqs)
1103 1.35 deraadt return (EINVAL);
1104 1.35 deraadt
1105 1.35 deraadt req = sreq2breq[req];
1106 1.35 deraadt if (req == -1)
1107 1.35 deraadt return (EINVAL);
1108 1.35 deraadt
1109 1.35 deraadt SCARG(&pa, req) = req;
1110 1.35 deraadt SCARG(&pa, pid) = (pid_t)SCARG(uap, pid);
1111 1.35 deraadt SCARG(&pa, addr) = (caddr_t)SCARG(uap, addr);
1112 1.35 deraadt SCARG(&pa, data) = SCARG(uap, data);
1113 1.35 deraadt
1114 1.55 mycroft return sys_ptrace(p, &pa, retval);
1115 1.44 christos }
1116 1.44 christos
1117 1.44 christos /*
1118 1.44 christos * SunOS reboot system call (for compatibility).
1119 1.44 christos * Sun lets you pass in a boot string which the PROM
1120 1.44 christos * saves and provides to the next boot program.
1121 1.44 christos */
1122 1.68 mrg
1123 1.68 mrg #define SUNOS_RB_ASKNAME 0x001
1124 1.68 mrg #define SUNOS_RB_SINGLE 0x002
1125 1.68 mrg #define SUNOS_RB_NOSYNC 0x004
1126 1.68 mrg #define SUNOS_RB_HALT 0x008
1127 1.68 mrg #define SUNOS_RB_DUMP 0x080
1128 1.68 mrg #define SUNOS_RB_STRING 0x200
1129 1.68 mrg
1130 1.44 christos static struct sunos_howto_conv {
1131 1.46 gwr int sun_howto;
1132 1.44 christos int bsd_howto;
1133 1.44 christos } sunos_howto_conv[] = {
1134 1.68 mrg { SUNOS_RB_ASKNAME, RB_ASKNAME },
1135 1.68 mrg { SUNOS_RB_SINGLE, RB_SINGLE },
1136 1.68 mrg { SUNOS_RB_NOSYNC, RB_NOSYNC },
1137 1.68 mrg { SUNOS_RB_HALT, RB_HALT },
1138 1.68 mrg { SUNOS_RB_DUMP, RB_DUMP },
1139 1.68 mrg { SUNOS_RB_STRING, RB_STRING },
1140 1.68 mrg { 0x000, 0 },
1141 1.44 christos };
1142 1.44 christos
1143 1.46 gwr int
1144 1.55 mycroft sunos_sys_reboot(p, v, retval)
1145 1.44 christos struct proc *p;
1146 1.54 thorpej void *v;
1147 1.46 gwr register_t *retval;
1148 1.44 christos {
1149 1.55 mycroft struct sunos_sys_reboot_args *uap = v;
1150 1.68 mrg struct sys_reboot_args ua;
1151 1.44 christos struct sunos_howto_conv *convp;
1152 1.46 gwr int error, bsd_howto, sun_howto;
1153 1.68 mrg char *bootstr;
1154 1.44 christos
1155 1.68 mrg if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
1156 1.44 christos return (error);
1157 1.44 christos
1158 1.44 christos /*
1159 1.44 christos * Convert howto bits to BSD format.
1160 1.44 christos */
1161 1.46 gwr sun_howto = SCARG(uap, howto);
1162 1.44 christos bsd_howto = 0;
1163 1.44 christos convp = sunos_howto_conv;
1164 1.46 gwr while (convp->sun_howto) {
1165 1.68 mrg if (sun_howto & convp->sun_howto)
1166 1.44 christos bsd_howto |= convp->bsd_howto;
1167 1.44 christos convp++;
1168 1.44 christos }
1169 1.44 christos
1170 1.44 christos /*
1171 1.44 christos * Sun RB_STRING (Get user supplied bootstring.)
1172 1.46 gwr * If the machine supports passing a string to the
1173 1.67 mrg * next booted kernel.
1174 1.44 christos */
1175 1.46 gwr if (sun_howto & SUNOS_RB_STRING) {
1176 1.46 gwr char bs[128];
1177 1.46 gwr
1178 1.47 christos error = copyinstr(SCARG(uap, bootstr), bs, sizeof(bs), 0);
1179 1.67 mrg
1180 1.68 mrg if (error)
1181 1.68 mrg bootstr = NULL;
1182 1.68 mrg else
1183 1.68 mrg bootstr = bs;
1184 1.67 mrg } else
1185 1.68 mrg bootstr = NULL;
1186 1.46 gwr
1187 1.68 mrg SCARG(&ua, opt) = bsd_howto;
1188 1.68 mrg SCARG(&ua, bootstr) = bootstr;
1189 1.68 mrg sys_reboot(p, &ua, retval);
1190 1.68 mrg return(0);
1191 1.50 christos }
1192 1.50 christos
1193 1.50 christos /*
1194 1.50 christos * Generalized interface signal handler, 4.3-compatible.
1195 1.50 christos */
1196 1.50 christos /* ARGSUSED */
1197 1.50 christos int
1198 1.55 mycroft sunos_sys_sigvec(p, v, retval)
1199 1.50 christos struct proc *p;
1200 1.54 thorpej void *v;
1201 1.54 thorpej register_t *retval;
1202 1.54 thorpej {
1203 1.55 mycroft register struct sunos_sys_sigvec_args /* {
1204 1.50 christos syscallarg(int) signum;
1205 1.50 christos syscallarg(struct sigvec *) nsv;
1206 1.50 christos syscallarg(struct sigvec *) osv;
1207 1.54 thorpej } */ *uap = v;
1208 1.50 christos struct sigvec vec;
1209 1.50 christos register struct sigacts *ps = p->p_sigacts;
1210 1.50 christos register struct sigvec *sv;
1211 1.50 christos register int signum;
1212 1.50 christos int bit, error;
1213 1.50 christos
1214 1.50 christos signum = SCARG(uap, signum);
1215 1.50 christos if (signum <= 0 || signum >= NSIG ||
1216 1.50 christos signum == SIGKILL || signum == SIGSTOP)
1217 1.50 christos return (EINVAL);
1218 1.50 christos sv = &vec;
1219 1.50 christos if (SCARG(uap, osv)) {
1220 1.50 christos *(sig_t *)&sv->sv_handler = ps->ps_sigact[signum];
1221 1.50 christos sv->sv_mask = ps->ps_catchmask[signum];
1222 1.50 christos bit = sigmask(signum);
1223 1.50 christos sv->sv_flags = 0;
1224 1.50 christos if ((ps->ps_sigonstack & bit) != 0)
1225 1.50 christos sv->sv_flags |= SV_ONSTACK;
1226 1.50 christos if ((ps->ps_sigintr & bit) != 0)
1227 1.50 christos sv->sv_flags |= SV_INTERRUPT;
1228 1.55 mycroft if ((ps->ps_sigreset & bit) != 0)
1229 1.55 mycroft sv->sv_flags |= SA_RESETHAND;
1230 1.55 mycroft sv->sv_mask &= ~bit;
1231 1.64 christos error = copyout((caddr_t)sv, (caddr_t)SCARG(uap, osv),
1232 1.64 christos sizeof (vec));
1233 1.64 christos if (error)
1234 1.50 christos return (error);
1235 1.50 christos }
1236 1.50 christos if (SCARG(uap, nsv)) {
1237 1.64 christos error = copyin((caddr_t)SCARG(uap, nsv), (caddr_t)sv,
1238 1.64 christos sizeof (vec));
1239 1.64 christos if (error)
1240 1.50 christos return (error);
1241 1.50 christos /*
1242 1.53 gwr * SunOS uses the mask 0x0004 as SV_RESETHAND
1243 1.53 gwr * meaning: `reset to SIG_DFL on delivery'.
1244 1.53 gwr * We support only the bits in: 0xF
1245 1.53 gwr * (those bits are the same as ours)
1246 1.50 christos */
1247 1.53 gwr if (sv->sv_flags & ~0xF)
1248 1.53 gwr return (EINVAL);
1249 1.53 gwr /* SunOS binaries have a user-mode trampoline. */
1250 1.53 gwr sv->sv_flags |= SA_USERTRAMP;
1251 1.53 gwr /* Convert sigvec:SV_INTERRUPT to sigaction:SA_RESTART */
1252 1.53 gwr sv->sv_flags ^= SA_RESTART; /* same bit, inverted */
1253 1.50 christos setsigvec(p, signum, (struct sigaction *)sv);
1254 1.50 christos }
1255 1.50 christos return (0);
1256 1.1 deraadt }
1257