Index: lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java
===================================================================
--- lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java	(revision 1147539)
+++ lucene/contrib/misc/src/java/org/apache/lucene/store/DirectIOLinuxDirectory.java	(working copy)
@@ -27,6 +27,7 @@
 
 import org.apache.lucene.store.Directory; // javadoc
 import org.apache.lucene.store.NativeFSLockFactory; // javadoc
+import org.apache.lucene.store.IOContext.Context;
 
 /**
  * An {@link Directory} implementation that uses the
@@ -72,7 +73,7 @@
   public IndexInput openInput(String name, IOContext context) throws IOException {
     ensureOpen();
     return new DirectIOLinuxIndexInput(new File(getDirectory(), name),
-        bufferSize(context));
+        bufferSize(context), context);
   }
 
   @Override
@@ -243,9 +244,13 @@
     private long filePos;
     private int bufferPos;
 
-    public DirectIOLinuxIndexInput(File path, int bufferSize) throws IOException {
-      // TODO make use of IOContext
-      FileDescriptor fd = NativePosixUtil.open_direct(path.toString(), true);
+    public DirectIOLinuxIndexInput(File path, int bufferSize, IOContext context) throws IOException {
+      FileDescriptor fd;
+      if (context.context ==  Context.MERGE) 
+        fd = NativePosixUtil.open_direct(path.toString(), true);      
+      else
+        fd = NativePosixUtil.open_normal(path.toString(), true);
+      
       fis = new FileInputStream(fd);
       channel = fis.getChannel();
       this.bufferSize = bufferSize;
Index: lucene/contrib/misc/src/java/org/apache/lucene/store/NativePosixUtil.cpp
===================================================================
--- lucene/contrib/misc/src/java/org/apache/lucene/store/NativePosixUtil.cpp	(revision 1147539)
+++ lucene/contrib/misc/src/java/org/apache/lucene/store/NativePosixUtil.cpp	(working copy)
@@ -15,10 +15,20 @@
  * the License.
  */
 
-#include <jni.h>
-#include <fcntl.h>   // posix_fadvise, constants for open
-#include <string.h>   // strerror
-#include <errno.h>   // errno
+#if linux
+  #include "posix_fadvise.h"
+  #define DIRECT_FLAG O_DIRECT | O_NOATIME
+  #define NORMAL_FLAG O_NOATIME
+#elif __APPLE__
+  #define DIRECT_FLAG 0
+  #define NORMAL_FLAG 0
+  #define OSX "apple"
+#else
+  #include "posix_fadvise.h" // __unix__ is not used as even Linux falls under it.
+  #define DIRECT_FLAG O_DIRECT
+  #define NORMAL_FLAG 0
+#endif
+
 #include <unistd.h>   // pread
 #include <sys/mman.h>   // posix_madvise, madvise
 #include <sys/types.h>  // constants for open
@@ -28,76 +38,72 @@
 
 /*
  * Class:     org_apache_lucene_store_NativePosixUtil
- * Method:    posix_fadvise
- * Signature: (Ljava/io/FileDescriptor;JJI)V
+ * Method:    open_direct
+ * Signature: (Ljava/lang/String;Z)Ljava/io/FileDescriptor;
  */
+
 extern "C"
