mirror of
https://github.com/veracrypt/VeraCrypt
synced 2024-11-28 05:53:29 +01:00
Windows: better logic for FormatEx function call. To be replaced in the future by Microsoft COM interfaces.
This commit is contained in:
parent
724043be0b
commit
6a78f7eae2
@ -793,13 +793,64 @@ int FormatNoFs (HWND hwndDlg, unsigned __int64 startSector, __int64 num_sectors,
|
||||
}
|
||||
|
||||
|
||||
volatile BOOLEAN FormatExResult;
|
||||
volatile BOOLEAN FormatExError;
|
||||
|
||||
BOOLEAN __stdcall FormatExCallback (int command, DWORD subCommand, PVOID parameter)
|
||||
{
|
||||
if (command == FMIFS_DONE)
|
||||
FormatExResult = *(BOOLEAN *) parameter;
|
||||
return TRUE;
|
||||
if (FormatExError)
|
||||
return FALSE;
|
||||
|
||||
switch(command) {
|
||||
case FMIFS_PROGRESS:
|
||||
break;
|
||||
case FMIFS_STRUCTURE_PROGRESS:
|
||||
break;
|
||||
case FMIFS_DONE:
|
||||
if(*(BOOLEAN*)parameter == FALSE) {
|
||||
FormatExError = TRUE;
|
||||
}
|
||||
break;
|
||||
case FMIFS_DONE_WITH_STRUCTURE:
|
||||
break;
|
||||
case FMIFS_INCOMPATIBLE_FILE_SYSTEM:
|
||||
FormatExError = TRUE;
|
||||
break;
|
||||
case FMIFS_ACCESS_DENIED:
|
||||
FormatExError = TRUE;
|
||||
break;
|
||||
case FMIFS_MEDIA_WRITE_PROTECTED:
|
||||
FormatExError = TRUE;
|
||||
break;
|
||||
case FMIFS_VOLUME_IN_USE:
|
||||
FormatExError = TRUE;
|
||||
break;
|
||||
case FMIFS_DEVICE_NOT_READY:
|
||||
FormatExError = TRUE;
|
||||
break;
|
||||
case FMIFS_CANT_QUICK_FORMAT:
|
||||
FormatExError = TRUE;
|
||||
break;
|
||||
case FMIFS_BAD_LABEL:
|
||||
FormatExError = TRUE;
|
||||
break;
|
||||
case FMIFS_OUTPUT:
|
||||
break;
|
||||
case FMIFS_CLUSTER_SIZE_TOO_BIG:
|
||||
case FMIFS_CLUSTER_SIZE_TOO_SMALL:
|
||||
FormatExError = TRUE;
|
||||
break;
|
||||
case FMIFS_VOLUME_TOO_BIG:
|
||||
case FMIFS_VOLUME_TOO_SMALL:
|
||||
FormatExError = TRUE;
|
||||
break;
|
||||
case FMIFS_NO_MEDIA_IN_DRIVE:
|
||||
FormatExError = TRUE;
|
||||
break;
|
||||
default:
|
||||
FormatExError = TRUE;
|
||||
break;
|
||||
}
|
||||
return (FormatExError? FALSE : TRUE);
|
||||
}
|
||||
|
||||
BOOL FormatNtfs (int driveNo, int clusterSize)
|
||||
@ -830,12 +881,13 @@ BOOL FormatNtfs (int driveNo, int clusterSize)
|
||||
|
||||
StringCbCatW (dir, sizeof(dir), L":\\");
|
||||
|
||||
FormatExResult = FALSE;
|
||||
FormatExError = TRUE;
|
||||
|
||||
// Windows sometimes fails to format a volume (hosted on a removable medium) as NTFS.
|
||||
// It often helps to retry several times.
|
||||
for (i = 0; i < 50 && FormatExResult != TRUE; i++)
|
||||
for (i = 0; i < 50 && FormatExError; i++)
|
||||
{
|
||||
FormatExError = FALSE;
|
||||
FormatEx (dir, FMIFS_HARDDISK, L"NTFS", L"", TRUE, clusterSize * FormatSectorSize, FormatExCallback);
|
||||
}
|
||||
|
||||
@ -843,7 +895,7 @@ BOOL FormatNtfs (int driveNo, int clusterSize)
|
||||
Sleep (4000);
|
||||
|
||||
FreeLibrary (hModule);
|
||||
return FormatExResult;
|
||||
return FormatExError? FALSE : TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -44,7 +44,26 @@ typedef struct
|
||||
}
|
||||
FORMAT_VOL_PARAMETERS;
|
||||
|
||||
#define FMIFS_DONE 0xB
|
||||
#define FMIFS_PROGRESS 0x00
|
||||
#define FMIFS_DONE_WITH_STRUCTURE 0x01
|
||||
#define FMIFS_INCOMPATIBLE_FILE_SYSTEM 0x03
|
||||
#define FMIFS_ACCESS_DENIED 0x06
|
||||
#define FMIFS_MEDIA_WRITE_PROTECTED 0x07
|
||||
#define FMIFS_VOLUME_IN_USE 0x08
|
||||
#define FMIFS_CANT_QUICK_FORMAT 0x09
|
||||
#define FMIFS_DONE 0x0B
|
||||
#define FMIFS_BAD_LABEL 0x0C
|
||||
#define FMIFS_OUTPUT 0x0E
|
||||
#define FMIFS_STRUCTURE_PROGRESS 0x0F
|
||||
#define FMIFS_CLUSTER_SIZE_TOO_SMALL 0x10
|
||||
#define FMIFS_CLUSTER_SIZE_TOO_BIG 0x11
|
||||
#define FMIFS_VOLUME_TOO_SMALL 0x12
|
||||
#define FMIFS_VOLUME_TOO_BIG 0x13
|
||||
#define FMIFS_NO_MEDIA_IN_DRIVE 0x14
|
||||
#define FMIFS_DEVICE_NOT_READY 0x18
|
||||
#define FMIFS_CHECKDISK_PROGRESS 0x19
|
||||
#define FMIFS_READ_ONLY_MODE 0x20
|
||||
|
||||
#define FMIFS_HARDDISK 0xC
|
||||
|
||||
extern int FormatWriteBufferSize;
|
||||
|
Loading…
Reference in New Issue
Block a user