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

DeviceIoControl fails with opertion IOCTL_DISK_GET_DRIVE_LAYOUT

226 views
Skip to first unread message

zack

unread,
Jun 25, 2008, 7:48:03 AM6/25/08
to
Hi I am trying to get the drive name(d:\,f:\) with DeviceIoControlfunction,
but it fails with error 5= Access is denied.
i am working with vista SP1,any way to to correct this error ?
if i will call the function with IOCTL_DISK_GET_DRIVE_GEOMETRY it will work
GREAT.
any reason why it fails if i used this operation:IOCTL_DISK_GET_DRIVE_LAYOUT
HERE IS THE CODE:

PARTITION_INFORMATION pdg;

hDevice = CreateFile(physicalDrive, // drive
0, // no access to the drive
FILE_SHARE_READ | // share mode
FILE_SHARE_WRITE,
NULL, // default security attributes
OPEN_EXISTING, // disposition
0, // file attributes
NULL); // do not copy file attributes

if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drive
{
return (FALSE);
}

bResult = DeviceIoControl(hDevice, // device to be queried
IOCTL_DISK_GET_DRIVE_LAYOUT, // operation to perform
NULL,
0, // no input buffer
&pdg,
sizeof(pdg), // output buffer
&junk, // # bytes
returned
(LPOVERLAPPED) NULL); // synchronous I/O

if(! bResult)
{

win = GetLastError();
}

Joseph M. Newcomer

unread,
Jun 25, 2008, 1:07:11 PM6/25/08
to
Where does this code exist? In a system service?

Note that you need admin privileges (at least!) to open a physical drive.

I just read the description of IOCT_DISK_GET_DRIVE_LAYOUT and all it returns is a
DRIVE_LAYOUT_INFORMATION structure. In the DRIVE_LAYOUT_INFORMATION structure, there is a
count of the number of partitions on the drive, a drive signature value, and an array of
PARTITION_INFORMATION blocks. If I look at a PARTITION_INFORMATION_BLOCK, I find the
starting offset of the partition, the length of the partition in bytes, the number of
hidden sectors in the partition, the partition number, the partition type, whether or not
the partition is bootable, whether or not the partition is recognized, and whether or not
the partition information needs to be rewritten.

At no point do I see any information describing the logical drive letter assigned to the
partition. So how do you expect to get from the information from this IOCTL to a
partition logical drive letter? Note that they are not correlated where partition 1 is C:
and partition 2 is D:, since these can be assigned by the user.

I'm not sure how to find out this information, but it is clear from the documentation that
IOCTL_DISK_GET_DRIVE_LAYOUT is *not* the answer.
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

0 new messages