USB flash eject

Hi,
I am developing a composite USB device that has an embedded flash as one of the devices.

This device shall have two switches (A and B). On pressing switch A, I want to achieve USB eject and on pressing switch B, I want the USB flash to be re-inserted.
Since this flash is embedded, it cannot be physically removed or inserted.

Can this be acheived through software? Any pointers to this would be appreciated.

Regards,
Vinod

What you can do here is to emulate the storage device (if I got it right, by “flash” you mean flash memory storage), so that, from the system’s perspective, all storage-related operations will get done on this emulated storage device. The system should believe that your composite device itself does not provide storage functionality - only emulated device should know that it does, so that it will submit requests to the composite device via a proprietary interface. If you do it this way, insertion and removal of the storage device can be emulated in a software.

Anton Bassov

> What you can do here is to emulate the storage device

I think that the device has a real USB flash inside the device and the
standard USBSTOR stack will be used but it will grow from composite.sys
driver which attaches FDO to usbhub’s PDO. The question was, as I think, how
to emulate device arrival-removal from the software and it is possible to
force the system to dismount device’s stack( to send IRP_MN_REMOVE ) from
the user mode. The stack will be dismounted only the composite driver’s PDO
will survive.


Slava Imameyev, xxxxx@hotmail.com

wrote in message news:xxxxx@ntdev…
> What you can do here is to emulate the storage device (if I got it right,
> by “flash” you mean flash memory storage), so that, from the system’s
> perspective, all storage-related operations will get done on this emulated
> storage device. The system should believe that your composite device
> itself does not provide storage functionality - only emulated device
> should know that it does, so that it will submit requests to the composite
> device via a proprietary interface. If you do it this way, insertion and
> removal of the storage device can be emulated in a software.
>
>
> Anton Bassov
>

> I think that the device has a real USB flash inside the device and the

standard USBSTOR stack will be used but it will grow from composite.sys
driver which attaches FDO to usbhub’s PDO. The question was, as I think, how
to emulate device arrival-removal from the software and it is possible to
force the system to dismount device’s stack( to send IRP_MN_REMOVE ) from
the user mode. The stack will be dismounted only the composite driver’s PDO will survive.

The way I understood it, this is *NOT* what the OP wants…

I think that his composite device will create FDO above USBHUB’s PDO, plus multiple PDOs that participate in multiple stacks. He wants to be able to “insert/remove” one of PDO’s without
either touching the physical composite device or affecting other PDOs. Have you got any other explanation to the following statement: “Since this flash is embedded, it cannot be physically removed or inserted”. Apperantly, he does not want to say that his USB device cannot be physically inserted or removed, does he???

Anton Bassov

Thanks for your replies.

You guys are right in understanding that the composite device itself shall not be removed. Only the flash device / its PDO, needs to be ejected/re-inserted by means of software.

I feel emulation of the storage device may turn out complex.
I was wondering if there is any information on how the “soft eject” from the icon tray is achieved.

Many Thanks,
Vinod

> The way I understood it, this is *NOT* what the OP wants…

Actually, this is what he wants.

I think that his composite device will create FDO above USBHUB’s PDO

There are standard MS’s driver for composite devices.

Have you got any other explanation to the following statement: “Since this
flash is embedded, it cannot be physically removed or inserted”.

Yes, there are a lot of such devices, for example SanDisk which is inserted
in my PC - it has two devices - CD ROM and disk.


Slava Imameyev, xxxxx@hotmail.com

wrote in message news:xxxxx@ntdev…
>> I think that the device has a real USB flash inside the device and the
>> standard USBSTOR stack will be used but it will grow from composite.sys
>> driver which attaches FDO to usbhub’s PDO. The question was, as I think,
>> how
>> to emulate device arrival-removal from the software and it is possible to
>> force the system to dismount device’s stack( to send IRP_MN_REMOVE ) from
>> the user mode. The stack will be dismounted only the composite driver’s
>> PDO will survive.
>
> The way I understood it, this is NOT what the OP wants…
>
> I think that his composite device will create FDO above USBHUB’s PDO, plus
> multiple PDOs that participate in multiple stacks. He wants to be able to
> “insert/remove” one of PDO’s without
> either touching the physical composite device or affecting other PDOs.
> Have you got any other explanation to the following statement: “Since this
> flash is embedded, it cannot be physically removed or inserted”.
> Apperantly, he does not want to say that his USB device cannot be
> physically inserted or removed, does he???
>
> Anton Bassov
>
>
>
>
>
>

“I was wondering if there is any information on how the “soft eject”
from the icon tray is achieved.”

Yup…

My moneys on a combination of the “setupdi” and config manager apis…

