Fix compile on older systems that don't have fallocate() on Linux
Commit a596f047 broke build en eg CentOS 5:
filesetup.c:17:26: error: linux/falloc.h: No such file or directory
filesetup.c: In function 'extend_file':
filesetup.c:95: warning: implicit declaration of function 'fallocate'
filesetup.c:95: error: 'FALLOC_FL_KEEP_SIZE' undeclared (first use in this function)
filesetup.c:95: error: (Each undeclared identifier is reported only once
filesetup.c:95: error: for each function it appears in.)
make: *** [filesetup.o] Error 1
Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
diff --git a/helpers.c b/helpers.c
index 1b6dea8..9562567 100644
--- a/helpers.c
+++ b/helpers.c
@@ -9,6 +9,12 @@
#include "arch/arch.h"
#include "os/os.h"
+int _weak fallocate(int fd, int mode, off_t offset, off_t len)
+{
+ errno = ENOSYS;
+ return -1;
+}
+
#ifndef __NR_fallocate
int _weak posix_fallocate(int fd, off_t offset, off_t len)
{
diff --git a/helpers.h b/helpers.h
index 7b1ad34..da20a6b 100644
--- a/helpers.h
+++ b/helpers.h
@@ -7,6 +7,7 @@
struct in_addr;
+extern int _weak fallocate(int fd, int mode, off_t offset, off_t len);
extern int _weak posix_memalign(void **ptr, size_t align, size_t size);
extern int _weak posix_fallocate(int fd, off_t offset, off_t len);
extern int _weak inet_aton(const char *cp, struct in_addr *inp);
diff --git a/os/os-linux.h b/os/os-linux.h
index 024ef89..34a7cc5 100644
--- a/os/os-linux.h
+++ b/os/os-linux.h
@@ -32,7 +32,6 @@
#define FIO_HAVE_BLKTRACE
#define FIO_HAVE_STRSEP
#define FIO_HAVE_FALLOCATE
-#define FIO_HAVE_LINUX_FALLOCATE
#define FIO_HAVE_POSIXAIO_FSYNC
#define FIO_HAVE_PSHARED_MUTEX
#define FIO_HAVE_CL_SIZE
@@ -43,6 +42,14 @@
#define FIO_HAVE_BINJECT
#define FIO_HAVE_CLOCK_MONOTONIC
+/*
+ * Can only enable this for newer glibcs, or the header and defines are
+ * missing
+ */
+#if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 6
+#define FIO_HAVE_LINUX_FALLOCATE
+#endif
+
#ifdef SYNC_FILE_RANGE_WAIT_BEFORE
#define FIO_HAVE_SYNC_FILE_RANGE
#endif