From patchwork Sun Aug 31 21:27:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 384587 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 31645140093 for ; Mon, 1 Sep 2014 07:27:23 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:in-reply-to; q=dns; s=default; b=hhrr vtszN5o239jBsrXvHhsbWXgso8l/KdQIRohcG058kvAAQuoiV2rgOq8BGVu4axGk t2PB0i8eDyZTtWHOkVCgCoEzpX1onITI4P5bdrLcB8KojmUcfSdxdrTTtIRjtEKm tIKnG+itShRn+vzLXXyDjuCXxnfQZpJVQizmUQQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:in-reply-to; s=default; bh=+P6B+Po+m7 BRqq+AV0J/CxzXt6Y=; b=DyqAGCwqzbbc8C5HzSD6DkCto26g9XgdRuicLdLfHP 8t25ySj5KRclIvbUH4votpvkuYXrUQBS+H6d84ZLCy0baThsMgU6JODzKAVNCxRg SPgtmAUBkqN1Cr/3WnejPVkZ10Wf9dN0XuaGexJZMth2GZBMQetWqR05D8xIXVEs 8= Received: (qmail 27162 invoked by alias); 31 Aug 2014 21:27:18 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 27151 invoked by uid 89); 31 Aug 2014 21:27:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 X-HELO: sonata.ens-lyon.org Date: Sun, 31 Aug 2014 23:27:08 +0200 From: Samuel Thibault To: Roland McGrath Cc: libc-alpha@sourceware.org, bug-hurd@gnu.org Subject: [PATCH,Hurd] Fix F_*LK* fcntl with __USE_FILE_OFFSET64 Message-ID: <20140831212708.GN19374@type.youpi.perso.aquilenet.fr> Mail-Followup-To: Roland McGrath , libc-alpha@sourceware.org, bug-hurd@gnu.org References: <20140827230625.GW3343@type.youpi.perso.aquilenet.fr> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20140827230625.GW3343@type.youpi.perso.aquilenet.fr> User-Agent: Mutt/1.5.21+34 (58baf7c9f32f) (2010-12-30) 2014-08-31 Samuel Thibault 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/flockconv.c: New file. * sysdeps/mach/hurd/fcntl.c (__libc_fcntl): Include "flockconv.c", handle F_GETLK64, F_SETLK64, F_SETLKW64 cases. --- sysdeps/mach/hurd/bits/fcntl.h | 11 ++++++- sysdeps/mach/hurd/fcntl.c | 37 +++++++++++++++++++++- sysdeps/mach/hurd/flockconv.c | 69 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+), 2 deletions(-) diff --git a/sysdeps/mach/hurd/bits/fcntl.h b/sysdeps/mach/hurd/bits/fcntl.h index 9d598a1..3202971 100644 --- a/sysdeps/mach/hurd/bits/fcntl.h +++ b/sysdeps/mach/hurd/bits/fcntl.h @@ -1,5 +1,5 @@ /* O_*, F_*, FD_* bit values for GNU. - Copyright (C) 1993-2013 Free Software Foundation, Inc. + Copyright (C) 1993-2014 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,9 +163,18 @@ # 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). */ #ifdef __USE_XOPEN2K8 # define F_DUPFD_CLOEXEC 1030 /* Duplicate, set FD_CLOEXEC on new one. */ diff --git a/sysdeps/mach/hurd/fcntl.c b/sysdeps/mach/hurd/fcntl.c index 70180fa..7ab58c0 100644 --- a/sysdeps/mach/hurd/fcntl.c +++ b/sysdeps/mach/hurd/fcntl.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1992-2013 Free Software Foundation, Inc. +/* Copyright (C) 1992-2014 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 @@ -22,6 +22,8 @@ #include #include /* XXX for LOCK_* */ +#include "flockconv.c" + /* Perform file control operations on FD. */ int __libc_fcntl (int fd, int cmd, ...) @@ -180,6 +182,39 @@ __libc_fcntl (int fd, int cmd, ...) return __flock (fd, cmd); } + case F_GETLK64: + case F_SETLK64: + case F_SETLKW64: + { + struct flock64 *fl64 = va_arg (ap, struct flock64 *); + struct flock fl; + + if (flock64_conv (&fl, fl64)) + { + result = -1; + break; + } + + switch (cmd) + { + case F_GETLK64: + result = fcntl (fd, F_GETLK, &fl); + if (flock_conv (fl64, &fl)) + result = -1; + break; + + case F_SETLK64: + result = fcntl (fd, F_SETLK, &fl); + break; + + case F_SETLKW64: + result = fcntl (fd, F_SETLKW, &fl); + break; + } + + break; + } + case F_GETFL: /* Get per-open flags. */ if (err = HURD_FD_PORT_USE (d, __io_get_openmodes (port, &result))) result = __hurd_dfail (fd, err); diff --git a/sysdeps/mach/hurd/flockconv.c b/sysdeps/mach/hurd/flockconv.c new file mode 100644 index 0000000..4438784 --- /dev/null +++ b/sysdeps/mach/hurd/flockconv.c @@ -0,0 +1,69 @@ +/* Convert between `struct flock' format, and `struct flock64' format. + Copyright (C) 2014 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 + +static inline int +flock64_conv (struct flock *buf, const struct flock64 *buf64) +{ + if (sizeof *buf == sizeof *buf64 + && sizeof buf->l_start == sizeof buf64->l_start + && sizeof buf->l_len == sizeof buf64->l_len) + { + *buf = *(struct flock *) buf64; + return 0; + } + + buf->l_type = buf64->l_type; + buf->l_whence = buf64->l_whence; + buf->l_start = buf64->l_start; + buf->l_len = buf64->l_len; + buf->l_pid = buf64->l_pid; + + if ((sizeof buf->l_start != sizeof buf64->l_start + && buf->l_start != buf64->l_start) + || (sizeof buf->l_len != sizeof buf64->l_len + && buf->l_len != buf64->l_len)) + { + __set_errno (EOVERFLOW); + return -1; + } + + return 0; +} + +static inline int +flock_conv (struct flock64 *buf64, const struct flock *buf) +{ + if (sizeof *buf == sizeof *buf64 + && sizeof buf->l_start == sizeof buf64->l_start + && sizeof buf->l_len == sizeof buf64->l_len) + { + *buf64 = *(struct flock64 *) buf; + return 0; + } + + buf64->l_type = buf->l_type; + buf64->l_whence = buf->l_whence; + buf64->l_start = buf->l_start; + buf64->l_len = buf->l_len; + buf64->l_pid = buf->l_pid; + + return 0; +}