Home | History | Annotate | Line # | Download | only in sunos
sunos_misc.c revision 1.169.2.1
      1  1.169.2.1     skrll /*	$NetBSD: sunos_misc.c,v 1.169.2.1 2015/12/27 12:09:47 skrll Exp $	*/
      2       1.30       cgd 
      3        1.1   deraadt /*
      4        1.1   deraadt  * Copyright (c) 1992, 1993
      5        1.1   deraadt  *	The Regents of the University of California.  All rights reserved.
      6        1.1   deraadt  *
      7        1.1   deraadt  * This software was developed by the Computer Systems Engineering group
      8        1.1   deraadt  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9        1.1   deraadt  * contributed to Berkeley.
     10        1.1   deraadt  *
     11        1.1   deraadt  * All advertising materials mentioning features or use of this software
     12        1.1   deraadt  * must display the following acknowledgement:
     13        1.1   deraadt  *	This product includes software developed by the University of
     14        1.1   deraadt  *	California, Lawrence Berkeley Laboratory.
     15        1.1   deraadt  *
     16        1.1   deraadt  * Redistribution and use in source and binary forms, with or without
     17        1.1   deraadt  * modification, are permitted provided that the following conditions
     18        1.1   deraadt  * are met:
     19        1.1   deraadt  * 1. Redistributions of source code must retain the above copyright
     20        1.1   deraadt  *    notice, this list of conditions and the following disclaimer.
     21        1.1   deraadt  * 2. Redistributions in binary form must reproduce the above copyright
     22        1.1   deraadt  *    notice, this list of conditions and the following disclaimer in the
     23        1.1   deraadt  *    documentation and/or other materials provided with the distribution.
     24      1.125       agc  * 3. Neither the name of the University nor the names of its contributors
     25        1.1   deraadt  *    may be used to endorse or promote products derived from this software
     26        1.1   deraadt  *    without specific prior written permission.
     27        1.1   deraadt  *
     28        1.1   deraadt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29        1.1   deraadt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30        1.1   deraadt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31        1.1   deraadt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32        1.1   deraadt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33        1.1   deraadt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34        1.1   deraadt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35        1.1   deraadt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36        1.1   deraadt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37        1.1   deraadt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38        1.1   deraadt  * SUCH DAMAGE.
     39        1.1   deraadt  *
     40       1.33   deraadt  *	@(#)sunos_misc.c	8.1 (Berkeley) 6/18/93
     41        1.1   deraadt  *
     42      1.131     perry  *	Header: sunos_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
     43        1.1   deraadt  */
     44        1.1   deraadt 
     45        1.1   deraadt /*
     46        1.1   deraadt  * SunOS compatibility module.
     47        1.1   deraadt  *
     48        1.1   deraadt  * SunOS system calls that are implemented differently in BSD are
     49        1.1   deraadt  * handled here.
     50        1.1   deraadt  */
     51      1.111     lukem 
     52      1.111     lukem #include <sys/cdefs.h>
     53  1.169.2.1     skrll __KERNEL_RCSID(0, "$NetBSD: sunos_misc.c,v 1.169.2.1 2015/12/27 12:09:47 skrll Exp $");
     54        1.1   deraadt 
     55        1.1   deraadt #include <sys/param.h>
     56        1.1   deraadt #include <sys/systm.h>
     57       1.10   deraadt #include <sys/namei.h>
     58        1.1   deraadt #include <sys/proc.h>
     59       1.63       gwr #include <sys/dirent.h>
     60        1.1   deraadt #include <sys/file.h>
     61       1.10   deraadt #include <sys/stat.h>
     62        1.1   deraadt #include <sys/filedesc.h>
     63        1.1   deraadt #include <sys/ioctl.h>
     64        1.8   deraadt #include <sys/kernel.h>
     65       1.44  christos #include <sys/reboot.h>
     66        1.1   deraadt #include <sys/malloc.h>
     67        1.1   deraadt #include <sys/mbuf.h>
     68        1.1   deraadt #include <sys/mman.h>
     69        1.1   deraadt #include <sys/mount.h>
     70       1.35   deraadt #include <sys/ptrace.h>
     71        1.1   deraadt #include <sys/resource.h>
     72        1.1   deraadt #include <sys/resourcevar.h>
     73        1.1   deraadt #include <sys/signal.h>
     74        1.1   deraadt #include <sys/signalvar.h>
     75        1.1   deraadt #include <sys/socket.h>
     76       1.60        pk #include <sys/tty.h>
     77        1.1   deraadt #include <sys/vnode.h>
     78        1.1   deraadt #include <sys/uio.h>
     79        1.1   deraadt #include <sys/wait.h>
     80        1.8   deraadt #include <sys/utsname.h>
     81       1.12   deraadt #include <sys/unistd.h>
     82      1.142      matt #include <sys/syscall.h>
     83       1.33   deraadt #include <sys/syscallargs.h>
     84       1.64  christos #include <sys/conf.h>
     85       1.64  christos #include <sys/socketvar.h>
     86       1.73  christos #include <sys/exec.h>
     87       1.93       mrg #include <sys/swap.h>
     88      1.138      yamt #include <sys/kauth.h>
     89       1.55   mycroft 
     90      1.133        he #include <compat/sys/signal.h>
     91      1.133        he 
     92       1.33   deraadt #include <compat/sunos/sunos.h>
     93       1.33   deraadt #include <compat/sunos/sunos_syscallargs.h>
     94      1.106  jdolecek #include <compat/common/compat_util.h>
     95       1.56   mycroft #include <compat/sunos/sunos_dirent.h>
     96      1.151  christos #include <compat/sys/mount.h>
     97        1.1   deraadt 
     98       1.10   deraadt #include <netinet/in.h>
     99       1.10   deraadt 
    100        1.7   deraadt #include <miscfs/specfs/specdev.h>
    101        1.1   deraadt 
    102       1.27        pk #include <nfs/rpcv2.h>
    103       1.61        pk #include <nfs/nfsproto.h>
    104       1.27        pk #include <nfs/nfs.h>
    105       1.90      fvdl #include <nfs/nfsmount.h>
    106        1.1   deraadt 
    107      1.154       dsl static int sunstatfs(struct statvfs *, void *);
    108       1.70  christos 
    109       1.70  christos int
    110      1.157       dsl sunos_sys_stime(struct lwp *l, const struct sunos_sys_stime_args *uap, register_t *retval)
    111       1.70  christos {
    112      1.149       dsl 	struct timeval tv;
    113       1.70  christos 	int error;
    114       1.70  christos 
    115       1.70  christos 	error = copyin(SCARG(uap, tp), &tv.tv_sec, sizeof(tv.tv_sec));
    116       1.70  christos 	if (error)
    117       1.70  christos 		return error;
    118       1.70  christos 	tv.tv_usec = 0;
    119       1.70  christos 
    120      1.149       dsl 	return settimeofday1(&tv, false, NULL, l, true);
    121       1.70  christos }
    122       1.70  christos 
    123       1.33   deraadt int
    124      1.157       dsl sunos_sys_wait4(struct lwp *l, const struct sunos_sys_wait4_args *uap, register_t *retval)
    125        1.1   deraadt {
    126      1.164   tsutsui 	struct compat_50_sys_wait4_args bsd_ua;
    127      1.157       dsl 
    128      1.157       dsl 	SCARG(&bsd_ua, pid) = SCARG(uap, pid) == 0 ? WAIT_ANY : SCARG(uap, pid);
    129      1.157       dsl 	SCARG(&bsd_ua, status) = SCARG(uap, status);
    130      1.157       dsl 	SCARG(&bsd_ua, options) = SCARG(uap, options);
    131      1.157       dsl 	SCARG(&bsd_ua, rusage) = SCARG(uap, rusage);
    132      1.157       dsl 
    133      1.164   tsutsui 	return (compat_50_sys_wait4(l, &bsd_ua, retval));
    134        1.1   deraadt }
    135        1.1   deraadt 
    136       1.33   deraadt int
    137      1.157       dsl sunos_sys_creat(struct lwp *l, const struct sunos_sys_creat_args *uap, register_t *retval)
    138        1.1   deraadt {
    139       1.55   mycroft 	struct sys_open_args ouap;
    140        1.1   deraadt 
    141       1.33   deraadt 	SCARG(&ouap, path) = SCARG(uap, path);
    142       1.33   deraadt 	SCARG(&ouap, flags) = O_WRONLY | O_CREAT | O_TRUNC;
    143       1.33   deraadt 	SCARG(&ouap, mode) = SCARG(uap, mode);
    144       1.55   mycroft 
    145      1.117   thorpej 	return (sys_open(l, &ouap, retval));
    146        1.1   deraadt }
    147        1.1   deraadt 
    148       1.33   deraadt int
    149      1.157       dsl sunos_sys_execv(struct lwp *l, const struct sunos_sys_execv_args *uap, register_t *retval)
    150        1.1   deraadt {
    151      1.157       dsl 	/* {
    152       1.99  christos 		syscallarg(const char *) path;
    153       1.71   mycroft 		syscallarg(char **) argv;
    154      1.157       dsl 	} */
    155       1.71   mycroft 	struct sys_execve_args ap;
    156       1.48        pk 
    157       1.71   mycroft 	SCARG(&ap, path) = SCARG(uap, path);
    158       1.71   mycroft 	SCARG(&ap, argp) = SCARG(uap, argp);
    159       1.71   mycroft 	SCARG(&ap, envp) = NULL;
    160       1.69   thorpej 
    161      1.117   thorpej 	return (sys_execve(l, &ap, retval));
    162       1.69   thorpej }
    163       1.69   thorpej 
    164       1.69   thorpej int
    165      1.157       dsl sunos_sys_execve(struct lwp *l, const struct sunos_sys_execve_args *uap, register_t *retval)
    166       1.69   thorpej {
    167      1.157       dsl 	/* {
    168       1.99  christos 		syscallarg(const char *) path;
    169       1.71   mycroft 		syscallarg(char **) argv;
    170       1.71   mycroft 		syscallarg(char **) envp;
    171      1.157       dsl 	} */
    172       1.71   mycroft 	struct sys_execve_args ap;
    173       1.71   mycroft 
    174       1.71   mycroft 	SCARG(&ap, path) = SCARG(uap, path);
    175       1.71   mycroft 	SCARG(&ap, argp) = SCARG(uap, argp);
    176       1.71   mycroft 	SCARG(&ap, envp) = SCARG(uap, envp);
    177       1.55   mycroft 
    178      1.117   thorpej 	return (sys_execve(l, &ap, retval));
    179        1.1   deraadt }
    180        1.1   deraadt 
    181       1.33   deraadt int
    182      1.157       dsl sunos_sys_omsync(struct lwp *l, const struct sunos_sys_omsync_args *uap, register_t *retval)
    183        1.1   deraadt {
    184       1.86      fvdl 	struct sys___msync13_args ouap;
    185        1.1   deraadt 
    186       1.33   deraadt 	SCARG(&ouap, addr) = SCARG(uap, addr);
    187       1.33   deraadt 	SCARG(&ouap, len) = SCARG(uap, len);
    188       1.86      fvdl 	SCARG(&ouap, flags) = SCARG(uap, flags);
    189       1.55   mycroft 
    190      1.117   thorpej 	return (sys___msync13(l, &ouap, retval));
    191        1.1   deraadt }
    192        1.1   deraadt 
    193       1.33   deraadt int
    194      1.157       dsl sunos_sys_unmount(struct lwp *l, const struct sunos_sys_unmount_args *uap, register_t *retval)
    195        1.1   deraadt {
    196       1.55   mycroft 	struct sys_unmount_args ouap;
    197       1.54   thorpej 
    198       1.55   mycroft 	SCARG(&ouap, path) = SCARG(uap, path);
    199       1.55   mycroft 	SCARG(&ouap, flags) = 0;
    200       1.55   mycroft 
    201      1.117   thorpej 	return (sys_unmount(l, &ouap, retval));
    202       1.33   deraadt }
    203        1.1   deraadt 
    204       1.61        pk /*
    205       1.61        pk  * Conversion table for SunOS NFS mount flags.
    206       1.61        pk  */
    207       1.61        pk static struct {
    208       1.61        pk 	int	sun_flg;
    209       1.61        pk 	int	bsd_flg;
    210       1.61        pk } sunnfs_flgtab[] = {
    211       1.61        pk 	{ SUNNFS_SOFT,		NFSMNT_SOFT },
    212       1.61        pk 	{ SUNNFS_WSIZE,		NFSMNT_WSIZE },
    213       1.61        pk 	{ SUNNFS_RSIZE,		NFSMNT_RSIZE },
    214       1.61        pk 	{ SUNNFS_TIMEO,		NFSMNT_TIMEO },
    215       1.61        pk 	{ SUNNFS_RETRANS,	NFSMNT_RETRANS },
    216       1.61        pk 	{ SUNNFS_HOSTNAME,	0 },			/* Ignored */
    217       1.61        pk 	{ SUNNFS_INT,		NFSMNT_INT },
    218       1.61        pk 	{ SUNNFS_NOAC,		0 },			/* Ignored */
    219       1.61        pk 	{ SUNNFS_ACREGMIN,	0 },			/* Ignored */
    220       1.61        pk 	{ SUNNFS_ACREGMAX,	0 },			/* Ignored */
    221       1.61        pk 	{ SUNNFS_ACDIRMIN,	0 },			/* Ignored */
    222       1.61        pk 	{ SUNNFS_ACDIRMAX,	0 },			/* Ignored */
    223       1.61        pk 	{ SUNNFS_SECURE,	0 },			/* Ignored */
    224       1.61        pk 	{ SUNNFS_NOCTO,		0 },			/* Ignored */
    225       1.61        pk 	{ SUNNFS_POSIX,		0 }			/* Ignored */
    226       1.61        pk };
    227       1.61        pk 
    228       1.33   deraadt int
    229      1.157       dsl sunos_sys_mount(struct lwp *l, const struct sunos_sys_mount_args *uap, register_t *retval)
    230        1.1   deraadt {
    231       1.33   deraadt 	int oflags = SCARG(uap, flags), nflags, error;
    232       1.16   deraadt 	char fsname[MFSNAMELEN];
    233      1.150       dsl 	register_t dummy;
    234       1.16   deraadt 
    235        1.1   deraadt 	if (oflags & (SUNM_NOSUB | SUNM_SYS5))
    236        1.1   deraadt 		return (EINVAL);
    237       1.16   deraadt 	if ((oflags & SUNM_NEWTYPE) == 0)
    238       1.16   deraadt 		return (EINVAL);
    239        1.1   deraadt 	nflags = 0;
    240        1.1   deraadt 	if (oflags & SUNM_RDONLY)
    241        1.1   deraadt 		nflags |= MNT_RDONLY;
    242        1.1   deraadt 	if (oflags & SUNM_NOSUID)
    243        1.1   deraadt 		nflags |= MNT_NOSUID;
    244        1.1   deraadt 	if (oflags & SUNM_REMOUNT)
    245        1.1   deraadt 		nflags |= MNT_UPDATE;
    246       1.10   deraadt 
    247      1.150       dsl 	error = copyinstr(SCARG(uap, type), fsname, sizeof fsname, NULL);
    248       1.64  christos 	if (error)
    249       1.16   deraadt 		return (error);
    250       1.16   deraadt 
    251      1.150       dsl 	if (strcmp(fsname, "nfs") == 0) {
    252       1.33   deraadt 		struct sunos_nfs_args sna;
    253       1.10   deraadt 		struct nfs_args na;
    254       1.61        pk 		int n;
    255       1.10   deraadt 
    256       1.64  christos 		error = copyin(SCARG(uap, data), &sna, sizeof sna);
    257       1.64  christos 		if (error)
    258       1.10   deraadt 			return (error);
    259      1.150       dsl 		/* sa.sa_len = sizeof(sain); */
    260       1.61        pk 		na.version = NFS_ARGSVERSION;
    261      1.150       dsl 		na.addr = (void *)sna.addr;
    262       1.29        pk 		na.addrlen = sizeof(struct sockaddr);
    263       1.10   deraadt 		na.sotype = SOCK_DGRAM;
    264       1.10   deraadt 		na.proto = IPPROTO_UDP;
    265      1.150       dsl 		na.fh = sna.fh;
    266       1.61        pk 		na.fhsize = NFSX_V2FH;
    267       1.61        pk 		na.flags = 0;
    268       1.61        pk 		n = sizeof(sunnfs_flgtab) / sizeof(sunnfs_flgtab[0]);
    269       1.61        pk 		while (--n >= 0)
    270       1.61        pk 			if (sna.flags & sunnfs_flgtab[n].sun_flg)
    271       1.61        pk 				na.flags |= sunnfs_flgtab[n].bsd_flg;
    272       1.10   deraadt 		na.wsize = sna.wsize;
    273       1.10   deraadt 		na.rsize = sna.rsize;
    274       1.62        pk 		if (na.flags & NFSMNT_RSIZE) {
    275       1.62        pk 			na.flags |= NFSMNT_READDIRSIZE;
    276       1.62        pk 			na.readdirsize = na.rsize;
    277       1.62        pk 		}
    278       1.10   deraadt 		na.timeo = sna.timeo;
    279       1.10   deraadt 		na.retrans = sna.retrans;
    280      1.150       dsl 		na.hostname = /* (char *)(u_long) */ sna.hostname;
    281       1.10   deraadt 
    282  1.169.2.1     skrll 		return do_sys_mount(l, "nfs", UIO_SYSSPACE,
    283      1.150       dsl 		    SCARG(uap, dir), nflags, &na,
    284      1.150       dsl 		    UIO_SYSSPACE, sizeof na, &dummy);
    285       1.10   deraadt 	}
    286      1.150       dsl 
    287      1.150       dsl 	if (strcmp(fsname, "4.2") == 0)
    288      1.150       dsl 		strcpy(fsname, "ffs");
    289      1.150       dsl 
    290  1.169.2.1     skrll 	return do_sys_mount(l, fsname, UIO_SYSSPACE,
    291      1.150       dsl 	    SCARG(uap, dir), nflags, SCARG(uap, data),
    292      1.150       dsl 	    UIO_USERSPACE, 0, &dummy);
    293        1.1   deraadt }
    294        1.1   deraadt 
    295       1.33   deraadt int
    296      1.157       dsl async_daemon(struct lwp *l, const void *v, register_t *retval)
    297       1.27        pk {
    298       1.55   mycroft 
    299      1.163        ad 	return kpause("fakeniod", false, 0, NULL);
    300       1.27        pk }
    301       1.27        pk 
    302      1.154       dsl void	native_to_sunos_sigset(const sigset_t *, int *);
    303      1.154       dsl void	sunos_to_native_sigset(const int, sigset_t *);
    304       1.95        pk 
    305      1.135     perry inline void
    306      1.155       dsl native_to_sunos_sigset(const sigset_t *ss, int *mask)
    307       1.95        pk {
    308       1.95        pk 	*mask = ss->__bits[0];
    309       1.95        pk }
    310       1.95        pk 
    311      1.135     perry inline void
    312      1.155       dsl sunos_to_native_sigset(const int mask, sigset_t *ss)
    313       1.95        pk {
    314       1.95        pk 
    315       1.95        pk 	ss->__bits[0] = mask;
    316       1.95        pk 	ss->__bits[1] = 0;
    317       1.95        pk 	ss->__bits[2] = 0;
    318       1.95        pk 	ss->__bits[3] = 0;
    319       1.95        pk }
    320       1.95        pk 
    321       1.33   deraadt int
    322      1.157       dsl sunos_sys_sigpending(struct lwp *l, const struct sunos_sys_sigpending_args *uap, register_t *retval)
    323        1.1   deraadt {
    324       1.95        pk 	sigset_t ss;
    325       1.95        pk 	int mask;
    326       1.95        pk 
    327      1.144        ad 	sigpending1(l, &ss);
    328       1.95        pk 	native_to_sunos_sigset(&ss, &mask);
    329        1.1   deraadt 
    330      1.145  christos 	return (copyout((void *)&mask, (void *)SCARG(uap, mask), sizeof(int)));
    331        1.1   deraadt }
    332        1.1   deraadt 
    333      1.131     perry int
    334      1.157       dsl sunos_sys_sigsuspend(struct lwp *l, const struct sunos_sys_sigsuspend_args *uap, register_t *retval)
    335       1.95        pk {
    336      1.157       dsl 	/* {
    337       1.95        pk 		syscallarg(int) mask;
    338      1.157       dsl 	} */
    339       1.95        pk 	int mask;
    340       1.95        pk 	sigset_t ss;
    341      1.131     perry 
    342       1.95        pk 	mask = SCARG(uap, mask);
    343       1.95        pk 	sunos_to_native_sigset(mask, &ss);
    344      1.144        ad 	return (sigsuspend1(l, &ss));
    345       1.95        pk }
    346       1.95        pk 
    347        1.1   deraadt /*
    348        1.1   deraadt  * Read Sun-style directory entries.  We suck them into kernel space so
    349        1.1   deraadt  * that they can be massaged before being copied out to user code.  Like
    350        1.1   deraadt  * SunOS, we squish out `empty' entries.
    351        1.1   deraadt  *
    352        1.1   deraadt  * This is quite ugly, but what do you expect from compatibility code?
    353        1.1   deraadt  */
    354       1.33   deraadt int
    355      1.157       dsl sunos_sys_getdents(struct lwp *l, const struct sunos_sys_getdents_args *uap, register_t *retval)
    356        1.1   deraadt {
    357       1.56   mycroft 	struct dirent *bdp;
    358       1.56   mycroft 	struct vnode *vp;
    359      1.146   tsutsui 	char *inp, *buf;	/* BSD-format */
    360       1.56   mycroft 	int len, reclen;	/* BSD-format */
    361      1.146   tsutsui 	char *outp;		/* Sun-format */
    362       1.56   mycroft 	int resid, sunos_reclen;/* Sun-format */
    363        1.1   deraadt 	struct file *fp;
    364        1.1   deraadt 	struct uio auio;
    365        1.1   deraadt 	struct iovec aiov;
    366       1.56   mycroft 	struct sunos_dirent idb;
    367        1.1   deraadt 	off_t off;			/* true file offset */
    368        1.1   deraadt 	int buflen, error, eofflag;
    369       1.90      fvdl 	off_t *cookiebuf, *cookie;
    370       1.56   mycroft 	int ncookies;
    371        1.1   deraadt 
    372      1.159        ad 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
    373        1.1   deraadt 		return (error);
    374       1.56   mycroft 
    375      1.101   thorpej 	if ((fp->f_flag & FREAD) == 0) {
    376      1.101   thorpej 		error = EBADF;
    377      1.101   thorpej 		goto out1;
    378      1.101   thorpej 	}
    379       1.56   mycroft 
    380      1.169      matt 	vp = fp->f_vnode;
    381      1.101   thorpej 	if (vp->v_type != VDIR) {
    382      1.101   thorpej 		error = EINVAL;
    383      1.101   thorpej 		goto out1;
    384      1.101   thorpej 	}
    385       1.56   mycroft 
    386       1.33   deraadt 	buflen = min(MAXBSIZE, SCARG(uap, nbytes));
    387        1.1   deraadt 	buf = malloc(buflen, M_TEMP, M_WAITOK);
    388       1.88      fvdl 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    389        1.1   deraadt 	off = fp->f_offset;
    390        1.1   deraadt again:
    391        1.1   deraadt 	aiov.iov_base = buf;
    392        1.1   deraadt 	aiov.iov_len = buflen;
    393        1.1   deraadt 	auio.uio_iov = &aiov;
    394        1.1   deraadt 	auio.uio_iovcnt = 1;
    395        1.1   deraadt 	auio.uio_rw = UIO_READ;
    396        1.1   deraadt 	auio.uio_resid = buflen;
    397        1.1   deraadt 	auio.uio_offset = off;
    398      1.136      yamt 	UIO_SETUP_SYSSPACE(&auio);
    399        1.1   deraadt 	/*
    400        1.1   deraadt 	 * First we read into the malloc'ed buffer, then
    401        1.1   deraadt 	 * we massage it into user space, one record at a time.
    402        1.1   deraadt 	 */
    403       1.88      fvdl 	error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &cookiebuf,
    404       1.88      fvdl 	    &ncookies);
    405       1.59   ghudson 	if (error)
    406       1.59   ghudson 		goto out;
    407       1.56   mycroft 
    408        1.1   deraadt 	inp = buf;
    409       1.33   deraadt 	outp = SCARG(uap, buf);
    410       1.33   deraadt 	resid = SCARG(uap, nbytes);
    411       1.83      fvdl 	if ((len = buflen - auio.uio_resid) == 0)
    412        1.1   deraadt 		goto eof;
    413       1.56   mycroft 
    414       1.56   mycroft 	for (cookie = cookiebuf; len > 0; len -= reclen) {
    415       1.56   mycroft 		bdp = (struct dirent *)inp;
    416       1.56   mycroft 		reclen = bdp->d_reclen;
    417        1.1   deraadt 		if (reclen & 3)
    418       1.33   deraadt 			panic("sunos_getdents");
    419       1.82      fvdl 		if ((*cookie >> 32) != 0) {
    420       1.82      fvdl 			compat_offseterr(vp, "sunos_getdents");
    421       1.82      fvdl 			error = EINVAL;
    422       1.82      fvdl 			goto out;
    423       1.82      fvdl 		}
    424       1.56   mycroft 		if (bdp->d_fileno == 0) {
    425        1.1   deraadt 			inp += reclen;	/* it is a hole; squish it out */
    426      1.132  christos 			if (cookie)
    427      1.132  christos 				off = *cookie++;
    428      1.132  christos 			else
    429      1.132  christos 				off += reclen;
    430        1.1   deraadt 			continue;
    431        1.1   deraadt 		}
    432       1.56   mycroft 		sunos_reclen = SUNOS_RECLEN(&idb, bdp->d_namlen);
    433       1.56   mycroft 		if (reclen > len || resid < sunos_reclen) {
    434        1.1   deraadt 			/* entry too big for buffer, so just stop */
    435        1.1   deraadt 			outp++;
    436        1.1   deraadt 			break;
    437        1.1   deraadt 		}
    438      1.132  christos 		if (cookie)
    439      1.132  christos 			off = *cookie++;	/* each entry points to next */
    440      1.132  christos 		else
    441      1.132  christos 			off += reclen;
    442        1.1   deraadt 		/*
    443        1.1   deraadt 		 * Massage in place to make a Sun-shaped dirent (otherwise
    444        1.1   deraadt 		 * we have to worry about touching user memory outside of
    445        1.1   deraadt 		 * the copyout() call).
    446        1.1   deraadt 		 */
    447       1.56   mycroft 		idb.d_fileno = bdp->d_fileno;
    448       1.56   mycroft 		idb.d_off = off;
    449       1.56   mycroft 		idb.d_reclen = sunos_reclen;
    450       1.56   mycroft 		idb.d_namlen = bdp->d_namlen;
    451      1.121    itojun 		strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
    452      1.145  christos 		if ((error = copyout((void *)&idb, outp, sunos_reclen)) != 0)
    453        1.1   deraadt 			goto out;
    454        1.1   deraadt 		/* advance past this real entry */
    455        1.1   deraadt 		inp += reclen;
    456        1.1   deraadt 		/* advance output past Sun-shaped entry */
    457       1.56   mycroft 		outp += sunos_reclen;
    458       1.56   mycroft 		resid -= sunos_reclen;
    459        1.1   deraadt 	}
    460       1.56   mycroft 
    461        1.1   deraadt 	/* if we squished out the whole block, try again */
    462      1.166        he 	if (outp == SCARG(uap, buf)) {
    463      1.166        he 		if (cookiebuf)
    464      1.166        he 			free(cookiebuf, M_TEMP);
    465      1.166        he 		cookiebuf = NULL;
    466        1.1   deraadt 		goto again;
    467      1.166        he 	}
    468        1.1   deraadt 	fp->f_offset = off;		/* update the vnode offset */
    469       1.56   mycroft 
    470        1.1   deraadt eof:
    471       1.33   deraadt 	*retval = SCARG(uap, nbytes) - resid;
    472        1.1   deraadt out:
    473      1.168   hannken 	VOP_UNLOCK(vp);
    474       1.90      fvdl 	free(cookiebuf, M_TEMP);
    475        1.1   deraadt 	free(buf, M_TEMP);
    476      1.101   thorpej  out1:
    477      1.159        ad  	fd_putfile(SCARG(uap, fd));
    478        1.1   deraadt 	return (error);
    479        1.1   deraadt }
    480        1.1   deraadt 
    481       1.33   deraadt #define	SUNOS__MAP_NEW	0x80000000	/* if not, old mmap & cannot handle */
    482        1.4   deraadt 
    483       1.33   deraadt int
    484      1.157       dsl sunos_sys_mmap(struct lwp *l, const struct sunos_sys_mmap_args *uap, register_t *retval)
    485        1.1   deraadt {
    486       1.55   mycroft 	struct sys_mmap_args ouap;
    487        1.1   deraadt 
    488        1.1   deraadt 	/*
    489       1.14       cgd 	 * Verify the arguments.
    490        1.1   deraadt 	 */
    491       1.33   deraadt 	if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
    492       1.14       cgd 		return (EINVAL);			/* XXX still needed? */
    493        1.4   deraadt 
    494       1.33   deraadt 	if ((SCARG(uap, flags) & SUNOS__MAP_NEW) == 0)
    495        1.1   deraadt 		return (EINVAL);
    496        1.1   deraadt 
    497       1.34   deraadt 	SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUNOS__MAP_NEW;
    498       1.34   deraadt 	SCARG(&ouap, addr) = SCARG(uap, addr);
    499       1.34   deraadt 	SCARG(&ouap, len) = SCARG(uap, len);
    500       1.34   deraadt 	SCARG(&ouap, prot) = SCARG(uap, prot);
    501       1.34   deraadt 	SCARG(&ouap, fd) = SCARG(uap, fd);
    502       1.34   deraadt 	SCARG(&ouap, pos) = SCARG(uap, pos);
    503        1.4   deraadt 
    504      1.117   thorpej 	return (sys_mmap(l, &ouap, retval));
    505        1.1   deraadt }
    506        1.1   deraadt 
    507        1.1   deraadt #define	MC_SYNC		1
    508        1.1   deraadt #define	MC_LOCK		2
    509        1.1   deraadt #define	MC_UNLOCK	3
    510        1.1   deraadt #define	MC_ADVISE	4
    511        1.1   deraadt #define	MC_LOCKAS	5
    512        1.1   deraadt #define	MC_UNLOCKAS	6
    513        1.1   deraadt 
    514       1.33   deraadt int
    515      1.157       dsl sunos_sys_mctl(struct lwp *l, const struct sunos_sys_mctl_args *uap, register_t *retval)
    516        1.1   deraadt {
    517        1.1   deraadt 
    518       1.33   deraadt 	switch (SCARG(uap, func)) {
    519        1.1   deraadt 	case MC_ADVISE:		/* ignore for now */
    520        1.1   deraadt 		return (0);
    521        1.1   deraadt 	case MC_SYNC:		/* translate to msync */
    522      1.157       dsl 		return (sys___msync13(l, (const void *)uap, retval));
    523        1.1   deraadt 	default:
    524        1.1   deraadt 		return (EINVAL);
    525        1.1   deraadt 	}
    526        1.1   deraadt }
    527        1.1   deraadt 
    528       1.33   deraadt int
    529      1.157       dsl sunos_sys_setsockopt(struct lwp *l, const struct sunos_sys_setsockopt_args *uap, register_t *retval)
    530        1.1   deraadt {
    531      1.161    plunky 	struct sockopt sopt;
    532      1.159        ad 	struct socket *so;
    533      1.157       dsl 	int name = SCARG(uap, name);
    534        1.1   deraadt 	int error;
    535        1.1   deraadt 
    536      1.160        ad 	/* fd_getsock() will use the descriptor for us */
    537      1.159        ad 	if ((error = fd_getsock(SCARG(uap, s), &so)) != 0)
    538        1.1   deraadt 		return (error);
    539        1.1   deraadt #define	SO_DONTLINGER (~SO_LINGER)
    540      1.157       dsl 	if (name == SO_DONTLINGER) {
    541      1.161    plunky 		struct linger lg;
    542      1.161    plunky 
    543      1.161    plunky 		lg.l_onoff = 0;
    544      1.161    plunky 		error = so_setsockopt(l, so, SCARG(uap, level), SO_LINGER,
    545      1.161    plunky 		    &lg, sizeof(lg));
    546      1.101   thorpej 		goto out;
    547        1.1   deraadt 	}
    548       1.37        pk 	if (SCARG(uap, level) == IPPROTO_IP) {
    549       1.37        pk #define		SUNOS_IP_MULTICAST_IF		2
    550       1.37        pk #define		SUNOS_IP_MULTICAST_TTL		3
    551       1.37        pk #define		SUNOS_IP_MULTICAST_LOOP		4
    552       1.37        pk #define		SUNOS_IP_ADD_MEMBERSHIP		5
    553       1.37        pk #define		SUNOS_IP_DROP_MEMBERSHIP	6
    554      1.128      matt 		static const int ipoptxlat[] = {
    555       1.37        pk 			IP_MULTICAST_IF,
    556       1.37        pk 			IP_MULTICAST_TTL,
    557       1.37        pk 			IP_MULTICAST_LOOP,
    558       1.37        pk 			IP_ADD_MEMBERSHIP,
    559       1.37        pk 			IP_DROP_MEMBERSHIP
    560       1.37        pk 		};
    561      1.157       dsl 		if (name >= SUNOS_IP_MULTICAST_IF &&
    562      1.157       dsl 		    name <= SUNOS_IP_DROP_MEMBERSHIP) {
    563      1.157       dsl 			name = ipoptxlat[name - SUNOS_IP_MULTICAST_IF];
    564       1.37        pk 		}
    565       1.37        pk 	}
    566      1.101   thorpej 	if (SCARG(uap, valsize) > MLEN) {
    567      1.101   thorpej 		error = EINVAL;
    568      1.101   thorpej 		goto out;
    569      1.101   thorpej 	}
    570      1.161    plunky 	sockopt_init(&sopt, SCARG(uap, level), name, SCARG(uap, valsize));
    571       1.33   deraadt 	if (SCARG(uap, val)) {
    572      1.161    plunky 		error = copyin(SCARG(uap, val), sopt.sopt_data,
    573       1.64  christos 		    (u_int)SCARG(uap, valsize));
    574        1.1   deraadt 	}
    575      1.161    plunky 	if (error == 0)
    576      1.161    plunky 		error = sosetopt(so, &sopt);
    577      1.161    plunky 	sockopt_destroy(&sopt);
    578      1.101   thorpej  out:
    579      1.159        ad  	fd_putfile(SCARG(uap, s));
    580      1.101   thorpej 	return (error);
    581      1.113       mrg }
    582      1.113       mrg 
    583      1.135     perry static inline int sunos_sys_socket_common(struct lwp *, register_t *,
    584      1.113       mrg 					      int type);
    585      1.135     perry static inline int
    586      1.155       dsl sunos_sys_socket_common(struct lwp *l, register_t *retval, int type)
    587      1.113       mrg {
    588      1.113       mrg 	struct socket *so;
    589      1.113       mrg 	int error, fd;
    590      1.113       mrg 
    591      1.160        ad 	/* fd_getsock() will use the descriptor for us */
    592      1.113       mrg 	fd = (int)*retval;
    593      1.159        ad 	if ((error = fd_getsock(fd, &so)) == 0) {
    594      1.113       mrg 		if (type == SOCK_DGRAM)
    595      1.113       mrg 			so->so_options |= SO_BROADCAST;
    596      1.159        ad 		fd_putfile(fd);
    597      1.113       mrg 	}
    598      1.113       mrg 	return (error);
    599      1.113       mrg }
    600      1.113       mrg 
    601      1.113       mrg int
    602      1.157       dsl sunos_sys_socket(struct lwp *l, const struct sunos_sys_socket_args *uap, register_t *retval)
    603      1.113       mrg {
    604      1.157       dsl 	/* {
    605      1.113       mrg 		syscallarg(int) domain;
    606      1.113       mrg 		syscallarg(int) type;
    607      1.113       mrg 		syscallarg(int) protocol;
    608      1.157       dsl 	} */
    609      1.113       mrg 	int error;
    610      1.113       mrg 
    611      1.157       dsl 	error = compat_30_sys_socket(l, (const void *)uap, retval);
    612      1.113       mrg 	if (error)
    613      1.113       mrg 		return (error);
    614      1.117   thorpej 	return sunos_sys_socket_common(l, retval, SCARG(uap, type));
    615      1.113       mrg }
    616      1.113       mrg 
    617      1.113       mrg int
    618      1.157       dsl sunos_sys_socketpair(struct lwp *l, const struct sunos_sys_socketpair_args *uap, register_t *retval)
    619      1.113       mrg {
    620      1.157       dsl 	/* {
    621      1.113       mrg 		syscallarg(int) domain;
    622      1.113       mrg 		syscallarg(int) type;
    623      1.113       mrg 		syscallarg(int) protocol;
    624      1.113       mrg 		syscallarg(int *) rsv;
    625      1.157       dsl 	} */
    626      1.113       mrg 	int error;
    627      1.113       mrg 
    628      1.157       dsl 	error = sys_socketpair(l, (const void *)uap, retval);
    629      1.113       mrg 	if (error)
    630      1.113       mrg 		return (error);
    631      1.117   thorpej 	return sunos_sys_socket_common(l, retval, SCARG(uap, type));
    632        1.3   deraadt }
    633        1.3   deraadt 
    634        1.3   deraadt /*
    635        1.3   deraadt  * XXX: This needs cleaning up.
    636        1.3   deraadt  */
    637       1.33   deraadt int
    638      1.157       dsl sunos_sys_auditsys(struct lwp *l, const struct sunos_sys_auditsys_args *uap, register_t *retval)
    639        1.3   deraadt {
    640        1.3   deraadt 	return 0;
    641        1.8   deraadt }
    642        1.8   deraadt 
    643       1.33   deraadt int
    644      1.157       dsl sunos_sys_uname(struct lwp *l, const struct sunos_sys_uname_args *uap, register_t *retval)
    645        1.8   deraadt {
    646       1.33   deraadt 	struct sunos_utsname sut;
    647        1.8   deraadt 
    648       1.92     perry 	memset(&sut, 0, sizeof(sut));
    649        1.8   deraadt 
    650       1.92     perry 	memcpy(sut.sysname, ostype, sizeof(sut.sysname) - 1);
    651       1.92     perry 	memcpy(sut.nodename, hostname, sizeof(sut.nodename));
    652       1.22   deraadt 	sut.nodename[sizeof(sut.nodename)-1] = '\0';
    653       1.92     perry 	memcpy(sut.release, osrelease, sizeof(sut.release) - 1);
    654       1.92     perry 	memcpy(sut.version, "1", sizeof(sut.version) - 1);
    655       1.92     perry 	memcpy(sut.machine, machine, sizeof(sut.machine) - 1);
    656        1.8   deraadt 
    657      1.145  christos 	return copyout((void *)&sut, (void *)SCARG(uap, name),
    658       1.33   deraadt 	    sizeof(struct sunos_utsname));
    659        1.8   deraadt }
    660        1.8   deraadt 
    661        1.8   deraadt int
    662      1.157       dsl sunos_sys_setpgrp(struct lwp *l, const struct sunos_sys_setpgrp_args *uap, register_t *retval)
    663        1.8   deraadt {
    664      1.117   thorpej 	struct proc *p = l->l_proc;
    665       1.54   thorpej 
    666        1.8   deraadt 	/*
    667        1.8   deraadt 	 * difference to our setpgid call is to include backwards
    668        1.8   deraadt 	 * compatibility to pre-setsid() binaries. Do setsid()
    669        1.8   deraadt 	 * instead of setpgid() in those cases where the process
    670        1.8   deraadt 	 * tries to create a new session the old way.
    671        1.8   deraadt 	 */
    672       1.55   mycroft 	if (!SCARG(uap, pgid) &&
    673       1.55   mycroft 	    (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
    674      1.157       dsl 		return sys_setsid(l, NULL, retval);
    675        1.8   deraadt 	else
    676      1.157       dsl 		return sys_setpgid(l, (const void *)uap, retval);
    677        1.8   deraadt }
    678        1.8   deraadt 
    679       1.33   deraadt int
    680      1.157       dsl sunos_sys_open(struct lwp *l, const struct sunos_sys_open_args *uap, register_t *retval)
    681        1.8   deraadt {
    682      1.148    dogcow 	struct proc *p = l->l_proc;
    683      1.157       dsl 	struct sys_open_args open_ua;
    684      1.117   thorpej 	int smode, nmode;
    685       1.39        pk 	int noctty;
    686        1.8   deraadt 	int ret;
    687      1.131     perry 
    688        1.8   deraadt 	/* convert mode into NetBSD mode */
    689      1.117   thorpej 	smode = SCARG(uap, flags);
    690      1.117   thorpej 	noctty = smode & 0x8000;
    691      1.117   thorpej 	nmode =	smode &
    692      1.117   thorpej 		(0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800);
    693      1.117   thorpej 	nmode |= ((smode & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
    694      1.117   thorpej 	nmode |= ((smode & 0x0080) ? O_SHLOCK : 0);
    695      1.117   thorpej 	nmode |= ((smode & 0x0100) ? O_EXLOCK : 0);
    696      1.117   thorpej 	nmode |= ((smode & 0x2000) ? O_FSYNC : 0);
    697        1.8   deraadt 
    698      1.157       dsl 	SCARG(&open_ua, path) = SCARG(uap, path);
    699      1.157       dsl 	SCARG(&open_ua, flags) = nmode;
    700      1.157       dsl 	SCARG(&open_ua, mode) = SCARG(uap, mode);
    701      1.157       dsl 	ret = sys_open(l, &open_ua, retval);
    702        1.8   deraadt 
    703      1.144        ad 	/* XXXSMP */
    704      1.144        ad 	if (!ret && !noctty && SESS_LEADER(p) && !(p->p_lflag & PL_CONTROLT)) {
    705      1.159        ad 		file_t *fp;
    706      1.159        ad 		int fd;
    707      1.110   thorpej 
    708      1.159        ad 		fd = (int)*retval;
    709      1.159        ad 		fp = fd_getfile(fd);
    710        1.8   deraadt 
    711        1.8   deraadt 		/* ignore any error, just give it a try */
    712      1.152        ad 		if (fp != NULL) {
    713      1.152        ad 			if (fp->f_type == DTYPE_VNODE)
    714      1.159        ad 				(fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, NULL);
    715      1.159        ad 			fd_putfile(fd);
    716      1.152        ad 		}
    717        1.8   deraadt 	}
    718        1.8   deraadt 	return ret;
    719       1.10   deraadt }
    720       1.10   deraadt 
    721       1.33   deraadt int
    722      1.157       dsl sunos_sys_ustat(struct lwp *l, const struct sunos_sys_ustat_args *uap, register_t *retval)
    723       1.10   deraadt {
    724       1.33   deraadt 	struct sunos_ustat us;
    725       1.10   deraadt 	int error;
    726       1.10   deraadt 
    727       1.92     perry 	memset(&us, 0, sizeof us);
    728       1.10   deraadt 
    729       1.10   deraadt 	/*
    730       1.10   deraadt 	 * XXX: should set f_tfree and f_tinode at least
    731       1.33   deraadt 	 * How do we translate dev -> fstat? (and then to sunos_ustat)
    732       1.10   deraadt 	 */
    733       1.10   deraadt 
    734       1.64  christos 	if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0)
    735       1.10   deraadt 		return (error);
    736       1.10   deraadt 	return 0;
    737       1.10   deraadt }
    738       1.10   deraadt 
    739       1.33   deraadt int
    740      1.157       dsl sunos_sys_quotactl(struct lwp *l, const struct sunos_sys_quotactl_args *uap, register_t *retval)
    741       1.10   deraadt {
    742       1.54   thorpej 
    743       1.10   deraadt 	return EINVAL;
    744       1.10   deraadt }
    745       1.10   deraadt 
    746       1.33   deraadt int
    747      1.157       dsl sunos_sys_vhangup(struct lwp *l, const void *v, register_t *retval)
    748       1.10   deraadt {
    749      1.117   thorpej 	struct proc *p = l->l_proc;
    750       1.60        pk 	struct session *sp = p->p_session;
    751       1.60        pk 
    752       1.60        pk 	if (sp->s_ttyvp == 0)
    753       1.60        pk 		return 0;
    754       1.60        pk 
    755       1.60        pk 	if (sp->s_ttyp && sp->s_ttyp->t_session == sp && sp->s_ttyp->t_pgrp)
    756       1.60        pk 		pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1);
    757       1.60        pk 
    758       1.60        pk 	(void) ttywait(sp->s_ttyp);
    759       1.60        pk 	if (sp->s_ttyvp)
    760       1.90      fvdl 		VOP_REVOKE(sp->s_ttyvp, REVOKEALL);
    761       1.60        pk 	if (sp->s_ttyvp)
    762       1.60        pk 		vrele(sp->s_ttyvp);
    763       1.60        pk 	sp->s_ttyvp = NULL;
    764       1.55   mycroft 
    765       1.10   deraadt 	return 0;
    766       1.10   deraadt }
    767       1.10   deraadt 
    768       1.64  christos static int
    769      1.155       dsl sunstatfs(struct statvfs *sp, void *buf)
    770       1.10   deraadt {
    771       1.33   deraadt 	struct sunos_statfs ssfs;
    772       1.10   deraadt 
    773       1.92     perry 	memset(&ssfs, 0, sizeof ssfs);
    774       1.10   deraadt 	ssfs.f_type = 0;
    775       1.16   deraadt 	ssfs.f_bsize = sp->f_bsize;
    776       1.10   deraadt 	ssfs.f_blocks = sp->f_blocks;
    777       1.10   deraadt 	ssfs.f_bfree = sp->f_bfree;
    778       1.10   deraadt 	ssfs.f_bavail = sp->f_bavail;
    779       1.10   deraadt 	ssfs.f_files = sp->f_files;
    780       1.10   deraadt 	ssfs.f_ffree = sp->f_ffree;
    781      1.126  christos 	ssfs.f_fsid = sp->f_fsidx;
    782      1.145  christos 	return copyout((void *)&ssfs, buf, sizeof ssfs);
    783      1.131     perry }
    784       1.10   deraadt 
    785       1.33   deraadt int
    786      1.157       dsl sunos_sys_statfs(struct lwp *l, const struct sunos_sys_statfs_args *uap, register_t *retval)
    787       1.10   deraadt {
    788      1.104  augustss 	struct mount *mp;
    789      1.127   hannken 	struct statvfs *sp;
    790       1.10   deraadt 	int error;
    791      1.165  dholland 	struct vnode *vp;
    792       1.10   deraadt 
    793      1.165  dholland 	error = namei_simple_user(SCARG(uap, path),
    794      1.165  dholland 				NSM_FOLLOW_TRYEMULROOT, &vp);
    795      1.165  dholland 	if (error != 0)
    796       1.10   deraadt 		return (error);
    797      1.165  dholland 	mp = vp->v_mount;
    798       1.10   deraadt 	sp = &mp->mnt_stat;
    799      1.165  dholland 	vrele(vp);
    800      1.153    dogcow 	if ((error = VFS_STATVFS(mp, sp)) != 0)
    801       1.10   deraadt 		return (error);
    802      1.127   hannken 	sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
    803      1.145  christos 	return sunstatfs(sp, (void *)SCARG(uap, buf));
    804       1.10   deraadt }
    805       1.10   deraadt 
    806       1.33   deraadt int
    807      1.157       dsl sunos_sys_fstatfs(struct lwp *l, const struct sunos_sys_fstatfs_args *uap, register_t *retval)
    808       1.10   deraadt {
    809      1.159        ad 	file_t *fp;
    810       1.10   deraadt 	struct mount *mp;
    811      1.127   hannken 	struct statvfs *sp;
    812       1.10   deraadt 	int error;
    813       1.10   deraadt 
    814      1.160        ad 	/* fd_getvnode() will use the descriptor for us */
    815      1.159        ad 	if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
    816       1.10   deraadt 		return (error);
    817      1.169      matt 	mp = fp->f_vnode->v_mount;
    818       1.10   deraadt 	sp = &mp->mnt_stat;
    819      1.153    dogcow 	if ((error = VFS_STATVFS(mp, sp)) != 0)
    820      1.101   thorpej 		goto out;
    821      1.127   hannken 	sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
    822      1.145  christos 	error = sunstatfs(sp, (void *)SCARG(uap, buf));
    823      1.101   thorpej  out:
    824      1.159        ad  	fd_putfile(SCARG(uap, fd));
    825      1.101   thorpej 	return (error);
    826       1.10   deraadt }
    827       1.10   deraadt 
    828       1.33   deraadt int
    829      1.157       dsl sunos_sys_exportfs(struct lwp *l, const struct sunos_sys_exportfs_args *uap, register_t *retval)
    830       1.10   deraadt {
    831       1.10   deraadt 	/*
    832       1.10   deraadt 	 * XXX: should perhaps translate into a mount(2)
    833       1.10   deraadt 	 * with MOUNT_EXPORT?
    834       1.10   deraadt 	 */
    835       1.10   deraadt 	return 0;
    836       1.10   deraadt }
    837       1.10   deraadt 
    838       1.33   deraadt int
    839      1.157       dsl sunos_sys_mknod(struct lwp *l, const struct sunos_sys_mknod_args *uap, register_t *retval)
    840       1.10   deraadt {
    841      1.157       dsl 	struct sys_mkfifo_args fifo_ua;
    842       1.48        pk 
    843      1.157       dsl 	if (S_ISFIFO(SCARG(uap, mode))) {
    844      1.157       dsl 		SCARG(&fifo_ua, path) = SCARG(uap, path);
    845      1.157       dsl 		SCARG(&fifo_ua, mode) = SCARG(uap, mode);
    846      1.157       dsl 		return sys_mkfifo(l, &fifo_ua, retval);
    847      1.157       dsl 	}
    848       1.10   deraadt 
    849      1.164   tsutsui 	return compat_50_sys_mknod(l,
    850      1.164   tsutsui 	    (const struct compat_50_sys_mknod_args *)uap, retval);
    851       1.12   deraadt }
    852       1.12   deraadt 
    853       1.33   deraadt #define SUNOS_SC_ARG_MAX	1
    854       1.33   deraadt #define SUNOS_SC_CHILD_MAX	2
    855       1.33   deraadt #define SUNOS_SC_CLK_TCK	3
    856       1.33   deraadt #define SUNOS_SC_NGROUPS_MAX	4
    857       1.33   deraadt #define SUNOS_SC_OPEN_MAX	5
    858       1.33   deraadt #define SUNOS_SC_JOB_CONTROL	6
    859       1.33   deraadt #define SUNOS_SC_SAVED_IDS	7
    860       1.33   deraadt #define SUNOS_SC_VERSION	8
    861       1.12   deraadt 
    862       1.33   deraadt int
    863      1.157       dsl sunos_sys_sysconf(struct lwp *l, const struct sunos_sys_sysconf_args *uap, register_t *retval)
    864       1.12   deraadt {
    865       1.12   deraadt 
    866       1.33   deraadt 	switch(SCARG(uap, name)) {
    867       1.33   deraadt 	case SUNOS_SC_ARG_MAX:
    868       1.12   deraadt 		*retval = ARG_MAX;
    869       1.13   deraadt 		break;
    870       1.33   deraadt 	case SUNOS_SC_CHILD_MAX:
    871       1.12   deraadt 		*retval = maxproc;
    872       1.13   deraadt 		break;
    873       1.33   deraadt 	case SUNOS_SC_CLK_TCK:
    874       1.12   deraadt 		*retval = 60;		/* should this be `hz', ie. 100? */
    875       1.13   deraadt 		break;
    876       1.33   deraadt 	case SUNOS_SC_NGROUPS_MAX:
    877       1.12   deraadt 		*retval = NGROUPS_MAX;
    878       1.13   deraadt 		break;
    879       1.33   deraadt 	case SUNOS_SC_OPEN_MAX:
    880       1.24   deraadt 		*retval = maxfiles;
    881       1.13   deraadt 		break;
    882       1.33   deraadt 	case SUNOS_SC_JOB_CONTROL:
    883       1.12   deraadt 		*retval = 1;
    884       1.13   deraadt 		break;
    885       1.33   deraadt 	case SUNOS_SC_SAVED_IDS:
    886       1.12   deraadt #ifdef _POSIX_SAVED_IDS
    887       1.12   deraadt 		*retval = 1;
    888       1.12   deraadt #else
    889       1.12   deraadt 		*retval = 0;
    890       1.12   deraadt #endif
    891       1.13   deraadt 		break;
    892       1.33   deraadt 	case SUNOS_SC_VERSION:
    893       1.12   deraadt 		*retval = 198808;
    894       1.13   deraadt 		break;
    895       1.12   deraadt 	default:
    896       1.12   deraadt 		return EINVAL;
    897       1.12   deraadt 	}
    898       1.12   deraadt 	return 0;
    899       1.17        pk }
    900       1.17        pk 
    901       1.33   deraadt #define SUNOS_RLIMIT_NOFILE	6	/* Other RLIMIT_* are the same */
    902       1.33   deraadt #define SUNOS_RLIM_NLIMITS	7
    903       1.17        pk 
    904       1.33   deraadt int
    905      1.157       dsl sunos_sys_getrlimit(struct lwp *l, const struct sunos_sys_getrlimit_args *uap, register_t *retval)
    906       1.17        pk {
    907      1.157       dsl 	struct compat_43_sys_getrlimit_args ua_43;
    908      1.157       dsl 
    909      1.157       dsl 	SCARG(&ua_43, which) = SCARG(uap, which);
    910      1.157       dsl 	SCARG(&ua_43, rlp) = SCARG(uap, rlp);
    911       1.54   thorpej 
    912       1.33   deraadt 	if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
    913       1.17        pk 		return EINVAL;
    914       1.17        pk 
    915       1.33   deraadt 	if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
    916      1.157       dsl 		SCARG(&ua_43, which) = RLIMIT_NOFILE;
    917       1.17        pk 
    918      1.157       dsl 	return compat_43_sys_getrlimit(l, &ua_43, retval);
    919       1.17        pk }
    920       1.17        pk 
    921       1.33   deraadt int
    922      1.157       dsl sunos_sys_setrlimit(struct lwp *l, const struct sunos_sys_setrlimit_args *uap, register_t *retval)
    923       1.17        pk {
    924      1.157       dsl 	struct compat_43_sys_setrlimit_args ua_43;
    925      1.157       dsl 
    926      1.157       dsl 	SCARG(&ua_43, which) = SCARG(uap, which);
    927      1.157       dsl 	SCARG(&ua_43, rlp) = SCARG(uap, rlp);
    928       1.54   thorpej 
    929       1.33   deraadt 	if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
    930       1.17        pk 		return EINVAL;
    931       1.17        pk 
    932       1.33   deraadt 	if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
    933      1.157       dsl 		SCARG(&ua_43, which) = RLIMIT_NOFILE;
    934       1.17        pk 
    935      1.157       dsl 	return compat_43_sys_setrlimit(l, &ua_43, retval);
    936       1.35   deraadt }
    937       1.36   deraadt 
    938       1.36   deraadt /* for the m68k machines */
    939       1.36   deraadt #ifndef PT_GETFPREGS
    940       1.36   deraadt #define PT_GETFPREGS -1
    941       1.36   deraadt #endif
    942       1.36   deraadt #ifndef PT_SETFPREGS
    943       1.36   deraadt #define PT_SETFPREGS -1
    944       1.36   deraadt #endif
    945       1.35   deraadt 
    946      1.129      matt static const int sreq2breq[] = {
    947       1.35   deraadt 	PT_TRACE_ME,    PT_READ_I,      PT_READ_D,      -1,
    948       1.35   deraadt 	PT_WRITE_I,     PT_WRITE_D,     -1,             PT_CONTINUE,
    949       1.35   deraadt 	PT_KILL,        -1,             PT_ATTACH,      PT_DETACH,
    950       1.35   deraadt 	PT_GETREGS,     PT_SETREGS,     PT_GETFPREGS,   PT_SETFPREGS
    951       1.35   deraadt };
    952      1.129      matt static const int nreqs = sizeof(sreq2breq) / sizeof(sreq2breq[0]);
    953       1.35   deraadt 
    954       1.64  christos int
    955      1.157       dsl sunos_sys_ptrace(struct lwp *l, const struct sunos_sys_ptrace_args *uap, register_t *retval)
    956       1.35   deraadt {
    957       1.55   mycroft 	struct sys_ptrace_args pa;
    958       1.35   deraadt 	int req;
    959       1.35   deraadt 
    960      1.142      matt #define	sys_ptrace sysent[SYS_ptrace].sy_call
    961      1.142      matt 	if (sys_ptrace == sys_nosys)
    962      1.142      matt 		return ENOSYS;
    963      1.142      matt 
    964       1.35   deraadt 	req = SCARG(uap, req);
    965       1.35   deraadt 
    966       1.35   deraadt 	if (req < 0 || req >= nreqs)
    967       1.35   deraadt 		return (EINVAL);
    968       1.35   deraadt 
    969       1.35   deraadt 	req = sreq2breq[req];
    970       1.35   deraadt 	if (req == -1)
    971       1.35   deraadt 		return (EINVAL);
    972       1.35   deraadt 
    973       1.35   deraadt 	SCARG(&pa, req) = req;
    974       1.35   deraadt 	SCARG(&pa, pid) = (pid_t)SCARG(uap, pid);
    975      1.145  christos 	SCARG(&pa, addr) = (void *)SCARG(uap, addr);
    976       1.35   deraadt 	SCARG(&pa, data) = SCARG(uap, data);
    977       1.35   deraadt 
    978      1.117   thorpej 	return sys_ptrace(l, &pa, retval);
    979       1.44  christos }
    980       1.44  christos 
    981       1.44  christos /*
    982       1.44  christos  * SunOS reboot system call (for compatibility).
    983       1.44  christos  * Sun lets you pass in a boot string which the PROM
    984       1.44  christos  * saves and provides to the next boot program.
    985       1.44  christos  */
    986       1.68       mrg 
    987       1.68       mrg #define SUNOS_RB_ASKNAME	0x001
    988       1.68       mrg #define SUNOS_RB_SINGLE 	0x002
    989       1.68       mrg #define SUNOS_RB_NOSYNC		0x004
    990       1.68       mrg #define SUNOS_RB_HALT		0x008
    991       1.68       mrg #define SUNOS_RB_DUMP		0x080
    992       1.68       mrg #define	SUNOS_RB_STRING		0x200
    993       1.68       mrg 
    994       1.44  christos static struct sunos_howto_conv {
    995       1.46       gwr 	int sun_howto;
    996       1.44  christos 	int bsd_howto;
    997       1.44  christos } sunos_howto_conv[] = {
    998       1.68       mrg 	{ SUNOS_RB_ASKNAME,	RB_ASKNAME },
    999       1.68       mrg 	{ SUNOS_RB_SINGLE,	RB_SINGLE },
   1000       1.68       mrg 	{ SUNOS_RB_NOSYNC,	RB_NOSYNC },
   1001       1.68       mrg 	{ SUNOS_RB_HALT,	RB_HALT },
   1002       1.68       mrg 	{ SUNOS_RB_DUMP,	RB_DUMP },
   1003       1.68       mrg 	{ SUNOS_RB_STRING,	RB_STRING },
   1004       1.68       mrg 	{ 0x000,		0 },
   1005       1.44  christos };
   1006       1.44  christos 
   1007       1.46       gwr int
   1008      1.157       dsl sunos_sys_reboot(struct lwp *l, const struct sunos_sys_reboot_args *uap, register_t *retval)
   1009       1.44  christos {
   1010       1.68       mrg 	struct sys_reboot_args ua;
   1011       1.44  christos 	struct sunos_howto_conv *convp;
   1012       1.46       gwr 	int error, bsd_howto, sun_howto;
   1013       1.68       mrg 	char *bootstr;
   1014       1.44  christos 
   1015      1.143      elad 	if ((error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_REBOOT,
   1016      1.143      elad 	    0, NULL, NULL, NULL)) != 0)
   1017       1.44  christos 		return (error);
   1018       1.44  christos 
   1019       1.44  christos 	/*
   1020       1.44  christos 	 * Convert howto bits to BSD format.
   1021       1.44  christos 	 */
   1022       1.46       gwr 	sun_howto = SCARG(uap, howto);
   1023       1.44  christos 	bsd_howto = 0;
   1024       1.44  christos 	convp = sunos_howto_conv;
   1025       1.46       gwr 	while (convp->sun_howto) {
   1026       1.68       mrg 		if (sun_howto & convp->sun_howto)
   1027       1.44  christos 			bsd_howto |= convp->bsd_howto;
   1028       1.44  christos 		convp++;
   1029       1.44  christos 	}
   1030       1.44  christos 
   1031       1.44  christos 	/*
   1032       1.44  christos 	 * Sun RB_STRING (Get user supplied bootstring.)
   1033       1.46       gwr 	 * If the machine supports passing a string to the
   1034       1.67       mrg 	 * next booted kernel.
   1035       1.44  christos 	 */
   1036       1.46       gwr 	if (sun_howto & SUNOS_RB_STRING) {
   1037       1.46       gwr 		char bs[128];
   1038       1.46       gwr 
   1039       1.47  christos 		error = copyinstr(SCARG(uap, bootstr), bs, sizeof(bs), 0);
   1040       1.67       mrg 
   1041       1.68       mrg 		if (error)
   1042       1.68       mrg 			bootstr = NULL;
   1043       1.68       mrg 		else
   1044       1.68       mrg 			bootstr = bs;
   1045       1.67       mrg 	} else
   1046       1.68       mrg 		bootstr = NULL;
   1047       1.46       gwr 
   1048       1.68       mrg 	SCARG(&ua, opt) = bsd_howto;
   1049       1.68       mrg 	SCARG(&ua, bootstr) = bootstr;
   1050      1.117   thorpej 	sys_reboot(l, &ua, retval);
   1051       1.68       mrg 	return(0);
   1052       1.50  christos }
   1053       1.50  christos 
   1054       1.50  christos /*
   1055       1.50  christos  * Generalized interface signal handler, 4.3-compatible.
   1056       1.50  christos  */
   1057       1.50  christos /* ARGSUSED */
   1058       1.50  christos int
   1059      1.157       dsl sunos_sys_sigvec(struct lwp *l, const struct sunos_sys_sigvec_args *uap, register_t *retval)
   1060       1.54   thorpej {
   1061      1.157       dsl 	/* {
   1062       1.50  christos 		syscallarg(int) signum;
   1063       1.50  christos 		syscallarg(struct sigvec *) nsv;
   1064       1.50  christos 		syscallarg(struct sigvec *) osv;
   1065      1.157       dsl 	} */
   1066       1.95        pk 	struct sigvec nsv, osv;
   1067       1.95        pk 	struct sigaction nsa, osa;
   1068       1.95        pk 	int error;
   1069       1.95        pk /*XXX*/extern	void compat_43_sigvec_to_sigaction
   1070      1.154       dsl (const struct sigvec *, struct sigaction *);
   1071       1.95        pk /*XXX*/extern	void compat_43_sigaction_to_sigvec
   1072      1.154       dsl (const struct sigaction *, struct sigvec *);
   1073       1.95        pk 
   1074       1.50  christos 	if (SCARG(uap, nsv)) {
   1075       1.95        pk 		error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv));
   1076       1.95        pk 		if (error != 0)
   1077       1.50  christos 			return (error);
   1078       1.95        pk 
   1079       1.50  christos 		/*
   1080       1.53       gwr 		 * SunOS uses the mask 0x0004 as SV_RESETHAND
   1081       1.53       gwr 		 * meaning: `reset to SIG_DFL on delivery'.
   1082       1.53       gwr 		 * We support only the bits in: 0xF
   1083       1.53       gwr 		 * (those bits are the same as ours)
   1084       1.50  christos 		 */
   1085       1.95        pk 		if (nsv.sv_flags & ~0xF)
   1086       1.53       gwr 			return (EINVAL);
   1087       1.95        pk 
   1088       1.95        pk 		compat_43_sigvec_to_sigaction(&nsv, &nsa);
   1089       1.95        pk 	}
   1090      1.144        ad 	error = sigaction1(l, SCARG(uap, signum),
   1091       1.95        pk 			   SCARG(uap, nsv) ? &nsa : 0,
   1092      1.115   thorpej 			   SCARG(uap, osv) ? &osa : 0,
   1093      1.115   thorpej 			   NULL, 0);
   1094       1.95        pk 	if (error != 0)
   1095       1.95        pk 		return (error);
   1096       1.95        pk 
   1097       1.95        pk 	if (SCARG(uap, osv)) {
   1098       1.95        pk 		compat_43_sigaction_to_sigvec(&osa, &osv);
   1099       1.96        pk 		error = copyout(&osv, SCARG(uap, osv), sizeof(osv));
   1100       1.95        pk 		if (error != 0)
   1101       1.95        pk 			return (error);
   1102       1.50  christos 	}
   1103       1.95        pk 
   1104       1.50  christos 	return (0);
   1105        1.1   deraadt }
   1106