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