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