http://bugs.winehq.org/show_bug.cgi?id=14915
Summary: FlushFileBuffers() fails on disk volume, sets ERROR_INVALID_HANDLE when handle supposedly valid Product: Wine Version: 1.1.2 Platform: PC OS/Version: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: -unknown AssignedTo: wine-bugs@winehq.org ReportedBy: vesselinpeev@hotmail.com
Ran under Wine, the following program receives ERROR_INVALID_HANDLE as a Windows last error when the flushing call fails.
Note that if you are testing under Windows Vista, you need to run the program with administrative privileges to be able to get the handle to the volume.
For brevity, I've omitted GetLastError() printing for failure cases except the flushing one, but, needless to say, you may want to add them for full correctness / error handling / safety, or do let me know and I'll happily add these and re-post the code.
# include <windows.h> # include <stdio.h> # include <tchar.h>
int _tmain() { LPCTSTR volName = _T("\\.\C:"); HANDLE hFile = CreateFile(volName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0); if (hFile != INVALID_HANDLE_VALUE) { _tprintf(_T("Opened volume %s\n"), volName);
SetLastError(0xdeadbeef); /* to make sure that it's really the next call that sets the last error -- advice taken from Dmitry Timoshkov's comment at http://bugs.winehq.org/show_bug.cgi?id=14855 */
if (FlushFileBuffers(hFile)) { _tprintf(_T("File buffers flushed\n")); } else { DWORD dwRet = GetLastError(); _ftprintf(stderr, _T("File buffers not flushed, GetLastError() returned %lu"), dwRet); if(dwRet == ERROR_INVALID_HANDLE) { _ftprintf(stderr, _T(" ("The handle is invalid")")); } _ftprintf(stderr, ".\n"); } } else { _ftprintf(stderr, _T("Could not open volume %s\n"), volName); return -2; } if(! CloseHandle(hFile)) { _ftprintf(stderr, _T("Could not close handle to volume %s\n"), volName); return -3; } return 0; }