summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common/fallocate.c
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2014-09-07 15:33:46 -0400
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2014-09-09 13:48:45 +0200
commit33a12b5540b8abbc4ee0ecb3a51912b3c7868517 (patch)
tree399a161fa8ae09eab39c25f17686c496a05b9b2b /libc/sysdeps/linux/common/fallocate.c
parent7efe10ec5fc772f5328b35ba6716bde815212b45 (diff)
libc: add fallocate() and fallocate64()
We add the Linux-specific function fallocate() which allows the user to directly manipulate allocate space for a file. fallocate() can operate in different modes, but the default mode is equivalent to posix_fallocate() which is specified in POSIX.1. Recent releases of e2fsprogs 1.42.11 and above expect fallocate64() to be available. Signed-off-by: Anthony G. Basile <blueness@gentoo.org> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Diffstat (limited to 'libc/sysdeps/linux/common/fallocate.c')
-rw-r--r--libc/sysdeps/linux/common/fallocate.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/libc/sysdeps/linux/common/fallocate.c b/libc/sysdeps/linux/common/fallocate.c
new file mode 100644
index 000000000..b23122669
--- /dev/null
+++ b/libc/sysdeps/linux/common/fallocate.c
@@ -0,0 +1,48 @@
+/* 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 <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
+extern __typeof(fallocate) __libc_fallocate attribute_hidden;
+int attribute_hidden __libc_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 __UCLIBC_LINUX_SPECIFIC__ && defined __USE_GNU
+strong_alias(__libc_fallocate,fallocate)
+# if __WORDSIZE == 64
+strong_alias(__libc_fallocate,fallocate64)
+# endif
+# endif
+#endif