Storport virtual miniport and Eject Explorer command

I have a Storport virtual miniport that can create removable disks (but non-removable media). I am exploring whether it is possible to enable the Eject menu command in Windows Explorer for such devices.

This appears to be possible: the virtual disk miniport (vhdmp.sys) certainly allows users to use the Explorer Eject command to eject a VHD/VHDX. What’s peculiar is that the virtual disk miniport marks its devices as fixed (non-removable and non-removable media). It also marks them as EjectSupported.

When I tried to mark my own devices in the same manner I had no luck: Explorer insists on not showing the Eject command. Which means that either the virtual disk miniport does some other magic or that Explorer uses its own heuristics to determine when to show the Eject command and my devices do not satisfy them.

Thank you for any help.

Bill

EDIT: This is on Windows 8.

Does your device support multiple partitions?

On Thu, Jan 24, 2019 at 5:38 PM Bill_Zissimopoulos
wrote:

> OSR https://community.osr.com/
> Bill_Zissimopoulos started a new discussion: Storport virtual miniport and
> Eject Explorer command
>
> I have a Storport virtual miniport that can create removable disks (but
> non-removable media). I am exploring whether it is possible to enable the
> Eject menu command in Windows Explorer for such devices.
>
> This appears to be possible: the virtual disk miniport (vhdmp.sys)
> certainly allows users to use the Explorer Eject command to eject a
> VHD/VHDX. What’s peculiar is that the virtual disk miniport marks its
> devices as fixed (non-removable and non-removable media). It also marks
> them as EjectSupported.
>
> When I tried to mark my own devices in the same manner I had no luck:
> Explorer insists on not showing the Eject command. Which means that either
> the virtual disk miniport does some other magic or that Explorer uses its
> own heuristics to determine when to show the Eject command and my devices
> do not satisfy them.
>
> Thank you for any help.
>
> Bill
>
> –
> Reply to this email directly or follow the link below to check it out:
>
> https://community.osr.com/discussion/290981/storport-virtual-miniport-and-eject-explorer-command
>
> Check it out:
> https://community.osr.com/discussion/290981/storport-virtual-miniport-and-eject-explorer-command
>

Does your device support multiple partitions?

Yes.

I am curious though. Do I have any control over this in a miniport?

This is handled in layers above you. If you have several partitions and you
select to eject one of them, what happens to the other partitions? See how
this can be an issue? I am not aware of any way to eject a disk that has
multiple partitions mounted.

On Thu, Jan 24, 2019 at 8:10 PM Bill_Zissimopoulos
wrote:

> OSR https://community.osr.com/
> Bill_Zissimopoulos commented on Storport virtual miniport and Eject
> Explorer command
>
> > Does your device support multiple partitions?
>
> Yes.
>
> I am curious though. Do I have any control over this in a miniport?
>
> –
> Reply to this email directly or follow the link below to check it out:
> https://community.osr.com/discussion/comment/292293#Comment_292293
>
> Check it out:
> https://community.osr.com/discussion/comment/292293#Comment_292293
>

This is handled in layers above you. If you have several partitions and you
select to eject one of them, what happens to the other partitions? See how
this can be an issue? I am not aware of any way to eject a disk that has
multiple partitions mounted.

Jamey, thanks. What you say makes perfect sense.

However I am running the same diskpart commands against a disk created by vhdmp.sys and a disk created by my own miniport:

create partition primary
format quick
assign letter v

This creates a single partition, formats it with the default file system and assigns it letter V. When using vhdmp.sys the the resulting volume appears as “Fixed” drive V: in Explorer, but Eject is enabled. When using my own miniport the Eject command never appears. I am trying to understand why.

For the record I am creating the virtual disk using diskpart and the following commands:

create vdisk file="C:\PATH\TO\FILE.VHDX" type=expandable maximum=512
attach vdisk

Is the vhdmp device allowing multiple partitions to mount?

On Thu, Jan 24, 2019 at 8:36 PM Bill_Zissimopoulos
wrote:

> OSR https://community.osr.com/
> Bill_Zissimopoulos commented on Storport virtual miniport and Eject
> Explorer command
>
> > This is handled in layers above you. If you have several partitions and
> you
> >
> > select to eject one of them, what happens to the other partitions? See
> how
> >
> > this can be an issue? I am not aware of any way to eject a disk that
> has
> >
> > multiple partitions mounted.
>
> Jamey, thanks. What you say makes perfect sense.
>
> However I am running the same diskpart commands against a disk created by
> vhdmp.sys and a disk created by my own miniport:
>
> create partition primary format quick assign letter v
>
> This creates a single partition, formats it with the default file system
> and assigns it letter V. When using vhdmp.sys the the resulting volume
> appears as “Fixed” drive V: in Explorer, but Eject is enabled. When using
> my own miniport the Eject command never appears. I am trying to understand
> why.
>
> For the record I am creating the virtual disk using diskpart and the
> following commands:
>
> create vdisk file=“C:\PATH\TO\FILE.VHDX” type=expandable maximum=512
> attach vdisk
>
> –
> Reply to this email directly or follow the link below to check it out:
> https://community.osr.com/discussion/comment/292295#Comment_292295
>
> Check it out:
> https://community.osr.com/discussion/comment/292295#Comment_292295
>

Is the vhdmp device allowing multiple partitions to mount?

