]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: support O_DIRECT functionality for Mac OS X
authorTheodore Ts'o <tytso@mit.edu>
Tue, 21 Feb 2012 01:45:52 +0000 (20:45 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 21 Feb 2012 01:45:52 +0000 (20:45 -0500)
Darwin uses fcntl(fd, F_NOCACHE, 1) instead of the O_DIRECT flag.

Addresses-SourceForge-Bug: #3140289

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/ext2fs/unix_io.c

index 53370224233e16bb07980726734422acc0dd7395..9f0613a2b29463ee94907852cc1cb9a47dad1126 100644 (file)
@@ -445,6 +445,7 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel)
        struct unix_private_data *data = NULL;
        errcode_t       retval;
        int             open_flags, zeroes = 0;
+       int             f_nocache = 0;
        ext2fs_struct_stat st;
 #ifdef __linux__
        struct          utsname ut;
@@ -480,9 +481,12 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel)
        open_flags = (flags & IO_FLAG_RW) ? O_RDWR : O_RDONLY;
        if (flags & IO_FLAG_EXCLUSIVE)
                open_flags |= O_EXCL;
-#ifdef O_DIRECT
+#if defined(O_DIRECT)
        if (flags & IO_FLAG_DIRECT_IO)
                open_flags |= O_DIRECT;
+#elif defined(F_NOCACHE)
+       if (flags & IO_FLAG_DIRECT_IO)
+               f_nocache = F_NOCACHE;
 #endif
        data->flags = flags;
 
@@ -491,6 +495,12 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel)
                retval = errno;
                goto cleanup;
        }
+       if (f_nocache) {
+               if (fcntl(data->dev, f_nocache, 1) < 0) {
+                       retval = errno;
+                       goto cleanup;
+               }
+       }
 
        /*
         * If the device is really a block device, then set the