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();
}
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