Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Volume to physical drive

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

(E: is a SD card)

DeviceName is "\Device\HarddiskVolume3"

How do I "convert" it to something like "\\.\PHYSICALDRIVE1"

like image 349
Cornwell Avatar asked Sep 29 '10 17:09

Cornwell


1 Answers

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

like image 120
snoone Avatar answered Sep 17 '22 22:09

snoone