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