I changed my code to use the DISK_GEOMETRY_EX like you suggest and this seems to work fine too.
The is the patch based on this verson:
unsigned long long getNumberOfSectors(HANDLE handle, unsigned long long *sectorsize)
{
DWORD junk;
DISK_GEOMETRY_EX diskgeometry;
BOOL bResult;
bResult = DeviceIoControl(handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &diskgeometry, sizeof(diskgeometry), &junk, NULL);
if (!bResult)
{
char *errormessage=NULL;
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, GetLastError(), 0, errormessage, 0, NULL);
QMessageBox::critical(NULL, "Device Error", QString("An error occurred when attempting to get the device's geometry.\nError %1: %2").arg(GetLastError()).arg(errormessage));
LocalFree(errormessage);
return 0;
}
if (sectorsize != NULL)
*sectorsize = (unsigned long long)diskgeometry.Geometry.BytesPerSector;
return (unsigned long long)diskgeometry.DiskSize.QuadPart / (unsigned long long)diskgeometry.Geometry.BytesPerSector;
I changed my code to use the DISK_GEOMETRY_EX like you suggest and this seems to work fine too.
The is the patch based on this verson:
unsigned long long getNumberOfSect ors(HANDLE handle, unsigned long long *sectorsize)
{
DWORD junk;
DISK_GEOMETRY_EX diskgeometry;
BOOL bResult;
bResult = DeviceIoControl (handle, IOCTL_DISK_ GET_DRIVE_ GEOMETRY_ EX, NULL, 0, &diskgeometry, sizeof( diskgeometry) , &junk, NULL); (FORMAT_ MESSAGE_ FROM_SYSTEM | FORMAT_ MESSAGE_ ALLOCATE_ BUFFER, NULL, GetLastError(), 0, errormessage, 0, NULL); :critical( NULL, "Device Error", QString("An error occurred when attempting to get the device's geometry.\nError %1: %2").arg( GetLastError( )).arg( errormessage) ); errormessage) ;
if (!bResult)
{
char *errormessage=NULL;
FormatMessage
QMessageBox:
LocalFree(
return 0;
}
if (sectorsize != NULL) ry.Geometry. BytesPerSector; ry.DiskSize. QuadPart / (unsigned long long)diskgeomet ry.Geometry. BytesPerSector;
*sectorsize = (unsigned long long)diskgeomet
return (unsigned long long)diskgeomet
}