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