Commit 62904287 authored by dgrogan@chromium.org's avatar dgrogan@chromium.org

Do fcntl(...F_FULLFSYNC...) on mac instead of fsync

From mac's fsync man page:

For applications that require tighter guarantees about the integrity of their
data, Mac OS X provides the F_FULLFSYNC fcntl.  The F_FULLFSYNC fcntl asks the
drive to flush all buffered data to permanent storage.  Applications, such as
databases, that require a strict ordering of writes should use F_FULLFSYNC to
ensure that their data is written in the order they expect.

Also, specifically check for a return value of -1 from fdatasync. mac's fcntl
only guarantees to return -1 on error and something other than -1 on success.
All other platforms agree to return -1 on error for fsync/fdatasync/_commit.

Review URL: https://chromiumcodereview.appspot.com/23549017

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221413 0039d316-1c4b-4281-b951-d872f2087c98
parent c8c18c75
...@@ -68,6 +68,8 @@ int fflush_wrapper(FILE *file) { ...@@ -68,6 +68,8 @@ int fflush_wrapper(FILE *file) {
int fdatasync(int fildes) { int fdatasync(int fildes) {
#if defined(OS_WIN) #if defined(OS_WIN)
return _commit(fildes); return _commit(fildes);
#elif defined(OS_MACOSX)
return HANDLE_EINTR(fcntl(fildes, F_FULLFSYNC, 0));
#else #else
return HANDLE_EINTR(fsync(fildes)); return HANDLE_EINTR(fsync(fildes));
#endif #endif
...@@ -510,7 +512,7 @@ Status ChromiumWritableFile::Sync() { ...@@ -510,7 +512,7 @@ Status ChromiumWritableFile::Sync() {
error = errno; error = errno;
// Sync even if fflush gave an error; perhaps the data actually got out, // Sync even if fflush gave an error; perhaps the data actually got out,
// even though something went wrong. // even though something went wrong.
if (fdatasync(fileno(file_)) && !error) if (fdatasync(fileno(file_)) == -1 && !error)
error = errno; error = errno;
// Report the first error we found. // Report the first error we found.
if (error) { if (error) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment