tags:

views:

295

answers:

4

In windows is it possible to know what kind of disk we are dealing with from a c/c++ program? forget about gpt or mbr, how to know whether it is basic or dynamic? Program input can be drive letter or any info related to disk, output should be dynamic or basic. No need of a direct way of doing, even if it is lengthy process, its okay. I couldn't find much in msdn. Please help me out.

A: 

check out for GetDriveType() .

Ashish
+1  A: 

As per from MSDN http://msdn.microsoft.com/en-us/library/aa363785%28VS.85%29.aspx

Detecting the Type of Disk

There is no specific function to programmatically detect the type of disk a particular file or directory is located on. There is an indirect method.

First, call GetVolumePathName. Then, call CreateFile to open the volume using the path. Next, use IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS with the volume handle to obtain the disk number and use the disk number to construct the disk path, such as "\?\PhysicalDriveX". Finally, use IOCTL_DISK_GET_DRIVE_LAYOUT_EX to obtain the partition list, and check the PartitionType for each entry in the partition list.

Nitin Midha
i think, it refers to gpt or mbr, i need basic or dynamic.anyway i got it from alan :)
calvin
+4  A: 

There is a way in windows, but it's not straight forward.

There is no direct API to determine if a disk is Basic or Dynamic, however all dynamic disks will have LDM Information.

So if a drive has a partion with LDM information on it, then it's going to be a dynamic disk.

the DeviceIoControl() method with the IOCTL_DISK_GET_DRIVE_LAYOUT_EX control code can be used to get this information.

Here is a post with a sample console application to do what you're asking for.

Alan
Thanks alan, just 1 min before u post this i got it from another friend. Anyways thanks alot. I need to checkout how it works for my env :)
calvin
A: 

Of cause you can. But I have to tell you that you must know the information that dynamic disk offer much features than the basic disk do. Actually, we would like to convert basic disk to dynamic disk to experience its advantages. Nevertheless, we should know there still has many problem waiting to be solved—such as the dynamic get invalid or unreadable. However, convert dynamic disk back to basic disk can not realized by the Windows built-in disk management flawlessly. Fortunately, this series of problems can be achieved through third-party software, such as Dynamic Disk Converter.