--- old/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c 2017-08-09 14:53:24.390811156 -0700 +++ new/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c 2017-08-09 14:53:24.284811155 -0700 @@ -34,6 +34,7 @@ #include #include #include +#include #if defined(__linux__) #include #include @@ -323,3 +324,50 @@ { closeFileDescriptor(env, fd); } + +JNIEXPORT jint JNICALL +Java_sun_nio_ch_FileDispatcherImpl_setDirect0(JNIEnv *env, jclass clazz, + jobject fdo) +{ + jint fd = fdval(env, fdo); + jint result; + struct statvfs file_stat; + +#if defined(O_DIRECT) || defined(F_NOCACHE) || defined(DIRECTIO_ON) +#ifdef O_DIRECT + jint orig_flag; + orig_flag = fcntl(fd, F_GETFL); + if (orig_flag == -1) { + JNU_ThrowIOExceptionWithLastError(env, "DirectIO setup failed"); + return -1; + } + result = fcntl(fd, F_SETFL, orig_flag | O_DIRECT); + if (result == -1) { + JNU_ThrowIOExceptionWithLastError(env, "DirectIO setup failed"); + return result; + } +#elif F_NOCACHE + result = fcntl(fd, F_NOCACHE, 1); + if (result == -1) { + JNU_ThrowIOExceptionWithLastError(env, "DirectIO setup failed"); + return result; + } +#elif DIRECTIO_ON + result = directio(fd, DIRECTIO_ON); + if (result == -1) { + JNU_ThrowIOExceptionWithLastError(env, "DirectIO setup failed"); + return result; + } +#endif + result = fstatvfs(fd, &file_stat); + if(result == -1) { + JNU_ThrowIOExceptionWithLastError(env, "DirectIO setup failed"); + return result; + } else { + result = (int)file_stat.f_frsize; + } +#else + result == -1; +#endif + return result; +}