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