Volume Locken und Dismounten
-
Hallo Forum,
ich habe ein Programm geschrieben der CompactFlashs im Raw Modus beschreibt. Unter Win7 musste ich das Volume Locken und Dismounten weil der Schreibvorgang nicht funktioniert hat.
res = DeviceIoControl(hDrive, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0,&ol, NULL);
if (!res)
TRACE(_T("FSCTL_LOCK_VOLUME Error"));res = DeviceIoControl(hDrive, FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0,&ol, NULL);
if (!res)
TRACE(_T("FSCTL_LOCK_VOLUME Error"));Teilauszug für das Schreiben eines CFs.
....
SetFilePointer(hCF, 0, NULL, FILE_BEGIN);
// Move to first Cylinder for something interesting to read.
SetFilePointer(hFile, 0, NULL, FILE_BEGIN);// Read Cylinders from the file and write them to disk.
ULONG Block = 0;
for( Block = 0; Block < BlockCount; Block++ )
{
if(ReadFile( hFile, lpBlock, (DWORD)BytesPerBlock, &dwReadBytes,NULL))
{if(!WriteFile( hCF, lpBlock, (DWORD)dwReadBytes, &dwWriteBytes, NULL) )
{
....Ich habe aber ein Problem dass während des Schreibvogangs eine Fehlermeldung "Zugriff verweigert" auftreten kann. Grund dafür habe ich bereits gefunden. Immer wenn ich zwischen meine Applikation und Arbeitsplatz (CF Laufwerk) oder Total Commandert umschalte passiert es. Es wird der Zugriff aufs das CF Laufwerk ausgeführt und schon ist der Fehler da.
Aber ich dachte dass durch das Locken und Unmouten genau dieses verhindert werden soll.Weiss jemand ein Rat?