Driver letter assigned to mounted disk

Hi,

I have written a virtual storport miniport driver to mount disk image
files. Is there any way to know the drive letters assigned to the mounted
image?

I have read about mount manager and RegisterDeviceNotification Win32 API,
but couldn’t find a clear answer.

Thanks,
Lloyd

Are you emulating a removable media drive or fixed media?
“Lloyd” wrote in message news:xxxxx@ntdev…
Hi,

I have written a virtual storport miniport driver to mount disk image files. Is there any way to know the drive letters assigned to the mounted image?

I have read about mount manager and RegisterDeviceNotification Win32 API, but couldn’t find a clear answer.

Thanks,
Lloyd

Can a disk be mounted ? I don’t know, but a volume can be mounted.

Take a look at IoVolumeDeviceToDosName.

Note that a volume could be mounted within an already mounted filesystem. For example a volume can be mounted in C:\MNT.

Now I am mounting it as a fixed media.

On Mon, Nov 17, 2014 at 8:02 PM, wrote:

> Can a disk be mounted ? I don’t know, but a volume can be mounted.
>
> Take a look at IoVolumeDeviceToDosName.
>
> Note that a volume could be mounted within an already mounted filesystem.
> For example a volume can be mounted in C:\MNT.
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> 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
>

Then emulate the fake MBR there.

The drive letter assigned by Windows will be persistent and will be in 1-to-1 relation with the MBR signature 32bit word.

Look at volume management user mode APIs to enforce some particular drive letter.

“Lloyd” wrote in message news:xxxxx@ntdev…
Now I am mounting it as a fixed media.

On Mon, Nov 17, 2014 at 8:02 PM, wrote:

Can a disk be mounted ? I don’t know, but a volume can be mounted.

Take a look at IoVolumeDeviceToDosName.

Note that a volume could be mounted within an already mounted filesystem. For example a volume can be mounted in C:\MNT.


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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

Thanks ntdevgeek. Sorry, I think the word “mount” caused the confusion. We
are attaching a disk (image file) to a virtual adapter.

I looked at “IoVolumeDeviceToDosName”, the first argument to this call
is “VolumeDeviceObject”.
I dont have direct access to this from the miniport, and also I have
searched in storport support routines, but couldn’t find one.

On Mon, Nov 17, 2014 at 8:02 PM, wrote:

> Can a disk be mounted ? I don’t know, but a volume can be mounted.
>
> Take a look at IoVolumeDeviceToDosName.
>
> Note that a volume could be mounted within an already mounted filesystem.
> For example a volume can be mounted in C:\MNT.
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> 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
>

>I have written a virtual storport miniport driver to mount disk image files. Is there any way to know the

drive letters assigned to the mounted image?

Oh, now I see.

This is not about assignment of the drive letter. This is for kmode code to know it.

Then the question: why? to keep some per-instance info of the vdisk? and why is this a good idea? what if the user will change the drive letter?

I have major doubts VHDMP mounter bothers about drive letters.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

The purpose is -

The user has a disk image file and he initiates “mount” operation. The
driver needs to inform the user, which drive letters are assigned to the
volumes in the image file. This will help the user to know where are his
new volumes. It is not a problem if the user changes the drive letter, as
we are interested only to let him know which drives are the new ones.

"This requirement is not not for storing anything

On Tue, Nov 18, 2014 at 12:36 PM, Maxim S. Shatskih
wrote:

> >I have written a virtual storport miniport driver to mount disk image
> files. Is there any way to know the
> >drive letters assigned to the mounted image?
>
> Oh, now I see.
>
> This is not about assignment of the drive letter. This is for kmode code
> to know it.
>
> Then the question: why? to keep some per-instance info of the vdisk? and
> why is this a good idea? what if the user will change the drive letter?
>
> I have major doubts VHDMP mounter bothers about drive letters.
>
> –
> Maxim S. Shatskih
> Microsoft MVP on File System And Storage
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> 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
>

The driver must not and cannot inform the user. It cannot show UI.

The user-mode app (probably in Windows tray) must do this, and can even display a list of mounted vdisks with their drive letters.

Yes, it is the same app which sends the mount IOCTL down.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

“Lloyd” wrote in message news:xxxxx@ntdev…
The purpose is -

The user has a disk image file and he initiates “mount” operation. The driver needs to inform the user, which drive letters are assigned to the volumes in the image file. This will help the user to know where are his new volumes. It is not a problem if the user changes the drive letter, as we are interested only to let him know which drives are the new ones.



"This requirement is not not for storing anything

On Tue, Nov 18, 2014 at 12:36 PM, Maxim S. Shatskih wrote:

