OSDN Git Service

Fix the mac host build of e2fsprogs
authorKen Sumrall <ksumrall@android.com>
Fri, 27 Apr 2012 02:27:17 +0000 (19:27 -0700)
committerKen Sumrall <ksumrall@android.com>
Fri, 27 Apr 2012 02:27:17 +0000 (19:27 -0700)
Mac OS doesn't support the O_DIRECT flag, so use the F_NOCACHE
option of fcntl() instead.  Fix taken from the libext2 project
on soruceforge.

Change-Id: I1e88a95e53f1bbbd8dbcfc7aa43a27443dfd6807

lib/ext2fs/unix_io.c

index 1df1fdd..5bf2c92 100644 (file)
@@ -428,6 +428,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;
+       int             f_nocache = 0;
        struct stat     st;
 #ifdef __linux__
        struct          utsname ut;
@@ -464,7 +465,11 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel)
        if (flags & IO_FLAG_EXCLUSIVE)
                open_flags |= O_EXCL;
        if (flags & IO_FLAG_DIRECT_IO)
+#if !defined(O_DIRECT) && defined(F_NOCACHE)
+               f_nocache = F_NOCACHE;
+#else
                open_flags |= O_DIRECT;
+#endif
        data->flags = flags;
 
 #ifdef HAVE_OPEN64
@@ -477,6 +482,13 @@ static errcode_t unix_open(const char *name, int flags, io_channel *channel)
                goto cleanup;
        }
 
+       if (f_nocache) {
+               if (fcntl(data->dev, f_nocache, 1) < 0) {
+                       retval = errno;
+                       goto cleanup;
+               }
+       }
+
 #ifdef BLKSSZGET
        if (flags & IO_FLAG_DIRECT_IO) {
                if (ioctl(data->dev, BLKSSZGET, &data->align) != 0)