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