Windows DeviceIoContro() with IOCTL_DISK_GET_LENGTH_INFO takes realllllllly long

1.5k views Asked by At

The call DeviceIoContro() with IOCTL_DISK_GET_LENGTH_INFO holds in windows for a minute or more on drives that are not mounted. I am trying to survey and print online drives with their lengths. This hold behavior is unacceptable in the user interface. Does anyone have a good way around this?

I am using the call on physical disk names in Windows, like "\\.\PhysicalDrive0". The drive it is halting on is a DVD drive, ie., removable. I don't care if windows can spin the drive up given enough time. As it is, there is no disk in the drive, and Windows apparently waits a long time to try to get the drive to come on line. I want it to fail immediately if the drive is not spun up.

Thanks in advance.

Scott Moore

The code for this is:

int testsize( /** drive number to set / int drive, /* return size of disc */ long long *size )

{

GET_LENGTH_INFORMATION li;
BOOL r;
DWORD rsize;

HANDLE driveh;

//open the physical disk
driveh = CreateFile(phystr[drive],
                 GENERIC_READ | GENERIC_WRITE,
                 FILE_SHARE_DELETE |
                 FILE_SHARE_READ |
                 FILE_SHARE_WRITE,
                 NULL,
                 OPEN_EXISTING,
                 0,
                 NULL);

if (driveh == INVALID_HANDLE_VALUE) return 1;

// get size of disk
r = DeviceIoControl(driveh, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &li, sizeof(li), 
                    &rsize, NULL);
if (r == 0) {

    return 1; // just return error

}

// place to caller
*size = li.Length.QuadPart;

//close the disk
CloseHandle(driveh);

return 0;

}

0

There are 0 answers