Home | History | Annotate | Line # | Download | only in common
linux_fcntl64.c revision 1.1
      1  1.1  dsl /*	$NetBSD: linux_fcntl64.c,v 1.1 2008/02/02 19:37:53 dsl Exp $	*/
      2  1.1  dsl 
      3  1.1  dsl /*-
      4  1.1  dsl  * Copyright (c) 1995, 1998, 2000 The NetBSD Foundation, Inc.
      5  1.1  dsl  * All rights reserved.
      6  1.1  dsl  *
      7  1.1  dsl  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  dsl  * by Frank van der Linden and Eric Haszlakiewicz.
      9  1.1  dsl  *
     10  1.1  dsl  * Redistribution and use in source and binary forms, with or without
     11  1.1  dsl  * modification, are permitted provided that the following conditions
     12  1.1  dsl  * are met:
     13  1.1  dsl  * 1. Redistributions of source code must retain the above copyright
     14  1.1  dsl  *    notice, this list of conditions and the following disclaimer.
     15  1.1  dsl  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  dsl  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  dsl  *    documentation and/or other materials provided with the distribution.
     18  1.1  dsl  * 3. All advertising materials mentioning features or use of this software
     19  1.1  dsl  *    must display the following acknowledgement:
     20  1.1  dsl  *	This product includes software developed by the NetBSD
     21  1.1  dsl  *	Foundation, Inc. and its contributors.
     22  1.1  dsl  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  dsl  *    contributors may be used to endorse or promote products derived
     24  1.1  dsl  *    from this software without specific prior written permission.
     25  1.1  dsl  *
     26  1.1  dsl  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  dsl  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  dsl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  dsl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  dsl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  dsl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  dsl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  dsl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  dsl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  dsl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  dsl  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  dsl  */
     38  1.1  dsl 
     39  1.1  dsl /*
     40  1.1  dsl  * Linux 64bit filesystem calls. Used on 32bit archs, not used on 64bit ones.
     41  1.1  dsl  */
     42  1.1  dsl 
     43  1.1  dsl #include <sys/cdefs.h>
     44  1.1  dsl __KERNEL_RCSID(0, "$NetBSD: linux_fcntl64.c,v 1.1 2008/02/02 19:37:53 dsl Exp $");
     45  1.1  dsl 
     46  1.1  dsl #include <sys/param.h>
     47  1.1  dsl #include <sys/systm.h>
     48  1.1  dsl #include <sys/namei.h>
     49  1.1  dsl #include <sys/proc.h>
     50  1.1  dsl #include <sys/dirent.h>
     51  1.1  dsl #include <sys/file.h>
     52  1.1  dsl #include <sys/stat.h>
     53  1.1  dsl #include <sys/filedesc.h>
     54  1.1  dsl #include <sys/ioctl.h>
     55  1.1  dsl #include <sys/kernel.h>
     56  1.1  dsl #include <sys/mount.h>
     57  1.1  dsl #include <sys/malloc.h>
     58  1.1  dsl #include <sys/namei.h>
     59  1.1  dsl #include <sys/vfs_syscalls.h>
     60  1.1  dsl #include <sys/vnode.h>
     61  1.1  dsl #include <sys/tty.h>
     62  1.1  dsl #include <sys/conf.h>
     63  1.1  dsl 
     64  1.1  dsl #include <sys/syscallargs.h>
     65  1.1  dsl 
     66  1.1  dsl #include <compat/linux/common/linux_types.h>
     67  1.1  dsl #include <compat/linux/common/linux_signal.h>
     68  1.1  dsl #include <compat/linux/common/linux_fcntl.h>
     69  1.1  dsl #include <compat/linux/common/linux_util.h>
     70  1.1  dsl #include <compat/linux/common/linux_machdep.h>
     71  1.1  dsl #include <compat/linux/common/linux_dirent.h>
     72  1.1  dsl #include <compat/linux/common/linux_ipc.h>
     73  1.1  dsl #include <compat/linux/common/linux_sem.h>
     74  1.1  dsl 
     75  1.1  dsl #include <compat/linux/linux_syscallargs.h>
     76  1.1  dsl 
     77  1.1  dsl # if !defined(__m68k__) && (!defined(__amd64__) || defined(COMPAT_LINUX32))
     78  1.1  dsl static void bsd_to_linux_flock64(struct linux_flock64 *,
     79  1.1  dsl     const struct flock *);
     80  1.1  dsl static void linux_to_bsd_flock64(struct flock *,
     81  1.1  dsl     const struct linux_flock64 *);
     82  1.1  dsl 
     83  1.1  dsl static void
     84  1.1  dsl bsd_to_linux_flock64(struct linux_flock64 *lfp, const struct flock *bfp)
     85  1.1  dsl {
     86  1.1  dsl 
     87  1.1  dsl 	lfp->l_start = bfp->l_start;
     88  1.1  dsl 	lfp->l_len = bfp->l_len;
     89  1.1  dsl 	lfp->l_pid = bfp->l_pid;
     90  1.1  dsl 	lfp->l_whence = bfp->l_whence;
     91  1.1  dsl 	switch (bfp->l_type) {
     92  1.1  dsl 	case F_RDLCK:
     93  1.1  dsl 		lfp->l_type = LINUX_F_RDLCK;
     94  1.1  dsl 		break;
     95  1.1  dsl 	case F_UNLCK:
     96  1.1  dsl 		lfp->l_type = LINUX_F_UNLCK;
     97  1.1  dsl 		break;
     98  1.1  dsl 	case F_WRLCK:
     99  1.1  dsl 		lfp->l_type = LINUX_F_WRLCK;
    100  1.1  dsl 		break;
    101  1.1  dsl 	}
    102  1.1  dsl }
    103  1.1  dsl 
    104  1.1  dsl static void
    105  1.1  dsl linux_to_bsd_flock64(struct flock *bfp, const struct linux_flock64 *lfp)
    106  1.1  dsl {
    107  1.1  dsl 
    108  1.1  dsl 	bfp->l_start = lfp->l_start;
    109  1.1  dsl 	bfp->l_len = lfp->l_len;
    110  1.1  dsl 	bfp->l_pid = lfp->l_pid;
    111  1.1  dsl 	bfp->l_whence = lfp->l_whence;
    112  1.1  dsl 	switch (lfp->l_type) {
    113  1.1  dsl 	case LINUX_F_RDLCK:
    114  1.1  dsl 		bfp->l_type = F_RDLCK;
    115  1.1  dsl 		break;
    116  1.1  dsl 	case LINUX_F_UNLCK:
    117  1.1  dsl 		bfp->l_type = F_UNLCK;
    118  1.1  dsl 		break;
    119  1.1  dsl 	case LINUX_F_WRLCK:
    120  1.1  dsl 		bfp->l_type = F_WRLCK;
    121  1.1  dsl 		break;
    122  1.1  dsl 	}
    123  1.1  dsl }
    124  1.1  dsl 
    125  1.1  dsl int
    126  1.1  dsl linux_sys_fcntl64(struct lwp *l, const struct linux_sys_fcntl64_args *uap, register_t *retval)
    127  1.1  dsl {
    128  1.1  dsl 	/* {
    129  1.1  dsl 		syscallarg(int) fd;
    130  1.1  dsl 		syscallarg(int) cmd;
    131  1.1  dsl 		syscallarg(void *) arg;
    132  1.1  dsl 	} */
    133  1.1  dsl 	struct linux_flock64 lfl;
    134  1.1  dsl 	struct flock bfl;
    135  1.1  dsl 	int error;
    136  1.1  dsl 	void *arg = SCARG(uap, arg);
    137  1.1  dsl 	int cmd = SCARG(uap, cmd);
    138  1.1  dsl 	int fd = SCARG(uap, fd);
    139  1.1  dsl 
    140  1.1  dsl 	switch (cmd) {
    141  1.1  dsl 	case LINUX_F_GETLK64:
    142  1.1  dsl 		if ((error = copyin(arg, &lfl, sizeof lfl)) != 0)
    143  1.1  dsl 			return error;
    144  1.1  dsl 		linux_to_bsd_flock64(&bfl, &lfl);
    145  1.1  dsl 		error = do_fcntl_lock(l, fd, F_GETLK, &bfl);
    146  1.1  dsl 		if (error != 0)
    147  1.1  dsl 			return error;
    148  1.1  dsl 		bsd_to_linux_flock64(&lfl, &bfl);
    149  1.1  dsl 		return copyout(&lfl, arg, sizeof lfl);
    150  1.1  dsl 	case LINUX_F_SETLK64:
    151  1.1  dsl 	case LINUX_F_SETLKW64:
    152  1.1  dsl 		cmd = (cmd == LINUX_F_SETLK64 ? F_SETLK : F_SETLKW);
    153  1.1  dsl 		if ((error = copyin(arg, &lfl, sizeof lfl)) != 0)
    154  1.1  dsl 			return error;
    155  1.1  dsl 		linux_to_bsd_flock64(&bfl, &lfl);
    156  1.1  dsl 		return do_fcntl_lock(l, fd, cmd, &bfl);
    157  1.1  dsl 	default:
    158  1.1  dsl 		return linux_sys_fcntl(l, (const void *)uap, retval);
    159  1.1  dsl 	}
    160  1.1  dsl }
    161  1.1  dsl # endif /* !m69k && !amd64  && !COMPAT_LINUX32 */
    162