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