summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2012-04-17 09:30:15 +0200
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2013-02-11 09:42:15 +0100
commit5643900913f64c00f1c2958914586708efa5a473 (patch)
tree4b0c5fcf655a00181098bbdfee1614fc119dd10a /libc
parent971db25812b6b7176f509a5f37964610a8f4b475 (diff)
libc: add posix_fallocate()
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Diffstat (limited to 'libc')
-rw-r--r--libc/sysdeps/linux/common/Makefile.in3
-rw-r--r--libc/sysdeps/linux/common/bits/kernel-features.h8
-rw-r--r--libc/sysdeps/linux/common/posix_fallocate.c43
-rw-r--r--libc/sysdeps/linux/common/posix_fallocate64.c39
4 files changed, 92 insertions, 1 deletions
diff --git a/libc/sysdeps/linux/common/Makefile.in b/libc/sysdeps/linux/common/Makefile.in
index 566722d44..29566dd98 100644
--- a/libc/sysdeps/linux/common/Makefile.in
+++ b/libc/sysdeps/linux/common/Makefile.in
@@ -82,7 +82,8 @@ CSRC-$(UCLIBC_HAS_REALTIME) += clock_getres.c clock_gettime.c clock_settime.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_typed_mem_get_info|pthread_mutex_timedlock|sem_timedwait
-CSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_fadvise64.c posix_fadvise.c posix_madvise.c
+CSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_fadvise64.c posix_fadvise.c posix_madvise.c \
+ posix_fallocate.c posix_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/bits/kernel-features.h b/libc/sysdeps/linux/common/bits/kernel-features.h
index 4d1e0cbc3..6184c2b9d 100644
--- a/libc/sysdeps/linux/common/bits/kernel-features.h
+++ b/libc/sysdeps/linux/common/bits/kernel-features.h
@@ -495,6 +495,14 @@
# define __ASSUME_PRIVATE_FUTEX 1
#endif
+/* Support for fallocate was added in 2.6.23,
+ on s390 only after 2.6.23-rc1, on alpha only after 2.6.33-rc1. */
+#if __LINUX_KERNEL_VERSION >= 0x020617 \
+ && (!defined __s390__ || __LINUX_KERNEL_VERSION >= 0x020618) \
+ && (!defined __alpha__ || __LINUX_KERNEL_VERSION >= 0x020621)
+# define __ASSUME_FALLOCATE 1
+#endif
+
/* getcpu is a syscall for x86-64 since 3.1. */
#if defined __x86_64__ && __LINUX_KERNEL_VERSION >= 0x030100
# define __ASSUME_GETCPU_SYSCALL 1
diff --git a/libc/sysdeps/linux/common/posix_fallocate.c b/libc/sysdeps/linux/common/posix_fallocate.c
new file mode 100644
index 000000000..9aaa6ce15
--- /dev/null
+++ b/libc/sysdeps/linux/common/posix_fallocate.c
@@ -0,0 +1,43 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * posix_fallocate() for uClibc
+ * http://www.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html
+ *
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
+ */
+
+#include <sys/syscall.h>
+#include <fcntl.h>
+#include <bits/kernel-features.h>
+#include <stdint.h>
+
+#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;
+}
+# if defined __UCLIBC_HAS_LFS__ && __WORDSIZE == 64
+strong_alias(posix_fallocate,posix_fallocate64)
+# endif
+#endif
diff --git a/libc/sysdeps/linux/common/posix_fallocate64.c b/libc/sysdeps/linux/common/posix_fallocate64.c
new file mode 100644
index 000000000..818d86884
--- /dev/null
+++ b/libc/sysdeps/linux/common/posix_fallocate64.c
@@ -0,0 +1,39 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * posix_fallocate() for uClibc
+ * http://www.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html
+ *
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
+ */
+
+#include <sys/syscall.h>
+#include <fcntl.h>
+#include <bits/kernel-features.h>
+#include <stdint.h>
+
+#if defined __NR_fallocate
+
+# if __WORDSIZE == 64
+/* Can use normal posix_fallocate() */
+# elif __WORDSIZE == 32
+int posix_fallocate64(int fd, __off64_t offset, __off64_t len)
+{
+ int ret;
+ uint32_t off_low = offset & 0xffffffff;
+ uint32_t off_high = offset >> 32;
+ uint32_t len_low = len & 0xffffffff;
+ uint32_t len_high = len >> 32;
+ INTERNAL_SYSCALL_DECL(err);
+ ret = (int) (INTERNAL_SYSCALL(fallocate, err, 6, fd, 0,
+ __LONG_LONG_PAIR (off_high, off_low),
+ __LONG_LONG_PAIR (len_high, len_low)));
+ if (unlikely(INTERNAL_SYSCALL_ERROR_P (ret, err)))
+ return INTERNAL_SYSCALL_ERRNO (ret, err);
+ return 0;
+}
+# else
+# error your machine is neither 32 bit or 64 bit ... it must be magical
+# endif
+#endif