Message-Id: <200404102207.i3AM7iHB026301@delorie.com> Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com From: "GARY VANSICKLE" To: Subject: RE: working sync() code Date: Sat, 10 Apr 2004 15:05:35 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit In-Reply-To: <4078041C.1020AC42@karasik.eu.org> X-IsSubscribed: yes > Hi all, > > I found a way to issue an actual sync() on win32, and as browsing > through winsup directory gave me only this > > > winsup/sygwin/syscalls.cc #1128 > extern "C" int > sync () > { > return 0; > } > > > I think cygwin DLL might benefit from a code I found by looking in > sync.exe by M.Russinovich, which is schematically as such: > > > int > sync( char drive) > { > HANDLE f; > int ret; > char file[7] = "\\\\.\\X:"; > file[5] = drive; > f = CreateFile( file, GENERIC_READ|GENERIC_WRITE, > FILE_SHARE_READ|FILE_SHARE_WRITE, > NULL, OPEN_EXISTING, 0, NULL); > if ((int) f < 0) > return -1; > ret = FlushFileBuffers(f) ? 0 : -1; > CloseHandle(f); > return ret; > } > FlushFileBuffers() doesn't actually do much last I checked. Despite its misleading name, it is not a "commit-to-disk-and-don't-return-until-its-done" at any rate, which is what's needed here. The only way I ever found to actually do this is to open a handle to the underlying physical drive (and just try mapping drive letters to physical drives!) and then there's an IOCTL_ that will do the trick. And as long as the account has the right privileges, you can do that, otherwise you can't. -- 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/