filesetup: add native fallocate
[fio.git] / os / os-mac.h
index 76d388e9201f357b8c6867ca9f8e0e5c799e1602..a1536c70fabaf9e2de907eab9ffec0740f2bb3db 100644 (file)
@@ -20,6 +20,7 @@
 #define FIO_USE_GENERIC_INIT_RANDOM_STATE
 #define FIO_HAVE_GETTID
 #define FIO_HAVE_CHARDEV_SIZE
+#define FIO_HAVE_NATIVE_FALLOCATE
 
 #define OS_MAP_ANON            MAP_ANON
 
@@ -35,7 +36,9 @@
 
 typedef off_t off64_t;
 
+#ifndef CONFIG_CLOCKID_T
 typedef unsigned int clockid_t;
+#endif
 
 #define FIO_OS_DIRECTIO
 static inline int fio_set_odirect(int fd)
@@ -75,7 +78,7 @@ static inline int chardev_size(struct fio_file *f, unsigned long long *bytes)
 
 static inline int blockdev_invalidate_cache(struct fio_file *f)
 {
-       return EINVAL;
+       return ENOTSUP;
 }
 
 static inline unsigned long long os_phys_mem(void)
@@ -99,4 +102,15 @@ static inline int gettid(void)
  */
 extern int fdatasync(int fd);
 
+static inline bool fio_fallocate(struct fio_file *f, uint64_t offset, uint64_t len)
+{
+       fstore_t store = {F_ALLOCATEALL, F_PEOFPOSMODE, offset, len};
+       if (fcntl(f->fd, F_PREALLOCATE, &store) != -1) {
+               if (ftruncate(f->fd, len) == 0)
+                       return true;
+       }
+
+       return false;
+}
+
 #endif