I believe so. I just did the following test using diskpart on top of a VHDX:

select vdisk file="PATH"
attach vdisk
clean
create partition primary size=128
create partition primary
format quick
assign letter u
select partition 1
format quick
assign letter v

This resulted in volumes U: and V: appear in Explorer. The Eject menu command was shown on both of them. When I selected Eject on one of them both drives disappeared. (Also confirmed by diskpart and list disk.)

Excellent. Then you shoudl be able to get this to work. Let me see what i
can find out.

On Thu, Jan 24, 2019 at 10:35 PM Bill_Zissimopoulos
wrote:

> OSR https://community.osr.com/
> Bill_Zissimopoulos commented on Storport virtual miniport and Eject
> Explorer command
>
> > Is the vhdmp device allowing multiple partitions to mount?
>
> I believe so. I just did the following test using diskpart on top of a
> VHDX:
>
> select vdisk file=“PATH” attach vdisk clean create partition primary
> size=128 create partition primary format quick assign letter u select
> partition 1 format quick assign letter v
>
> This resulted in volumes U: and V: appear in Explorer. The Eject menu
> command was shown on both of them. When I selected Eject on one of them
> both drives disappeared. (Also confirmed by diskpart and list disk.)
>
> –
> Reply to this email directly or follow the link below to check it out:
> https://community.osr.com/discussion/comment/292298#Comment_292298
>
> Check it out:
> https://community.osr.com/discussion/comment/292298#Comment_292298
>

I could not accept defeat, without at least knowing why this was happening.

After a few false starts I decided to run Explorer via a VM connected to the kernel debugger. The basic idea was to set a user mode breakpoint at TrackPopupMenu and follow the debugger wherever it takes us.

To summarize my findings: after the “Eject” popup menu command is selected, Explorer eventually runs the following procs:

SHELL32!CMtPtLocal::Eject
    SHELL32!CMtPtLocal::IsEjectable
        SHELL32!CMtPtLocal::IsCDROM
        SHELL32!CMtPtLocal::IsMediaRemovable
            SHELL32!CMtPtLocal::CanUseVolume
            SHELL32!CMtPtLocal::IsFloppy
            SHELL32!CMtPtLocal::IsVirtualDevice
                SHELL32!CMtPtLocal::IsFloppy
                SHELL32!CMtPtLocal::_GetHandleWithAccessAndShareMode
                SHELL32!GetDiskInformation
                    _imp_GetStorageDependencyInformation
    SHELL32!CMtPtLocal::_TryVirtualDiscImageDriveEject
        SHELL32!_imp_load_OpenVirtualDisk
        SHELL32!_imp_DetachVirtualDisk

The important part is checking if the device is ejectable via GetStorageDependencyInformation and ejecting the device via DetachVirtualDisk. Unfortunately this means that SHELL32 has special knowledge of virtual disks and we cannot easily replicate this behavior with another virtual miniport.

It sounds like if I insist on replicating this behavior in my own miniport I would need a context menu handler thingy. Gah!

I spent a little time poking around this weekend, and could find nothing
documented or on GitHub that accomplishes this. I was going to write back
saying that i suspect Microsoft has done some hocus pocus in the upper
layers to accomplish this. It looks like you went all the way. Thanks for
the information. Now we know for sure.

On Mon, Jan 28, 2019 at 1:40 AM Bill_Zissimopoulos
wrote:

> OSR https://community.osr.com/
> Bill_Zissimopoulos commented on Storport virtual miniport and Eject
> Explorer command
>
> I could not accept defeat, without at least knowing why this was happening.
>
> After a few false starts I decided to run Explorer via a VM connected to
> the kernel debugger. The basic idea was to set a user mode breakpoint at
> TrackPopupMenu and follow the debugger wherever it takes us.
>
> To summarize my findings: after the “Eject” popup menu command is
> selected, Explorer eventually runs the following procs:
>
> SHELL32!CMtPtLocal::Eject SHELL32!CMtPtLocal::IsEjectable
> SHELL32!CMtPtLocal::IsCDROM SHELL32!CMtPtLocal::IsMediaRemovable
> SHELL32!CMtPtLocal::CanUseVolume
> SHELL32!CMtPtLocal::IsFloppy
> SHELL32!CMtPtLocal::IsVirtualDevice
> SHELL32!CMtPtLocal::IsFloppy
> SHELL32!CMtPtLocal::_GetHandleWithAccessAndShareMode
> SHELL32!GetDiskInformation
> _imp_GetStorageDependencyInformation
> SHELL32!CMtPtLocal::_TryVirtualDiscImageDriveEject
> SHELL32!_imp_load_OpenVirtualDisk SHELL32!_imp_DetachVirtualDisk
>
> The important part is checking if the device is ejectable via
> GetStorageDependencyInformation and ejecting the device via
> DetachVirtualDisk. Unfortunately this means that SHELL32 has special
> knowledge of virtual disks and we cannot easily replicate this behavior
> with another virtual miniport.
>
> It sounds like if I insist on replicating this behavior in my own
> miniport I would need a context menu handler thingy. Gah!
>
> –
> Reply to this email directly or follow the link below to check it out:
> https://community.osr.com/discussion/comment/292317#Comment_292317
>
> Check it out:
> https://community.osr.com/discussion/comment/292317#Comment_292317
>