REVERT!! commit 346ef23f197a0c8ba807c344bd39101b711050ee Author: Samuel Thibault Date: Thu Nov 15 00:52:36 2018 +0100 hurd: Fix F_*LK* fcntl with __USE_FILE_OFFSET64 struct flock64 uses 64bit values. This introduces other values for F_GETLK, F_SETLK, F_SETLKW to distinguish between both. * sysdeps/mach/hurd/bits/fcntl.h (F_GETLK64, F_SETLK64, F_SETLKW64): New macros [__USE_FILE_OFFSET64] (F_GETLK, F_SETLK, F_SETLKW): Define to F_GETLK64, F_SETLK64, F_SETLKW64, respectively. * sysdeps/mach/hurd/f_setlk.c: New file. * sysdeps/mach/hurd/f_setlk.h: New file. * sysdeps/mach/hurd/Makefile [$(subdir) = io] (sysdeps_routines): Add f_setlk. * sysdeps/mach/hurd/fcntl.c: Include "f_setlk.h".h". (__libc_fcntl): Move non-flock operations to... * sysdeps/mach/hurd/vfcntl.c (__libc_vfcntl): ... New file. --- a/sysdeps/mach/hurd/Makefile 2019-09-11 10:50:11.000000000 +0200 +++ b/sysdeps/mach/hurd/Makefile 2019-09-11 10:52:30.000000000 +0200 @@ -195,10 +195,6 @@ sysdep_routines += cthreads endif -ifeq (io, $(subdir)) -sysdep_routines += f_setlk -endif - ifeq ($(subdir),sunrpc) sysdep_headers += nfs/nfs.h endif --- a/sysdeps/mach/hurd/bits/fcntl.h 2019-09-11 14:48:46.000000000 +0200 +++ b/sysdeps/mach/hurd/bits/fcntl.h 2019-09-11 14:50:24.000000000 +0200 @@ -1,5 +1,5 @@ /* O_*, F_*, FD_* bit values for GNU. - Copyright (C) 1993-2019 Free Software Foundation, Inc. + Copyright (C) 1993-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -163,18 +163,9 @@ # define F_GETOWN 5 /* Get owner (receiver of SIGIO). */ # define F_SETOWN 6 /* Set owner (receiver of SIGIO). */ #endif -#ifdef __USE_FILE_OFFSET64 -# define F_GETLK F_GETLK64 -# define F_SETLK F_SETLK64 -# define F_SETLKW F_SETLKW64 -#else -# define F_GETLK 7 /* Get record locking info. */ -# define F_SETLK 8 /* Set record locking info (non-blocking). */ -# define F_SETLKW 9 /* Set record locking info (blocking). */ -#endif -#define F_GETLK64 10 /* Get record locking info. */ -#define F_SETLK64 11 /* Set record locking info (non-blocking). */ -#define F_SETLKW64 12 /* Set record locking info (blocking). */ +#define F_GETLK 7 /* Get record locking info. */ +#define F_SETLK 8 /* Set record locking info (non-blocking). */ +#define F_SETLKW 9 /* Set record locking info (blocking). */ #ifdef __USE_XOPEN2K8 # define F_DUPFD_CLOEXEC 1030 /* Duplicate, set FD_CLOEXEC on new one. */ --- a/sysdeps/mach/hurd/f_setlk.c 2019-09-11 14:34:15.000000000 +0200 +++ /dev/null 2017-01-20 12:59:50.000000000 +0100 @@ -1,69 +0,0 @@ -/* f_setlk -- locking part of fcntl - Copyright (C) 2014-2015 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#include -#include -#include -#include - -/* XXX - We need new RPCs to support POSIX.1 fcntl file locking!! - For the time being we support the whole-file case only, - with all kinds of WRONG WRONG WRONG semantics, - by using flock. This is definitely the Wrong Thing, - but it might be better than nothing (?). */ -int -__f_setlk (int fd, int type, int whence, __off64_t start, __off64_t len, int wait) -{ - int cmd = 0; - - switch (type) - { - case F_RDLCK: cmd = LOCK_SH; break; - case F_WRLCK: cmd = LOCK_EX; break; - case F_UNLCK: cmd = LOCK_UN; break; - default: - errno = EINVAL; - return -1; - } - - if (cmd != LOCK_UN && wait == 0) - cmd |= LOCK_NB; - - switch (whence) - { - case SEEK_SET: - if (start == 0 && len == 0) /* Whole file request. */ - break; - /* It seems to be common for applications to lock the first - byte of the file when they are really doing whole-file locking. - So, since it's so wrong already, might as well do that too. */ - if (start == 0 && len == 1) - break; - /* FALLTHROUGH */ - case SEEK_CUR: - case SEEK_END: - errno = ENOTSUP; - return -1; - default: - errno = EINVAL; - return -1; - } - - return __flock (fd, cmd); -} --- a/sysdeps/mach/hurd/f_setlk.h 2019-01-31 17:45:36.000000000 +0100 +++ /dev/null 2017-01-20 12:59:50.000000000 +0100 @@ -1,23 +0,0 @@ -/* Copyright (C) 2014-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifndef _F_SETLK_H -#define _F_SETLK_H 1 - -extern int __f_setlk (int fd, int type, int whence, __off64_t start, __off64_t len, int wait); - -#endif /* f_setlk.h */ --- a/sysdeps/mach/hurd/fcntl.c.orig 2019-01-31 17:45:36.000000000 +0100 +++ b/sysdeps/mach/hurd/fcntl.c 2019-09-11 11:12:34.000000000 +0200 @@ -1,4 +1,4 @@ -/* Copyright (C) 1992-2019 Free Software Foundation, Inc. +/* Copyright (C) 1992-2018 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -21,7 +21,6 @@ #include #include #include /* XXX for LOCK_* */ -#include "f_setlk.h" /* Perform file control operations on FD. */ int @@ -129,48 +128,56 @@ case F_SETLK: case F_SETLKW: { + /* XXX + We need new RPCs to support POSIX.1 fcntl file locking!! + For the time being we support the whole-file case only, + with all kinds of WRONG WRONG WRONG semantics, + by using flock. This is definitely the Wrong Thing, + but it might be better than nothing (?). */ struct flock *fl = va_arg (ap, struct flock *); - int wait = 0; va_end (ap); switch (cmd) { case F_GETLK: errno = ENOSYS; return -1; - case F_SETLKW: - wait = 1; - /* FALLTHROUGH */ case F_SETLK: - return __f_setlk (fd, fl->l_type, fl->l_whence, - fl->l_start, fl->l_len, wait); + cmd = LOCK_NB; + break; + default: + cmd = 0; + break; + } + switch (fl->l_type) + { + case F_RDLCK: cmd |= LOCK_SH; break; + case F_WRLCK: cmd |= LOCK_EX; break; + case F_UNLCK: cmd |= LOCK_UN; break; default: errno = EINVAL; return -1; } - } - - case F_GETLK64: - case F_SETLK64: - case F_SETLKW64: - { - struct flock64 *fl = va_arg (ap, struct flock64 *); - int wait = 0; - va_end (ap); - switch (cmd) + switch (fl->l_whence) { - case F_GETLK64: - errno = ENOSYS; - return -1; - case F_SETLKW64: - wait = 1; + case SEEK_SET: + if (fl->l_start == 0 && fl->l_len == 0) /* Whole file request. */ + break; + /* It seems to be common for applications to lock the first + byte of the file when they are really doing whole-file locking. + So, since it's so wrong already, might as well do that too. */ + if (fl->l_start == 0 && fl->l_len == 1) + break; /* FALLTHROUGH */ - case F_SETLK64: - return __f_setlk (fd, fl->l_type, fl->l_whence, - fl->l_start, fl->l_len, wait); + case SEEK_CUR: + case SEEK_END: + errno = ENOTSUP; + return -1; default: errno = EINVAL; return -1; } + + return __flock (fd, cmd); } case F_GETFL: /* Get per-open flags. */ @@ -208,4 +215,3 @@ libc_hidden_def (__libc_fcntl64) weak_alias (__libc_fcntl64, __fcntl64) libc_hidden_weak (__fcntl64) -weak_alias (__fcntl64, fcntl64) --- a/sysdeps/mach/hurd/fcntl64.c 2019-01-31 17:45:36.000000000 +0100 +++ /dev/null 2017-01-20 12:59:50.000000000 +0100 @@ -1 +0,0 @@ -/* fcntl64 is defined in fcntl.c as an alias. */