This is the mail archive of the cygwin 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]

proposed sync() patch


ChangeLog:

2004-13-04  Dmitry Karasik <dmitry@karasik.eu.org>

	* syscalls.cc: Implement sync() for letter-mapped drives



Diff:

--- syscalls.cc	2004-04-13 23:25:28.000000000 +0200
+++ syscalls.cc	2004-04-13 23:50:56.000000000 +0200
@@ -1075,10 +1075,47 @@ fsync (int fd)
   return 0;
 }
 
+/*
+   Forces a write of modified buffers in the block buffer cache out to
disk.
+   Original idea:
http://www.sysinternals.com/ntw2k/source/misc.shtml#sync 
+ */
+static int 
+sync_drive( char drive) 
+{
+   HANDLE f;
+   int ret;
+   char file[7] = "\\\\.\\X:";
+   file[4] = drive;
+   
+   f = CreateFile( file, 
+		   GENERIC_READ|GENERIC_WRITE, 
+		   FILE_SHARE_READ|FILE_SHARE_WRITE, 
+		   NULL, OPEN_EXISTING, 
+		   0, NULL);
+   if ( f == INVALID_HANDLE_VALUE)
+      return -1;
+
+   ret = FlushFileBuffers(f) ? 0 : -1;
+   CloseHandle(f);
+   return ret;
+}
+
+
 /* sync: SUSv3 */
 extern "C" void
 sync ()
 {
+   DWORD map;
+   char i, drive[4] = "X:\\";
+
+   map = GetLogicalDrives();
+   /* sync all letter-mapped local 'fixed' drives */
+   for ( i = 0; i < 26; i++) 
+      if (( map << ( 31 - i)) >> 31) {
+	 drive[0] = 'A' + i;
+	 if ( GetDriveType( drive) == DRIVE_FIXED) 
+	    sync_drive('A' + i);
+      }
 }
 
 /* Cygwin internal */

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


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