From patchwork Mon Sep 1 14:27:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Basile X-Patchwork-Id: 384883 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from fraxinus.osuosl.org (fraxinus.osuosl.org [140.211.166.137]) by ozlabs.org (Postfix) with ESMTP id ADB1F1401B1 for ; Tue, 2 Sep 2014 00:25:08 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id B2E36A0AC2; Mon, 1 Sep 2014 14:25:07 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ElZ9NbpJadwL; Mon, 1 Sep 2014 14:25:02 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by fraxinus.osuosl.org (Postfix) with ESMTP id 92EF5A0AC8; Mon, 1 Sep 2014 14:25:02 +0000 (UTC) X-Original-To: uclibc@lists.busybox.net Delivered-To: uclibc@osuosl.org Received: from whitealder.osuosl.org (whitealder.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id 4105C1BFA1A for ; Mon, 1 Sep 2014 14:25:02 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 3D27A8D2C3 for ; Mon, 1 Sep 2014 14:25:02 +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 yQR1paw8t364 for ; Mon, 1 Sep 2014 14:24:57 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from virtual.dyc.edu (mail.virtual.dyc.edu [67.222.116.22]) by whitealder.osuosl.org (Postfix) with ESMTP id 1CF218F482 for ; Mon, 1 Sep 2014 14:24:57 +0000 (UTC) Received: from yellow.dyc.edu (unknown [192.168.3.7]) by virtual.dyc.edu (Postfix) with ESMTP id 424E47E000B; Mon, 1 Sep 2014 10:24:56 -0400 (EDT) Received: by yellow.dyc.edu (Postfix, from userid 1000) id 920403198057; Mon, 1 Sep 2014 10:27:47 -0400 (EDT) From: basile@opensource.dyc.edu To: uclibc@uclibc.org Subject: [PATCH] libc: add fallocate() and fallocate64() Date: Mon, 1 Sep 2014 10:27:42 -0400 Message-Id: <1409581662-19636-1-git-send-email-basile@opensource.dyc.edu> X-Mailer: git-send-email 1.8.5.5 Cc: "Anthony G. Basile" X-BeenThere: uclibc@uclibc.org X-Mailman-Version: 2.1.14 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-bounces@uclibc.org From: "Anthony G. Basile" We add the Linux-specific system call fallocate() which allows the user to directly manipulate allocate space for a file. The default operation is equivalent to posix_fallocate() which is specified in POSIX.1. However, recent releases of e2fsprogs 1.42.11 and above expect fallocate() to be available. Signed-off-by: Anthony G. Basile --- extra/Configs/Config.in | 1 + include/fcntl.h | 14 ++++++++ libc/sysdeps/linux/common/Makefile.in | 4 +-- libc/sysdeps/linux/common/fallocate.c | 51 +++++++++++++++++++++++++++ libc/sysdeps/linux/common/fallocate64.c | 44 +++++++++++++++++++++++ libc/sysdeps/linux/common/posix_fallocate.c | 21 +---------- libc/sysdeps/linux/common/posix_fallocate64.c | 8 +---- 7 files changed, 114 insertions(+), 29 deletions(-) create mode 100644 libc/sysdeps/linux/common/fallocate.c create mode 100644 libc/sysdeps/linux/common/fallocate64.c diff --git a/extra/Configs/Config.in b/extra/Configs/Config.in index 7789002..b22ffc7 100644 --- a/extra/Configs/Config.in +++ b/extra/Configs/Config.in @@ -1155,6 +1155,7 @@ config UCLIBC_HAS_ADVANCED_REALTIME clock_getcpuclockid() clock_nanosleep() + fallocate() mq_timedreceive() mq_timedsend() posix_fadvise() diff --git a/include/fcntl.h b/include/fcntl.h index c749ad5..c46cdc0 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -225,17 +225,31 @@ extern int posix_fadvise64 (int __fd, __off64_t __offset, __off64_t __len, marked with __THROW. */ # ifndef __USE_FILE_OFFSET64 extern int posix_fallocate (int __fd, __off_t __offset, __off_t __len); +# ifdef __USE_GNU +extern int fallocate (int __fd, int __mode, __off_t __offset, __off_t __len); +# endif # else # ifdef __REDIRECT extern int __REDIRECT (posix_fallocate, (int __fd, __off64_t __offset, __off64_t __len), posix_fallocate64); +# ifdef __USE_GNU +extern int __REDIRECT (fallocate, (int __fd, int __mode, __off64_t __offset, + __off64_t __len), + fallocate64); +# endif # else # define posix_fallocate posix_fallocate64 +# ifdef __USE_GNU +# define fallocate fallocate64 +# endif # endif # endif # ifdef __USE_LARGEFILE64 extern int posix_fallocate64 (int __fd, __off64_t __offset, __off64_t __len); +# ifdef __USE_GNU +extern int fallocate64 (int __fd, int __mode, __off64_t __offset, __off64_t __len); +# endif # endif #endif diff --git a/libc/sysdeps/linux/common/Makefile.in b/libc/sysdeps/linux/common/Makefile.in index 13dd77b..b0f1bde 100644 --- a/libc/sysdeps/linux/common/Makefile.in +++ b/libc/sysdeps/linux/common/Makefile.in @@ -86,9 +86,9 @@ CSRC-$(UCLIBC_HAS_REALTIME) += clock_adjtime.c clock_getres.c clock_gettime.c cl nanosleep.c __rt_sigtimedwait.c __rt_sigwaitinfo.c sched_getparam.c \ sched_get_priority_max.c sched_get_priority_min.c sched_getscheduler.c \ sched_rr_get_interval.c sched_setparam.c sched_setscheduler.c sigqueue.c -# clock_getcpuclockid|clock_nanosleep|mq_timedreceive|mq_timedsend|posix_fadvise|posix_fallocate|posix_madvise|posix_memalign|posix_mem_offset|posix_spawnattr_destroy|posix_spawnattr_init|posix_spawnattr_getflags|posix_spawnattr_setflags|posix_spawnattr_getpgroup|posix_spawnattr_setpgroup|posix_spawnattr_getschedparam|posix_spawnattr_setschedparam|posix_spawnattr_getschedpolicy|posix_spawnattr_setschedpolicy|posix_spawnattr_getsigdefault|posix_spawnattr_setsigdefault|posix_spawnattr_getsigmask|posix_spawnattr_setsigmask|posix_spawnattr_init|posix_spawnattr_setflags|posix_spawnattr_setpgroup|posix_spawnattr_setschedparam|posix_spawnattr_setschedpolicy|posix_spawnattr_setsigdefault|posix_spawnattr_setsigmask|posix_spawn_file_actions_addclose|posix_spawn_file_actions_addopen|posix_spawn_file_actions_adddup2|posix_spawn_file_actions_addopen|posix_spawn_file_actions_destroy|posix_spawn_file_actions_init|posix_spawn_file_actions_init|posix_spawn|posix_spawnp|posix_spawnp|posix_typ ed_mem_g et_info|pthread_mutex_timedlock|sem_timedwait +# clock_getcpuclockid|clock_nanosleep|mq_timedreceive|mq_timedsend|posix_fadvise|posix_fallocate|fallocate|posix_madvise|posix_memalign|posix_mem_offset|posix_spawnattr_destroy|posix_spawnattr_init|posix_spawnattr_getflags|posix_spawnattr_setflags|posix_spawnattr_getpgroup|posix_spawnattr_setpgroup|posix_spawnattr_getschedparam|posix_spawnattr_setschedparam|posix_spawnattr_getschedpolicy|posix_spawnattr_setschedpolicy|posix_spawnattr_getsigdefault|posix_spawnattr_setsigdefault|posix_spawnattr_getsigmask|posix_spawnattr_setsigmask|posix_spawnattr_init|posix_spawnattr_setflags|posix_spawnattr_setpgroup|posix_spawnattr_setschedparam|posix_spawnattr_setschedpolicy|posix_spawnattr_setsigdefault|posix_spawnattr_setsigmask|posix_spawn_file_actions_addclose|posix_spawn_file_actions_addopen|posix_spawn_file_actions_adddup2|posix_spawn_file_actions_addopen|posix_spawn_file_actions_destroy|posix_spawn_file_actions_init|posix_spawn_file_actions_init|posix_spawn|posix_spawnp|posix_spawnp |posix_t yped_mem_get_info|pthread_mutex_timedlock|sem_timedwait CSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_fadvise64.c posix_fadvise.c posix_madvise.c \ - posix_fallocate.c posix_fallocate64.c + posix_fallocate.c posix_fallocate64.c fallocate.c fallocate64.c CSRC-$(UCLIBC_SUSV4_LEGACY) += utime.c CSRC-$(UCLIBC_HAS_EPOLL) += epoll.c CSRC-$(UCLIBC_HAS_XATTR) += xattr.c diff --git a/libc/sysdeps/linux/common/fallocate.c b/libc/sysdeps/linux/common/fallocate.c new file mode 100644 index 0000000..4f37265 --- /dev/null +++ b/libc/sysdeps/linux/common/fallocate.c @@ -0,0 +1,51 @@ +/* vi: set sw=4 ts=4: */ +/* + * fallocate() for uClibc - Based off of posix_fallocate() by Erik Andersen + * http://www.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html + * + * Copyright (C) 2000-2006 Erik Andersen + * + * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball. + */ + +#include +#include +#include +#include + +#if defined __NR_fallocate +int attribute_hidden _fallocate(int fd, int mode, __off_t offset, __off_t len) +{ + int ret; + +# if __WORDSIZE == 32 + uint32_t off_low = offset; + uint32_t len_low = len; + /* may assert that these >>31 are 0 */ + uint32_t zero = 0; + INTERNAL_SYSCALL_DECL(err); + ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, mode, + __LONG_LONG_PAIR (zero, off_low), + __LONG_LONG_PAIR (zero, len_low))); +# elif __WORDSIZE == 64 + INTERNAL_SYSCALL_DECL(err); + ret = (int) (INTERNAL_SYSCALL(fallocate, err, 4, fd, mode, offset, len)); +# 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 defined __USE_GNU +int fallocate(int fd, int mode, __off_t offset, __off_t len) +{ + return _fallocate(fd, mode, offset, len); +} +# if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64 +strong_alias(fallocate,fallocate64) +# endif +# endif + +#endif diff --git a/libc/sysdeps/linux/common/fallocate64.c b/libc/sysdeps/linux/common/fallocate64.c new file mode 100644 index 0000000..9dc0234 --- /dev/null +++ b/libc/sysdeps/linux/common/fallocate64.c @@ -0,0 +1,44 @@ +/* vi: set sw=4 ts=4: */ +/* + * fallocate() for uClibc - based off posix_fallocate() by Erik Andersen + * http://www.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html + * + * Copyright (C) 2000-2006 Erik Andersen + * + * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball. + */ + +#include + +#include +#include +#include + +#if defined __NR_fallocate + +# if __WORDSIZE == 64 +/* Can use normal fallocate() */ +# elif __WORDSIZE == 32 +int attribute_hidden _fallocate64(int fd, int mode, __off64_t offset, __off64_t len) +{ + int ret; + 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 defined __USE_GNU +int fallocate64(int fd, int mode, __off64_t offset, __off64_t len) +{ + return _fallocate64(fd, mode, offset, len); +} +# endif + +# else +# error your machine is neither 32 bit or 64 bit ... it must be magical +# endif +#endif + diff --git a/libc/sysdeps/linux/common/posix_fallocate.c b/libc/sysdeps/linux/common/posix_fallocate.c index 9aaa6ce..0da9267 100644 --- a/libc/sysdeps/linux/common/posix_fallocate.c +++ b/libc/sysdeps/linux/common/posix_fallocate.c @@ -16,26 +16,7 @@ #if defined __NR_fallocate int posix_fallocate(int fd, __off_t offset, __off_t len) { - int ret; - -# if __WORDSIZE == 32 - uint32_t off_low = offset; - uint32_t len_low = len; - /* may assert that these >>31 are 0 */ - uint32_t zero = 0; - INTERNAL_SYSCALL_DECL(err); - ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, 0, - __LONG_LONG_PAIR (zero, off_low), - __LONG_LONG_PAIR (zero, len_low))); -# elif __WORDSIZE == 64 - INTERNAL_SYSCALL_DECL(err); - ret = (int) (INTERNAL_SYSCALL(fallocate, err, 4, fd, 0, offset, len)); -# 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; + return _fallocate(fd, 0, offset, len); } # if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64 strong_alias(posix_fallocate,posix_fallocate64) diff --git a/libc/sysdeps/linux/common/posix_fallocate64.c b/libc/sysdeps/linux/common/posix_fallocate64.c index 76dc9b8..f003a57 100644 --- a/libc/sysdeps/linux/common/posix_fallocate64.c +++ b/libc/sysdeps/linux/common/posix_fallocate64.c @@ -20,13 +20,7 @@ # elif __WORDSIZE == 32 int posix_fallocate64(int fd, __off64_t offset, __off64_t len) { - int ret; - INTERNAL_SYSCALL_DECL(err); - ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, 0, - OFF64_HI_LO (offset), OFF64_HI_LO (len))); - if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err))) - return INTERNAL_SYSCALL_ERRNO (ret, err); - return 0; + return _fallocate64(fd, 0, offset, len); } # else # error your machine is neither 32 bit or 64 bit ... it must be magical