Volume to physical drive

北慕城南 提交于 2019-12-03 15:03:32

Volumes are made up of one or more partitions, which reside on disks. So, E: doesn't necessarily map to a single disk in the system (think software RAID).

The way you map volumes to the 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 that has one DISK_EXTENT entry for every partition that the volume spans:

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

The extents have a disk number in them:

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

The DiskNumber is what goes into the PhsyicalDriveX link, so you can just sprintf that number with "\\.\PhysicalDrive%d"

-scott

Since you're using WMI anyway, start with Win32_LogicalDiskToPartition. On the Win32_LogicalDisk side, the Caption will be the drive letter. Then use Win32_DiskDriveToDiskPartition to see what physical drive holds that partition.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!