filesetup: add native fallocate
[fio.git] / os / os-linux.h
index 8c1e93be067c9e0cd702ed23b4e8baba5a7f5ef7..e7d600dd58cbb3f6ffd1e43f5516fdd6fc0bd18a 100644 (file)
@@ -392,4 +392,22 @@ static inline int shm_attach_to_open_removed(void)
        return 1;
 }
 
+#ifdef CONFIG_LINUX_FALLOCATE
+#define FIO_HAVE_NATIVE_FALLOCATE
+static inline bool fio_fallocate(struct fio_file *f, uint64_t offset,
+                                uint64_t len)
+{
+       int ret;
+       ret = fallocate(f->fd, 0, 0, len);
+       if (ret == 0)
+               return true;
+
+       /* Work around buggy old glibc versions... */
+       if (ret > 0)
+               errno = ret;
+
+       return false;
+}
+#endif
+
 #endif