This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix bogus fsync() error


If used on raw devices like /dev/sda fsync() always fails with EBADRQC (54) because FlushFileBuffers() always fails with ERROR_INVALID_FUNCTION (1).

The attached patch fixes this by simply ignoring this error in the fhandler_base implementation. This should not affect any real flush errors which likely would return other error codes.

An alternative approach would be to ignore the error only in a new fhandler_raw_dev/floppy::fsync(). IMO not worth the effort is this case.

Christian

2011-01-31  Christian Franke  <franke@computer.org>

	* fhandler.cc (fhandler_base::fsync): Ignore ERROR_INVALID_FUNCTION
	error from FlushFileBuffers().


diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index c97cc01..d7f46ec 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -1588,7 +1588,15 @@ fhandler_base::fsync ()
     return 0;
   if (FlushFileBuffers (get_handle ()))
     return 0;
-  __seterrno ();
+
+  /* Ignore ERROR_INVALID_FUNCTION because FlushFileBuffers()
+     always fails with this code on raw devices which are
+     unbuffered by default.  */
+  DWORD errcode = GetLastError();
+  if (errcode == ERROR_INVALID_FUNCTION)
+    return 0;
+
+  __seterrno_from_win_error (errcode);
   return -1;
 }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]