Share via

How to read MBR Partition Layout using IOCTL_DISK_GET_DRIVE_LAYOUT of a drive that has logical partitions?

Anonymous
2025-11-20T14:17:43.3433333+00:00

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
0 comments No comments

Answer accepted by question author

RLWA32 52,571 Reputation points
2025-11-20T15:04:02.63+00:00

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.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.