0

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;

}

jdphenix
  • 15,022
  • 3
  • 41
  • 74
Scott Franco
  • 481
  • 2
  • 15
  • Your best bet is probably to use asynchronous IO. That way, if you don't get a response quickly enough, you can cancel the request (or just ignore it). – Harry Johnston Dec 18 '13 at 00:11
  • Is there an async version of deviceiocontrol(), or just branch a thread to handle that? – Scott Franco Dec 18 '13 at 00:35
  • 1
    If you open the handle in asynchronous mode, `DeviceIoControl` is asynchronous. That's what the `lpOverlapped` parameter is for. – Harry Johnston Dec 18 '13 at 00:43
  • Wow, cool. I'll start looking that over. I'd say anything that does not resolve in < 1sec is probably not online storage. – Scott Franco Dec 18 '13 at 03:32

0 Answers0