ultrix_misc.c revision 1.3 1 /*
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This software was developed by the Computer Systems Engineering group
6 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7 * contributed to Berkeley.
8 *
9 * All advertising materials mentioning features or use of this software
10 * must display the following acknowledgement:
11 * This product includes software developed by the University of
12 * California, Lawrence Berkeley Laboratory.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. All advertising materials mentioning features or use of this software
23 * must display the following acknowledgement:
24 * This product includes software developed by the University of
25 * California, Berkeley and its contributors.
26 * 4. Neither the name of the University nor the names of its contributors
27 * may be used to endorse or promote products derived from this software
28 * without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * SUCH DAMAGE.
41 *
42 * @(#)sun_misc.c 8.1 (Berkeley) 6/18/93
43 *
44 * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
45 * $Id: ultrix_misc.c,v 1.3 1994/06/22 03:37:17 glass Exp $
46 */
47
48 /*
49 * SunOS compatibility module.
50 *
51 * SunOS system calls that are implemented differently in BSD are
52 * handled here.
53 */
54
55 #include <sys/param.h>
56 #include <sys/systm.h>
57 #include <sys/namei.h>
58 #include <sys/dir.h>
59 #include <sys/proc.h>
60 #include <sys/file.h>
61 #include <sys/stat.h>
62 #include <sys/filedesc.h>
63 #include <sys/ioctl.h>
64 #include <sys/kernel.h>
65 #include <sys/exec.h>
66 #include <sys/malloc.h>
67 #include <sys/mbuf.h>
68 #include <sys/mman.h>
69 #include <sys/mount.h>
70 #include <sys/resource.h>
71 #include <sys/resourcevar.h>
72 #include <sys/signal.h>
73 #include <sys/signalvar.h>
74 #include <sys/socket.h>
75 #include <sys/vnode.h>
76 #include <sys/uio.h>
77 #include <sys/wait.h>
78 #include <sys/utsname.h>
79 #include <sys/unistd.h>
80
81 #include <netinet/in.h>
82
83 #include <miscfs/specfs/specdev.h>
84
85 #include <nfs/rpcv2.h>
86 #include <nfs/nfsv2.h>
87 #include <nfs/nfs.h>
88
89 #include <vm/vm.h>
90
91 struct ultrix_waitpid_args {
92 int pid;
93 int *status;
94 int options;
95 struct rusage *rusage;
96 };
97 ultrix_waitpid(p, uap, retval)
98 struct proc *p;
99 struct ultrix_waitpid_args *uap;
100 int *retval;
101 {
102
103 uap->rusage = 0;
104 return (wait4(p, uap, retval));
105 }
106 struct sun_wait4_args {
107 int pid;
108 int *status;
109 int options;
110 struct rusage *rusage;
111 int compat;
112 };
113 sun_wait4(p, uap, retval)
114 struct proc *p;
115 struct sun_wait4_args *uap;
116 int *retval;
117 {
118
119 if (uap->pid == 0)
120 uap->pid = WAIT_ANY;
121 return (wait4(p, uap, retval));
122 }
123
124 struct sun_wait3_args {
125 int *status;
126 int options;
127 struct rusage *rusage;
128 };
129
130 sun_wait3(p, uap, retval)
131 struct proc *p;
132 struct sun_wait3_args *uap;
133 int *retval;
134 {
135 struct sun_wait4_args ua;
136
137 if (uap == NULL)
138 panic("uap == NULL");
139 ua.pid = -1;
140 ua.status = uap->status;
141 ua.options = uap->options;
142 ua.rusage = uap->rusage;
143
144 return (wait4(p, &ua, retval));
145 }
146
147 struct sun_creat_args {
148 char *fname;
149 int fmode;
150 };
151 sun_creat(p, uap, retval)
152 struct proc *p;
153 struct sun_creat_args *uap;
154 int *retval;
155 {
156 struct args {
157 char *fname;
158 int mode;
159 int crtmode;
160 } openuap;
161
162 openuap.fname = uap->fname;
163 openuap.crtmode = uap->fmode;
164 openuap.mode = O_WRONLY | O_CREAT | O_TRUNC;
165 return (open(p, &openuap, retval));
166 }
167
168 struct sun_execv_args {
169 char *fname;
170 char **argp;
171 char **envp; /* pseudo */
172 };
173 sun_execv(p, uap, retval)
174 struct proc *p;
175 struct sun_execv_args *uap;
176 int *retval;
177 {
178
179 uap->envp = NULL;
180 return (execve(p, uap, retval));
181 }
182
183 struct sun_omsync_args {
184 caddr_t addr;
185 int len;
186 int flags;
187 };
188 sun_omsync(p, uap, retval)
189 struct proc *p;
190 struct sun_omsync_args *uap;
191 int *retval;
192 {
193
194 if (uap->flags)
195 return (EINVAL);
196 return (msync(p, uap, retval));
197 }
198
199 struct sun_unmount_args {
200 char *name;
201 int flags; /* pseudo */
202 };
203 sun_unmount(p, uap, retval)
204 struct proc *p;
205 struct sun_unmount_args *uap;
206 int *retval;
207 {
208
209 uap->flags = 0;
210 return (unmount(p, uap, retval));
211 }
212
213 #define SUNM_RDONLY 0x01 /* mount fs read-only */
214 #define SUNM_NOSUID 0x02 /* mount fs with setuid disallowed */
215 #define SUNM_NEWTYPE 0x04 /* type is string (char *), not int */
216 #define SUNM_GRPID 0x08 /* (bsd semantics; ignored) */
217 #define SUNM_REMOUNT 0x10 /* update existing mount */
218 #define SUNM_NOSUB 0x20 /* prevent submounts (rejected) */
219 #define SUNM_MULTI 0x40 /* (ignored) */
220 #define SUNM_SYS5 0x80 /* Sys 5-specific semantics (rejected) */
221
222 struct sun_nfs_args {
223 struct sockaddr_in *addr; /* file server address */
224 caddr_t fh; /* file handle to be mounted */
225 int flags; /* flags */
226 int wsize; /* write size in bytes */
227 int rsize; /* read size in bytes */
228 int timeo; /* initial timeout in .1 secs */
229 int retrans; /* times to retry send */
230 char *hostname; /* server's hostname */
231 int acregmin; /* attr cache file min secs */
232 int acregmax; /* attr cache file max secs */
233 int acdirmin; /* attr cache dir min secs */
234 int acdirmax; /* attr cache dir max secs */
235 char *netname; /* server's netname */
236 struct pathcnf *pathconf; /* static pathconf kludge */
237 };
238
239 struct sun_mount_args {
240 char *type;
241 char *dir;
242 int flags;
243 caddr_t data;
244 };
245 sun_mount(p, uap, retval)
246 struct proc *p;
247 struct sun_mount_args *uap;
248 int *retval;
249 {
250 int oflags = uap->flags, nflags, error;
251 extern char sigcode[], esigcode[];
252 char fsname[MFSNAMELEN];
253
254 #define szsigcode (esigcode - sigcode)
255
256 if (oflags & (SUNM_NOSUB | SUNM_SYS5))
257 return (EINVAL);
258 if ((oflags & SUNM_NEWTYPE) == 0)
259 return (EINVAL);
260 nflags = 0;
261 if (oflags & SUNM_RDONLY)
262 nflags |= MNT_RDONLY;
263 if (oflags & SUNM_NOSUID)
264 nflags |= MNT_NOSUID;
265 if (oflags & SUNM_REMOUNT)
266 nflags |= MNT_UPDATE;
267 uap->flags = nflags;
268
269 if (error = copyinstr((caddr_t)uap->type, fsname, sizeof fsname, (u_int *)0))
270 return (error);
271
272 if (strcmp(fsname, "4.2") == 0) {
273 uap->type = (caddr_t)ALIGN(PS_STRINGS - szsigcode - STACKGAPLEN);
274 if (error = copyout("ufs", uap->type, sizeof("ufs")))
275 return (error);
276 } else if (strcmp(fsname, "nfs") == 0) {
277 struct sun_nfs_args sna;
278 struct sockaddr_in sain;
279 struct nfs_args na;
280 struct sockaddr sa;
281
282 if (error = copyin(uap->data, &sna, sizeof sna))
283 return (error);
284 if (error = copyin(sna.addr, &sain, sizeof sain))
285 return (error);
286 bcopy(&sain, &sa, sizeof sa);
287 sa.sa_len = sizeof(sain);
288 uap->data = (caddr_t)ALIGN(PS_STRINGS - szsigcode - STACKGAPLEN);
289 na.addr = (struct sockaddr *)((int)uap->data + sizeof na);
290 na.sotype = SOCK_DGRAM;
291 na.proto = IPPROTO_UDP;
292 na.fh = (nfsv2fh_t *)sna.fh;
293 na.flags = sna.flags;
294 na.wsize = sna.wsize;
295 na.rsize = sna.rsize;
296 na.timeo = sna.timeo;
297 na.retrans = sna.retrans;
298 na.hostname = sna.hostname;
299
300 if (error = copyout(&sa, na.addr, sizeof sa))
301 return (error);
302 if (error = copyout(&na, uap->data, sizeof na))
303 return (error);
304 }
305 return (mount(p, uap, retval));
306 }
307
308 #if defined(NFSCLIENT)
309 async_daemon(p, uap, retval)
310 struct proc *p;
311 void *uap;
312 int *retval;
313 {
314 struct nfssvc_args {
315 int flag;
316 caddr_t argp;
317 } args;
318
319 args.flag = NFSSVC_BIOD;
320 return nfssvc(p, &args, retval);
321 }
322 #endif /* NFSCLIENT */
323
324 struct sun_sigpending_args {
325 int *mask;
326 };
327 sun_sigpending(p, uap, retval)
328 struct proc *p;
329 struct sun_sigpending_args *uap;
330 int *retval;
331 {
332 int mask = p->p_siglist & p->p_sigmask;
333
334 return (copyout((caddr_t)&mask, (caddr_t)uap->mask, sizeof(int)));
335 }
336
337 /* XXX: Temporary until sys/dir.h, include/dirent.h and sys/dirent.h are fixed */
338 struct dirent {
339 u_long d_fileno; /* file number of entry */
340 u_short d_reclen; /* length of this record */
341 u_short d_namlen; /* length of string in d_name */
342 char d_name[255 + 1]; /* name must be no longer than this */
343 };
344
345 /*
346 * Here is the sun layout. (Compare the BSD layout in <sys/dirent.h>.)
347 * We can assume big-endian, so the BSD d_type field is just the high
348 * byte of the SunOS d_namlen field, after adjusting for the extra "long".
349 */
350 struct sun_dirent {
351 long d_off;
352 u_long d_fileno;
353 u_short d_reclen;
354 u_short d_namlen;
355 char d_name[256];
356 };
357
358 /*
359 * Read Sun-style directory entries. We suck them into kernel space so
360 * that they can be massaged before being copied out to user code. Like
361 * SunOS, we squish out `empty' entries.
362 *
363 * This is quite ugly, but what do you expect from compatibility code?
364 */
365 struct sun_getdents_args {
366 int fd;
367 char *buf;
368 int nbytes;
369 };
370 sun_getdents(p, uap, retval)
371 struct proc *p;
372 register struct sun_getdents_args *uap;
373 int *retval;
374 {
375 register struct vnode *vp;
376 register caddr_t inp, buf; /* BSD-format */
377 register int len, reclen; /* BSD-format */
378 register caddr_t outp; /* Sun-format */
379 register int resid; /* Sun-format */
380 struct file *fp;
381 struct uio auio;
382 struct iovec aiov;
383 off_t off; /* true file offset */
384 long soff; /* Sun file offset */
385 int buflen, error, eofflag;
386 #define BSD_DIRENT(cp) ((struct dirent *)(cp))
387 #define SUN_RECLEN(reclen) (reclen + sizeof(long))
388
389 if ((error = getvnode(p->p_fd, uap->fd, &fp)) != 0)
390 return (error);
391 if ((fp->f_flag & FREAD) == 0)
392 return (EBADF);
393 vp = (struct vnode *)fp->f_data;
394 if (vp->v_type != VDIR) /* XXX vnode readdir op should do this */
395 return (EINVAL);
396 buflen = min(MAXBSIZE, uap->nbytes);
397 buf = malloc(buflen, M_TEMP, M_WAITOK);
398 VOP_LOCK(vp);
399 off = fp->f_offset;
400 again:
401 aiov.iov_base = buf;
402 aiov.iov_len = buflen;
403 auio.uio_iov = &aiov;
404 auio.uio_iovcnt = 1;
405 auio.uio_rw = UIO_READ;
406 auio.uio_segflg = UIO_SYSSPACE;
407 auio.uio_procp = p;
408 auio.uio_resid = buflen;
409 auio.uio_offset = off;
410 /*
411 * First we read into the malloc'ed buffer, then
412 * we massage it into user space, one record at a time.
413 */
414 if (error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, (u_long *)0,
415 0))
416 goto out;
417 inp = buf;
418 outp = uap->buf;
419 resid = uap->nbytes;
420 if ((len = buflen - auio.uio_resid) == 0)
421 goto eof;
422 for (; len > 0; len -= reclen) {
423 reclen = ((struct dirent *)inp)->d_reclen;
424 if (reclen & 3)
425 panic("sun_getdents");
426 off += reclen; /* each entry points to next */
427 if (BSD_DIRENT(inp)->d_fileno == 0) {
428 inp += reclen; /* it is a hole; squish it out */
429 continue;
430 }
431 if (reclen > len || resid < SUN_RECLEN(reclen)) {
432 /* entry too big for buffer, so just stop */
433 outp++;
434 break;
435 }
436 /*
437 * Massage in place to make a Sun-shaped dirent (otherwise
438 * we have to worry about touching user memory outside of
439 * the copyout() call).
440 */
441 BSD_DIRENT(inp)->d_reclen = SUN_RECLEN(reclen);
442 #if notdef
443 BSD_DIRENT(inp)->d_type = 0; /* 4.4 specific */
444 #endif
445 soff = off;
446 if ((error = copyout((caddr_t)&soff, outp, sizeof soff)) != 0 ||
447 (error = copyout(inp, outp + sizeof soff, reclen)) != 0)
448 goto out;
449 /* advance past this real entry */
450 inp += reclen;
451 /* advance output past Sun-shaped entry */
452 outp += SUN_RECLEN(reclen);
453 resid -= SUN_RECLEN(reclen);
454 }
455 /* if we squished out the whole block, try again */
456 if (outp == uap->buf)
457 goto again;
458 fp->f_offset = off; /* update the vnode offset */
459 eof:
460 *retval = uap->nbytes - resid;
461 out:
462 VOP_UNLOCK(vp);
463 free(buf, M_TEMP);
464 return (error);
465 }
466
467 #define SUN__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */
468
469 struct sun_mmap_args {
470 caddr_t addr;
471 size_t len;
472 int prot;
473 int flags;
474 int fd;
475 long off; /* not off_t! */
476 off_t qoff; /* created here and fed to mmap() */
477 };
478 sun_mmap(p, uap, retval)
479 register struct proc *p;
480 register struct sun_mmap_args *uap;
481 int *retval;
482 {
483 register struct filedesc *fdp;
484 register struct file *fp;
485 register struct vnode *vp;
486
487 /*
488 * Verify the arguments.
489 */
490 if (uap->prot & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
491 return (EINVAL); /* XXX still needed? */
492
493 if ((uap->flags & SUN__MAP_NEW) == 0)
494 return (EINVAL);
495 uap->flags &= ~SUN__MAP_NEW;
496
497 if ((uap->flags & MAP_FIXED) == 0 &&
498 uap->addr != 0 &&
499 uap->addr < (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ))
500 uap->addr = (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ);
501
502 /*
503 * Special case: if fd refers to /dev/zero, map as MAP_ANON. (XXX)
504 */
505 fdp = p->p_fd;
506 if ((unsigned)uap->fd < fdp->fd_nfiles && /*XXX*/
507 (fp = fdp->fd_ofiles[uap->fd]) != NULL && /*XXX*/
508 fp->f_type == DTYPE_VNODE && /*XXX*/
509 (vp = (struct vnode *)fp->f_data)->v_type == VCHR && /*XXX*/
510 iszerodev(vp->v_rdev)) { /*XXX*/
511 uap->flags |= MAP_ANON;
512 uap->fd = -1;
513 }
514
515 uap->qoff = uap->off;
516 return (mmap(p, uap, retval));
517 }
518
519 #define MC_SYNC 1
520 #define MC_LOCK 2
521 #define MC_UNLOCK 3
522 #define MC_ADVISE 4
523 #define MC_LOCKAS 5
524 #define MC_UNLOCKAS 6
525
526 struct sun_mctl_args {
527 caddr_t addr;
528 size_t len;
529 int func;
530 void *arg;
531 };
532 sun_mctl(p, uap, retval)
533 register struct proc *p;
534 register struct sun_mctl_args *uap;
535 int *retval;
536 {
537
538 switch (uap->func) {
539
540 case MC_ADVISE: /* ignore for now */
541 return (0);
542
543 case MC_SYNC: /* translate to msync */
544 return (msync(p, uap, retval));
545
546 default:
547 return (EINVAL);
548 }
549 }
550
551 struct sun_setsockopt_args {
552 int s;
553 int level;
554 int name;
555 caddr_t val;
556 int valsize;
557 };
558 sun_setsockopt(p, uap, retval)
559 struct proc *p;
560 register struct sun_setsockopt_args *uap;
561 int *retval;
562 {
563 struct file *fp;
564 struct mbuf *m = NULL;
565 int error;
566
567 if (error = getsock(p->p_fd, uap->s, &fp))
568 return (error);
569 #define SO_DONTLINGER (~SO_LINGER)
570 if (uap->name == SO_DONTLINGER) {
571 m = m_get(M_WAIT, MT_SOOPTS);
572 if (m == NULL)
573 return (ENOBUFS);
574 mtod(m, struct linger *)->l_onoff = 0;
575 m->m_len = sizeof(struct linger);
576 return (sosetopt((struct socket *)fp->f_data, uap->level,
577 SO_LINGER, m));
578 }
579 if (uap->valsize > MLEN)
580 return (EINVAL);
581 if (uap->val) {
582 m = m_get(M_WAIT, MT_SOOPTS);
583 if (m == NULL)
584 return (ENOBUFS);
585 if (error = copyin(uap->val, mtod(m, caddr_t),
586 (u_int)uap->valsize)) {
587 (void) m_free(m);
588 return (error);
589 }
590 m->m_len = uap->valsize;
591 }
592 return (sosetopt((struct socket *)fp->f_data, uap->level,
593 uap->name, m));
594 }
595
596 struct sun_fchroot_args {
597 int fdes;
598 };
599 sun_fchroot(p, uap, retval)
600 register struct proc *p;
601 register struct sun_fchroot_args *uap;
602 int *retval;
603 {
604 register struct filedesc *fdp = p->p_fd;
605 register struct vnode *vp;
606 struct file *fp;
607 int error;
608
609 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
610 return (error);
611 if ((error = getvnode(fdp, uap->fdes, &fp)) != 0)
612 return (error);
613 vp = (struct vnode *)fp->f_data;
614 VOP_LOCK(vp);
615 if (vp->v_type != VDIR)
616 error = ENOTDIR;
617 else
618 error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p);
619 VOP_UNLOCK(vp);
620 if (error)
621 return (error);
622 VREF(vp);
623 if (fdp->fd_rdir != NULL)
624 vrele(fdp->fd_rdir);
625 fdp->fd_rdir = vp;
626 return (0);
627 }
628
629 /*
630 * XXX: This needs cleaning up.
631 */
632 sun_auditsys(...)
633 {
634 return 0;
635 }
636
637 struct sun_utsname {
638 char sysname[9];
639 char nodename[9];
640 char nodeext[65-9];
641 char release[9];
642 char version[9];
643 char machine[9];
644 };
645
646 struct sun_uname_args {
647 struct sun_utsname *name;
648 };
649 sun_uname(p, uap, retval)
650 struct proc *p;
651 struct sun_uname_args *uap;
652 int *retval;
653 {
654 struct sun_utsname sut;
655 extern char ostype[], machine[], osrelease[];
656
657 bzero(&sut, sizeof(sut));
658
659 bcopy(ostype, sut.sysname, sizeof(sut.sysname) - 1);
660 bcopy(hostname, sut.nodename, sizeof(sut.nodename));
661 sut.nodename[sizeof(sut.nodename)-1] = '\0';
662 bcopy(osrelease, sut.release, sizeof(sut.release) - 1);
663 bcopy("1", sut.version, sizeof(sut.version) - 1);
664 bcopy(machine, sut.machine, sizeof(sut.machine) - 1);
665
666 return copyout((caddr_t)&sut, (caddr_t)uap->name, sizeof(struct sun_utsname));
667 }
668
669 struct sun_setpgid_args {
670 int pid; /* target process id */
671 int pgid; /* target pgrp id */
672 };
673 int
674 sun_setpgid(p, uap, retval)
675 struct proc *p;
676 struct sun_setpgid_args *uap;
677 int *retval;
678 {
679 /*
680 * difference to our setpgid call is to include backwards
681 * compatibility to pre-setsid() binaries. Do setsid()
682 * instead of setpgid() in those cases where the process
683 * tries to create a new session the old way.
684 */
685 if (!uap->pgid && (!uap->pid || uap->pid == p->p_pid))
686 return setsid(p, uap, retval);
687 else
688 return setpgid(p, uap, retval);
689 }
690
691 struct sun_open_args {
692 char *fname;
693 int fmode;
694 int crtmode;
695 };
696 sun_open(p, uap, retval)
697 struct proc *p;
698 struct sun_open_args *uap;
699 int *retval;
700 {
701 int l, r;
702 int noctty = uap->fmode & 0x8000;
703 int ret;
704
705 /* convert mode into NetBSD mode */
706 l = uap->fmode;
707 r = (l & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
708 r |= ((l & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
709 r |= ((l & 0x0080) ? O_SHLOCK : 0);
710 r |= ((l & 0x0100) ? O_EXLOCK : 0);
711 r |= ((l & 0x2000) ? O_FSYNC : 0);
712
713 uap->fmode = r;
714 ret = open(p, uap, retval);
715
716 if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
717 struct filedesc *fdp = p->p_fd;
718 struct file *fp = fdp->fd_ofiles[*retval];
719
720 /* ignore any error, just give it a try */
721 if (fp->f_type == DTYPE_VNODE)
722 (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t) 0, p);
723 }
724 return ret;
725 }
726
727 #if defined (NFSSERVER)
728 struct nfssvc_args {
729 int fd;
730 caddr_t mskval;
731 int msklen;
732 caddr_t mtchval;
733 int mtchlen;
734 };
735 struct sun_nfssvc_args {
736 int fd;
737 };
738 sun_nfssvc(p, uap, retval)
739 struct proc *p;
740 struct sun_nfssvc_args *uap;
741 int *retval;
742 {
743 struct nfssvc_args outuap;
744 struct sockaddr sa;
745 int error;
746 extern char sigcode[], esigcode[];
747
748 bzero(&outuap, sizeof outuap);
749 outuap.fd = uap->fd;
750 outuap.mskval = (caddr_t)ALIGN(PS_STRINGS - szsigcode - STACKGAPLEN);
751 outuap.msklen = sizeof sa;
752 outuap.mtchval = outuap.mskval + sizeof sa;
753 outuap.mtchlen = sizeof sa;
754
755 bzero(&sa, sizeof sa);
756 if (error = copyout(&sa, outuap.mskval, outuap.msklen))
757 return (error);
758 if (error = copyout(&sa, outuap.mtchval, outuap.mtchlen))
759 return (error);
760
761 return nfssvc(p, &outuap, retval);
762 }
763 #endif /* NFSSERVER */
764
765 struct sun_ustat {
766 daddr_t f_tfree; /* total free */
767 ino_t f_tinode; /* total inodes free */
768 char f_fname[6]; /* filsys name */
769 char f_fpack[6]; /* filsys pack name */
770 };
771 struct sun_ustat_args {
772 int dev;
773 struct sun_ustat *buf;
774 };
775 sun_ustat(p, uap, retval)
776 struct proc *p;
777 struct sun_ustat_args *uap;
778 int *retval;
779 {
780 struct sun_ustat us;
781 int error;
782
783 bzero(&us, sizeof us);
784
785 /*
786 * XXX: should set f_tfree and f_tinode at least
787 * How do we translate dev -> fstat? (and then to sun_ustat)
788 */
789
790 if (error = copyout(&us, uap->buf, sizeof us))
791 return (error);
792 return 0;
793 }
794
795 struct sun_quotactl_args {
796 int cmd;
797 char *special;
798 int uid;
799 caddr_t addr;
800 };
801 sun_quotactl(p, uap, retval)
802 struct proc *p;
803 struct sun_quotactl_args *uap;
804 int *retval;
805 {
806 return EINVAL;
807 }
808
809 sun_vhangup(p, uap, retval)
810 struct proc *p;
811 void *uap;
812 int *retval;
813 {
814 return 0;
815 }
816
817 struct sun_statfs {
818 long f_type; /* type of info, zero for now */
819 long f_bsize; /* fundamental file system block size */
820 long f_blocks; /* total blocks in file system */
821 long f_bfree; /* free blocks */
822 long f_bavail; /* free blocks available to non-super-user */
823 long f_files; /* total file nodes in file system */
824 long f_ffree; /* free file nodes in fs */
825 fsid_t f_fsid; /* file system id */
826 long f_spare[7]; /* spare for later */
827 };
828 static
829 sunstatfs(sp, buf)
830 struct statfs *sp;
831 caddr_t buf;
832 {
833 struct sun_statfs ssfs;
834
835 bzero(&ssfs, sizeof ssfs);
836 ssfs.f_type = 0;
837 ssfs.f_bsize = sp->f_bsize;
838 ssfs.f_blocks = sp->f_blocks;
839 ssfs.f_bfree = sp->f_bfree;
840 ssfs.f_bavail = sp->f_bavail;
841 ssfs.f_files = sp->f_files;
842 ssfs.f_ffree = sp->f_ffree;
843 ssfs.f_fsid = sp->f_fsid;
844 return copyout((caddr_t)&ssfs, buf, sizeof ssfs);
845 }
846
847 struct sun_statfs_args {
848 char *path;
849 struct sun_statfs *buf;
850 };
851 sun_statfs(p, uap, retval)
852 struct proc *p;
853 struct sun_statfs_args *uap;
854 int *retval;
855 {
856 register struct mount *mp;
857 register struct statfs *sp;
858 int error;
859 struct nameidata nd;
860
861 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, p);
862 if (error = namei(&nd))
863 return (error);
864 mp = nd.ni_vp->v_mount;
865 sp = &mp->mnt_stat;
866 vrele(nd.ni_vp);
867 if (error = VFS_STATFS(mp, sp, p))
868 return (error);
869 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
870 return sunstatfs(sp, (caddr_t)uap->buf);
871 }
872
873 struct sun_fstatfs_args {
874 int fd;
875 struct sun_statfs *buf;
876 };
877 sun_fstatfs(p, uap, retval)
878 struct proc *p;
879 struct sun_fstatfs_args *uap;
880 int *retval;
881 {
882 struct file *fp;
883 struct mount *mp;
884 register struct statfs *sp;
885 int error;
886
887 if (error = getvnode(p->p_fd, uap->fd, &fp))
888 return (error);
889 mp = ((struct vnode *)fp->f_data)->v_mount;
890 sp = &mp->mnt_stat;
891 if (error = VFS_STATFS(mp, sp, p))
892 return (error);
893 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
894 return sunstatfs(sp, (caddr_t)uap->buf);
895 }
896
897 struct sun_exportfs_args {
898 char *path;
899 char *ex; /* struct sun_export * */
900 };
901 sun_exportfs(p, uap, retval)
902 struct proc *p;
903 struct sun_exportfs_args *uap;
904 int *retval;
905 {
906 /*
907 * XXX: should perhaps translate into a mount(2)
908 * with MOUNT_EXPORT?
909 */
910 return 0;
911 }
912
913 struct sun_mknod_args {
914 char *fname;
915 int fmode;
916 int dev;
917 };
918
919 sun_mknod(p, uap, retval)
920 struct proc *p;
921 struct sun_mknod_args *uap;
922 int *retval;
923 {
924 if (S_ISFIFO(uap->fmode))
925 return mkfifo(p, uap, retval);
926
927 return mknod(p, uap, retval);
928 }
929
930 #define SUN_SC_ARG_MAX 1
931 #define SUN_SC_CHILD_MAX 2
932 #define SUN_SC_CLK_TCK 3
933 #define SUN_SC_NGROUPS_MAX 4
934 #define SUN_SC_OPEN_MAX 5
935 #define SUN_SC_JOB_CONTROL 6
936 #define SUN_SC_SAVED_IDS 7
937 #define SUN_SC_VERSION 8
938
939 struct sun_sysconf_args {
940 int name;
941 };
942
943 sun_sysconf(p, uap, retval)
944 struct proc *p;
945 struct sun_sysconf_args *uap;
946 int *retval;
947 {
948 extern int maxfiles;
949
950 switch(uap->name) {
951 case SUN_SC_ARG_MAX:
952 *retval = ARG_MAX;
953 break;
954 case SUN_SC_CHILD_MAX:
955 *retval = maxproc;
956 break;
957 case SUN_SC_CLK_TCK:
958 *retval = 60; /* should this be `hz', ie. 100? */
959 break;
960 case SUN_SC_NGROUPS_MAX:
961 *retval = NGROUPS_MAX;
962 break;
963 case SUN_SC_OPEN_MAX:
964 *retval = maxfiles;
965 break;
966 case SUN_SC_JOB_CONTROL:
967 *retval = 1;
968 break;
969 case SUN_SC_SAVED_IDS:
970 #ifdef _POSIX_SAVED_IDS
971 *retval = 1;
972 #else
973 *retval = 0;
974 #endif
975 break;
976 case SUN_SC_VERSION:
977 *retval = 198808;
978 break;
979 default:
980 return EINVAL;
981 }
982 return 0;
983 }
984
985 #define SUN_RLIMIT_NOFILE 6 /* Other RLIMIT_* are the same */
986 #define SUN_RLIM_NLIMITS 7
987
988 struct sun_getrlimit_args {
989 int which;
990 struct orlimit *rlp;
991 };
992
993 sun_getrlimit(p, uap, retval)
994 struct proc *p;
995 struct sun_getrlimit_args *uap;
996 int *retval;
997 {
998 if (uap->which >= SUN_RLIM_NLIMITS)
999 return EINVAL;
1000
1001 if (uap->which == SUN_RLIMIT_NOFILE)
1002 uap->which = RLIMIT_NOFILE;
1003
1004 return ogetrlimit(p, uap, retval);
1005 }
1006
1007 struct sun_setrlimit_args {
1008 int which;
1009 struct orlimit *rlp;
1010 };
1011
1012 sun_setrlimit(p, uap, retval)
1013 struct proc *p;
1014 struct sun_getrlimit_args *uap;
1015 int *retval;
1016 {
1017 if (uap->which >= SUN_RLIM_NLIMITS)
1018 return EINVAL;
1019
1020 if (uap->which == SUN_RLIMIT_NOFILE)
1021 uap->which = RLIMIT_NOFILE;
1022
1023 return osetrlimit(p, uap, retval);
1024 }
1025