Hello,
I'm writing a program to make images from CompactFlash cards and vice versa. With the following code I get the list of available devices:
Code:
void win32_get_drives()
{
HANDLE cf_card;
DWORD rc, dwError, dwRead;
char devices[100000];
char drive[MAX_PATH + 1];
char drive_full[MAX_PATH + 1 + 10];
char drive_to_open[MAX_PATH + 1 + 8];
char lpBuf[BUF_SIZE + 1];
char *tmp_str, *idx;
cout << "Available devices:" << endl << "\t";
rc = QueryDosDevice(NULL, devices, sizeof(devices));
if(rc == 0)
{
dwError = GetLastError();
cout << "Error querying devices (" << dwError << ")" << endl;
exit(0);
}
tmp_str = devices;
while(1)
{
idx = strstr(tmp_str, "PhysicalDrive");
if(idx == NULL)
{
if(tmp_str[1] == '\0')
break;
tmp_str += strlen(tmp_str) + 1;
continue;
}
strcpy(drive, idx);
sprintf(drive_full, "\\\\.\\%s\\", drive);
rc = GetDriveType(drive_full);
if(rc == DRIVE_REMOVABLE)
{
// open CompactFlash card
sprintf(drive_to_open, "\\\\.\\%s", drive);
cf_card = CreateFile(drive_to_open,
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (cf_card != INVALID_HANDLE_VALUE)
{
rc = ReadFile(cf_card,lpBuf,BUF_SIZE,&dwRead,NULL);
if(rc)
cout << drive;
CloseHandle(cf_card);
}
}
tmp_str += strlen(tmp_str) + 1;
}
cout << endl;
}
How can I acquire the size of the ext2 partition? My program can only handle 512Mb cards.
Thanks