Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IOCTL_STORAGE_GET_DEVICE_NUMBER fails.

634 views
Skip to first unread message

hitesh

unread,
Jul 22, 2009, 3:02:02 AM7/22/09
to
hi all,
i am writing one simple application to find out the disk related
information.
i am using deviceIoControl function with ioctl call
IOCTL_STORAGE_GET_DEVICE_NUMBER.
i have two vista machine of the same configuration, it is working in
one machine and not working on other machine.
can anyone tell what could be the problem? it returns error code 0x01
after calling GetLastError() function.
i am getting the handle properly during createfile() call.
but deviceiocontrol function is failing,

HANDLE hDiskHandle;
unsigned int Error = 0;
char caDirBuf[256] = {0};
char Drive[] = {'\\', '\\', '.', '\\', 'A', ':', '\0'};
STORAGE_DEVICE_NUMBER sdn;
DWORD dwBytesReturned = 0;
HANDLE hDriveHandle = INVALID_HANDLE_VALUE;
if(GetSystemDirectoryA(caDirBuf, MAX_PATH) == 0)
{
Error = 1;
return ;
}
Drive[4] = caDirBuf[0];
hDriveHandle = CreateFileA(Drive, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if(hDriveHandle == INVALID_HANDLE_VALUE)
{
//printf("Unable to open drive." );
return ;
}
if (DeviceIoControl(hDriveHandle,IOCTL_STORAGE_GET_DEVICE_NUMBER,
NULL, 0, &sdn,
sizeof(sdn), &dwBytesReturned, NULL))
{
}
else
{
Error = GetLastError();
}

please help me,
thanks,
hitesh ughreja

Uwe Sieber

unread,
Jul 22, 2009, 3:14:50 AM7/22/09
to
hitesh wrote:
> hi all,
> i am writing one simple application to find out the disk related
> information.
> i am using deviceIoControl function with ioctl call
> IOCTL_STORAGE_GET_DEVICE_NUMBER.
> i have two vista machine of the same configuration, it is working in
> one machine and not working on other machine.


This does not work with legacy floppy drives.
Probably drive A: is one on the one Vista
computer and an USB floppy or an flash drive
on the other.


Uwe

hitesh ughreja

unread,
Jul 22, 2009, 4:58:07 AM7/22/09
to

hi uwe,
thanks for the reply.
i have checked, it is not floppy drive or any usb drive.
but it is performing operation on C:\ where it is a bootable partition
on both machines.
it is SATA connected disk on both machines on AHCI port.
does it have any relation with such driver?
if i am not wrong it is only disk driver which plays role,
please reply me,
thanks,
Hitesh

Uwe Sieber

unread,
Jul 22, 2009, 5:47:21 AM7/22/09
to

hitesh ughreja wrote:
>>> i am writing one simple application to find out the disk related
>>> information.
>>> i am using deviceIoControl function with ioctl call
>>> IOCTL_STORAGE_GET_DEVICE_NUMBER.
>>> i have two vista machine of the same configuration, it is working in
>>> one machine and not working on other machine.
>> This does not work with legacy floppy drives.
>> Probably drive A: is one on the one Vista
>> computer and an USB floppy or an flash drive
>> on the other.
>>
> i have checked, it is not floppy drive or any usb drive.
> but it is performing operation on C:\ where it is a bootable partition
> on both machines.
> it is SATA connected disk on both machines on AHCI port.
> does it have any relation with such driver?

The drive must answer the request. If it says
ERROR_INVALID_FUNCTION then there is a good
reason.
Is it a dynamic volume or RAID? Then the volume
has more than one device number. Try
IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS instead.

What does my ListUsbDrives tool say?
ListUsbDrives -a

http://www.uwe-sieber.de/files/listusbdrives.zip


Uwe

hitesh ughreja

unread,
Jul 23, 2009, 1:06:56 AM7/23/09
to
> Uwe- Hide quoted text -
>
> - Show quoted text -

thanks very much,
my problem gets solved.
regards,
hitesh

Tim Roberts

unread,
Jul 24, 2009, 12:30:54 AM7/24/09
to
hitesh <hitesh....@gmail.com> wrote:
>
> HANDLE hDiskHandle;
> unsigned int Error = 0;
> char caDirBuf[256] = {0};
> char Drive[] = {'\\', '\\', '.', '\\', 'A', ':', '\0'};

Do you realize this is exactly the same as this:
char Drive[] = "\\\\.\\A:";
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

0 new messages