1

I'm working on a project which requires me to operate at a low level on Windows drives, and am doing so primarily using Windows API calls. But before I can operate on the drive, I need to know the types of partitions present on it.

This is fairly simple on a disk formatted by MBR, because

DeviceIoControl(...,IOCTL_DISK_GET_DRIVE_LAYOUT_EX,...);

returns a structure in format DRIVE_LAYOUT_INFORMATION_EX, which contains an array of PARTITION_INFORMATION_EX. On an MBR disk, the PARTITION_INFORMATION_EX.Mbr.PartitionType element contains a unique identifier for the partition type, e.g. for NTFS it is 0x07, for Extended it is 0x05.

However, this isn't so simple on a GPT disk. I know that I can read the identifier off of the beginning of the partition, but I'd prefer to handle this with API calls, such as DeviceIoControl. When I run DeviceIoControl on a GPT disk, the PARTITION_INFORMATION_EX.Mbr.PartitionType contains completely different values than those which would be normally there.

Note that the GUID is useless to me because that only tells me the purpose of the partition, not what type of partition it is. I'm trying to figure out if the drive is NTFS, FAT, etc.

3 Answers3

1

For GPT partition in your code when you call DeviceIoControl(), this call will return the Partition information in the object of PARTITION_INFORMATION_EX. If you see the PARTITION_INFORMATION_EX structure, there are two separate structure for MBR and GPT disk. So when you get the information in PARTITION_INFORMATION_EX object, you'll have to first confirm that whether the disk type is GPT or MBR, if GPT you can get the specific partition type by comparing it's GUID.

0

Look at Microsoft's PARTITION_INFORMATION_GPT struct for GPT partitions.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Yes, but it doesn't actually contain the partition type. – The name's Bob. MS Bob. Aug 07 '14 at 19:48
  • Yes, it does: "A GUID that identifies the partition type", which can be `PARTITION_BASIC_DATA_GUID`, `PARTITION_SYSTEM_GUID`, etc. – Remy Lebeau Aug 07 '14 at 19:49
  • That only tells me metadata regarding the way the system uses the partition. I need to know if the partition is NTFS, FAT, Extended, etc. – The name's Bob. MS Bob. Aug 07 '14 at 19:51
  • You didn't say that part. In that case, you need to look at the file system header within the partition instead. Or, if the partitions have drive letters assigned, you could use `GetVolumeInformation()` instead – Remy Lebeau Aug 07 '14 at 20:00
  • I know I can read the filesystem headers, I just want to avoid that as it will greatly increase the complexity of some of my code, and force a small scale re-implementation. I have no guarantee that the filesystems will be mounted, so `GetVolumeInformation()` is unfortunately not an option. – The name's Bob. MS Bob. Aug 07 '14 at 20:06
0

Instead of going through PARTITION_INFORMATION_EX, I found the best way to find the filesystem of a volume is to call GetVolumeInformation. On Vista+, this seems to be just a wrapper for GetVolumeInformationByHandleW. The later might be the best for you if you already have a volume handle.

Both work well with either MBR or GPT disks. The result is the filesystem name string instead of a type ID, but should be easy to adapt.

Djof
  • 603
  • 1
  • 7
  • 20