How to map \\.\PHYSICALDRIVE0 to drive name and vice versa

Hi,

i am looking for some way to map a “\.\PHYSICALDRIVE0” to e.g. a “C:” and vice versa (in user mode). The first idea was to use ZwQueryVolumeInformationFile with “FileFsVolumeInformation” but the documentation say (and its true because i get a NTSTATUS != STATUS_SUCCESS):

“If the FileHandle represents a direct device open, only FileFsDeviceInformation can be specified as the value of FsInformationClass.”

Any ideas would be nice,…

First, remember that a volume can span multiple physical devices, so you may need to identify multiple devices per volume (i.e. C:).

For the simplest case, look at WMI Win32_LogicalDiskToPartition, specifically the Antecedent and Dependent. Disk # will match to PhysicalDrive#, but once you start getting into MPIO configs and other scenarios, you’ll need to use other WMI classes for the mapping.

You should be able to accomplish this completely through WMI. I’m sure you could also do this through Win32.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@arcor.de
Sent: Saturday, December 1, 2012 3:35 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] How to map \.\PHYSICALDRIVE0 to drive name and vice versa

Hi,

i am looking for some way to map a “\.\PHYSICALDRIVE0” to e.g. a “C:” and vice versa (in user mode). The first idea was to use ZwQueryVolumeInformationFile with “FileFsVolumeInformation” but the documentation say (and its true because i get a NTSTATUS != STATUS_SUCCESS):

“If the FileHandle represents a direct device open, only FileFsDeviceInformation can be specified as the value of FsInformationClass.”

Any ideas would be nice,…


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Take a look at winobj from SysInternals then check out the Zw calls for
objects. It can be done.

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

xxxxx@arcor.de” wrote in message
news:xxxxx@ntdev:

> Hi,
>
> i am looking for some way to map a “\.\PHYSICALDRIVE0” to e.g. a “C:” and vice versa (in user mode). The first idea was to use ZwQueryVolumeInformationFile with “FileFsVolumeInformation” but the documentation say (and its true because i get a NTSTATUS != STATUS_SUCCESS):
>
> “If the FileHandle represents a direct device open, only FileFsDeviceInformation can be specified as the value of FsInformationClass.”
>
> Any ideas would be nice,…

@ Kenny

First, remember that a volume can span multiple physical devices, so you may
need to identify multiple devices per volume (i.e. C:).

Yes, thanks for the reminder. I only need to know that a specific device belongs to a specific drive letter, thats all. That Multipath stuff is not of interest at this moment. Anyway thank you for reminding me that.

WMI is very powerful and one fine thing, but its pretty difficult to relate the classes to each other even with those things like Win32_LogicalDiskToPartition. Yesterday i already found out, that some of the classes look as if they where strongly connected to another class, but on a closer look, its very difficult to glue them together, at least in my case :frowning:

@Don Burn

Yes, the "\GLOBAL??" directory looks promising. I remember this can be done with NtOpenDirectoryObject, NtQueryDirectoryObject, NtOpenSymbolicLinkObject and NtQuerySymbolicLinkObject.

Note also that a “drive letter” may not map to a partition on the disk,
but could be a random sbudirectory, and most commonly might be a
subdirectory of a remote server. So don’t think that every drive letter
maps 1:1 to physical drives or even partitions. You first have to figure
out the mappnig, and then figure out what to do with that information.
For example, on many of my systems

I: = \server5\x
J: = \server5\x

at one time, I had two RAID-5 arrays on my server (\server, and the next
server became \server2, etc.), and files could be on one bank or the
other. As disk prices dropped, I consolidated all my files on one single
RAID-5 array (of 1TB disks, currently). But I had lots of scripts that
used J: so I just mapped both. \server5\x is not a physical volume, but
a subdirectory, C:\xfiles, on the server. On the first server, there was
a separate boot drive (not in the RAID-5 array) and two banks of hot-swap
2GB drives (and those were BIG disks in those days). The current server
just has one bank of hot-swap 1TB drives, and no separate boot drive.
(Actually, it also has a NAS array of four 2TB drives as well, currently
known as “Y:”, which maps to \server5\DroboY).

So don’t base your assumptions on the configuration of one machine. The
reality can be vastly more complex.
joe

@ Kenny

>First, remember that a volume can span multiple physical devices, so you
> may
>need to identify multiple devices per volume (i.e. C:).

Yes, thanks for the reminder. I only need to know that a specific device
belongs to a specific drive letter, thats all. That Multipath stuff is not
of interest at this moment. Anyway thank you for reminding me that.

WMI is very powerful and one fine thing, but its pretty difficult to
relate the classes to each other even with those things like
Win32_LogicalDiskToPartition. Yesterday i already found out, that some of
the classes look as if they where strongly connected to another class, but
on a closer look, its very difficult to glue them together, at least in my
case :frowning:

@Don Burn

Yes, the "\GLOBAL??" directory looks promising. I remember this can be
done with NtOpenDirectoryObject, NtQueryDirectoryObject,
NtOpenSymbolicLinkObject and NtQuerySymbolicLinkObject.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Hi Joe,

So don’t base your assumptions on the configuration of one machine. The reality can
be vastly more complex.

…and this is exactly the reason why i am trying to verify if a particular device belongs or is part of a volume letter, otherwise i wont ask this question. As you wrote, there are many constelations on many different scenarios, virtual drives/devices etc. so i have to make sure that some device A is either part or maps exactly to some volume letter B and if not, i am not interested in that object anymore.

Let Maxim S. Shatskih correct me, I do it in the following way (using Maxim’s advices):

  1. Enumerate all volumes by GUID.
  2. Enumerate all disks by GUID.
  3. Ask every volume about its disks (IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS)
  4. Ask every disk about its number ((IOCTL_STORAGE_GET_DEVICE_NUMBER).
  5. Map results from 3 to 4 and vice versa.