I am trying to identify if a drive is system reserved drive(PhysicalDrive0
or C-Drive
) using DeviceIoControl
function. However my code is always returning true for all the drives.
HANDLE hDevice; // handle to the drive to be examined
BOOL bResult; // results flag
DWORD junk; // discard results
PARTITION_INFORMATION_MBR *pdg
hDevice = CreateFile(TEXT("\\\\.\\C:"), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ |
FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
bResult = DeviceIoControl(
hDevice, // device to be queried
IOCTL_DISK_GET_PARTITION_INFO_EX, // operation to perform
NULL, 0, // no input buffer
pdg, sizeof(*pdg), // output buffer
&junk, // # bytes returned
(LPOVERLAPPED) NULL // synchronous I/O
);
bResult
isalways returning 0, indicating that the function succeeded.- Even
pdg->PartitionType
has junk information and not returningtrue
.