attempt to flush memory cards on unmount

This commit is contained in:
Glenn Maynard
2005-12-24 02:08:17 +00:00
parent 3f14485b5d
commit 99d586c5a9
@@ -80,17 +80,17 @@ void MemoryCardDriverThreaded_Windows::GetUSBStorageDevices( vector<UsbStorageDe
if( IsFloppyDrive((char)i+'a') )
continue;
CString sDrive = ssprintf( "%c:\\", 'a'+i%26 );
if( GetDriveType(sDrive) != DRIVE_REMOVABLE ) // is a removable drive
CString sDrive = ssprintf( "%c:", 'a'+i%26 );
if( GetDriveType(sDrive + "\\") != DRIVE_REMOVABLE ) // is a removable drive
continue;
CString sVolumeLabel;
if( !TestReady(sDrive, sVolumeLabel) )
if( !TestReady(sDrive + "\\", sVolumeLabel) )
continue;
vDevicesOut.push_back( UsbStorageDevice() );
UsbStorageDevice &usbd = vDevicesOut.back();
usbd.SetOsMountDir( sDrive );
usbd.SetOsMountDir( sDrive + "\\" );
usbd.sDevice = sDrive;
usbd.sVolumeLabel = sVolumeLabel;
@@ -127,7 +127,20 @@ bool MemoryCardDriverThreaded_Windows::Mount( UsbStorageDevice* pDevice )
void MemoryCardDriverThreaded_Windows::Unmount( UsbStorageDevice* pDevice )
{
// nothing to do here...
/* Try to flush the device before returning. This requires administrator priviliges. */
HANDLE hDevice = CreateFile( "\\\\.\\" + pDevice->sDevice, GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL );
if( hDevice == INVALID_HANDLE_VALUE )
{
LOG->Warn( werr_ssprintf(GetLastError(), "Couldn't open memory card device to flush: CreateFile") );
return;
}
if( !FlushFileBuffers(hDevice) )
LOG->Warn( werr_ssprintf(GetLastError(), "Couldn't flush memory card device: FlushFileBuffers") );
CloseHandle( hDevice );
}
/*