>I have written a virtual storport miniport driver to mount disk image files. Is there any way to know the
>drive letters assigned to the mounted image?

Oh, now I see.

This is not about assignment of the drive letter. This is for kmode code to know it.

Then the question: why? to keep some per-instance info of the vdisk? and why is this a good idea? what if the user will change the drive letter?

I have major doubts VHDMP mounter bothers about drive letters.


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

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

I understand that kernel mode code cannot show the UI. I was trying to
solve it this way - My driver would know the assigned drive letters *some
how*. The user mode app will send a custom IOCTL to query this data, and it
will display it. I was thinking in this way. If this is the right approach,
my question is how to know the assigned drive letters from the miniport.

otherwise is it possible to solve it from user mode *alone*, can you please
give some hint?

Thanks a lot,
Lloyd

On Tue, Nov 18, 2014 at 1:56 PM, Maxim S. Shatskih
wrote:

> The driver must not and cannot inform the user. It cannot show UI.
>
> The user-mode app (probably in Windows tray) must do this, and can
> even display a list of mounted vdisks with their drive letters.
>
> Yes, it is the same app which sends the mount IOCTL down.
>
> –
> Maxim S. Shatskih
> Microsoft MVP on File System And Storage
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
> “Lloyd” wrote in message news:xxxxx@ntdev…
> The purpose is -
>
>
> The user has a disk image file and he initiates “mount” operation. The
> driver needs to inform the user, which drive letters are assigned to the
> volumes in the image file. This will help the user to know where are his
> new volumes. It is not a problem if the user changes the drive letter, as
> we are interested only to let him know which drives are the new ones.
>
>
>


>
>
>
> "This requirement is not not for storing anything
>
>
>
>
>
>
>
> On Tue, Nov 18, 2014 at 12:36 PM, Maxim S. Shatskih <
> xxxxx@storagecraft.com> wrote:
>
> >I have written a virtual storport miniport driver to mount disk image
> files. Is there any way to know the
> >drive letters assigned to the mounted image?
>
> Oh, now I see.
>
> This is not about assignment of the drive letter. This is for kmode code
> to know it.
>
> Then the question: why? to keep some per-instance info of the vdisk? and
> why is this a good idea? what if the user will change the drive letter?
>
> I have major doubts VHDMP mounter bothers about drive letters.
>
> –
> Maxim S. Shatskih
> Microsoft MVP on File System And Storage
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> 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
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> 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
>

>My driver would know the assigned drive letters *some how*.

No. It would not.

The user mode app will send a custom IOCTL to query this data

No, it will determine it using:

a) get the volume instance (i.e. drive letter), you can enum all volumes using volmgmt API
b) from volume instance, send IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, it will return the StorageDeviceNumber of the underlying physical disk.
c) open (\.\PhysicalDrive%d, StorageDeviceNumber), and read the MBR signature (either faked by your driver or contained in your image file)
d) the driver must also know all of its MBR signatures. Then you send the custom IOCTL of “get vdisk info by MBR signature” to your driver.

For GPT case, use GPT GUID instead of MBR signature.

To simplify all of this, you can read about IOCTL_STORAGE_QUERY_PROPERTY, this will probably allow some piece of data which will replace the MBR signature for c) and d).

Also, instead of c), you can:

c1) enumerate all physical disks in the system using SetupDi APIs
c2) call CM_Get_Parent for each to filter away the disks not belonging to your driver
c3) call IOCTL_STORAGE_GET_DEVICE_NUMBER on each, and match this to device number from item b) to corellate volumes/partitions/drive letters to the physical disk.
c4) call IOCTL_SCSI_GET_ADDRESS to get bus/target/LUN (faked by your driver)
c5) call your custom IOCTL about “get vdisk info by bus/target/LUN”

As you can see, the StorageDeviceNumber (NOTE: not persistent across boots and even across disk plug/unplug) is the standard way of corellating volumes/partitions to physical disks.

And, to corellate phys disk to your driver internal instance, you can use bus/target/LUN, or MBR signature, or some storage propery (possibly).


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

You can list the volumes present on the system with IoGetDeviceInterfaces and GUID_DEVINTERFACE_VOLUME. Your driver recieves a list of symbolic links in the REG_MULTI_SZ string format.

You could also register for PNP notifications. You’re driver would be notified of the arrival/removal of interfaces of the specified device interface class (volumes in that case with GUID_DEVINTERFACE_VOLUME).

Any of these links can be passed to ZwCreateFile to obtain a file handle representing the volume. You could use this handle to send IOCTL codes or obtain a FILE_OBJECT pointer and check for the presence of the Vpb member.