sunos_misc.c revision 1.33 1 /* $NetBSD: sunos_misc.c,v 1.33 1994/10/25 23:03:27 deraadt Exp $ */
2
3 /*
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
10 *
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratory.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed by the University of
27 * California, Berkeley and its contributors.
28 * 4. Neither the name of the University nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * SUCH DAMAGE.
43 *
44 * @(#)sunos_misc.c 8.1 (Berkeley) 6/18/93
45 *
46 * Header: sunos_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
47 */
48
49 /*
50 * SunOS compatibility module.
51 *
52 * SunOS system calls that are implemented differently in BSD are
53 * handled here.
54 */
55
56 #include <sys/param.h>
57 #include <sys/systm.h>
58 #include <sys/namei.h>
59 #include <sys/proc.h>
60 #include <sys/dir.h>
61 #include <sys/file.h>
62 #include <sys/stat.h>
63 #include <sys/filedesc.h>
64 #include <sys/ioctl.h>
65 #include <sys/kernel.h>
66 #include <sys/exec.h>
67 #include <sys/malloc.h>
68 #include <sys/mbuf.h>
69 #include <sys/mman.h>
70 #include <sys/mount.h>
71 #include <sys/resource.h>
72 #include <sys/resourcevar.h>
73 #include <sys/signal.h>
74 #include <sys/signalvar.h>
75 #include <sys/socket.h>
76 #include <sys/vnode.h>
77 #include <sys/uio.h>
78 #include <sys/wait.h>
79 #include <sys/utsname.h>
80 #include <sys/unistd.h>
81 #include <sys/syscallargs.h>
82 #include <compat/sunos/sunos.h>
83 #include <compat/sunos/sunos_syscallargs.h>
84
85 #include <netinet/in.h>
86
87 #include <miscfs/specfs/specdev.h>
88
89 #include <nfs/rpcv2.h>
90 #include <nfs/nfsv2.h>
91 #include <nfs/nfs.h>
92
93 #include <vm/vm.h>
94
95 int
96 sunos_wait4(p, uap, retval)
97 struct proc *p;
98 struct sunos_wait4_args *uap;
99 register_t *retval;
100 {
101 if (SCARG(uap, pid) == 0)
102 SCARG(uap, pid) = WAIT_ANY;
103 return (wait4(p, uap, retval, 1));
104 }
105
106 int
107 sunos_creat(p, uap, retval)
108 struct proc *p;
109 struct sunos_creat_args *uap;
110 register_t *retval;
111 {
112 struct sunos_open_args ouap;
113
114 SCARG(&ouap, path) = SCARG(uap, path);
115 SCARG(&ouap, flags) = O_WRONLY | O_CREAT | O_TRUNC;
116 SCARG(&ouap, mode) = SCARG(uap, mode);
117 return (open(p, &ouap, retval));
118 }
119
120 int
121 sunos_execv(p, uap, retval)
122 struct proc *p;
123 struct sunos_execv_args *uap;
124 register_t *retval;
125 {
126 struct execve_args ouap;
127
128 SCARG(&ouap, path) = SCARG(uap, path);
129 SCARG(&ouap, argp) = SCARG(uap, argp);
130 SCARG(&ouap, envp) = NULL;
131 return (execve(p, &ouap, retval));
132 }
133
134 int
135 sunos_omsync(p, uap, retval)
136 struct proc *p;
137 struct sunos_omsync_args *uap;
138 register_t *retval;
139 {
140 struct msync_args ouap;
141
142 if (SCARG(uap, flags))
143 return (EINVAL);
144 SCARG(&ouap, addr) = SCARG(uap, addr);
145 SCARG(&ouap, len) = SCARG(uap, len);
146 return (msync(p, &ouap, retval));
147 }
148
149 int
150 sunos_unmount(p, uap, retval)
151 struct proc *p;
152 struct sunos_unmount_args *uap;
153 register_t *retval;
154 {
155 SCARG(uap, flags) = 0;
156 return (unmount(p, (struct unmount_args *)uap, retval));
157 }
158
159 int
160 sunos_mount(p, uap, retval)
161 struct proc *p;
162 struct sunos_mount_args *uap;
163 register_t *retval;
164 {
165 int oflags = SCARG(uap, flags), nflags, error;
166 extern char sigcode[], esigcode[];
167 char fsname[MFSNAMELEN];
168
169 #define szsigcode (esigcode - sigcode)
170
171 if (oflags & (SUNM_NOSUB | SUNM_SYS5))
172 return (EINVAL);
173 if ((oflags & SUNM_NEWTYPE) == 0)
174 return (EINVAL);
175 nflags = 0;
176 if (oflags & SUNM_RDONLY)
177 nflags |= MNT_RDONLY;
178 if (oflags & SUNM_NOSUID)
179 nflags |= MNT_NOSUID;
180 if (oflags & SUNM_REMOUNT)
181 nflags |= MNT_UPDATE;
182 SCARG(uap, flags) = nflags;
183
184 if (error = copyinstr((caddr_t)SCARG(uap, type), fsname,
185 sizeof fsname, (u_int *)0))
186 return (error);
187
188 if (strcmp(fsname, "4.2") == 0) {
189 SCARG(uap, type) = STACKGAPBASE;
190 if (error = copyout("ufs", SCARG(uap, type), sizeof("ufs")))
191 return (error);
192 } else if (strcmp(fsname, "nfs") == 0) {
193 struct sunos_nfs_args sna;
194 struct sockaddr_in sain;
195 struct nfs_args na;
196 struct sockaddr sa;
197
198 if (error = copyin(SCARG(uap, data), &sna, sizeof sna))
199 return (error);
200 if (error = copyin(sna.addr, &sain, sizeof sain))
201 return (error);
202 bcopy(&sain, &sa, sizeof sa);
203 sa.sa_len = sizeof(sain);
204 SCARG(uap, data) = STACKGAPBASE;
205 na.addr = (struct sockaddr *)((int)SCARG(uap, data) + sizeof na);
206 na.addrlen = sizeof(struct sockaddr);
207 na.sotype = SOCK_DGRAM;
208 na.proto = IPPROTO_UDP;
209 na.fh = (nfsv2fh_t *)sna.fh;
210 na.flags = sna.flags;
211 na.wsize = sna.wsize;
212 na.rsize = sna.rsize;
213 na.timeo = sna.timeo;
214 na.retrans = sna.retrans;
215 na.hostname = sna.hostname;
216
217 if (error = copyout(&sa, na.addr, sizeof sa))
218 return (error);
219 if (error = copyout(&na, SCARG(uap, data), sizeof na))
220 return (error);
221 }
222 return (mount(p, (struct mount_args *)uap, retval));
223 }
224
225 #if defined(NFSCLIENT)
226 int
227 async_daemon(p, uap, retval)
228 struct proc *p;
229 void *uap;
230 register_t *retval;
231 {
232 struct nfssvc_args ouap;
233
234 SCARG(&ouap, flag) = NFSSVC_BIOD;
235 SCARG(&ouap, argp) = NULL;
236 return nfssvc(p, &ouap, retval);
237 }
238 #endif /* NFSCLIENT */
239
240 int
241 sunos_sigpending(p, uap, retval)
242 struct proc *p;
243 struct sunos_sigpending_args *uap;
244 register_t *retval;
245 {
246 int mask = p->p_siglist & p->p_sigmask;
247
248 return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int)));
249 }
250
251 /*
252 * Read Sun-style directory entries. We suck them into kernel space so
253 * that they can be massaged before being copied out to user code. Like
254 * SunOS, we squish out `empty' entries.
255 *
256 * This is quite ugly, but what do you expect from compatibility code?
257 */
258 int
259 sunos_getdents(p, uap, retval)
260 struct proc *p;
261 register struct sunos_getdents_args *uap;
262 register_t *retval;
263 {
264 register struct vnode *vp;
265 register caddr_t inp, buf; /* BSD-format */
266 register int len, reclen; /* BSD-format */
267 register caddr_t outp; /* Sun-format */
268 register int resid; /* Sun-format */
269 struct file *fp;
270 struct uio auio;
271 struct iovec aiov;
272 off_t off; /* true file offset */
273 long soff; /* Sun file offset */
274 int buflen, error, eofflag;
275 #define BSD_DIRENT(cp) ((struct dirent *)(cp))
276 #define SUNOS_RECLEN(reclen) (reclen + sizeof(long))
277
278 if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
279 return (error);
280 if ((fp->f_flag & FREAD) == 0)
281 return (EBADF);
282 vp = (struct vnode *)fp->f_data;
283 if (vp->v_type != VDIR) /* XXX vnode readdir op should do this */
284 return (EINVAL);
285 buflen = min(MAXBSIZE, SCARG(uap, nbytes));
286 buf = malloc(buflen, M_TEMP, M_WAITOK);
287 VOP_LOCK(vp);
288 off = fp->f_offset;
289 again:
290 aiov.iov_base = buf;
291 aiov.iov_len = buflen;
292 auio.uio_iov = &aiov;
293 auio.uio_iovcnt = 1;
294 auio.uio_rw = UIO_READ;
295 auio.uio_segflg = UIO_SYSSPACE;
296 auio.uio_procp = p;
297 auio.uio_resid = buflen;
298 auio.uio_offset = off;
299 /*
300 * First we read into the malloc'ed buffer, then
301 * we massage it into user space, one record at a time.
302 */
303 if (error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag,
304 (u_long *)0, 0))
305 goto out;
306 inp = buf;
307 outp = SCARG(uap, buf);
308 resid = SCARG(uap, nbytes);
309 if ((len = buflen - auio.uio_resid) == 0)
310 goto eof;
311 for (; len > 0; len -= reclen) {
312 reclen = ((struct dirent *)inp)->d_reclen;
313 if (reclen & 3)
314 panic("sunos_getdents");
315 off += reclen; /* each entry points to next */
316 if (BSD_DIRENT(inp)->d_fileno == 0) {
317 inp += reclen; /* it is a hole; squish it out */
318 continue;
319 }
320 if (reclen > len || resid < SUNOS_RECLEN(reclen)) {
321 /* entry too big for buffer, so just stop */
322 outp++;
323 break;
324 }
325 /*
326 * Massage in place to make a Sun-shaped dirent (otherwise
327 * we have to worry about touching user memory outside of
328 * the copyout() call).
329 */
330 BSD_DIRENT(inp)->d_reclen = SUNOS_RECLEN(reclen);
331 #if notdef
332 BSD_DIRENT(inp)->d_type = 0; /* 4.4 specific */
333 #endif
334 soff = off;
335 if ((error = copyout((caddr_t)&soff, outp, sizeof soff)) != 0 ||
336 (error = copyout(inp, outp + sizeof soff, reclen)) != 0)
337 goto out;
338 /* advance past this real entry */
339 inp += reclen;
340 /* advance output past Sun-shaped entry */
341 outp += SUNOS_RECLEN(reclen);
342 resid -= SUNOS_RECLEN(reclen);
343 }
344 /* if we squished out the whole block, try again */
345 if (outp == SCARG(uap, buf))
346 goto again;
347 fp->f_offset = off; /* update the vnode offset */
348 eof:
349 *retval = SCARG(uap, nbytes) - resid;
350 out:
351 VOP_UNLOCK(vp);
352 free(buf, M_TEMP);
353 return (error);
354 }
355
356 #define SUNOS__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */
357
358 int
359 sunos_mmap(p, uap, retval)
360 register struct proc *p;
361 register struct sunos_mmap_args *uap;
362 register_t *retval;
363 {
364 struct mmap_args ouap;
365 register struct filedesc *fdp;
366 register struct file *fp;
367 register struct vnode *vp;
368
369 /*
370 * Verify the arguments.
371 */
372 if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
373 return (EINVAL); /* XXX still needed? */
374
375 if ((SCARG(uap, flags) & SUNOS__MAP_NEW) == 0)
376 return (EINVAL);
377 SCARG(uap, flags) &= ~SUNOS__MAP_NEW;
378
379 if ((SCARG(uap, flags) & MAP_FIXED) == 0 &&
380 SCARG(uap, addr) != 0 &&
381 SCARG(uap, addr) < (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ))
382 SCARG(uap, addr) = (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ);
383
384 /*
385 * Special case: if fd refers to /dev/zero, map as MAP_ANON. (XXX)
386 */
387 fdp = p->p_fd;
388 if ((unsigned)SCARG(uap, fd) < fdp->fd_nfiles && /*XXX*/
389 (fp = fdp->fd_ofiles[SCARG(uap, fd)]) != NULL && /*XXX*/
390 fp->f_type == DTYPE_VNODE && /*XXX*/
391 (vp = (struct vnode *)fp->f_data)->v_type == VCHR && /*XXX*/
392 iszerodev(vp->v_rdev)) { /*XXX*/
393 SCARG(uap, flags) |= MAP_ANON;
394 SCARG(uap, fd) = -1;
395 }
396
397 return (compat_43_mmap(p, (struct ommap_args *)uap, retval));
398 }
399
400 #define MC_SYNC 1
401 #define MC_LOCK 2
402 #define MC_UNLOCK 3
403 #define MC_ADVISE 4
404 #define MC_LOCKAS 5
405 #define MC_UNLOCKAS 6
406
407 int
408 sunos_mctl(p, uap, retval)
409 register struct proc *p;
410 register struct sunos_mctl_args *uap;
411 register_t *retval;
412 {
413
414 switch (SCARG(uap, func)) {
415 case MC_ADVISE: /* ignore for now */
416 return (0);
417 case MC_SYNC: /* translate to msync */
418 return (msync(p, uap, retval));
419 default:
420 return (EINVAL);
421 }
422 }
423
424 int
425 sunos_setsockopt(p, uap, retval)
426 struct proc *p;
427 register struct sunos_setsockopt_args *uap;
428 register_t *retval;
429 {
430 struct file *fp;
431 struct mbuf *m = NULL;
432 int error;
433
434 if (error = getsock(p->p_fd, SCARG(uap, s), &fp))
435 return (error);
436 #define SO_DONTLINGER (~SO_LINGER)
437 if (SCARG(uap, name) == SO_DONTLINGER) {
438 m = m_get(M_WAIT, MT_SOOPTS);
439 if (m == NULL)
440 return (ENOBUFS);
441 mtod(m, struct linger *)->l_onoff = 0;
442 m->m_len = sizeof(struct linger);
443 return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
444 SO_LINGER, m));
445 }
446 if (SCARG(uap, valsize) > MLEN)
447 return (EINVAL);
448 if (SCARG(uap, val)) {
449 m = m_get(M_WAIT, MT_SOOPTS);
450 if (m == NULL)
451 return (ENOBUFS);
452 if (error = copyin(SCARG(uap, val), mtod(m, caddr_t),
453 (u_int)SCARG(uap, valsize))) {
454 (void) m_free(m);
455 return (error);
456 }
457 m->m_len = SCARG(uap, valsize);
458 }
459 return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
460 SCARG(uap, name), m));
461 }
462
463 int
464 sunos_fchroot(p, uap, retval)
465 register struct proc *p;
466 register struct sunos_fchroot_args *uap;
467 register_t *retval;
468 {
469 register struct filedesc *fdp = p->p_fd;
470 register struct vnode *vp;
471 struct file *fp;
472 int error;
473
474 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
475 return (error);
476 if ((error = getvnode(fdp, SCARG(uap, fd), &fp)) != 0)
477 return (error);
478 vp = (struct vnode *)fp->f_data;
479 VOP_LOCK(vp);
480 if (vp->v_type != VDIR)
481 error = ENOTDIR;
482 else
483 error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p);
484 VOP_UNLOCK(vp);
485 if (error)
486 return (error);
487 VREF(vp);
488 if (fdp->fd_rdir != NULL)
489 vrele(fdp->fd_rdir);
490 fdp->fd_rdir = vp;
491 return (0);
492 }
493
494 /*
495 * XXX: This needs cleaning up.
496 */
497 int
498 sunos_auditsys(...)
499 {
500 return 0;
501 }
502
503 int
504 sunos_uname(p, uap, retval)
505 struct proc *p;
506 struct sunos_uname_args *uap;
507 register_t *retval;
508 {
509 struct sunos_utsname sut;
510 extern char ostype[], machine[], osrelease[];
511
512 bzero(&sut, sizeof(sut));
513
514 bcopy(ostype, sut.sysname, sizeof(sut.sysname) - 1);
515 bcopy(hostname, sut.nodename, sizeof(sut.nodename));
516 sut.nodename[sizeof(sut.nodename)-1] = '\0';
517 bcopy(osrelease, sut.release, sizeof(sut.release) - 1);
518 bcopy("1", sut.version, sizeof(sut.version) - 1);
519 bcopy(machine, sut.machine, sizeof(sut.machine) - 1);
520
521 return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
522 sizeof(struct sunos_utsname));
523 }
524
525 int
526 sunos_setpgid(p, uap, retval)
527 struct proc *p;
528 struct sunos_setpgid_args *uap;
529 register_t *retval;
530 {
531 /*
532 * difference to our setpgid call is to include backwards
533 * compatibility to pre-setsid() binaries. Do setsid()
534 * instead of setpgid() in those cases where the process
535 * tries to create a new session the old way.
536 */
537 if (!SCARG(uap, pgid) && (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
538 return setsid(p, uap, retval);
539 else
540 return setpgid(p, uap, retval);
541 }
542
543 int
544 sunos_open(p, uap, retval)
545 struct proc *p;
546 struct sunos_open_args *uap;
547 register_t *retval;
548 {
549 int l, r;
550 int noctty = SCARG(uap, mode) & 0x8000;
551 int ret;
552
553 /* convert mode into NetBSD mode */
554 l = SCARG(uap, mode);
555 r = (l & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
556 r |= ((l & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
557 r |= ((l & 0x0080) ? O_SHLOCK : 0);
558 r |= ((l & 0x0100) ? O_EXLOCK : 0);
559 r |= ((l & 0x2000) ? O_FSYNC : 0);
560
561 SCARG(uap, mode) = r;
562 ret = open(p, (struct open_args *)uap, retval);
563
564 if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
565 struct filedesc *fdp = p->p_fd;
566 struct file *fp = fdp->fd_ofiles[*retval];
567
568 /* ignore any error, just give it a try */
569 if (fp->f_type == DTYPE_VNODE)
570 (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t) 0, p);
571 }
572 return ret;
573 }
574
575 #if defined (NFSSERVER)
576 int
577 sunos_nfssvc(p, uap, retval)
578 struct proc *p;
579 struct sunos_nfssvc_args *uap;
580 register_t *retval;
581 {
582 struct nfssvc_args outuap;
583 struct nfsd_srvargs nfsdarg;
584 struct sockaddr sa;
585 int error;
586 extern char sigcode[], esigcode[];
587
588 #if 0
589 bzero(&outuap, sizeof outuap);
590 SCARG(&outuap, fd) = SCARG(uap, fd);
591 SCARG(&outuap, mskval) = STACKGAPBASE;
592 SCARG(&outuap, msklen) = sizeof sa;
593 SCARG(&outuap, mtchval) = SCARG(&outuap, mskval) + sizeof sa;
594 SCARG(&outuap, mtchlen) = sizeof sa;
595
596 bzero(&sa, sizeof sa);
597 if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
598 return (error);
599 if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
600 return (error);
601
602 return nfssvc(p, &outuap, retval);
603 #else
604 return (ENOSYS);
605 #endif
606 }
607 #endif /* NFSSERVER */
608
609 int
610 sunos_ustat(p, uap, retval)
611 struct proc *p;
612 struct sunos_ustat_args *uap;
613 register_t *retval;
614 {
615 struct sunos_ustat us;
616 int error;
617
618 bzero(&us, sizeof us);
619
620 /*
621 * XXX: should set f_tfree and f_tinode at least
622 * How do we translate dev -> fstat? (and then to sunos_ustat)
623 */
624
625 if (error = copyout(&us, SCARG(uap, buf), sizeof us))
626 return (error);
627 return 0;
628 }
629
630 int
631 sunos_quotactl(p, uap, retval)
632 struct proc *p;
633 struct sunos_quotactl_args *uap;
634 register_t *retval;
635 {
636 return EINVAL;
637 }
638
639 int
640 sunos_vhangup(p, uap, retval)
641 struct proc *p;
642 void *uap;
643 register_t *retval;
644 {
645 return 0;
646 }
647
648 static
649 sunstatfs(sp, buf)
650 struct statfs *sp;
651 caddr_t buf;
652 {
653 struct sunos_statfs ssfs;
654
655 bzero(&ssfs, sizeof ssfs);
656 ssfs.f_type = 0;
657 ssfs.f_bsize = sp->f_bsize;
658 ssfs.f_blocks = sp->f_blocks;
659 ssfs.f_bfree = sp->f_bfree;
660 ssfs.f_bavail = sp->f_bavail;
661 ssfs.f_files = sp->f_files;
662 ssfs.f_ffree = sp->f_ffree;
663 ssfs.f_fsid = sp->f_fsid;
664 return copyout((caddr_t)&ssfs, buf, sizeof ssfs);
665 }
666
667 int
668 sunos_statfs(p, uap, retval)
669 struct proc *p;
670 struct sunos_statfs_args *uap;
671 register_t *retval;
672 {
673 register struct mount *mp;
674 register struct statfs *sp;
675 int error;
676 struct nameidata nd;
677
678 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
679 if (error = namei(&nd))
680 return (error);
681 mp = nd.ni_vp->v_mount;
682 sp = &mp->mnt_stat;
683 vrele(nd.ni_vp);
684 if (error = VFS_STATFS(mp, sp, p))
685 return (error);
686 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
687 return sunstatfs(sp, (caddr_t)SCARG(uap, buf));
688 }
689
690 int
691 sunos_fstatfs(p, uap, retval)
692 struct proc *p;
693 struct sunos_fstatfs_args *uap;
694 register_t *retval;
695 {
696 struct file *fp;
697 struct mount *mp;
698 register struct statfs *sp;
699 int error;
700
701 if (error = getvnode(p->p_fd, SCARG(uap, fd), &fp))
702 return (error);
703 mp = ((struct vnode *)fp->f_data)->v_mount;
704 sp = &mp->mnt_stat;
705 if (error = VFS_STATFS(mp, sp, p))
706 return (error);
707 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
708 return sunstatfs(sp, (caddr_t)SCARG(uap, buf));
709 }
710
711 int
712 sunos_exportfs(p, uap, retval)
713 struct proc *p;
714 struct sunos_exportfs_args *uap;
715 register_t *retval;
716 {
717 /*
718 * XXX: should perhaps translate into a mount(2)
719 * with MOUNT_EXPORT?
720 */
721 return 0;
722 }
723
724 int
725 sunos_mknod(p, uap, retval)
726 struct proc *p;
727 struct sunos_mknod_args *uap;
728 register_t *retval;
729 {
730 if (S_ISFIFO(SCARG(uap, mode)))
731 return mkfifo(p, uap, retval);
732
733 return mknod(p, (struct mknod_args *)uap, retval);
734 }
735
736 #define SUNOS_SC_ARG_MAX 1
737 #define SUNOS_SC_CHILD_MAX 2
738 #define SUNOS_SC_CLK_TCK 3
739 #define SUNOS_SC_NGROUPS_MAX 4
740 #define SUNOS_SC_OPEN_MAX 5
741 #define SUNOS_SC_JOB_CONTROL 6
742 #define SUNOS_SC_SAVED_IDS 7
743 #define SUNOS_SC_VERSION 8
744
745 int
746 sunos_sysconf(p, uap, retval)
747 struct proc *p;
748 struct sunos_sysconf_args *uap;
749 register_t *retval;
750 {
751 extern int maxfiles;
752
753 switch(SCARG(uap, name)) {
754 case SUNOS_SC_ARG_MAX:
755 *retval = ARG_MAX;
756 break;
757 case SUNOS_SC_CHILD_MAX:
758 *retval = maxproc;
759 break;
760 case SUNOS_SC_CLK_TCK:
761 *retval = 60; /* should this be `hz', ie. 100? */
762 break;
763 case SUNOS_SC_NGROUPS_MAX:
764 *retval = NGROUPS_MAX;
765 break;
766 case SUNOS_SC_OPEN_MAX:
767 *retval = maxfiles;
768 break;
769 case SUNOS_SC_JOB_CONTROL:
770 *retval = 1;
771 break;
772 case SUNOS_SC_SAVED_IDS:
773 #ifdef _POSIX_SAVED_IDS
774 *retval = 1;
775 #else
776 *retval = 0;
777 #endif
778 break;
779 case SUNOS_SC_VERSION:
780 *retval = 198808;
781 break;
782 default:
783 return EINVAL;
784 }
785 return 0;
786 }
787
788 #define SUNOS_RLIMIT_NOFILE 6 /* Other RLIMIT_* are the same */
789 #define SUNOS_RLIM_NLIMITS 7
790
791 int
792 sunos_getrlimit(p, uap, retval)
793 struct proc *p;
794 struct sunos_getrlimit_args *uap;
795 register_t *retval;
796 {
797 if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
798 return EINVAL;
799
800 if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
801 SCARG(uap, which) = RLIMIT_NOFILE;
802
803 return compat_43_getrlimit(p, uap, retval);
804 }
805
806 int
807 sunos_setrlimit(p, uap, retval)
808 struct proc *p;
809 struct sunos_getrlimit_args *uap;
810 register_t *retval;
811 {
812 if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
813 return EINVAL;
814
815 if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
816 SCARG(uap, which) = RLIMIT_NOFILE;
817
818 return compat_43_setrlimit(p, uap, retval);
819 }
820