The documentation for the DRIVE_LAYOUT_INFORMATION structure indicates that for MBR disks the number of partitions contained in the PartitionCount member must be a multiple of 4. Try increasing the size of your array to accommodate at least 8 partitions. The docs also say "Any partitions that are unused have a partition type of PARTITION_ENTRY_UNUSED (0)." If 8 is insufficient try 12.
How to read MBR Partition Layout using IOCTL_DISK_GET_DRIVE_LAYOUT of a drive that has logical partitions?
API IOCTL_DISK_GET_DRIVE_LAYOUT can retrieve information for both primary and logical partitions as noted here. My disk has 3 primary, 1 extended that contains 2 logical partitions. I have setup an output buffer of type DRIVE_LAYOUT_INFORMATION with PartitionEntry array size as 6 to hold the output of the API call. The total bytes allocated is 200. But the API call fails with System Error 122: "The data area passed to a system call is too small" and return only 24 bytes (lpBytesReturned). Can someone please help figure out the issue in this? Why is the API call failing when my output buffer has enough space to hold data for all the partitions my disk contains?
Windows development | Windows API - Win32
Answer accepted by question author