From 457be276d829dfa9f9756778ab153ccaa9247eaf Mon Sep 17 00:00:00 2001 From: Brian Burkhalter Date: Thu, 21 May 2015 09:57:59 -0700 Subject: [PATCH] 8080589: (fs) FileChannel.force should use fcntl(F_FULLFSYNC) instead of fsync on OS X Replace f[data]sync(fd) with fcntl(fd, F_FULLSYNC) on OS X. Reviewed-by: alanb --- .../unix/native/libnio/ch/FileDispatcherImpl.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/jdk/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c b/jdk/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c index 403c15cad06..8738d5f9f68 100644 --- a/jdk/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c +++ b/jdk/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c @@ -148,6 +148,13 @@ Java_sun_nio_ch_FileDispatcherImpl_force0(JNIEnv *env, jobject this, jint fd = fdval(env, fdo); int result = 0; +#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); + } +#else /* end MACOSX, begin not-MACOSX */ if (md == JNI_FALSE) { result = fdatasync(fd); } else { @@ -163,9 +170,10 @@ Java_sun_nio_ch_FileDispatcherImpl_force0(JNIEnv *env, jobject this, if (getfl >= 0 && (getfl & O_ACCMODE) == O_RDONLY) { return 0; } -#endif +#endif /* _AIX */ result = fsync(fd); } +#endif /* not-MACOSX */ return handle(env, result, "Force failed"); }