From patchwork Wed Sep 23 12:43:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuriy Kolerov X-Patchwork-Id: 521683 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ozlabs.org (Postfix) with ESMTP id E4DD714018C for ; Wed, 23 Sep 2015 22:43:49 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id AB953335E9; Wed, 23 Sep 2015 12:43:47 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ya-agOK09ej9; Wed, 23 Sep 2015 12:43:46 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 0CD3F335E4; Wed, 23 Sep 2015 12:43:46 +0000 (UTC) X-Original-To: uclibc@lists.busybox.net Delivered-To: uclibc@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 1D9F61CE80D for ; Wed, 23 Sep 2015 12:43:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 195DA91A2D for ; Wed, 23 Sep 2015 12:43:45 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id N6vVB+43VTK5 for ; Wed, 23 Sep 2015 12:43:43 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from smtprelay.synopsys.com (smtprelay.synopsys.com [198.182.47.9]) by whitealder.osuosl.org (Postfix) with ESMTPS id DFAD5912B7 for ; Wed, 23 Sep 2015 12:43:43 +0000 (UTC) Received: from dc8secmta2.synopsys.com (dc8secmta2.synopsys.com [10.13.218.202]) by smtprelay.synopsys.com (Postfix) with ESMTP id 50D0524E140E for ; Wed, 23 Sep 2015 05:43:43 -0700 (PDT) Received: from dc8secmta2.internal.synopsys.com (dc8secmta2.internal.synopsys.com [127.0.0.1]) by dc8secmta2.internal.synopsys.com (Service) with ESMTP id 450BFA4114 for ; Wed, 23 Sep 2015 05:43:43 -0700 (PDT) Received: from mailhost.synopsys.com (unknown [10.13.184.66]) by dc8secmta2.internal.synopsys.com (Service) with ESMTP id 262D6A4102 for ; Wed, 23 Sep 2015 05:43:43 -0700 (PDT) Received: from mailhost.synopsys.com (localhost [127.0.0.1]) by mailhost.synopsys.com (Postfix) with ESMTP id 148A4E55; Wed, 23 Sep 2015 05:43:43 -0700 (PDT) Received: from ykolerov-lab.internal.synopsys.com (ykolerov-lab.internal.synopsys.com [10.121.8.82]) by mailhost.synopsys.com (Postfix) with ESMTP id 5E810E4B; Wed, 23 Sep 2015 05:43:41 -0700 (PDT) From: Yuriy Kolerov To: uclibc@uclibc.org, Vineet.Gupta1@synopsys.com, Alexey.Brodkin@synopsys.com, Anton.Kolesov@synopsys.com Subject: [PATCH v3 1/3] libc: fix setting return value and errno in fallocate() Date: Wed, 23 Sep 2015 15:43:37 +0300 Message-Id: <1443012219-10992-1-git-send-email-yuriy.kolerov@synopsys.com> X-Mailer: git-send-email 2.2.0 Cc: Francois.Bedard@synopsys.com X-BeenThere: uclibc@uclibc.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "Discussion and development of uClibc \(the embedded C library\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: uclibc-bounces@uclibc.org Sender: "uClibc" fallocate system call must return 0 on success. On error, -1 is returned and errno is set to indicate the error. However there is an error in fallocate which is fixed by this patch - it does not set errno and returns invalid value on error (it returns error code instead of -1). This error is detected in LTP's test kernel/syscalls/fallocate02: ----------->8---------- fallocate(..., 1, 0, 1024) failed, expected errno:9: TEST_ERRNO=0 fallocate(..., 1, -1024, 1024) failed, expected errno:22: TEST_ERRNO=0 fallocate(..., 1, 1024, -1024) failed, expected errno:22: TEST_ERRNO=0 fallocate(..., 1, 12288, 0) failed, expected errno:22: TEST_ERRNO=0 fallocate(..., 1, 12288, -1024) failed, expected errno:22: TEST_ERRNO=0 fallocate(..., 1, -24576, 1024) failed, expected errno:22: TEST_ERRNO=0 ----------->8---------- Signed-off-by: Yuriy Kolerov --- libc/sysdeps/linux/common/fallocate.c | 9 ++++++--- libc/sysdeps/linux/common/fallocate64.c | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/libc/sysdeps/linux/common/fallocate.c b/libc/sysdeps/linux/common/fallocate.c index b231226..b2309e9 100644 --- a/libc/sysdeps/linux/common/fallocate.c +++ b/libc/sysdeps/linux/common/fallocate.c @@ -12,6 +12,7 @@ #include #include #include +#include #if defined __NR_fallocate extern __typeof(fallocate) __libc_fallocate attribute_hidden; @@ -34,9 +35,11 @@ int attribute_hidden __libc_fallocate(int fd, int mode, __off_t offset, __off_t # else # error your machine is neither 32 bit or 64 bit ... it must be magical # endif - if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) - return INTERNAL_SYSCALL_ERRNO (ret, err); - return 0; + if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) { + __set_errno(INTERNAL_SYSCALL_ERRNO (ret, err)); + ret = -1; + } + return ret; } # if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU diff --git a/libc/sysdeps/linux/common/fallocate64.c b/libc/sysdeps/linux/common/fallocate64.c index cf75693..1aa351e 100644 --- a/libc/sysdeps/linux/common/fallocate64.c +++ b/libc/sysdeps/linux/common/fallocate64.c @@ -13,6 +13,7 @@ #include #include #include +#include #if defined __NR_fallocate @@ -27,9 +28,11 @@ int attribute_hidden __libc_fallocate64(int fd, int mode, __off64_t offset, INTERNAL_SYSCALL_DECL(err); ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, mode, OFF64_HI_LO (offset), OFF64_HI_LO (len))); - if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) - return INTERNAL_SYSCALL_ERRNO (ret, err); - return 0; + if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) { + __set_errno(INTERNAL_SYSCALL_ERRNO (ret, err)); + ret = -1; + } + return ret; } # if defined __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU