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