Home | History | Annotate | Line # | Download | only in ultrix
ultrix_misc.c revision 1.104
      1  1.104  christos /*	$NetBSD: ultrix_misc.c,v 1.104 2005/12/11 12:20:30 christos Exp $	*/
      2    1.5       cgd 
      3    1.1     glass /*
      4   1.30  jonathan  * Copyright (c) 1995, 1997 Jonathan Stone (hereinafter referred to as the author)
      5   1.30  jonathan  * All rights reserved.
      6   1.23  jonathan  *
      7   1.23  jonathan  * Redistribution and use in source and binary forms, with or without
      8   1.23  jonathan  * modification, are permitted provided that the following conditions
      9   1.23  jonathan  * are met:
     10   1.23  jonathan  * 1. Redistributions of source code must retain the above copyright
     11   1.23  jonathan  *    notice, this list of conditions and the following disclaimer.
     12   1.23  jonathan  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.23  jonathan  *    notice, this list of conditions and the following disclaimer in the
     14   1.23  jonathan  *    documentation and/or other materials provided with the distribution.
     15   1.28  jonathan  * 3. All advertising materials mentioning features or use of this software
     16   1.28  jonathan  *    must display the following acknowledgement:
     17   1.37  jonathan  *      This product includes software developed by Jonathan Stone for
     18   1.28  jonathan  *      the NetBSD Project.
     19   1.28  jonathan  * 4. The name of the author may not be used to endorse or promote products
     20   1.23  jonathan  *    derived from this software without specific prior written permission.
     21   1.23  jonathan  *
     22   1.23  jonathan  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
     23   1.23  jonathan  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24   1.23  jonathan  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25   1.23  jonathan  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
     26   1.23  jonathan  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27   1.23  jonathan  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28   1.23  jonathan  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29   1.23  jonathan  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30   1.23  jonathan  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31   1.23  jonathan  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32   1.23  jonathan  * SUCH DAMAGE.
     33   1.23  jonathan  */
     34   1.23  jonathan 
     35   1.23  jonathan /*
     36    1.1     glass  * Copyright (c) 1992, 1993
     37    1.1     glass  *	The Regents of the University of California.  All rights reserved.
     38    1.1     glass  *
     39    1.1     glass  * This software was developed by the Computer Systems Engineering group
     40    1.1     glass  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     41    1.1     glass  * contributed to Berkeley.
     42    1.1     glass  *
     43    1.1     glass  * All advertising materials mentioning features or use of this software
     44    1.1     glass  * must display the following acknowledgement:
     45    1.1     glass  *	This product includes software developed by the University of
     46    1.1     glass  *	California, Lawrence Berkeley Laboratory.
     47    1.1     glass  *
     48    1.1     glass  * Redistribution and use in source and binary forms, with or without
     49    1.1     glass  * modification, are permitted provided that the following conditions
     50    1.1     glass  * are met:
     51    1.1     glass  * 1. Redistributions of source code must retain the above copyright
     52    1.1     glass  *    notice, this list of conditions and the following disclaimer.
     53    1.1     glass  * 2. Redistributions in binary form must reproduce the above copyright
     54    1.1     glass  *    notice, this list of conditions and the following disclaimer in the
     55    1.1     glass  *    documentation and/or other materials provided with the distribution.
     56   1.86       agc  * 3. Neither the name of the University nor the names of its contributors
     57    1.1     glass  *    may be used to endorse or promote products derived from this software
     58    1.1     glass  *    without specific prior written permission.
     59    1.1     glass  *
     60    1.1     glass  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     61    1.1     glass  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     62    1.1     glass  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     63    1.1     glass  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     64    1.1     glass  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     65    1.1     glass  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     66    1.1     glass  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     67    1.1     glass  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     68    1.1     glass  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     69    1.1     glass  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     70    1.1     glass  * SUCH DAMAGE.
     71    1.1     glass  *
     72    1.5       cgd  *
     73    1.1     glass  *	@(#)sun_misc.c	8.1 (Berkeley) 6/18/93
     74    1.1     glass  *
     75   1.98     perry  * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
     76    1.1     glass  */
     77   1.74     lukem 
     78   1.74     lukem #include <sys/cdefs.h>
     79  1.104  christos __KERNEL_RCSID(0, "$NetBSD: ultrix_misc.c,v 1.104 2005/12/11 12:20:30 christos Exp $");
     80    1.1     glass 
     81   1.69       mrg #if defined(_KERNEL_OPT)
     82   1.40    mhitch #include "opt_nfsserver.h"
     83   1.47      tron #include "opt_sysv.h"
     84   1.63  jdolecek #endif
     85   1.40    mhitch 
     86   1.38  jonathan #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
     87   1.38  jonathan 
     88    1.1     glass /*
     89   1.49  sommerfe  * Ultrix compatibility module.
     90    1.1     glass  *
     91   1.49  sommerfe  * Ultrix system calls that are implemented differently in BSD are
     92    1.1     glass  * handled here.
     93    1.1     glass  */
     94   1.39   thorpej 
     95   1.69       mrg #if defined(_KERNEL_OPT)
     96   1.39   thorpej #include "fs_nfs.h"
     97   1.63  jdolecek #endif
     98    1.1     glass 
     99    1.1     glass #include <sys/param.h>
    100    1.1     glass #include <sys/systm.h>
    101    1.1     glass #include <sys/namei.h>
    102   1.25   mycroft #include <sys/dirent.h>
    103    1.1     glass #include <sys/proc.h>
    104    1.1     glass #include <sys/file.h>
    105    1.1     glass #include <sys/filedesc.h>
    106    1.1     glass #include <sys/kernel.h>
    107    1.1     glass #include <sys/exec.h>
    108    1.1     glass #include <sys/malloc.h>
    109    1.1     glass #include <sys/mbuf.h>
    110    1.1     glass #include <sys/mman.h>
    111    1.1     glass #include <sys/mount.h>
    112    1.1     glass #include <sys/resource.h>
    113    1.1     glass #include <sys/resourcevar.h>
    114    1.1     glass #include <sys/signal.h>
    115    1.1     glass #include <sys/signalvar.h>
    116    1.1     glass #include <sys/socket.h>
    117    1.1     glass #include <sys/vnode.h>
    118    1.1     glass #include <sys/uio.h>
    119    1.1     glass #include <sys/wait.h>
    120    1.1     glass #include <sys/utsname.h>
    121    1.1     glass #include <sys/unistd.h>
    122   1.30  jonathan #include <sys/ipc.h>
    123   1.20  jonathan 
    124   1.81   thorpej #include <sys/sa.h>
    125   1.16   mycroft #include <sys/syscallargs.h>
    126   1.16   mycroft 
    127   1.99      fvdl #include <uvm/uvm_extern.h>
    128   1.99      fvdl 
    129   1.16   mycroft #include <compat/ultrix/ultrix_syscall.h>
    130   1.16   mycroft #include <compat/ultrix/ultrix_syscallargs.h>
    131   1.30  jonathan #include <compat/common/compat_util.h>
    132    1.1     glass 
    133    1.1     glass #include <netinet/in.h>
    134    1.1     glass 
    135    1.1     glass #include <miscfs/specfs/specdev.h>
    136    1.1     glass 
    137    1.3     glass #include <nfs/rpcv2.h>
    138   1.21        pk #include <nfs/nfsproto.h>
    139    1.3     glass #include <nfs/nfs.h>
    140   1.11  christos 
    141   1.23  jonathan #include <sys/socketvar.h>				/* sosetopt() */
    142   1.23  jonathan 
    143   1.52  drochner #include <compat/ultrix/ultrix_flock.h>
    144   1.67    simonb 
    145  1.103  christos #include <compat/sys/signal.h>
    146  1.103  christos #include <compat/sys/signalvar.h>
    147  1.103  christos 
    148   1.67    simonb #ifdef __mips
    149   1.67    simonb #include <mips/cachectl.h>
    150   1.96  drochner #include <mips/frame.h>
    151   1.67    simonb #endif
    152   1.52  drochner 
    153   1.93    simonb static int ultrix_to_bsd_flock(struct ultrix_flock *, struct flock *);
    154   1.93    simonb static void bsd_to_ultrix_flock(struct flock *, struct ultrix_flock *);
    155   1.35  jonathan 
    156   1.11  christos extern struct sysent ultrix_sysent[];
    157   1.60    simonb extern const char * const ultrix_syscallnames[];
    158   1.45  drochner extern char ultrix_sigcode[], ultrix_esigcode[];
    159   1.19  jonathan 
    160   1.87       chs struct uvm_object *emul_ultrix_object;
    161   1.87       chs 
    162  1.101  christos #ifndef __HAVE_SYSCALL_INTERN
    163  1.101  christos void	syscall(void);
    164  1.101  christos #endif
    165  1.101  christos 
    166   1.61  jdolecek const struct emul emul_ultrix = {
    167   1.11  christos 	"ultrix",
    168   1.62  jdolecek 	"/emul/ultrix",
    169   1.68   thorpej #ifndef __HAVE_MINIMAL_EMUL
    170   1.66  jdolecek 	0,
    171   1.11  christos 	NULL,
    172   1.11  christos 	ULTRIX_SYS_syscall,
    173   1.80  jdolecek 	ULTRIX_SYS_NSYSENT,
    174   1.68   thorpej #endif
    175   1.11  christos 	ultrix_sysent,
    176   1.11  christos 	ultrix_syscallnames,
    177   1.97  drochner #ifdef __mips
    178   1.96  drochner 	sendsig_sigcontext,
    179   1.97  drochner #else /* vax */
    180   1.97  drochner 	sendsig,
    181   1.97  drochner #endif
    182   1.71  christos 	trapsignal,
    183   1.92      fvdl 	NULL,
    184   1.45  drochner 	ultrix_sigcode,
    185   1.45  drochner 	ultrix_esigcode,
    186   1.87       chs 	&emul_ultrix_object,
    187   1.73  jdolecek 	setregs,
    188   1.64  jdolecek 	NULL,
    189   1.64  jdolecek 	NULL,
    190   1.64  jdolecek 	NULL,
    191   1.91      manu 	NULL,
    192   1.91      manu 	NULL,
    193   1.68   thorpej #ifdef __HAVE_SYSCALL_INTERN
    194   1.68   thorpej 	syscall_intern,
    195   1.68   thorpej #else
    196   1.68   thorpej 	syscall,
    197   1.68   thorpej #endif
    198   1.79      manu 	NULL,
    199   1.79      manu 	NULL,
    200   1.99      fvdl 
    201   1.99      fvdl 	uvm_default_mapaddr,
    202   1.11  christos };
    203    1.1     glass 
    204    1.6     glass #define GSI_PROG_ENV 1
    205    1.6     glass 
    206   1.23  jonathan int
    207   1.93    simonb ultrix_sys_getsysinfo(struct lwp *l, void *v, register_t *retval)
    208    1.6     glass {
    209   1.16   mycroft 	struct ultrix_sys_getsysinfo_args *uap = v;
    210    1.6     glass 	static short progenv = 0;
    211    1.6     glass 
    212   1.16   mycroft 	switch (SCARG(uap, op)) {
    213    1.6     glass 		/* operations implemented: */
    214    1.6     glass 	case GSI_PROG_ENV:
    215   1.16   mycroft 		if (SCARG(uap, nbytes) < sizeof(short))
    216    1.6     glass 			return EINVAL;
    217    1.6     glass 		*retval = 1;
    218   1.16   mycroft 		return (copyout(&progenv, SCARG(uap, buffer), sizeof(short)));
    219    1.6     glass 	default:
    220    1.6     glass 		*retval = 0; /* info unavail */
    221    1.6     glass 		return 0;
    222    1.6     glass 	}
    223    1.6     glass }
    224    1.6     glass 
    225   1.23  jonathan int
    226   1.93    simonb ultrix_sys_setsysinfo(struct lwp *l, void *v, register_t *retval)
    227    1.6     glass {
    228   1.23  jonathan 
    229   1.23  jonathan #ifdef notyet
    230   1.16   mycroft 	struct ultrix_sys_setsysinfo_args *uap = v;
    231   1.23  jonathan #endif
    232   1.23  jonathan 
    233    1.6     glass 	*retval = 0;
    234    1.6     glass 	return 0;
    235    1.6     glass }
    236    1.6     glass 
    237   1.23  jonathan int
    238   1.93    simonb ultrix_sys_waitpid(struct lwp *l, void *v, register_t *retval)
    239    1.1     glass {
    240   1.16   mycroft 	struct ultrix_sys_waitpid_args *uap = v;
    241   1.16   mycroft 	struct sys_wait4_args ua;
    242    1.1     glass 
    243   1.16   mycroft 	SCARG(&ua, pid) = SCARG(uap, pid);
    244   1.16   mycroft 	SCARG(&ua, status) = SCARG(uap, status);
    245   1.16   mycroft 	SCARG(&ua, options) = SCARG(uap, options);
    246   1.16   mycroft 	SCARG(&ua, rusage) = 0;
    247    1.1     glass 
    248   1.81   thorpej 	return (sys_wait4(l, &ua, retval));
    249    1.2     glass }
    250    1.2     glass 
    251   1.23  jonathan int
    252   1.93    simonb ultrix_sys_wait3(struct lwp *l, void *v, register_t *retval)
    253    1.2     glass {
    254   1.16   mycroft 	struct ultrix_sys_wait3_args *uap = v;
    255   1.16   mycroft 	struct sys_wait4_args ua;
    256    1.2     glass 
    257   1.16   mycroft 	SCARG(&ua, pid) = -1;
    258   1.16   mycroft 	SCARG(&ua, status) = SCARG(uap, status);
    259   1.16   mycroft 	SCARG(&ua, options) = SCARG(uap, options);
    260   1.16   mycroft 	SCARG(&ua, rusage) = SCARG(uap, rusage);
    261    1.1     glass 
    262   1.81   thorpej 	return (sys_wait4(l, &ua, retval));
    263    1.1     glass }
    264    1.1     glass 
    265   1.20  jonathan /*
    266   1.20  jonathan  * Ultrix binaries pass in FD_MAX as the first arg to select().
    267   1.23  jonathan  * On Ultrix, FD_MAX is 4096, which is more than the NetBSD sys_select()
    268   1.20  jonathan  * can handle.
    269   1.98     perry  * Since we can't have more than the (native) FD_MAX descriptors open,
    270   1.23  jonathan  * limit nfds to at most FD_MAX.
    271   1.20  jonathan  */
    272   1.23  jonathan int
    273   1.93    simonb ultrix_sys_select(struct lwp *l, void *v, register_t *retval)
    274   1.18  jonathan {
    275   1.18  jonathan 	struct sys_select_args *uap = v;
    276   1.23  jonathan 	struct timeval atv;
    277   1.18  jonathan 	int error;
    278   1.18  jonathan 
    279   1.18  jonathan 	/* Limit number of FDs selected on to the native maximum */
    280   1.18  jonathan 
    281   1.18  jonathan 	if (SCARG(uap, nd) > FD_SETSIZE)
    282   1.18  jonathan 		SCARG(uap, nd) = FD_SETSIZE;
    283   1.18  jonathan 
    284   1.18  jonathan 	/* Check for negative timeval */
    285   1.18  jonathan 	if (SCARG(uap, tv)) {
    286   1.18  jonathan 		error = copyin((caddr_t)SCARG(uap, tv), (caddr_t)&atv,
    287   1.18  jonathan 			       sizeof(atv));
    288   1.18  jonathan 		if (error)
    289   1.18  jonathan 			goto done;
    290   1.18  jonathan #ifdef DEBUG
    291   1.18  jonathan 		/* Ultrix clients sometimes give negative timeouts? */
    292   1.18  jonathan 		if (atv.tv_sec < 0 || atv.tv_usec < 0)
    293   1.27  christos 			printf("ultrix select( %ld, %ld): negative timeout\n",
    294   1.26  christos 			    atv.tv_sec, atv.tv_usec);
    295   1.18  jonathan #endif
    296   1.18  jonathan 
    297   1.18  jonathan 	}
    298   1.81   thorpej 	error = sys_select(l, (void*) uap, retval);
    299   1.18  jonathan 	if (error == EINVAL)
    300   1.27  christos 		printf("ultrix select: bad args?\n");
    301   1.18  jonathan 
    302   1.18  jonathan done:
    303   1.18  jonathan 	return error;
    304    1.1     glass }
    305    1.1     glass 
    306   1.29   thorpej #if defined(NFS)
    307   1.23  jonathan int
    308   1.93    simonb async_daemon(struct lwp *l, void *v, register_t *retval)
    309    1.1     glass {
    310   1.16   mycroft 	struct sys_nfssvc_args ouap;
    311    1.1     glass 
    312   1.16   mycroft 	SCARG(&ouap, flag) = NFSSVC_BIOD;
    313   1.16   mycroft 	SCARG(&ouap, argp) = NULL;
    314    1.3     glass 
    315   1.81   thorpej 	return (sys_nfssvc(l, &ouap, retval));
    316    1.3     glass }
    317   1.29   thorpej #endif /* NFS */
    318    1.3     glass 
    319    1.1     glass 
    320    1.1     glass #define	SUN__MAP_NEW	0x80000000	/* if not, old mmap & cannot handle */
    321    1.1     glass 
    322   1.20  jonathan int
    323   1.93    simonb ultrix_sys_mmap(struct lwp *l, void *v, register_t *retval)
    324    1.1     glass {
    325   1.56  augustss 	struct ultrix_sys_mmap_args *uap = v;
    326   1.16   mycroft 	struct sys_mmap_args ouap;
    327    1.1     glass 
    328    1.1     glass 	/*
    329    1.1     glass 	 * Verify the arguments.
    330    1.1     glass 	 */
    331   1.16   mycroft 	if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
    332    1.1     glass 		return (EINVAL);			/* XXX still needed? */
    333    1.1     glass 
    334   1.16   mycroft 	if ((SCARG(uap, flags) & SUN__MAP_NEW) == 0)
    335    1.1     glass 		return (EINVAL);
    336    1.1     glass 
    337   1.16   mycroft 	SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUN__MAP_NEW;
    338   1.16   mycroft 	SCARG(&ouap, addr) = SCARG(uap, addr);
    339   1.16   mycroft 	SCARG(&ouap, len) = SCARG(uap, len);
    340   1.16   mycroft 	SCARG(&ouap, prot) = SCARG(uap, prot);
    341   1.16   mycroft 	SCARG(&ouap, fd) = SCARG(uap, fd);
    342   1.16   mycroft 	SCARG(&ouap, pos) = SCARG(uap, pos);
    343    1.1     glass 
    344   1.81   thorpej 	return (sys_mmap(l, &ouap, retval));
    345    1.1     glass }
    346    1.1     glass 
    347   1.23  jonathan int
    348   1.93    simonb ultrix_sys_setsockopt(struct lwp *l, void *v, register_t *retval)
    349    1.1     glass {
    350   1.56  augustss 	struct ultrix_sys_setsockopt_args *uap = v;
    351   1.81   thorpej 	struct proc *p = l->l_proc;
    352    1.1     glass 	struct file *fp;
    353    1.1     glass 	struct mbuf *m = NULL;
    354    1.1     glass 	int error;
    355    1.1     glass 
    356   1.51   thorpej 	/* getsock() will use the descriptor for us */
    357   1.23  jonathan 	if ((error = getsock(p->p_fd, SCARG(uap, s), &fp))  != 0)
    358    1.1     glass 		return (error);
    359    1.1     glass #define	SO_DONTLINGER (~SO_LINGER)
    360   1.16   mycroft 	if (SCARG(uap, name) == SO_DONTLINGER) {
    361    1.1     glass 		m = m_get(M_WAIT, MT_SOOPTS);
    362    1.1     glass 		mtod(m, struct linger *)->l_onoff = 0;
    363    1.1     glass 		m->m_len = sizeof(struct linger);
    364   1.51   thorpej 		error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
    365   1.51   thorpej 		    SO_LINGER, m);
    366    1.1     glass 	}
    367   1.30  jonathan 	if (SCARG(uap, level) == IPPROTO_IP) {
    368   1.30  jonathan #define		EMUL_IP_MULTICAST_IF		2
    369   1.30  jonathan #define		EMUL_IP_MULTICAST_TTL		3
    370   1.30  jonathan #define		EMUL_IP_MULTICAST_LOOP		4
    371   1.30  jonathan #define		EMUL_IP_ADD_MEMBERSHIP		5
    372   1.30  jonathan #define		EMUL_IP_DROP_MEMBERSHIP	6
    373   1.94      matt 		static const int ipoptxlat[] = {
    374   1.30  jonathan 			IP_MULTICAST_IF,
    375   1.30  jonathan 			IP_MULTICAST_TTL,
    376   1.30  jonathan 			IP_MULTICAST_LOOP,
    377   1.30  jonathan 			IP_ADD_MEMBERSHIP,
    378   1.30  jonathan 			IP_DROP_MEMBERSHIP
    379   1.30  jonathan 		};
    380   1.30  jonathan 		if (SCARG(uap, name) >= EMUL_IP_MULTICAST_IF &&
    381   1.30  jonathan 		    SCARG(uap, name) <= EMUL_IP_DROP_MEMBERSHIP) {
    382   1.30  jonathan 			SCARG(uap, name) =
    383   1.30  jonathan 			    ipoptxlat[SCARG(uap, name) - EMUL_IP_MULTICAST_IF];
    384   1.30  jonathan 		}
    385   1.30  jonathan 	}
    386   1.51   thorpej 	if (SCARG(uap, valsize) > MLEN) {
    387   1.51   thorpej 		error = EINVAL;
    388   1.51   thorpej 		goto out;
    389   1.51   thorpej 	}
    390   1.16   mycroft 	if (SCARG(uap, val)) {
    391    1.1     glass 		m = m_get(M_WAIT, MT_SOOPTS);
    392   1.30  jonathan 		error = copyin(SCARG(uap, val), mtod(m, caddr_t),
    393   1.30  jonathan 		    (u_int)SCARG(uap, valsize));
    394   1.30  jonathan 		if (error) {
    395    1.1     glass 			(void) m_free(m);
    396   1.51   thorpej 			goto out;
    397    1.1     glass 		}
    398   1.16   mycroft 		m->m_len = SCARG(uap, valsize);
    399    1.1     glass 	}
    400   1.51   thorpej 	error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
    401   1.51   thorpej 	    SCARG(uap, name), m);
    402   1.51   thorpej  out:
    403  1.104  christos 	FILE_UNUSE(fp, l);
    404   1.51   thorpej 	return (error);
    405    1.1     glass }
    406    1.1     glass 
    407   1.57    simonb #define	ULTRIX__SYS_NMLN	32
    408   1.57    simonb 
    409   1.16   mycroft struct ultrix_utsname {
    410   1.57    simonb 	char    sysname[ULTRIX__SYS_NMLN];
    411   1.57    simonb 	char    nodename[ULTRIX__SYS_NMLN];
    412   1.57    simonb 	char    release[ULTRIX__SYS_NMLN];
    413   1.57    simonb 	char    version[ULTRIX__SYS_NMLN];
    414   1.57    simonb 	char    machine[ULTRIX__SYS_NMLN];
    415    1.1     glass };
    416    1.1     glass 
    417   1.20  jonathan int
    418   1.93    simonb ultrix_sys_uname(struct lwp *l, void *v, register_t *retval)
    419    1.1     glass {
    420   1.16   mycroft 	struct ultrix_sys_uname_args *uap = v;
    421   1.16   mycroft 	struct ultrix_utsname sut;
    422   1.59  nisimura 	const char *cp;
    423   1.59  nisimura 	char *dp, *ep;
    424    1.1     glass 
    425   1.41     perry 	memset(&sut, 0, sizeof(sut));
    426    1.1     glass 
    427   1.57    simonb 	strncpy(sut.sysname, ostype, sizeof(sut.sysname) - 1);
    428   1.57    simonb 	strncpy(sut.nodename, hostname, sizeof(sut.nodename) - 1);
    429   1.57    simonb 	strncpy(sut.release, osrelease, sizeof(sut.release) - 1);
    430   1.59  nisimura 	dp = sut.version;
    431   1.59  nisimura 	ep = &sut.version[sizeof(sut.version) - 1];
    432   1.59  nisimura 	for (cp = version; *cp && *cp != '('; cp++)
    433   1.59  nisimura 		;
    434   1.59  nisimura 	for (cp++; *cp && *cp != ')' && dp < ep; cp++)
    435   1.59  nisimura 		*dp++ = *cp;
    436   1.59  nisimura 	for (; *cp && *cp != '#'; cp++)
    437   1.59  nisimura 		;
    438   1.59  nisimura 	for (; *cp && *cp != ':' && dp < ep; cp++)
    439   1.59  nisimura 		*dp++ = *cp;
    440   1.59  nisimura 	*dp = '\0';
    441   1.57    simonb 	strncpy(sut.machine, machine, sizeof(sut.machine) - 1);
    442    1.1     glass 
    443   1.16   mycroft 	return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
    444   1.16   mycroft 	    sizeof(struct ultrix_utsname));
    445    1.1     glass }
    446    1.1     glass 
    447    1.1     glass int
    448   1.93    simonb ultrix_sys_setpgrp(struct lwp *l, void *v, register_t *retval)
    449    1.1     glass {
    450   1.16   mycroft 	struct ultrix_sys_setpgrp_args *uap = v;
    451   1.81   thorpej 	struct proc *p = l->l_proc;
    452   1.15   thorpej 
    453    1.1     glass 	/*
    454    1.1     glass 	 * difference to our setpgid call is to include backwards
    455    1.1     glass 	 * compatibility to pre-setsid() binaries. Do setsid()
    456    1.1     glass 	 * instead of setpgid() in those cases where the process
    457    1.1     glass 	 * tries to create a new session the old way.
    458    1.1     glass 	 */
    459   1.16   mycroft 	if (!SCARG(uap, pgid) &&
    460   1.16   mycroft 	    (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
    461   1.81   thorpej 		return sys_setsid(l, uap, retval);
    462    1.1     glass 	else
    463   1.81   thorpej 		return sys_setpgid(l, uap, retval);
    464    1.1     glass }
    465    1.1     glass 
    466    1.1     glass #if defined (NFSSERVER)
    467   1.20  jonathan int
    468   1.93    simonb ultrix_sys_nfssvc(struct lwp *l, void *v, register_t *retval)
    469    1.1     glass {
    470   1.23  jonathan 
    471   1.23  jonathan #if 0	/* XXX */
    472   1.16   mycroft 	struct ultrix_sys_nfssvc_args *uap = v;
    473   1.16   mycroft 	struct emul *e = p->p_emul;
    474   1.16   mycroft 	struct sys_nfssvc_args outuap;
    475    1.1     glass 	struct sockaddr sa;
    476    1.1     glass 	int error;
    477   1.76  christos 	caddr_t sg = stackgap_init(p, 0);
    478    1.1     glass 
    479   1.41     perry 	memset(&outuap, 0, sizeof outuap);
    480   1.16   mycroft 	SCARG(&outuap, fd) = SCARG(uap, fd);
    481   1.76  christos 	SCARG(&outuap, mskval) = stackgap_alloc(p, &sg, sizeof sa);
    482   1.16   mycroft 	SCARG(&outuap, msklen) = sizeof sa;
    483   1.76  christos 	SCARG(&outuap, mtchval) = stackgap_alloc(p, &sg, sizeof sa);
    484   1.16   mycroft 	SCARG(&outuap, mtchlen) = sizeof sa;
    485    1.1     glass 
    486   1.41     perry 	memset(&sa, 0, sizeof sa);
    487   1.16   mycroft 	if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
    488    1.1     glass 		return (error);
    489   1.16   mycroft 	if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
    490    1.1     glass 		return (error);
    491    1.1     glass 
    492   1.81   thorpej 	return nfssvc(l, &outuap, retval);
    493   1.16   mycroft #else
    494   1.16   mycroft 	return (ENOSYS);
    495   1.16   mycroft #endif
    496    1.1     glass }
    497    1.1     glass #endif /* NFSSERVER */
    498    1.1     glass 
    499   1.16   mycroft struct ultrix_ustat {
    500    1.1     glass 	daddr_t	f_tfree;	/* total free */
    501  1.102  christos 	uint32_t f_tinode;	/* total inodes free */
    502    1.1     glass 	char	f_fname[6];	/* filsys name */
    503    1.1     glass 	char	f_fpack[6];	/* filsys pack name */
    504    1.1     glass };
    505   1.16   mycroft 
    506   1.20  jonathan int
    507   1.93    simonb ultrix_sys_ustat(struct lwp *l, void *v, register_t *retval)
    508    1.1     glass {
    509   1.16   mycroft 	struct ultrix_sys_ustat_args *uap = v;
    510   1.16   mycroft 	struct ultrix_ustat us;
    511    1.1     glass 	int error;
    512    1.1     glass 
    513   1.41     perry 	memset(&us, 0, sizeof us);
    514    1.1     glass 
    515    1.1     glass 	/*
    516    1.1     glass 	 * XXX: should set f_tfree and f_tinode at least
    517   1.16   mycroft 	 * How do we translate dev -> fstat? (and then to ultrix_ustat)
    518    1.1     glass 	 */
    519    1.1     glass 
    520   1.23  jonathan 	if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0)
    521    1.1     glass 		return (error);
    522    1.1     glass 	return 0;
    523    1.1     glass }
    524    1.1     glass 
    525   1.20  jonathan int
    526   1.93    simonb ultrix_sys_quotactl(struct lwp *l, void *v, register_t *retval)
    527    1.1     glass {
    528   1.23  jonathan 
    529   1.23  jonathan #ifdef notyet
    530   1.16   mycroft 	struct ultrix_sys_quotactl_args *uap = v;
    531   1.23  jonathan #endif
    532   1.15   thorpej 
    533    1.1     glass 	return EINVAL;
    534    1.1     glass }
    535    1.1     glass 
    536   1.20  jonathan int
    537   1.93    simonb ultrix_sys_vhangup(struct lwp *l, void *v, register_t *retval)
    538    1.1     glass {
    539   1.16   mycroft 
    540    1.1     glass 	return 0;
    541    1.1     glass }
    542   1.35  jonathan 
    543   1.35  jonathan 
    544   1.35  jonathan /*
    545   1.35  jonathan  * RISC Ultrix cache control syscalls
    546   1.35  jonathan  */
    547   1.35  jonathan #ifdef __mips
    548   1.35  jonathan int
    549   1.93    simonb ultrix_sys_cacheflush(struct lwp *l, void *v, register_t *retval)
    550   1.35  jonathan {
    551   1.56  augustss 	struct ultrix_sys_cacheflush_args /* {
    552   1.35  jonathan 		syscallarg(void *) addr;
    553   1.95     david 		syscallarg(unsigned) nbytes;
    554   1.35  jonathan 		syscallarg(int) flag;
    555   1.35  jonathan 	} */ *uap = v;
    556   1.81   thorpej 	struct proc *p = l->l_proc;
    557   1.56  augustss 	vaddr_t va  = (vaddr_t)SCARG(uap, addr);
    558   1.56  augustss 	int nbytes     = SCARG(uap, nbytes);
    559   1.56  augustss 	int whichcache = SCARG(uap, whichcache);
    560   1.35  jonathan 
    561   1.35  jonathan 	return (mips_user_cacheflush(p, va, nbytes, whichcache));
    562   1.35  jonathan }
    563   1.35  jonathan 
    564   1.35  jonathan 
    565   1.35  jonathan int
    566   1.93    simonb ultrix_sys_cachectl(struct lwp *l, void *v, register_t *retval)
    567   1.35  jonathan {
    568   1.56  augustss 	struct ultrix_sys_cachectl_args /* {
    569   1.35  jonathan 		syscallarg(void *) addr;
    570   1.35  jonathan 		syscallarg(int) nbytes;
    571   1.35  jonathan 		syscallarg(int) cacheop;
    572   1.35  jonathan 	} */ *uap = v;
    573   1.81   thorpej 	struct proc *p = l->l_proc;
    574   1.56  augustss 	vaddr_t va  = (vaddr_t)SCARG(uap, addr);
    575   1.56  augustss 	int nbytes  = SCARG(uap, nbytes);
    576   1.56  augustss 	int cacheop = SCARG(uap, cacheop);
    577   1.35  jonathan 
    578   1.35  jonathan 	return mips_user_cachectl(p, va, nbytes, cacheop);
    579   1.35  jonathan }
    580   1.35  jonathan 
    581   1.35  jonathan #endif	/* __mips */
    582   1.35  jonathan 
    583    1.1     glass 
    584   1.20  jonathan int
    585   1.93    simonb ultrix_sys_exportfs(struct lwp *l, void *v, register_t *retval)
    586    1.1     glass {
    587   1.23  jonathan #ifdef notyet
    588   1.16   mycroft 	struct ultrix_sys_exportfs_args *uap = v;
    589   1.23  jonathan #endif
    590   1.15   thorpej 
    591    1.1     glass 	/*
    592    1.1     glass 	 * XXX: should perhaps translate into a mount(2)
    593    1.1     glass 	 * with MOUNT_EXPORT?
    594    1.1     glass 	 */
    595    1.1     glass 	return 0;
    596    1.1     glass }
    597    1.1     glass 
    598   1.16   mycroft int
    599   1.93    simonb ultrix_sys_sigpending(struct lwp *l, void *v, register_t *retval)
    600   1.19  jonathan {
    601   1.19  jonathan 	struct ultrix_sys_sigpending_args *uap = v;
    602   1.43  drochner 	sigset_t ss;
    603   1.43  drochner 	int mask;
    604   1.43  drochner 
    605   1.81   thorpej 	sigpending1(l->l_proc, &ss);
    606   1.43  drochner 	mask = ss.__bits[0];
    607   1.19  jonathan 
    608   1.19  jonathan 	return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int)));
    609   1.19  jonathan }
    610   1.19  jonathan 
    611   1.19  jonathan int
    612   1.93    simonb ultrix_sys_sigreturn(struct lwp *l, void *v, register_t *retval)
    613   1.44  drochner {
    614   1.44  drochner 	struct ultrix_sys_sigreturn_args *uap = v;
    615   1.44  drochner 
    616   1.45  drochner 	/* struct sigcontext13 is close enough to Ultrix */
    617   1.45  drochner 
    618   1.81   thorpej 	return (compat_13_sys_sigreturn(l, uap, retval));
    619   1.44  drochner }
    620   1.44  drochner 
    621   1.44  drochner int
    622   1.93    simonb ultrix_sys_sigcleanup(struct lwp *l, void *v, register_t *retval)
    623   1.13    mellon {
    624   1.16   mycroft 	struct ultrix_sys_sigcleanup_args *uap = v;
    625   1.15   thorpej 
    626   1.45  drochner 	/* struct sigcontext13 is close enough to Ultrix */
    627   1.45  drochner 
    628   1.81   thorpej 	return (compat_13_sys_sigreturn(l, uap, retval));
    629   1.44  drochner }
    630   1.44  drochner 
    631   1.44  drochner int
    632   1.93    simonb ultrix_sys_sigsuspend(struct lwp *l, void *v, register_t *retval)
    633   1.44  drochner {
    634   1.44  drochner 	struct ultrix_sys_sigsuspend_args *uap = v;
    635   1.44  drochner 	int mask = SCARG(uap, mask);
    636   1.44  drochner 	sigset_t ss;
    637   1.44  drochner 
    638   1.44  drochner 	ss.__bits[0] = mask;
    639   1.44  drochner 	ss.__bits[1] = 0;
    640   1.44  drochner 	ss.__bits[2] = 0;
    641   1.44  drochner 	ss.__bits[3] = 0;
    642   1.44  drochner 
    643   1.81   thorpej 	return (sigsuspend1(l->l_proc, &ss));
    644   1.19  jonathan }
    645   1.19  jonathan 
    646   1.46  drochner #define ULTRIX_SV_ONSTACK 0x0001  /* take signal on signal stack */
    647   1.46  drochner #define ULTRIX_SV_INTERRUPT 0x0002  /* do not restart system on signal return */
    648   1.46  drochner #define ULTRIX_SV_OLDSIG 0x1000  /* Emulate old signal() for POSIX */
    649   1.46  drochner 
    650   1.46  drochner int
    651   1.93    simonb ultrix_sys_sigvec(struct lwp *l, void *v, register_t *retval)
    652   1.46  drochner {
    653   1.46  drochner 	struct ultrix_sys_sigvec_args *uap = v;
    654   1.46  drochner 	struct sigvec nsv, osv;
    655   1.46  drochner 	struct sigaction nsa, osa;
    656   1.46  drochner 	int error;
    657   1.46  drochner 
    658   1.46  drochner 	if (SCARG(uap, nsv)) {
    659   1.46  drochner 		error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv));
    660   1.46  drochner 		if (error)
    661   1.46  drochner 			return (error);
    662   1.46  drochner 		nsa.sa_handler = nsv.sv_handler;
    663   1.46  drochner #if 0 /* documentation */
    664   1.46  drochner 		/* ONSTACK is identical */
    665   1.46  drochner 		nsa.sa_flags = nsv.sv_flags & ULTRIX_SV_ONSTACK;
    666   1.46  drochner 		if ((nsv.sv_flags & ULTRIX_SV_OLDSIG)
    667   1.46  drochner 		    /* old signal() - always restart */
    668   1.46  drochner 		    || (!(nsv.sv_flags & ULTRIX_SV_INTERRUPT))
    669   1.46  drochner 		    /* inverted meaning (same bit) */
    670   1.46  drochner 		    )
    671   1.46  drochner 			nsa.sa_flags |= SA_RESTART;
    672   1.46  drochner #else /* optimized - assuming ULTRIX_SV_OLDSIG=>!ULTRIX_SV_INTERRUPT */
    673   1.46  drochner 		nsa.sa_flags = nsv.sv_flags & ~ULTRIX_SV_OLDSIG;
    674   1.46  drochner 		nsa.sa_flags ^= SA_RESTART;
    675   1.46  drochner #endif
    676   1.46  drochner 		native_sigset13_to_sigset(&nsv.sv_mask, &nsa.sa_mask);
    677   1.46  drochner 	}
    678   1.81   thorpej 	error = sigaction1(l->l_proc, SCARG(uap, signum),
    679   1.77   thorpej 	    SCARG(uap, nsv) ? &nsa : 0, SCARG(uap, osv) ? &osa : 0,
    680   1.77   thorpej 	    NULL, 0);
    681   1.46  drochner 	if (error)
    682   1.46  drochner 		return (error);
    683   1.46  drochner 	if (SCARG(uap, osv)) {
    684   1.46  drochner 		osv.sv_handler = osa.sa_handler;
    685   1.46  drochner 		osv.sv_flags = osa.sa_flags ^ SA_RESTART;
    686   1.46  drochner 		osv.sv_flags &= (ULTRIX_SV_ONSTACK | ULTRIX_SV_INTERRUPT);
    687   1.46  drochner 		native_sigset_to_sigset13(&osa.sa_mask, &osv.sv_mask);
    688   1.46  drochner 		error = copyout(&osv, SCARG(uap, osv), sizeof(osv));
    689   1.46  drochner 		if (error)
    690   1.46  drochner 			return (error);
    691   1.46  drochner 	}
    692   1.46  drochner 	return (0);
    693   1.46  drochner }
    694   1.30  jonathan 
    695   1.32  jonathan int
    696   1.93    simonb ultrix_sys_shmsys(struct lwp *l, void *v, register_t *retval)
    697   1.30  jonathan {
    698   1.30  jonathan 
    699   1.30  jonathan #ifdef SYSVSHM
    700   1.30  jonathan 	/* Ultrix SVSHM weirndess: */
    701   1.30  jonathan 	struct ultrix_sys_shmsys_args *uap = v;
    702   1.30  jonathan 	struct sys_shmat_args shmat_args;
    703   1.53   thorpej 	struct compat_14_sys_shmctl_args shmctl_args;
    704   1.30  jonathan 	struct sys_shmdt_args shmdt_args;
    705   1.30  jonathan 	struct sys_shmget_args shmget_args;
    706   1.30  jonathan 
    707   1.30  jonathan 
    708   1.30  jonathan 	switch (SCARG(uap, shmop)) {
    709   1.30  jonathan 	case 0:						/* Ultrix shmat() */
    710   1.30  jonathan 		SCARG(&shmat_args, shmid) = SCARG(uap, a2);
    711   1.30  jonathan 		SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a3);
    712   1.30  jonathan 		SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
    713   1.81   thorpej 		return (sys_shmat(l, &shmat_args, retval));
    714   1.30  jonathan 
    715   1.30  jonathan 	case 1:						/* Ultrix shmctl() */
    716   1.30  jonathan 		SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
    717   1.30  jonathan 		SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
    718   1.53   thorpej 		SCARG(&shmctl_args, buf) = (struct shmid_ds14 *)SCARG(uap, a4);
    719   1.81   thorpej 		return (compat_14_sys_shmctl(l, &shmctl_args, retval));
    720   1.30  jonathan 
    721   1.30  jonathan 	case 2:						/* Ultrix shmdt() */
    722   1.30  jonathan 		SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a2);
    723   1.81   thorpej 		return (sys_shmdt(l, &shmdt_args, retval));
    724   1.30  jonathan 
    725   1.30  jonathan 	case 3:						/* Ultrix shmget() */
    726   1.30  jonathan 		SCARG(&shmget_args, key) = SCARG(uap, a2);
    727   1.30  jonathan 		SCARG(&shmget_args, size) = SCARG(uap, a3);
    728   1.30  jonathan 		SCARG(&shmget_args, shmflg) = SCARG(uap, a4)
    729   1.30  jonathan 		    & (IPC_CREAT|IPC_EXCL|IPC_NOWAIT);
    730   1.81   thorpej 		return (sys_shmget(l, &shmget_args, retval));
    731   1.30  jonathan 
    732   1.30  jonathan 	default:
    733   1.30  jonathan 		return (EINVAL);
    734   1.30  jonathan 	}
    735   1.31  jonathan #else
    736   1.31  jonathan 	return (EOPNOTSUPP);
    737   1.30  jonathan #endif	/* SYSVSHM */
    738   1.52  drochner }
    739   1.52  drochner 
    740   1.52  drochner static int
    741   1.93    simonb ultrix_to_bsd_flock(struct ultrix_flock *ufl, struct flock *fl)
    742   1.52  drochner {
    743   1.52  drochner 
    744   1.52  drochner 	fl->l_start = ufl->l_start;
    745   1.52  drochner 	fl->l_len = ufl->l_len;
    746   1.52  drochner 	fl->l_pid = ufl->l_pid;
    747   1.52  drochner 	fl->l_whence = ufl->l_whence;
    748   1.52  drochner 
    749   1.52  drochner 	switch (ufl->l_type) {
    750   1.52  drochner 	case ULTRIX_F_RDLCK:
    751   1.52  drochner 		fl->l_type = F_RDLCK;
    752   1.52  drochner 		break;
    753   1.52  drochner 	case ULTRIX_F_WRLCK:
    754   1.52  drochner 		fl->l_type = F_WRLCK;
    755   1.52  drochner 		break;
    756   1.52  drochner 	case ULTRIX_F_UNLCK:
    757   1.52  drochner 		fl->l_type = F_UNLCK;
    758   1.52  drochner 		break;
    759   1.52  drochner 	default:
    760   1.52  drochner 		return (EINVAL);
    761   1.52  drochner 	}
    762   1.52  drochner 
    763   1.52  drochner 	return (0);
    764   1.52  drochner }
    765   1.52  drochner 
    766   1.52  drochner static void
    767   1.93    simonb bsd_to_ultrix_flock(struct flock *fl, struct ultrix_flock *ufl)
    768   1.52  drochner {
    769   1.52  drochner 
    770   1.52  drochner 	ufl->l_start = fl->l_start;
    771   1.52  drochner 	ufl->l_len = fl->l_len;
    772   1.52  drochner 	ufl->l_pid = fl->l_pid;
    773   1.52  drochner 	ufl->l_whence = fl->l_whence;
    774   1.52  drochner 
    775   1.52  drochner 	switch (fl->l_type) {
    776   1.52  drochner 	case F_RDLCK:
    777   1.52  drochner 		ufl->l_type = ULTRIX_F_RDLCK;
    778   1.52  drochner 		break;
    779   1.52  drochner 	case F_WRLCK:
    780   1.52  drochner 		ufl->l_type = ULTRIX_F_WRLCK;
    781   1.52  drochner 		break;
    782   1.52  drochner 	case F_UNLCK:
    783   1.52  drochner 		ufl->l_type = ULTRIX_F_UNLCK;
    784   1.52  drochner 		break;
    785   1.52  drochner 	}
    786   1.52  drochner }
    787   1.52  drochner 
    788   1.52  drochner int
    789   1.93    simonb ultrix_sys_fcntl(struct lwp *l, void *v, register_t *retval)
    790   1.52  drochner {
    791   1.52  drochner 	struct ultrix_sys_fcntl_args *uap = v;
    792   1.81   thorpej 	struct proc *p = l->l_proc;
    793   1.52  drochner 	int error;
    794   1.52  drochner 	struct ultrix_flock ufl;
    795   1.88    simonb 	struct flock fl, *flp = NULL;	/* XXX gcc */
    796   1.52  drochner 	caddr_t sg;
    797   1.52  drochner 	struct sys_fcntl_args *args, fca;
    798   1.52  drochner 
    799   1.52  drochner 	switch (SCARG(uap, cmd)) {
    800   1.52  drochner 	case F_GETLK:
    801   1.52  drochner 	case F_SETLK:
    802   1.52  drochner 	case F_SETLKW:
    803   1.52  drochner 		error = copyin(SCARG(uap, arg), &ufl, sizeof(ufl));
    804   1.52  drochner 		if (error)
    805   1.52  drochner 			return (error);
    806   1.52  drochner 		error = ultrix_to_bsd_flock(&ufl, &fl);
    807   1.52  drochner 		if (error)
    808   1.52  drochner 			return (error);
    809   1.75  christos 		sg = stackgap_init(p, 0);
    810   1.75  christos 		flp = (struct flock *)stackgap_alloc(p, &sg, sizeof(*flp));
    811   1.52  drochner 		error = copyout(&fl, flp, sizeof(*flp));
    812   1.52  drochner 		if (error)
    813   1.52  drochner 			return (error);
    814   1.52  drochner 
    815   1.52  drochner 		SCARG(&fca, fd) = SCARG(uap, fd);
    816   1.52  drochner 		SCARG(&fca, cmd) = SCARG(uap, cmd);
    817   1.52  drochner 		SCARG(&fca, arg) = flp;
    818   1.52  drochner 		args = &fca;
    819   1.52  drochner 		break;
    820   1.52  drochner 	default:
    821   1.52  drochner 		args = v;
    822   1.52  drochner 		break;
    823   1.52  drochner 	}
    824   1.52  drochner 
    825   1.81   thorpej 	error = sys_fcntl(l, args, retval);
    826   1.52  drochner 	if (error)
    827   1.52  drochner 		return (error);
    828   1.52  drochner 
    829   1.52  drochner 	switch (SCARG(uap, cmd)) {
    830   1.52  drochner 	case F_GETLK:
    831   1.52  drochner 		error = copyin(flp, &fl, sizeof(fl));
    832   1.52  drochner 		if (error)
    833   1.52  drochner 			return (error);
    834   1.52  drochner 		bsd_to_ultrix_flock(&fl, &ufl);
    835   1.52  drochner 		error = copyout(&ufl, SCARG(uap, arg), sizeof(ufl));
    836   1.52  drochner 		break;
    837   1.52  drochner 	}
    838   1.52  drochner 
    839   1.52  drochner 	return (error);
    840    1.1     glass }
    841