-JNIEXPORT jint JNICALL Java_org_apache_lucene_store_NativePosixUtil_posix_1fadvise(JNIEnv *env, jclass _ignore, jobject fileDescriptor, jlong offset, jlong len, jint advice)
+JNIEXPORT jobject JNICALL Java_org_apache_lucene_store_NativePosixUtil_open_1direct(JNIEnv *env, jclass _ignore, jstring filename, jboolean readOnly)
 {
   jfieldID field_fd;
   jmethodID const_fdesc;
+  jclass class_fdesc, class_ioex;
+  jobject ret;
+  int fd;
+  char *fname;
 
-  jclass ioex = env->FindClass("java/io/IOException");
-  if (ioex == NULL) {
-    return -1;
-  }
+  class_ioex = env->FindClass("java/io/IOException");
+  if (class_ioex == NULL) return NULL;
+  class_fdesc = env->FindClass("java/io/FileDescriptor");
+  if (class_fdesc == NULL) return NULL;
 
-  jclass fdesc = env->FindClass("java/io/FileDescriptor");
-  if (fdesc == NULL) {
-    return -2;
-  }
+  fname = (char *) env->GetStringUTFChars(filename, NULL);
 
-  // read the int fd field
-  jfieldID fdField = env->GetFieldID(fdesc, "fd", "I");
-  if (fdField == NULL) {
-    return -3;
+  if (readOnly) {
+    fd = open(fname, O_RDONLY | DIRECT_FLAG);
+    #ifdef OSX
+      fcntl(fd, F_NOCACHE, 1);
+    #endif 
+  } else {
+    fd = open(fname, O_RDWR | O_CREAT | DIRECT_FLAG, 0666);
+    #ifdef OSX
+      fcntl(fd, F_NOCACHE, 1);
+    #endif 
   }
 
-  int fd = env->GetIntField(fileDescriptor, fdField);
-  //printf("fd=%d\n", fd);  fflush(stdout);
+  //printf("open %s -> %d; ro %d\n", fname, fd, readOnly); fflush(stdout);
 
-  int osAdvice;
-  switch(advice) {
+  env->ReleaseStringUTFChars(filename, fname);
 
-  case 0:
-    osAdvice = POSIX_FADV_NORMAL;
-    break;
-  case 1:
-    osAdvice = POSIX_FADV_SEQUENTIAL;
-    break;
-  case 2:
-    osAdvice = POSIX_FADV_RANDOM;
-    break;
-  case 3:
-    osAdvice = POSIX_FADV_WILLNEED;
-    break;
-  case 4:
-    osAdvice = POSIX_FADV_DONTNEED;
-    break;
-  case 5:
-    osAdvice = POSIX_FADV_NOREUSE;
-    break;
+  if (fd < 0) {
+    // open returned an error. Throw an IOException with the error string
+    env->ThrowNew(class_ioex, strerror(errno));
+    return NULL;
   }
 
-  int result = posix_fadvise(fd, (off_t) offset, (off_t) len, osAdvice);
-  if (result == 0) {
-    // ok
-  } else {
-    env->ThrowNew(ioex, strerror(errno));
-    return -1;
-  }
+  // construct a new FileDescriptor
+  const_fdesc = env->GetMethodID(class_fdesc, "<init>", "()V");
+  if (const_fdesc == NULL) return NULL;
+  ret = env->NewObject(class_fdesc, const_fdesc);
 
-  return 0;
+  // poke the "fd" field with the file descriptor
+  field_fd = env->GetFieldID(class_fdesc, "fd", "I");
+  if (field_fd == NULL) return NULL;
+  env->SetIntField(ret, field_fd, fd);
+
+  // and return it
+  return ret;
 }
 
 
 /*
  * Class:     org_apache_lucene_store_NativePosixUtil
- * Method:    open_direct
+ * Method:    open_normal
  * Signature: (Ljava/lang/String;Z)Ljava/io/FileDescriptor;
  */
+
 extern "C"
-JNIEXPORT jobject JNICALL Java_org_apache_lucene_store_NativePosixUtil_open_1direct(JNIEnv *env, jclass _ignore, jstring filename, jboolean readOnly)
+JNIEXPORT jobject JNICALL Java_org_apache_lucene_store_NativePosixUtil_open_1normal(JNIEnv *env, jclass _ignore, jstring filename, jboolean readOnly)
 {
   jfieldID field_fd;
   jmethodID const_fdesc;
@@ -114,9 +120,9 @@
   fname = (char *) env->GetStringUTFChars(filename, NULL);
 
   if (readOnly) {
-    fd = open(fname, O_RDONLY | O_DIRECT | O_NOATIME);
+    fd = open(fname, O_RDONLY | NORMAL_FLAG);
   } else {
-    fd = open(fname, O_RDWR | O_CREAT | O_DIRECT | O_NOATIME, 0666);
+    fd = open(fname, O_RDWR | O_CREAT | NORMAL_FLAG, 0666);
   }
 
   //printf("open %s -> %d; ro %d\n", fname, fd, readOnly); fflush(stdout);
@@ -143,7 +149,6 @@
   return ret;
 }
 
-
 /*
  * Class:     org_apache_lucene_store_NativePosixUtil
  * Method:    pread
Index: lucene/contrib/misc/src/java/org/apache/lucene/store/NativePosixUtil.java
===================================================================
--- lucene/contrib/misc/src/java/org/apache/lucene/store/NativePosixUtil.java	(revision 1147539)
+++ lucene/contrib/misc/src/java/org/apache/lucene/store/NativePosixUtil.java	(working copy)
@@ -37,6 +37,7 @@
   public static native int posix_madvise(ByteBuffer buf, int advise) throws IOException;
   public static native int madvise(ByteBuffer buf, int advise) throws IOException;
   public static native FileDescriptor open_direct(String filename, boolean read) throws IOException;
+  public static native FileDescriptor open_normal(String filename, boolean read) throws IOException; 
   public static native long pread(FileDescriptor fd, long pos, ByteBuffer byteBuf) throws IOException;
 
   public static void advise(FileDescriptor fd, long offset, long len, int advise) throws IOException {
Index: lucene/contrib/misc/src/java/org/apache/lucene/store/posix_fadvise.h
===================================================================
--- lucene/contrib/misc/src/java/org/apache/lucene/store/posix_fadvise.h	(revision 0)
+++ lucene/contrib/misc/src/java/org/apache/lucene/store/posix_fadvise.h	(revision 0)
@@ -0,0 +1,85 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+#include <jni.h>
+#include <fcntl.h>   // posix_fadvise, constants for open
+#include <string.h>   // strerror
+#include <errno.h>   // errno
+
+/*
+ * Class:     org_apache_lucene_store_NativePosixUtil
+ * Method:    posix_fadvise
+ * Signature: (Ljava/io/FileDescriptor;JJI)V
+ */
+extern "C"
+JNIEXPORT jint JNICALL Java_org_apache_lucene_store_NativePosixUtil_posix_1fadvise(JNIEnv *env, jclass _ignore, jobject fileDescriptor, jlong offset, jlong len, jint advice)
+{
+  jfieldID field_fd;
+  jmethodID const_fdesc;
+
+  jclass ioex = env->FindClass("java/io/IOException");
+  if (ioex == NULL) {
+    return -1;
+  }
+
+  jclass fdesc = env->FindClass("java/io/FileDescriptor");
+  if (fdesc == NULL) {
+    return -2;
+  }
+
+  // read the int fd field
+  jfieldID fdField = env->GetFieldID(fdesc, "fd", "I");
+  if (fdField == NULL) {
+    return -3;
+  }
+
+  int fd = env->GetIntField(fileDescriptor, fdField);
+  //printf("fd=%d\n", fd);  fflush(stdout);
+
+  int osAdvice;
+  switch(advice) {
+
+  case 0:
+    osAdvice = POSIX_FADV_NORMAL;
+    break;
+  case 1:
+    osAdvice = POSIX_FADV_SEQUENTIAL;
+    break;
+  case 2:
+    osAdvice = POSIX_FADV_RANDOM;
+    break;
+  case 3:
+    osAdvice = POSIX_FADV_WILLNEED;
+    break;
+  case 4:
+    osAdvice = POSIX_FADV_DONTNEED;
+    break;
+  case 5:
+    osAdvice = POSIX_FADV_NOREUSE;
+    break;
+  }
+
+  int result = posix_fadvise(fd, (off_t) offset, (off_t) len, osAdvice);
+  if (result == 0) {
+    // ok
+  } else {
+    env->ThrowNew(ioex, strerror(errno));
+    return -1;
+  }
+
+  return 0;
+}
