]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blobdiff - lib/ext2fs/unix_io.c
Merge branch 'maint' into next
[thirdparty/e2fsprogs.git] / lib / ext2fs / unix_io.c
index 23f22e30f22b862b1b5ac42dcf9dfb266dc7c5e3..c3a8ea5f9f9ca5281b58b92593bc33bb3699174f 100644 (file)
@@ -15,6 +15,9 @@
  * %End-Header%
  */
 
+#define _XOPEN_SOURCE 600
+#define _DARWIN_C_SOURCE
+#define _FILE_OFFSET_BITS 64
 #define _LARGEFILE_SOURCE
 #define _LARGEFILE64_SOURCE
 #ifndef _GNU_SOURCE
@@ -35,6 +38,9 @@
 #ifdef __linux__
 #include <sys/utsname.h>
 #endif
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
 #ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
 #endif
@@ -44,9 +50,6 @@
 #if HAVE_SYS_STAT_H
 #include <sys/stat.h>
 #endif
-#if HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
 #if HAVE_SYS_RESOURCE_H
 #include <sys/resource.h>
 #endif
@@ -831,6 +834,23 @@ static errcode_t unix_write_blk64(io_channel channel, unsigned long long block,
 #endif /* NO_IO_CACHE */
 }
 
+static errcode_t unix_cache_readahead(io_channel channel,
+                                     unsigned long long block,
+                                     unsigned long long count)
+{
+#ifdef POSIX_FADV_WILLNEED
+       struct unix_private_data *data;
+
+       data = (struct unix_private_data *)channel->private_data;
+       return posix_fadvise(data->dev,
+                            (ext2_loff_t)block * channel->block_size,
+                            (ext2_loff_t)count * channel->block_size,
+                            POSIX_FADV_WILLNEED);
+#else
+       return EXT2_ET_OP_NOT_SUPPORTED;
+#endif
+}
+
 static errcode_t unix_write_blk(io_channel channel, unsigned long block,
                                int count, const void *buf)
 {
@@ -982,6 +1002,7 @@ static struct struct_io_manager struct_unix_manager = {
        .read_blk64     = unix_read_blk64,
        .write_blk64    = unix_write_blk64,
        .discard        = unix_discard,
+       .cache_readahead        = unix_cache_readahead,
 };
 
 io_manager unix_io_manager = &struct_unix_manager;