From 7e5ac7072db793d112e56ddfc15583624289d0bd Mon Sep 17 00:00:00 2001 From: dsl Date: Sat, 2 Feb 2008 19:37:52 +0000 Subject: [PATCH] Extract the fcntl64() suppoort from linux_file64.c into linux_fcntl64.c Unravel some of the knots that caused linux_file64.c to be compiled twice for an amd64 kernel (once for linux and once for linux32) with different parts being skipped each time. --- sys/compat/linux/arch/arm/linux_commons.c | 5 +- sys/compat/linux/arch/i386/linux_commons.c | 5 +- sys/compat/linux/arch/mips/files.linux_mips | 3 +- .../linux/arch/powerpc/files.linux_powerpc | 3 +- sys/compat/linux/common/linux_fcntl64.c | 161 ++++++++++++++++++ sys/compat/linux/common/linux_file64.c | 96 +---------- .../linux32/arch/amd64/linux32_missing.c | 4 +- 7 files changed, 175 insertions(+), 102 deletions(-) create mode 100644 sys/compat/linux/common/linux_fcntl64.c diff --git a/sys/compat/linux/arch/arm/linux_commons.c b/sys/compat/linux/arch/arm/linux_commons.c index 8b08b781a392..092d2ba8b3db 100644 --- a/sys/compat/linux/arch/arm/linux_commons.c +++ b/sys/compat/linux/arch/arm/linux_commons.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_commons.c,v 1.6 2008/01/15 22:38:34 njoly Exp $ */ +/* $NetBSD: linux_commons.c,v 1.7 2008/02/02 19:37:52 dsl Exp $ */ /* * This file includes C files from the common @@ -13,7 +13,7 @@ */ #include -__KERNEL_RCSID(1, "$NetBSD: linux_commons.c,v 1.6 2008/01/15 22:38:34 njoly Exp $"); +__KERNEL_RCSID(1, "$NetBSD: linux_commons.c,v 1.7 2008/02/02 19:37:52 dsl Exp $"); #if defined(_KERNEL_OPT) #include "opt_sysv.h" @@ -29,6 +29,7 @@ __KERNEL_RCSID(1, "$NetBSD: linux_commons.c,v 1.6 2008/01/15 22:38:34 njoly Exp #include "../../common/linux_pipe.c" #include "../../common/linux_file64.c" +#include "../../common/linux_fcntl64.c" #include "../../common/linux_ipccall.c" #include "../../common/linux_misc_notalpha.c" #include "../../common/linux_sig_notalpha.c" diff --git a/sys/compat/linux/arch/i386/linux_commons.c b/sys/compat/linux/arch/i386/linux_commons.c index 620ee011114d..a6be95526ae3 100644 --- a/sys/compat/linux/arch/i386/linux_commons.c +++ b/sys/compat/linux/arch/i386/linux_commons.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_commons.c,v 1.11 2008/01/15 22:38:34 njoly Exp $ */ +/* $NetBSD: linux_commons.c,v 1.12 2008/02/02 19:37:52 dsl Exp $ */ /* * This file includes C files from the common @@ -13,7 +13,7 @@ */ #include -__KERNEL_RCSID(1, "$NetBSD: linux_commons.c,v 1.11 2008/01/15 22:38:34 njoly Exp $"); +__KERNEL_RCSID(1, "$NetBSD: linux_commons.c,v 1.12 2008/02/02 19:37:52 dsl Exp $"); #if defined(_KERNEL_OPT) #include "opt_sysv.h" @@ -30,6 +30,7 @@ __KERNEL_RCSID(1, "$NetBSD: linux_commons.c,v 1.11 2008/01/15 22:38:34 njoly Exp #include "../../common/linux_pipe.c" #include "../../common/linux_futex.c" #include "../../common/linux_file64.c" +#include "../../common/linux_fcntl64.c" #include "../../common/linux_ipccall.c" #include "../../common/linux_misc_notalpha.c" #include "../../common/linux_sig_notalpha.c" diff --git a/sys/compat/linux/arch/mips/files.linux_mips b/sys/compat/linux/arch/mips/files.linux_mips index 305f40fa4953..9c5d9fff254e 100644 --- a/sys/compat/linux/arch/mips/files.linux_mips +++ b/sys/compat/linux/arch/mips/files.linux_mips @@ -1,4 +1,4 @@ -# $NetBSD: files.linux_mips,v 1.4 2006/08/30 11:14:39 matt Exp $ +# $NetBSD: files.linux_mips,v 1.5 2008/02/02 19:37:52 dsl Exp $ # # Config file description for mips-dependent Linux compat code. @@ -16,3 +16,4 @@ file compat/linux/common/linux_socketcall.c compat_linux file compat/linux/common/linux_llseek.c compat_linux file compat/linux/common/linux_olduname.c compat_linux file compat/linux/common/linux_file64.c compat_linux +file compat/linux/common/linux_fcntl64.c compat_linux diff --git a/sys/compat/linux/arch/powerpc/files.linux_powerpc b/sys/compat/linux/arch/powerpc/files.linux_powerpc index 44f55ac12f5c..310dcad832aa 100644 --- a/sys/compat/linux/arch/powerpc/files.linux_powerpc +++ b/sys/compat/linux/arch/powerpc/files.linux_powerpc @@ -1,4 +1,4 @@ -# $NetBSD: files.linux_powerpc,v 1.8 2006/09/01 21:20:47 matt Exp $ +# $NetBSD: files.linux_powerpc,v 1.9 2008/02/02 19:37:53 dsl Exp $ # # Config file description for powerpc-dependent Linux compat code. @@ -17,3 +17,4 @@ file compat/linux/common/linux_socketcall.c compat_linux file compat/linux/common/linux_llseek.c compat_linux file compat/linux/common/linux_olduname.c compat_linux file compat/linux/common/linux_file64.c compat_linux +file compat/linux/common/linux_fcntl64.c compat_linux diff --git a/sys/compat/linux/common/linux_fcntl64.c b/sys/compat/linux/common/linux_fcntl64.c new file mode 100644 index 000000000000..17a98dcf77ca --- /dev/null +++ b/sys/compat/linux/common/linux_fcntl64.c @@ -0,0 +1,161 @@ +/* $NetBSD: linux_fcntl64.c,v 1.1 2008/02/02 19:37:53 dsl Exp $ */ + +/*- + * Copyright (c) 1995, 1998, 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Frank van der Linden and Eric Haszlakiewicz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Linux 64bit filesystem calls. Used on 32bit archs, not used on 64bit ones. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: linux_fcntl64.c,v 1.1 2008/02/02 19:37:53 dsl Exp $"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +# if !defined(__m68k__) && (!defined(__amd64__) || defined(COMPAT_LINUX32)) +static void bsd_to_linux_flock64(struct linux_flock64 *, + const struct flock *); +static void linux_to_bsd_flock64(struct flock *, + const struct linux_flock64 *); + +static void +bsd_to_linux_flock64(struct linux_flock64 *lfp, const struct flock *bfp) +{ + + lfp->l_start = bfp->l_start; + lfp->l_len = bfp->l_len; + lfp->l_pid = bfp->l_pid; + lfp->l_whence = bfp->l_whence; + switch (bfp->l_type) { + case F_RDLCK: + lfp->l_type = LINUX_F_RDLCK; + break; + case F_UNLCK: + lfp->l_type = LINUX_F_UNLCK; + break; + case F_WRLCK: + lfp->l_type = LINUX_F_WRLCK; + break; + } +} + +static void +linux_to_bsd_flock64(struct flock *bfp, const struct linux_flock64 *lfp) +{ + + bfp->l_start = lfp->l_start; + bfp->l_len = lfp->l_len; + bfp->l_pid = lfp->l_pid; + bfp->l_whence = lfp->l_whence; + switch (lfp->l_type) { + case LINUX_F_RDLCK: + bfp->l_type = F_RDLCK; + break; + case LINUX_F_UNLCK: + bfp->l_type = F_UNLCK; + break; + case LINUX_F_WRLCK: + bfp->l_type = F_WRLCK; + break; + } +} + +int +linux_sys_fcntl64(struct lwp *l, const struct linux_sys_fcntl64_args *uap, register_t *retval) +{ + /* { + syscallarg(int) fd; + syscallarg(int) cmd; + syscallarg(void *) arg; + } */ + struct linux_flock64 lfl; + struct flock bfl; + int error; + void *arg = SCARG(uap, arg); + int cmd = SCARG(uap, cmd); + int fd = SCARG(uap, fd); + + switch (cmd) { + case LINUX_F_GETLK64: + if ((error = copyin(arg, &lfl, sizeof lfl)) != 0) + return error; + linux_to_bsd_flock64(&bfl, &lfl); + error = do_fcntl_lock(l, fd, F_GETLK, &bfl); + if (error != 0) + return error; + bsd_to_linux_flock64(&lfl, &bfl); + return copyout(&lfl, arg, sizeof lfl); + case LINUX_F_SETLK64: + case LINUX_F_SETLKW64: + cmd = (cmd == LINUX_F_SETLK64 ? F_SETLK : F_SETLKW); + if ((error = copyin(arg, &lfl, sizeof lfl)) != 0) + return error; + linux_to_bsd_flock64(&bfl, &lfl); + return do_fcntl_lock(l, fd, cmd, &bfl); + default: + return linux_sys_fcntl(l, (const void *)uap, retval); + } +} +# endif /* !m69k && !amd64 && !COMPAT_LINUX32 */ diff --git a/sys/compat/linux/common/linux_file64.c b/sys/compat/linux/common/linux_file64.c index afad14bcce27..72646b2c5d5a 100644 --- a/sys/compat/linux/common/linux_file64.c +++ b/sys/compat/linux/common/linux_file64.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux_file64.c,v 1.44 2007/12/20 23:02:54 dsl Exp $ */ +/* $NetBSD: linux_file64.c,v 1.45 2008/02/02 19:37:53 dsl Exp $ */ /*- * Copyright (c) 1995, 1998, 2000 The NetBSD Foundation, Inc. @@ -41,7 +41,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: linux_file64.c,v 1.44 2007/12/20 23:02:54 dsl Exp $"); +__KERNEL_RCSID(0, "$NetBSD: linux_file64.c,v 1.45 2008/02/02 19:37:53 dsl Exp $"); #include #include @@ -76,8 +76,6 @@ __KERNEL_RCSID(0, "$NetBSD: linux_file64.c,v 1.44 2007/12/20 23:02:54 dsl Exp $" #ifndef alpha -# ifndef COMPAT_LINUX32 - static void bsd_to_linux_stat(struct stat *, struct linux_stat64 *); /* @@ -212,94 +210,6 @@ linux_sys_ftruncate64(struct lwp *l, const struct linux_sys_ftruncate64_args *ua return sys_ftruncate(l, &ta, retval); } -# endif /* !COMPAT_LINUX32 */ - -# if !defined(__m68k__) && (!defined(__amd64__) || defined(COMPAT_LINUX32)) -static void bsd_to_linux_flock64(struct linux_flock64 *, - const struct flock *); -static void linux_to_bsd_flock64(struct flock *, - const struct linux_flock64 *); - -static void -bsd_to_linux_flock64(struct linux_flock64 *lfp, const struct flock *bfp) -{ - - lfp->l_start = bfp->l_start; - lfp->l_len = bfp->l_len; - lfp->l_pid = bfp->l_pid; - lfp->l_whence = bfp->l_whence; - switch (bfp->l_type) { - case F_RDLCK: - lfp->l_type = LINUX_F_RDLCK; - break; - case F_UNLCK: - lfp->l_type = LINUX_F_UNLCK; - break; - case F_WRLCK: - lfp->l_type = LINUX_F_WRLCK; - break; - } -} - -static void -linux_to_bsd_flock64(struct flock *bfp, const struct linux_flock64 *lfp) -{ - - bfp->l_start = lfp->l_start; - bfp->l_len = lfp->l_len; - bfp->l_pid = lfp->l_pid; - bfp->l_whence = lfp->l_whence; - switch (lfp->l_type) { - case LINUX_F_RDLCK: - bfp->l_type = F_RDLCK; - break; - case LINUX_F_UNLCK: - bfp->l_type = F_UNLCK; - break; - case LINUX_F_WRLCK: - bfp->l_type = F_WRLCK; - break; - } -} - -int -linux_sys_fcntl64(struct lwp *l, const struct linux_sys_fcntl64_args *uap, register_t *retval) -{ - /* { - syscallarg(int) fd; - syscallarg(int) cmd; - syscallarg(void *) arg; - } */ - struct linux_flock64 lfl; - struct flock bfl; - int error; - void *arg = SCARG(uap, arg); - int cmd = SCARG(uap, cmd); - int fd = SCARG(uap, fd); - - switch (cmd) { - case LINUX_F_GETLK64: - if ((error = copyin(arg, &lfl, sizeof lfl)) != 0) - return error; - linux_to_bsd_flock64(&bfl, &lfl); - error = do_fcntl_lock(l, fd, F_GETLK, &bfl); - if (error != 0) - return error; - bsd_to_linux_flock64(&lfl, &bfl); - return copyout(&lfl, arg, sizeof lfl); - case LINUX_F_SETLK64: - case LINUX_F_SETLKW64: - cmd = (cmd == LINUX_F_SETLK64 ? F_SETLK : F_SETLKW); - if ((error = copyin(arg, &lfl, sizeof lfl)) != 0) - return error; - linux_to_bsd_flock64(&bfl, &lfl); - return do_fcntl_lock(l, fd, cmd, &bfl); - default: - return linux_sys_fcntl(l, (const void *)uap, retval); - } -} -# endif /* !m69k && !amd64 && !COMPAT_LINUX32 */ - #endif /* !alpha */ /* @@ -316,7 +226,6 @@ linux_sys_fcntl64(struct lwp *l, const struct linux_sys_fcntl64_args *uap, regis * * Note that this doesn't handle union-mounted filesystems. */ -#ifndef COMPAT_LINUX32 int linux_sys_getdents64(struct lwp *l, const struct linux_sys_getdents64_args *uap, register_t *retval) { @@ -449,4 +358,3 @@ out1: FILE_UNUSE(fp, l); return error; } -#endif /* !COMPAT_LINUX32 */ diff --git a/sys/compat/linux32/arch/amd64/linux32_missing.c b/sys/compat/linux32/arch/amd64/linux32_missing.c index faace030aa6e..02d994d8469e 100644 --- a/sys/compat/linux32/arch/amd64/linux32_missing.c +++ b/sys/compat/linux32/arch/amd64/linux32_missing.c @@ -1,4 +1,4 @@ -/* $NetBSD: linux32_missing.c,v 1.4 2008/01/15 22:38:35 njoly Exp $ */ +/* $NetBSD: linux32_missing.c,v 1.5 2008/02/02 19:37:53 dsl Exp $ */ #include @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include #include