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