IoReadPartitionTable

NTSTATUS
    IoReadPartitionTable(

        IN PDEVICE_OBJECT  DeviceObject,
        IN ULONG  SectorSize,
        IN BOOLEAN  ReturnRecognizedPartitions,
        OUT struct _DRIVE_LAYOUT_INFORMATION  **PartitionBuffer
        );

IoReadPartitionTable reads a list of partitions on a disk having a specified sector size and creates an entry in the partition list for each recognized partition.

Parameters

DeviceObject
Points to the device object for the disk whose partitions are to be read.
SectorSize
Specifies the size of the sectors on the disk.
ReturnRecognizedPartitions
Indicates whether only recognized partitions or all partition entries should be returned.
PartitionBuffer
Is a pointer to an uninitialized address. If successful, IoReadPartitionTable allocates the memory for this buffer from nonpaged pool and returns the drive layout information in it.

Return Value

This routine returns a value of STATUS_SUCCESS if at least one sector table was read. Otherwise, it returns an error status and sets the pointer at PartitionBuffer to NULL.

Comments

Disk device drivers call this routine during driver initialization.

It is the responsibility of the caller to deallocate the PartitionBuffer that was allocated by this routine with ExFreePool.

The algorithm used by this routine is determined by the Boolean value ReturnRecognizedPartitions:

The drive layout structure contains a variable-sized array of partition information elements, defined as follows:

typedef struct _DRIVE_LAYOUT_INFORMATION {
    ULONG PartitionCount;
    ULONG Signature;                // of disk
    PARTITION_INFORMATION PartitionEntry[1];
} DRIVE_LAYOUT_INFORMATION, *PDRIVE_LAYOUT_INFORMATION;
 
typedef strtuct _PARTITION_INFORMATION {
    LARGE_INTEGER StartingOffset;
    LARGE_INTEGER PartitionLength;
    ULONG HiddenSectors;
    ULONG PartitionNumber;
    UCHAR PartitionType;            // 12-bit FAT etc.
    BOOLEAN BootIndicator;
    BOOLEAN RecognizedPartition;
    BOOLEAN RewritePartition;
} PARTITION_INFORMATION, *PPARTITION_INFORMATION;
 

For the currently defined PartitionType values, see the Win32 SDK.

Note that disk drivers also use the DRIVE_LAYOUT_INFORMATION structure to return and set partition information in response to IRP_MJ_DEVICE_CONTROL requests with the following I/O control codes:

IOCTL_DISK_GET_PARTITION_INFO
IOCTL_DISK_GET_DRIVE_LAYOUT
IOCTL_DISK_SET_DRIVE_LAYOUT

Callers of IoReadPartitionTable must be running at IRQL PASSIVE_LEVEL.

See Also

IOCTL_DISK_GET_PARTITION_INFO, IOCTL_DISK_GET_DRIVE_LAYOUT, IOCTL_DISK_SET_DRIVE_LAYOUT, IoSetPartitionInformation, IoWritePartitionTable