Specifically look at…

CM_Reenumerate_DevNode() Its even recommended by MS here…
http://support.microsoft.com/kb/259697

A good source for practically using those APIs is a MS sample called
“usbview”.

I know some of our USB devices have a “renumerate” IOCTL direct to the
PDO
not sure offhand how its done in the driver/device though.

BR,

Rob Linegar
Software Engineer
Data Encryption Systems Limited
www.des.co.uk | www.deslock.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@mindtree.com
Sent: 22 June 2007 12:02
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] USB flash eject

Thanks for your replies.

You guys are right in understanding that the composite device itself
shall not be removed. Only the flash device / its PDO, needs to be
ejected/re-inserted by means of software.

I feel emulation of the storage device may turn out complex.
I was wondering if there is any information on how the “soft eject” from
the icon tray is achieved.

Many Thanks,
Vinod


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

> I was wondering if there is any information on how the "soft eject" from

the icon tray is achieved.

I think you shoul build the device PnP tree using SetupDi* functions and
then( for each device in the tree ) call SetupDiSetClassInstallParams and
SetupDiChangeState, for more infromation read the DDK, e.g. for
SetupDiChangeState it says

" DICS_PROPCHANGE
Removes and reconfigures the device so the new properties can take effect.
This flag typically indicates that a user has changed a property on a device
manager property page for the device. The PnP manager directs the drivers
for the device to remove their device objects and then the PnP manager
reconfigures and restarts the device.
"

Slava Imameyev, xxxxx@hotmail.com

wrote in message news:xxxxx@ntdev...
> Thanks for your replies.
>
> You guys are right in understanding that the composite device itself shall
> not be removed. Only the flash device / its PDO, needs to be
> ejected/re-inserted by means of software.
>
> I feel emulation of the storage device may turn out complex.
> I was wondering if there is any information on how the "soft eject" from
> the icon tray is achieved.
>
> Many Thanks,
> Vinod
>
>
>
>

Yes this procedure is correct you should use CM_Reenumerate_DevNode() to
eject the
device like how the Sandisk thumb drive (U3 application) does.

status = CM_Locate_DevNode (
&devInstHandle,

NULL,

CM_LOCATE_DEVNODE_NORMAL );
ASSERT(!(CR_SUCCESS != status));
if (CR_SUCCESS == status )
{
status = CM_Reenumerate_DevNode
(devInstHandle, 0);
ASSERT(!(CR_SUCCESS != status));
}

Regards,
Elango C

On 6/22/07, Rob Linegar wrote:
>
>
>
> “I was wondering if there is any information on how the “soft eject”
> from the icon tray is achieved.”
>
> Yup…
>
> My moneys on a combination of the “setupdi” and config manager apis…
>
> Specifically look at…
>
> CM_Reenumerate_DevNode() Its even recommended by MS here…
> http://support.microsoft.com/kb/259697
>
> A good source for practically using those APIs is a MS sample called
> “usbview”.
>
>
> I know some of our USB devices have a “renumerate” IOCTL direct to the
> PDO
> not sure offhand how its done in the driver/device though.
>
>
>
> BR,
>
> Rob Linegar
> Software Engineer
> Data Encryption Systems Limited
> www.des.co.uk | www.deslock.com
>
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of
> xxxxx@mindtree.com
> Sent: 22 June 2007 12:02
> To: Windows System Software Devs Interest List
> Subject: RE:[ntdev] USB flash eject
>
> Thanks for your replies.
>
> You guys are right in understanding that the composite device itself
> shall not be removed. Only the flash device / its PDO, needs to be
> ejected/re-inserted by means of software.
>
> I feel emulation of the storage device may turn out complex.
> I was wondering if there is any information on how the “soft eject” from
> the icon tray is achieved.
>
> Many Thanks,
> Vinod
>
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Elango C
CompuApps, Inc.
Chennai, India.
website:http://celango.blogspot.com

Thank you all for your replies.

I will try out the options that you have suggested and will get back with my observations or problems :wink:

Many Thanks,
Vinod

> This device shall have two switches (A and B). On pressing switch A, I

want to achieve USB eject and on pressing switch B, I want the USB
flash to be re-inserted.

Since this flash is embedded, it cannot be physically removed or
inserted.

Do you want to remove / eject the storage device, or eject the “media” from the storage device and leave the storage device present? Depending on what your goal is maybe it makes sense to report the storage device as a removable media device and have the buttons “eject” and “insert” the “media” instead of trying to remove the storage device itself.

Hi Glen,
Yes, like you say, the media needs to be ejected/inserted by using the two buttons.
If the firmware can be changed, then is there some easier way of handling this.

Regards,
Vinod