diff --git a/CMakeLists.txt b/CMakeLists.txt index 62eab18..bfcf7d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,6 +93,12 @@ check_cxx_source_compiles ("#include " XATTR_ADD_OPT) set (CMAKE_REQUIRED_QUIET ${CMAKE_REQUIRED_QUIET_SAVE}) +# Check if we have fdatasync. +include (CheckCXXSourceCompiles) +check_cxx_source_compiles ("#include + int main() { fdatasync(0); return 1; } + " FDATASYNC) + # Check if we have some standard functions. include (CheckFuncs) check_function_exists_glibc (lchmod HAVE_LCHMOD) diff --git a/encfs/FileNode.cpp b/encfs/FileNode.cpp index 9d52763..02d5c11 100644 --- a/encfs/FileNode.cpp +++ b/encfs/FileNode.cpp @@ -236,15 +236,13 @@ int FileNode::sync(bool datasync) { int fh = io->open(O_RDONLY); if (fh >= 0) { int res = -EIO; -#ifdef linux +#ifdef FDATASYNC if (datasync) res = fdatasync(fh); else res = fsync(fh); #else (void)datasync; - // no fdatasync support - // TODO: use autoconfig to check for it.. res = fsync(fh); #endif diff --git a/encfs/RawFileIO.cpp b/encfs/RawFileIO.cpp index f28aa3f..b2cbb26 100644 --- a/encfs/RawFileIO.cpp +++ b/encfs/RawFileIO.cpp @@ -270,11 +270,13 @@ int RawFileIO::truncate(off_t size) { knownSize = true; } -#if !defined(__FreeBSD__) && !defined(__APPLE__) if (fd >= 0 && canWrite) { +#ifdef FDATASYNC ::fdatasync(fd); - } +#else + ::fsync(fd); #endif + } return res; }