Physical disk capacity

QueryDosDevice(L"E:", DeviceName, MAX_PATH);

(E: this is an SD card)

DeviceName - "\ Device \ HarddiskVolume3"

How can I "convert" it into something like "\\.\PHYSICALDRIVE1"

+5
source share
2 answers

Volumes consist of one or more partitions that reside on disks. Thus, E: is not necessarily mapped onto a single drive in the system (think about software RAID).

The way to map volumes to PhysicalDrive names in Win32 is to first open the volume and then send IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS. This will give you a structure in which there is one DISK_EXTENT entry for each section to which the scope extends:

typedef struct _VOLUME_DISK_EXTENTS {
  DWORD       NumberOfDiskExtents;
  DISK_EXTENT Extents[ANYSIZE_ARRAY];
} VOLUME_DISK_EXTENTS, *PVOLUME_DISK_EXTENTS;

Extents have a disk number in them:

typedef struct _DISK_EXTENT {
  DWORD         DiskNumber;
  LARGE_INTEGER StartingOffset;
  LARGE_INTEGER ExtentLength;
} DISK_EXTENT, *PDISK_EXTENT;

DiskNumber - , PhsyicalDriveX, "\\.\PhysicalDrive% d"

-

+15

WMI, Win32_LogicalDiskToPartition. Win32_LogicalDisk . Win32_DiskDriveToDiskPartition, , .

+2

All Articles