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