diff --git a/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c b/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c index 13972b92e4e..5f3658e70df 100644 --- a/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c +++ b/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include #include @@ -167,9 +169,18 @@ Java_sun_nio_ch_FileDispatcherImpl_force0(JNIEnv *env, jobject this, #ifdef MACOSX result = fcntl(fd, F_FULLFSYNC); - if (result == -1 && errno == ENOTSUP) { - /* Try fsync() in case F_FULLSYUNC is not implemented on the file system. */ - result = fsync(fd); + if (result == -1) { + struct statfs fbuf; + int errno_fcntl = errno; + if (fstatfs(fd, &fbuf) == 0) { + if ((fbuf.f_flags & MNT_LOCAL) == 0) { + /* Try fsync() in case file is not local. */ + result = fsync(fd); + } + } else { + /* fstatfs() failed so restore errno from fcntl(). */ + errno = errno_fcntl; + } } #else /* end MACOSX, begin not-MACOSX */ if (md == JNI_FALSE) {