[erlang-patches] Patch for file::sync() to use fcntl(F_FULLFSYNC) on Darwin / Mac OS X

Jan Lehnardt <>
Thu Jul 17 20:45:38 CEST 2008


Dear OTP Team,

traditionally, on UNIX systems the fsync() system call is used
to flush any filesystem buffers to disk. The file::sync() function
triggers a fsync() call in OTP R12B-3

On Darwin (and Mac OS X) systems, the fsync() system call
exists, but does not guarantee the writing to disk. The
fcntl(F_FULLFSYNC) function call exists to achieve this.
See http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/fsync.2.html
and http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/fcntl.2.html
for reference.

The patch below adds some #ifdefs to figure out if it is
compiled on a Darwin system and uses the fcntl() function
instead of the fsync() function.

Please note my poor understanding of how your build system
actually detects the target host. My way of detecting Darwin
was shamelessly ripped from elsewhere in the source tree
and might be wrong in this case (although testing was successful).
Please feel free to make any necessary changes in case you
choose to integrate the patch.

I'm working on the CouchDB project (yes, a database in Erlang),
and we require a reliable file::sync()-behaviour for data consistency.

Adding this to OTP would be highly appreciated.

Cheers
Jan & the CouchDB Team
--

--- erts/emulator/drivers/unix/unix_efile.c.orig	2008-07-17  
20:44:23.000000000 +0200
+++ erts/emulator/drivers/unix/unix_efile.c	2008-07-17  
20:44:21.000000000 +0200
@@ -44,6 +44,14 @@
  #endif
  #endif /* _OSE_ */

+#if defined(__APPLE__) && defined(__MACH__) && !defined(__DARWIN__)
+#define DARWIN 1
+#endif
+
+#ifdef DARWIN
+#include <fcntl.h>
+#endif /* DARWIN */
+
  #ifdef VXWORKS
  #include <ioLib.h>
  #include <dosFsLib.h>
@@ -818,7 +826,11 @@
    undefined fsync
  #endif /* VXWORKS */
  #else
+#if defined(DARWIN) && defined(F_FULLFSYNC)
+    return check_error(fcntl(fd, F_FULLFSYNC), errInfo);
+#else
      return check_error(fsync(fd), errInfo);
+#endif /* DARWIN */
  #endif /* NO_FSYNC */
  }





More information about the erlang-patches mailing list