ultrix_misc.c revision 1.15 1 /* $NetBSD: ultrix_misc.c,v 1.15 1995/09/19 22:49:22 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
10 *
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratory.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed by the University of
27 * California, Berkeley and its contributors.
28 * 4. Neither the name of the University nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * SUCH DAMAGE.
43 *
44 *
45 * @(#)sun_misc.c 8.1 (Berkeley) 6/18/93
46 *
47 * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
48 */
49
50 /*
51 * SunOS compatibility module.
52 *
53 * SunOS system calls that are implemented differently in BSD are
54 * handled here.
55 */
56
57 #include <sys/param.h>
58 #include <sys/systm.h>
59 #include <sys/namei.h>
60 #include <sys/dir.h>
61 #include <sys/proc.h>
62 #include <sys/file.h>
63 #include <sys/stat.h>
64 #include <sys/filedesc.h>
65 #include <sys/ioctl.h>
66 #include <sys/kernel.h>
67 #include <sys/exec.h>
68 #include <sys/malloc.h>
69 #include <sys/mbuf.h>
70 #include <sys/mman.h>
71 #include <sys/mount.h>
72 #include <sys/resource.h>
73 #include <sys/resourcevar.h>
74 #include <sys/signal.h>
75 #include <sys/signalvar.h>
76 #include <sys/socket.h>
77 #include <sys/vnode.h>
78 #include <sys/uio.h>
79 #include <sys/wait.h>
80 #include <sys/utsname.h>
81 #include <sys/unistd.h>
82
83 #include <netinet/in.h>
84
85 #include <miscfs/specfs/specdev.h>
86 #include <compat/ultrix/ultrix_syscall.h>
87
88 #include <nfs/rpcv2.h>
89 #include <nfs/nfsv2.h>
90 #include <nfs/nfs.h>
91
92 #include <vm/vm.h>
93
94 extern struct sysent ultrix_sysent[];
95 extern char *ultrix_syscallnames[];
96 extern void cpu_exec_ecoff_setregs __P((struct proc *, struct exec_package *,
97 u_long, register_t *));
98 struct emul emul_ultrix = {
99 "ultrix",
100 NULL,
101 sendsig,
102 ULTRIX_SYS_syscall,
103 ULTRIX_SYS_MAXSYSCALL,
104 ultrix_sysent,
105 ultrix_syscallnames,
106 0,
107 copyargs,
108 cpu_exec_ecoff_setregs,
109 0,
110 0,
111 };
112
113 #define GSI_PROG_ENV 1
114
115 struct ultrix_getsysinfo_args {
116 unsigned op;
117 char *buffer;
118 unsigned nbytes;
119 int *start;
120 char *arg;
121 };
122
123 ultrix_getsysinfo(p, v, retval)
124 struct proc *p;
125 void *v;
126 int *retval;
127 {
128 struct ultrix_getsysinfo_args *uap = v;
129 static short progenv = 0;
130
131 switch (uap->op) {
132 /* operations implemented: */
133 case GSI_PROG_ENV:
134 if (uap->nbytes < sizeof(short))
135 return EINVAL;
136 *retval = 1;
137 return(copyout(&progenv, uap->buffer, sizeof(short)));
138 default:
139 *retval = 0; /* info unavail */
140 return 0;
141 }
142 }
143
144 struct ultrix_setsysinfo_args {
145 unsigned op;
146 char *buffer;
147 unsigned nbytes;
148 unsigned arg;
149 unsigned flag;
150 };
151
152 ultrix_setsysinfo(p, v, retval)
153 struct proc *p;
154 void *v;
155 int *retval;
156 {
157 struct ultrix_setsysinfo_args *uap = v;
158 *retval = 0;
159 return 0;
160 }
161
162 struct ultrix_waitpid_args {
163 int pid;
164 int *status;
165 int options;
166 struct rusage *rusage;
167 };
168
169 ultrix_waitpid(p, v, retval)
170 struct proc *p;
171 void *v;
172 register_t *retval;
173 {
174 struct ultrix_waitpid_args *uap = v;
175
176 uap->rusage = 0;
177 return (wait4(p, uap, retval));
178 }
179 struct sun_wait4_args {
180 int pid;
181 int *status;
182 int options;
183 struct rusage *rusage;
184 int compat;
185 };
186 sun_wait4(p, v, retval)
187 struct proc *p;
188 void *v;
189 register_t *retval;
190 {
191 struct sun_wait4_args *uap = v;
192
193 if (uap->pid == 0)
194 uap->pid = WAIT_ANY;
195 return (wait4(p, uap, retval));
196 }
197
198 struct sun_wait3_args {
199 int *status;
200 int options;
201 struct rusage *rusage;
202 };
203
204 sun_wait3(p, v, retval)
205 struct proc *p;
206 void *v;
207 register_t *retval;
208 {
209 struct sun_wait3_args *uap = v;
210 struct sun_wait4_args ua;
211
212 if (uap == NULL)
213 panic("uap == NULL");
214 ua.pid = -1;
215 ua.status = uap->status;
216 ua.options = uap->options;
217 ua.rusage = uap->rusage;
218
219 return (wait4(p, &ua, retval));
220 }
221
222 struct sun_creat_args {
223 char *fname;
224 int fmode;
225 };
226 sun_creat(p, v, retval)
227 struct proc *p;
228 void *v;
229 register_t *retval;
230 {
231 struct sun_creat_args *uap = v;
232 struct args {
233 char *fname;
234 int mode;
235 int crtmode;
236 } openuap;
237
238 openuap.fname = uap->fname;
239 openuap.crtmode = uap->fmode;
240 openuap.mode = O_WRONLY | O_CREAT | O_TRUNC;
241 return (open(p, &openuap, retval));
242 }
243
244 struct sun_execv_args {
245 char *fname;
246 char **argp;
247 char **envp; /* pseudo */
248 };
249 sun_execv(p, v, retval)
250 struct proc *p;
251 void *v;
252 register_t *retval;
253 {
254 struct sun_execv_args *uap = v;
255
256 uap->envp = NULL;
257 return (execve(p, uap, retval));
258 }
259
260 struct sun_omsync_args {
261 caddr_t addr;
262 int len;
263 int flags;
264 };
265 sun_omsync(p, v, retval)
266 struct proc *p;
267 void *v;
268 register_t *retval;
269 {
270 struct sun_omsync_args *uap = v;
271
272 if (uap->flags)
273 return (EINVAL);
274 return (msync(p, uap, retval));
275 }
276
277 struct sun_unmount_args {
278 char *name;
279 int flags; /* pseudo */
280 };
281 sun_unmount(p, v, retval)
282 struct proc *p;
283 void *v;
284 register_t *retval;
285 {
286 struct sun_unmount_args *uap = v;
287
288 uap->flags = 0;
289 return (unmount(p, uap, retval));
290 }
291
292 #define SUNM_RDONLY 0x01 /* mount fs read-only */
293 #define SUNM_NOSUID 0x02 /* mount fs with setuid disallowed */
294 #define SUNM_NEWTYPE 0x04 /* type is string (char *), not int */
295 #define SUNM_GRPID 0x08 /* (bsd semantics; ignored) */
296 #define SUNM_REMOUNT 0x10 /* update existing mount */
297 #define SUNM_NOSUB 0x20 /* prevent submounts (rejected) */
298 #define SUNM_MULTI 0x40 /* (ignored) */
299 #define SUNM_SYS5 0x80 /* Sys 5-specific semantics (rejected) */
300
301 struct sun_nfs_args {
302 struct sockaddr_in *addr; /* file server address */
303 caddr_t fh; /* file handle to be mounted */
304 int flags; /* flags */
305 int wsize; /* write size in bytes */
306 int rsize; /* read size in bytes */
307 int timeo; /* initial timeout in .1 secs */
308 int retrans; /* times to retry send */
309 char *hostname; /* server's hostname */
310 int acregmin; /* attr cache file min secs */
311 int acregmax; /* attr cache file max secs */
312 int acdirmin; /* attr cache dir min secs */
313 int acdirmax; /* attr cache dir max secs */
314 char *netname; /* server's netname */
315 struct pathcnf *pathconf; /* static pathconf kludge */
316 };
317
318 struct sun_mount_args {
319 char *type;
320 char *dir;
321 int flags;
322 caddr_t data;
323 };
324 sun_mount(p, v, retval)
325 struct proc *p;
326 void *v;
327 register_t *retval;
328 {
329 struct sun_mount_args *uap = v;
330 int oflags = uap->flags, nflags, error;
331 extern char sigcode[], esigcode[];
332 char fsname[MFSNAMELEN];
333
334 #define szsigcode (esigcode - sigcode)
335
336 if (oflags & (SUNM_NOSUB | SUNM_SYS5))
337 return (EINVAL);
338 if ((oflags & SUNM_NEWTYPE) == 0)
339 return (EINVAL);
340 nflags = 0;
341 if (oflags & SUNM_RDONLY)
342 nflags |= MNT_RDONLY;
343 if (oflags & SUNM_NOSUID)
344 nflags |= MNT_NOSUID;
345 if (oflags & SUNM_REMOUNT)
346 nflags |= MNT_UPDATE;
347 uap->flags = nflags;
348
349 if (error = copyinstr((caddr_t)uap->type, fsname, sizeof fsname,
350 (size_t *)0))
351 return (error);
352
353 if (strncmp(fsname, "4.2", sizeof fsname) == 0) {
354 uap->type = (caddr_t)ALIGN(PS_STRINGS - szsigcode - STACKGAPLEN);
355 if (error = copyout("ufs", uap->type, sizeof("ufs")))
356 return (error);
357 } else if (strncmp(fsname, "nfs", sizeof fsname) == 0) {
358 struct sun_nfs_args sna;
359 struct sockaddr_in sain;
360 struct nfs_args na;
361 struct sockaddr sa;
362
363 if (error = copyin(uap->data, &sna, sizeof sna))
364 return (error);
365 if (error = copyin(sna.addr, &sain, sizeof sain))
366 return (error);
367 bcopy(&sain, &sa, sizeof sa);
368 sa.sa_len = sizeof(sain);
369 uap->data = (caddr_t)ALIGN(PS_STRINGS - szsigcode - STACKGAPLEN);
370 na.addr = (struct sockaddr *)((int)uap->data + sizeof na);
371 na.sotype = SOCK_DGRAM;
372 na.proto = IPPROTO_UDP;
373 na.fh = (nfsv2fh_t *)sna.fh;
374 na.flags = sna.flags;
375 na.wsize = sna.wsize;
376 na.rsize = sna.rsize;
377 na.timeo = sna.timeo;
378 na.retrans = sna.retrans;
379 na.hostname = sna.hostname;
380
381 if (error = copyout(&sa, na.addr, sizeof sa))
382 return (error);
383 if (error = copyout(&na, uap->data, sizeof na))
384 return (error);
385 }
386 return (mount(p, uap, retval));
387 }
388
389 #if defined(NFSCLIENT)
390 async_daemon(p, uap, retval)
391 struct proc *p;
392 void *uap;
393 register_t *retval;
394 {
395 struct nfssvc_args {
396 int flag;
397 caddr_t argp;
398 } args;
399
400 args.flag = NFSSVC_BIOD;
401 return nfssvc(p, &args, retval);
402 }
403 #endif /* NFSCLIENT */
404
405 struct sun_sigpending_args {
406 int *mask;
407 };
408 sun_sigpending(p, v, retval)
409 struct proc *p;
410 void *v;
411 register_t *retval;
412 {
413 struct sun_sigpending_args *uap = v;
414 int mask = p->p_siglist & p->p_sigmask;
415
416 return (copyout((caddr_t)&mask, (caddr_t)uap->mask, sizeof(int)));
417 }
418
419 #if 0
420 /* XXX: Temporary until sys/dir.h, include/dirent.h and sys/dirent.h are fixed */
421 struct dirent {
422 u_long d_fileno; /* file number of entry */
423 u_short d_reclen; /* length of this record */
424 u_short d_namlen; /* length of string in d_name */
425 char d_name[255 + 1]; /* name must be no longer than this */
426 };
427 #endif
428
429 /*
430 * Here is the sun layout. (Compare the BSD layout in <sys/dirent.h>.)
431 * We can assume big-endian, so the BSD d_type field is just the high
432 * byte of the SunOS d_namlen field, after adjusting for the extra "long".
433 */
434 struct sun_dirent {
435 long d_off;
436 u_long d_fileno;
437 u_short d_reclen;
438 u_short d_namlen;
439 char d_name[256];
440 };
441
442 /*
443 * Read Sun-style directory entries. We suck them into kernel space so
444 * that they can be massaged before being copied out to user code. Like
445 * SunOS, we squish out `empty' entries.
446 *
447 * This is quite ugly, but what do you expect from compatibility code?
448 */
449 struct sun_getdents_args {
450 int fd;
451 char *buf;
452 int nbytes;
453 };
454 sun_getdents(p, v, retval)
455 struct proc *p;
456 void *v;
457 register_t *retval;
458 {
459 register struct sun_getdents_args *uap = v;
460 register struct vnode *vp;
461 register caddr_t inp, buf; /* BSD-format */
462 register int len, reclen; /* BSD-format */
463 register caddr_t outp; /* Sun-format */
464 register int resid; /* Sun-format */
465 struct file *fp;
466 struct uio auio;
467 struct iovec aiov;
468 off_t off; /* true file offset */
469 long soff; /* Sun file offset */
470 int buflen, error, eofflag;
471 #define BSD_DIRENT(cp) ((struct dirent *)(cp))
472 #define SUN_RECLEN(reclen) (reclen + sizeof(long))
473
474 if ((error = getvnode(p->p_fd, uap->fd, &fp)) != 0)
475 return (error);
476 if ((fp->f_flag & FREAD) == 0)
477 return (EBADF);
478 vp = (struct vnode *)fp->f_data;
479 if (vp->v_type != VDIR) /* XXX vnode readdir op should do this */
480 return (EINVAL);
481 buflen = min(MAXBSIZE, uap->nbytes);
482 buf = malloc(buflen, M_TEMP, M_WAITOK);
483 VOP_LOCK(vp);
484 off = fp->f_offset;
485 again:
486 aiov.iov_base = buf;
487 aiov.iov_len = buflen;
488 auio.uio_iov = &aiov;
489 auio.uio_iovcnt = 1;
490 auio.uio_rw = UIO_READ;
491 auio.uio_segflg = UIO_SYSSPACE;
492 auio.uio_procp = p;
493 auio.uio_resid = buflen;
494 auio.uio_offset = off;
495 /*
496 * First we read into the malloc'ed buffer, then
497 * we massage it into user space, one record at a time.
498 */
499 if (error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, (u_long *)0,
500 0))
501 goto out;
502 inp = buf;
503 outp = uap->buf;
504 resid = uap->nbytes;
505 if ((len = buflen - auio.uio_resid) == 0)
506 goto eof;
507 for (; len > 0; len -= reclen) {
508 reclen = ((struct dirent *)inp)->d_reclen;
509 if (reclen & 3)
510 panic("sun_getdents");
511 off += reclen; /* each entry points to next */
512 if (BSD_DIRENT(inp)->d_fileno == 0) {
513 inp += reclen; /* it is a hole; squish it out */
514 continue;
515 }
516 if (reclen > len || resid < SUN_RECLEN(reclen)) {
517 /* entry too big for buffer, so just stop */
518 outp++;
519 break;
520 }
521 /*
522 * Massage in place to make a Sun-shaped dirent (otherwise
523 * we have to worry about touching user memory outside of
524 * the copyout() call).
525 */
526 BSD_DIRENT(inp)->d_reclen = SUN_RECLEN(reclen);
527 #if notdef
528 BSD_DIRENT(inp)->d_type = 0; /* 4.4 specific */
529 #endif
530 soff = off;
531 if ((error = copyout((caddr_t)&soff, outp, sizeof soff)) != 0 ||
532 (error = copyout(inp, outp + sizeof soff, reclen)) != 0)
533 goto out;
534 /* advance past this real entry */
535 inp += reclen;
536 /* advance output past Sun-shaped entry */
537 outp += SUN_RECLEN(reclen);
538 resid -= SUN_RECLEN(reclen);
539 }
540 /* if we squished out the whole block, try again */
541 if (outp == uap->buf)
542 goto again;
543 fp->f_offset = off; /* update the vnode offset */
544 eof:
545 *retval = uap->nbytes - resid;
546 out:
547 VOP_UNLOCK(vp);
548 free(buf, M_TEMP);
549 return (error);
550 }
551
552 #define SUN__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */
553
554 struct sun_mmap_args {
555 caddr_t addr;
556 size_t len;
557 int prot;
558 int flags;
559 int fd;
560 long off; /* not off_t! */
561 off_t qoff; /* created here and fed to mmap() */
562 };
563 sun_mmap(p, v, retval)
564 register struct proc *p;
565 void *v;
566 register_t *retval;
567 {
568 register struct sun_mmap_args *uap = v;
569 register struct filedesc *fdp;
570 register struct file *fp;
571 register struct vnode *vp;
572
573 /*
574 * Verify the arguments.
575 */
576 if (uap->prot & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
577 return (EINVAL); /* XXX still needed? */
578
579 if ((uap->flags & SUN__MAP_NEW) == 0)
580 return (EINVAL);
581 uap->flags &= ~SUN__MAP_NEW;
582
583 if ((uap->flags & MAP_FIXED) == 0 &&
584 uap->addr != 0 &&
585 uap->addr < (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ))
586 uap->addr = (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ);
587
588 /*
589 * Special case: if fd refers to /dev/zero, map as MAP_ANON. (XXX)
590 */
591 fdp = p->p_fd;
592 if ((unsigned)uap->fd < fdp->fd_nfiles && /*XXX*/
593 (fp = fdp->fd_ofiles[uap->fd]) != NULL && /*XXX*/
594 fp->f_type == DTYPE_VNODE && /*XXX*/
595 (vp = (struct vnode *)fp->f_data)->v_type == VCHR && /*XXX*/
596 iszerodev(vp->v_rdev)) { /*XXX*/
597 uap->flags |= MAP_ANON;
598 uap->fd = -1;
599 }
600
601 uap->qoff = uap->off;
602 return (mmap(p, uap, retval));
603 }
604
605 #define MC_SYNC 1
606 #define MC_LOCK 2
607 #define MC_UNLOCK 3
608 #define MC_ADVISE 4
609 #define MC_LOCKAS 5
610 #define MC_UNLOCKAS 6
611
612 struct sun_mctl_args {
613 caddr_t addr;
614 size_t len;
615 int func;
616 void *arg;
617 };
618 sun_mctl(p, v, retval)
619 register struct proc *p;
620 void *v;
621 register_t *retval;
622 {
623 register struct sun_mctl_args *uap = v;
624
625 switch (uap->func) {
626
627 case MC_ADVISE: /* ignore for now */
628 return (0);
629
630 case MC_SYNC: /* translate to msync */
631 return (msync(p, uap, retval));
632
633 default:
634 return (EINVAL);
635 }
636 }
637
638 struct sun_setsockopt_args {
639 int s;
640 int level;
641 int name;
642 caddr_t val;
643 int valsize;
644 };
645 sun_setsockopt(p, v, retval)
646 struct proc *p;
647 void *v;
648 register_t *retval;
649 {
650 register struct sun_setsockopt_args *uap = v;
651 struct file *fp;
652 struct mbuf *m = NULL;
653 int error;
654
655 if (error = getsock(p->p_fd, uap->s, &fp))
656 return (error);
657 #define SO_DONTLINGER (~SO_LINGER)
658 if (uap->name == SO_DONTLINGER) {
659 m = m_get(M_WAIT, MT_SOOPTS);
660 if (m == NULL)
661 return (ENOBUFS);
662 mtod(m, struct linger *)->l_onoff = 0;
663 m->m_len = sizeof(struct linger);
664 return (sosetopt((struct socket *)fp->f_data, uap->level,
665 SO_LINGER, m));
666 }
667 if (uap->valsize > MLEN)
668 return (EINVAL);
669 if (uap->val) {
670 m = m_get(M_WAIT, MT_SOOPTS);
671 if (m == NULL)
672 return (ENOBUFS);
673 if (error = copyin(uap->val, mtod(m, caddr_t),
674 (u_int)uap->valsize)) {
675 (void) m_free(m);
676 return (error);
677 }
678 m->m_len = uap->valsize;
679 }
680 return (sosetopt((struct socket *)fp->f_data, uap->level,
681 uap->name, m));
682 }
683
684 struct sun_fchroot_args {
685 int fdes;
686 };
687 sun_fchroot(p, v, retval)
688 register struct proc *p;
689 void *v;
690 register_t *retval;
691 {
692 register struct sun_fchroot_args *uap = v;
693 register struct filedesc *fdp = p->p_fd;
694 register struct vnode *vp;
695 struct file *fp;
696 int error;
697
698 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
699 return (error);
700 if ((error = getvnode(fdp, uap->fdes, &fp)) != 0)
701 return (error);
702 vp = (struct vnode *)fp->f_data;
703 VOP_LOCK(vp);
704 if (vp->v_type != VDIR)
705 error = ENOTDIR;
706 else
707 error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p);
708 VOP_UNLOCK(vp);
709 if (error)
710 return (error);
711 VREF(vp);
712 if (fdp->fd_rdir != NULL)
713 vrele(fdp->fd_rdir);
714 fdp->fd_rdir = vp;
715 return (0);
716 }
717
718 /*
719 * XXX: This needs cleaning up.
720 */
721 sun_auditsys()
722 {
723 return 0;
724 }
725
726 struct sun_utsname {
727 char sysname[9];
728 char nodename[9];
729 char nodeext[65-9];
730 char release[9];
731 char version[9];
732 char machine[9];
733 };
734
735 struct sun_uname_args {
736 struct sun_utsname *name;
737 };
738 sun_uname(p, v, retval)
739 struct proc *p;
740 void *v;
741 register_t *retval;
742 {
743 struct sun_uname_args *uap = v;
744 struct sun_utsname sut;
745 extern char ostype[], machine[], osrelease[];
746
747 bzero(&sut, sizeof(sut));
748
749 bcopy(ostype, sut.sysname, sizeof(sut.sysname) - 1);
750 bcopy(hostname, sut.nodename, sizeof(sut.nodename));
751 sut.nodename[sizeof(sut.nodename)-1] = '\0';
752 bcopy(osrelease, sut.release, sizeof(sut.release) - 1);
753 bcopy("1", sut.version, sizeof(sut.version) - 1);
754 bcopy(machine, sut.machine, sizeof(sut.machine) - 1);
755
756 return copyout((caddr_t)&sut, (caddr_t)uap->name, sizeof(struct sun_utsname));
757 }
758
759 struct sun_setpgid_args {
760 int pid; /* target process id */
761 int pgid; /* target pgrp id */
762 };
763 int
764 sun_setpgid(p, v, retval)
765 struct proc *p;
766 void *v;
767 register_t *retval;
768 {
769 struct sun_setpgid_args *uap = v;
770
771 /*
772 * difference to our setpgid call is to include backwards
773 * compatibility to pre-setsid() binaries. Do setsid()
774 * instead of setpgid() in those cases where the process
775 * tries to create a new session the old way.
776 */
777 if (!uap->pgid && (!uap->pid || uap->pid == p->p_pid))
778 return setsid(p, uap, retval);
779 else
780 return setpgid(p, uap, retval);
781 }
782
783 struct sun_open_args {
784 char *fname;
785 int fmode;
786 int crtmode;
787 };
788 sun_open(p, v, retval)
789 struct proc *p;
790 void *v;
791 register_t *retval;
792 {
793 struct sun_open_args *uap = v;
794 int l, r;
795 int noctty = uap->fmode & 0x8000;
796 int ret;
797
798 /* convert mode into NetBSD mode */
799 l = uap->fmode;
800 r = (l & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
801 r |= ((l & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
802 r |= ((l & 0x0080) ? O_SHLOCK : 0);
803 r |= ((l & 0x0100) ? O_EXLOCK : 0);
804 r |= ((l & 0x2000) ? O_FSYNC : 0);
805
806 uap->fmode = r;
807 ret = open(p, uap, retval);
808
809 if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
810 struct filedesc *fdp = p->p_fd;
811 struct file *fp = fdp->fd_ofiles[*retval];
812
813 /* ignore any error, just give it a try */
814 if (fp->f_type == DTYPE_VNODE)
815 (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t) 0, p);
816 }
817 return ret;
818 }
819
820 #if defined (NFSSERVER)
821 struct nfssvc_args {
822 int fd;
823 caddr_t mskval;
824 int msklen;
825 caddr_t mtchval;
826 int mtchlen;
827 };
828 struct sun_nfssvc_args {
829 int fd;
830 };
831 sun_nfssvc(p, v, retval)
832 struct proc *p;
833 void *v;
834 register_t *retval;
835 {
836 struct sun_nfssvc_args *uap = v;
837 struct nfssvc_args outuap;
838 struct sockaddr sa;
839 int error;
840 extern char sigcode[], esigcode[];
841
842 bzero(&outuap, sizeof outuap);
843 outuap.fd = uap->fd;
844 outuap.mskval = (caddr_t)ALIGN(PS_STRINGS - szsigcode - STACKGAPLEN);
845 outuap.msklen = sizeof sa;
846 outuap.mtchval = outuap.mskval + sizeof sa;
847 outuap.mtchlen = sizeof sa;
848
849 bzero(&sa, sizeof sa);
850 if (error = copyout(&sa, outuap.mskval, outuap.msklen))
851 return (error);
852 if (error = copyout(&sa, outuap.mtchval, outuap.mtchlen))
853 return (error);
854
855 return nfssvc(p, &outuap, retval);
856 }
857 #endif /* NFSSERVER */
858
859 struct sun_ustat {
860 daddr_t f_tfree; /* total free */
861 ino_t f_tinode; /* total inodes free */
862 char f_fname[6]; /* filsys name */
863 char f_fpack[6]; /* filsys pack name */
864 };
865 struct sun_ustat_args {
866 int dev;
867 struct sun_ustat *buf;
868 };
869 sun_ustat(p, v, retval)
870 struct proc *p;
871 void *v;
872 register_t *retval;
873 {
874 struct sun_ustat_args *uap = v;
875 struct sun_ustat us;
876 int error;
877
878 bzero(&us, sizeof us);
879
880 /*
881 * XXX: should set f_tfree and f_tinode at least
882 * How do we translate dev -> fstat? (and then to sun_ustat)
883 */
884
885 if (error = copyout(&us, uap->buf, sizeof us))
886 return (error);
887 return 0;
888 }
889
890 struct sun_quotactl_args {
891 int cmd;
892 char *special;
893 int uid;
894 caddr_t addr;
895 };
896 sun_quotactl(p, v, retval)
897 struct proc *p;
898 void *v;
899 register_t *retval;
900 {
901 struct sun_quotactl_args *uap = v;
902
903 return EINVAL;
904 }
905
906 sun_vhangup(p, uap, retval)
907 struct proc *p;
908 void *uap;
909 register_t *retval;
910 {
911 return 0;
912 }
913
914 struct sun_statfs {
915 long f_type; /* type of info, zero for now */
916 long f_bsize; /* fundamental file system block size */
917 long f_blocks; /* total blocks in file system */
918 long f_bfree; /* free blocks */
919 long f_bavail; /* free blocks available to non-super-user */
920 long f_files; /* total file nodes in file system */
921 long f_ffree; /* free file nodes in fs */
922 fsid_t f_fsid; /* file system id */
923 long f_spare[7]; /* spare for later */
924 };
925 static
926 sunstatfs(sp, buf)
927 struct statfs *sp;
928 caddr_t buf;
929 {
930 struct sun_statfs ssfs;
931
932 bzero(&ssfs, sizeof ssfs);
933 ssfs.f_type = 0;
934 ssfs.f_bsize = sp->f_bsize;
935 ssfs.f_blocks = sp->f_blocks;
936 ssfs.f_bfree = sp->f_bfree;
937 ssfs.f_bavail = sp->f_bavail;
938 ssfs.f_files = sp->f_files;
939 ssfs.f_ffree = sp->f_ffree;
940 ssfs.f_fsid = sp->f_fsid;
941 return copyout((caddr_t)&ssfs, buf, sizeof ssfs);
942 }
943
944 struct sun_statfs_args {
945 char *path;
946 struct sun_statfs *buf;
947 };
948 sun_statfs(p, v, retval)
949 struct proc *p;
950 void *v;
951 register_t *retval;
952 {
953 struct sun_statfs_args *uap = v;
954 register struct mount *mp;
955 register struct statfs *sp;
956 int error;
957 struct nameidata nd;
958
959 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, p);
960 if (error = namei(&nd))
961 return (error);
962 mp = nd.ni_vp->v_mount;
963 sp = &mp->mnt_stat;
964 vrele(nd.ni_vp);
965 if (error = VFS_STATFS(mp, sp, p))
966 return (error);
967 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
968 return sunstatfs(sp, (caddr_t)uap->buf);
969 }
970
971 struct sun_fstatfs_args {
972 int fd;
973 struct sun_statfs *buf;
974 };
975 sun_fstatfs(p, v, retval)
976 struct proc *p;
977 void *v;
978 register_t *retval;
979 {
980 struct sun_fstatfs_args *uap = v;
981 struct file *fp;
982 struct mount *mp;
983 register struct statfs *sp;
984 int error;
985
986 if (error = getvnode(p->p_fd, uap->fd, &fp))
987 return (error);
988 mp = ((struct vnode *)fp->f_data)->v_mount;
989 sp = &mp->mnt_stat;
990 if (error = VFS_STATFS(mp, sp, p))
991 return (error);
992 sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
993 return sunstatfs(sp, (caddr_t)uap->buf);
994 }
995
996 struct sun_exportfs_args {
997 char *path;
998 char *ex; /* struct sun_export * */
999 };
1000 sun_exportfs(p, v, retval)
1001 struct proc *p;
1002 void *v;
1003 register_t *retval;
1004 {
1005 struct sun_exportfs_args *uap = v;
1006
1007 /*
1008 * XXX: should perhaps translate into a mount(2)
1009 * with MOUNT_EXPORT?
1010 */
1011 return 0;
1012 }
1013
1014 struct sun_mknod_args {
1015 char *fname;
1016 int fmode;
1017 int dev;
1018 };
1019
1020 sun_mknod(p, v, retval)
1021 struct proc *p;
1022 void *v;
1023 register_t *retval;
1024 {
1025 struct sun_mknod_args *uap = v;
1026
1027 if (S_ISFIFO(uap->fmode))
1028 return mkfifo(p, uap, retval);
1029
1030 return mknod(p, uap, retval);
1031 }
1032
1033 #define SUN_SC_ARG_MAX 1
1034 #define SUN_SC_CHILD_MAX 2
1035 #define SUN_SC_CLK_TCK 3
1036 #define SUN_SC_NGROUPS_MAX 4
1037 #define SUN_SC_OPEN_MAX 5
1038 #define SUN_SC_JOB_CONTROL 6
1039 #define SUN_SC_SAVED_IDS 7
1040 #define SUN_SC_VERSION 8
1041
1042 struct sun_sysconf_args {
1043 int name;
1044 };
1045
1046 sun_sysconf(p, v, retval)
1047 struct proc *p;
1048 void *v;
1049 register_t *retval;
1050 {
1051 struct sun_sysconf_args *uap = v;
1052 extern int maxfiles;
1053
1054 switch(uap->name) {
1055 case SUN_SC_ARG_MAX:
1056 *retval = ARG_MAX;
1057 break;
1058 case SUN_SC_CHILD_MAX:
1059 *retval = maxproc;
1060 break;
1061 case SUN_SC_CLK_TCK:
1062 *retval = 60; /* should this be `hz', ie. 100? */
1063 break;
1064 case SUN_SC_NGROUPS_MAX:
1065 *retval = NGROUPS_MAX;
1066 break;
1067 case SUN_SC_OPEN_MAX:
1068 *retval = maxfiles;
1069 break;
1070 case SUN_SC_JOB_CONTROL:
1071 *retval = 1;
1072 break;
1073 case SUN_SC_SAVED_IDS:
1074 #ifdef _POSIX_SAVED_IDS
1075 *retval = 1;
1076 #else
1077 *retval = 0;
1078 #endif
1079 break;
1080 case SUN_SC_VERSION:
1081 *retval = 198808;
1082 break;
1083 default:
1084 return EINVAL;
1085 }
1086 return 0;
1087 }
1088
1089 struct ultrix_sigcleanup_args {
1090 struct sigcontext *sigcntxp;
1091 };
1092
1093 int ultrix_sigcleanup(p, v, retval)
1094 struct proc *p;
1095 void *v;
1096 register_t *retval;
1097 {
1098 struct ultrix_sigcleanup_args *uap = v;
1099
1100 sigreturn (p, (struct sigreturn_args *)uap, retval);
1101 }
1102