delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/04/13/18:05:39

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <407C641D.9A727023@karasik.eu.org>
Date: Wed, 14 Apr 2004 00:05:17 +0200
From: Dmitry Karasik <dmitry AT karasik DOT eu DOT org>
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: proposed sync() patch

ChangeLog:

2004-13-04  Dmitry Karasik <dmitry AT karasik DOT eu DOT 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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019