Prev: Writing File System Driver & Creating Virtual Disk Drive in Windows XP [Question by a Novice]
Next: Taking over a session..
From: Echo on 14 Jan 2007 22:34 Do you mean, even if media not really removed after calling IOCTL_STORAGE_EJECT_MEDIA, I can still safely unplug that media since buffers are flushed to that media. PS: When I say device/media "Removed from system", I mean you can't access the relative drive, and you can't see the device/media in Windows Explorer, Control Panel, or elsewhere. Just as what the "Safely Remove Hardware" icon in the system tray does. Thanks & Regards, Echo "David J. Craig" wrote: > You have two things when you have FlashMedia. Since I wrote or helped write > the drivers for a non-mass storage compliant SmartMedia & Compact Flash > reader, I know it works. The eject won't really remove the media, but it > will flush the dirty buffers including system areas to the media. This > worked on Windows 2000. With XP there is an option to optimize media for > speed and not safe removabililty so I am not sure it an speed optimized > drive will properly flush. Then an open exclusive of the drive would force > a flush. There is a good sequence of operations I have forgotten, but have > implemented in code somewhere that will properly allow a drive to be > formatted including repartitioning and then remounted with all new > partitions recognized. Look at disk.sys and cleanup.sys to see what is > needed. You may also want to look at fastfat.sys to see how a filesystem > assists in this because it is the driver that forces the flush by the cache > manager. > > "Echo" <Echo(a)discussions.microsoft.com> wrote in message > news:5BC94204-B26D-444B-B8DC-E7207C68F1C1(a)microsoft.com... > >I mean, FlashMedia Card, such as SdCard, sometimes can't be ejected by > > IOCTL_STORAGE_EJECT_MEDIA. > > > > Echo > > > > "Uwe Sieber" wrote: > > > >> > >> > >> What do you mean with "can't work with"? Is it one of these > >> scrap devices with GetDriveType returns DRIVE_UNKNOWN for? > >> > >> Uwe > >> > >> > >> Echo wrote: > >> > Some are PCI attached, some are internal usb attached. I tried many. > >> > Some can > >> > be ejected with IOCTL_STORAGE_EJECT_MEDIA, FSCTL_DISMOUNT_VOLUME, some > >> > can't. As to current one I'm testing, it's PCI attached, and can't work > >> > with > >> > IOCTL_STORAGE_EJECT_MEDIA, FSCTL_DISMOUNT_VOLUME. > >> > > >> > I refer to MS KB article: http://support.microsoft.com/kb/165721 when > >> > using > >> > IOCTL_STORAGE_EJECT_MEDIA method. > >> > > >> > Thanks & Regards, > >> > Echo > >> > > >> > "Uwe Sieber" wrote: > >> > > >> >> With 'SdCard' you mean a PCI attached SD card reader? Then > >> >> you have luck to get it back by means of "Scan for hardware > >> >> changes". It would not work that way with an internal USB > >> >> card reader. > >> >> Here the right way is to eject the media using > >> >> IOCTL_STORAGE_EJECT_MEDIA. > >> >> > >> >> > >> >> Uwe > >> >> > >> >> > >> >> Echo wrote: > >> >>> I tried the project, it works well with usb devices (calling > >> >>> CM_Request_Device_Eject), but has problem with fixed drive such as > >> >>> SdCard > >> >>> (calling CM_Query_And_Remove_SubTree). SdCard can be ejected, but > >> >>> can't be > >> >>> recognized after reinsertion. I have to "Scan for hardware changes" > >> >>> in > >> >>> Control Panel to force system to find the device. > >> >>> > >> >>> Thanks & Regards, > >> >>> Echo > >> >>> > >> >>> "Uwe Sieber" wrote: > >> >>> > >> >>>> Some are a bit hidden in too much text... > >> >>>> If you want to program it yourself, here is my demo project: > >> >>>> http://www.codeproject.com/system/RemoveDriveByLetter.asp > >> >>>> > >> >>>> > >> >>>> It uses CM_Query_And_Remove_SubTree to remove the USB device. > >> >>>> But this function requires admin previleges while > >> >>>> CM_Request_Device_Eject works without. No idea why. > >> >>>> > >> >>>> > >> >>>> Uwe > >> >>>> > >> >>>> > >> >>>> > >> >>>> > >> >>>> > >> >>>> Echo wrote: > >> >>>>> Thanks a lot! > >> >>>>> > >> >>>>> I got what I want! And many useful tools! > >> >>>>> > >> >>>>> Regards, > >> >>>>> Echo > >> >>>>> > >> >>>>> > >> >>>>> "Pavel A." wrote: > >> >>>>> > >> >>>>>> Look at http://www.uwe-sieber.de/ > >> >>>>>> > >> >>>>>> Regards, > >> >>>>>> --PA > >> >>>>>> > >> >>>>>> "Echo" wrote: > >> >>>>>>> Removable devices, such as usb devices, flashmedia card, can only > >> >>>>>>> be safely > >> >>>>>>> removed by clicking the icon in system tray in WinXP. But how to > >> >>>>>>> make it > >> >>>>>>> programmatically? > >> >>>>>>> > >> >>>>>>> I tried IOCTL_STORAGE_EJECT_MEDIA, FSCTL_DISMOUNT_VOLUME, but > >> >>>>>>> only have > >> >>>>>>> effect in several special cases. > >> >>>>>>> > >> >>>>>>> Any advice be appreciated! > >> >>>>>>> > >> >>>>>>> > >> > > >
From: Echo on 14 Jan 2007 22:36 Sorry, I think I didn't express myself clearly. What I want to ask is: How to programmatically eject media (such as SdCard, Memory Stick) inserted in Card Reader. The Card Reader is PCI attached, not Usb attached. Thanks & Regards, Echo "Pavel A." wrote: > "Uwe Sieber" wrote: > > He obviously wrote about an internal device. What sense should > > it make to prepare an internal device for save removal. It > > cannot be removed without opening the box. > > Internal device (USB or even PCI) can be electronically > powered down or removed from the bus, especially in laptop > platforms - has same effect as surprise removal. > > --PA >
From: Echo on 14 Jan 2007 23:01 Sorry, I'm talking about PCI attached card reader. As to usb attached card reader, no matter internal or external, it's a usb device from system or programmer's point of view. We can only eject this kind of card reader as a usb device. No way to eject its media except it's own specific driver. Regards, Echo "Uwe Sieber" wrote: > > With 'SdCard' you mean a PCI attached SD card reader? Then > you have luck to get it back by means of "Scan for hardware > changes". It would not work that way with an internal USB > card reader. > Here the right way is to eject the media using > IOCTL_STORAGE_EJECT_MEDIA. > > > Uwe > > > Echo wrote: > > I tried the project, it works well with usb devices (calling > > CM_Request_Device_Eject), but has problem with fixed drive such as SdCard > > (calling CM_Query_And_Remove_SubTree). SdCard can be ejected, but can't be > > recognized after reinsertion. I have to "Scan for hardware changes" in > > Control Panel to force system to find the device. > > > > Thanks & Regards, > > Echo > > > > "Uwe Sieber" wrote: > > > >> Some are a bit hidden in too much text... > >> If you want to program it yourself, here is my demo project: > >> http://www.codeproject.com/system/RemoveDriveByLetter.asp > >> > >> > >> It uses CM_Query_And_Remove_SubTree to remove the USB device. > >> But this function requires admin previleges while > >> CM_Request_Device_Eject works without. No idea why. > >> > >> > >> Uwe > >> > >> > >> > >> > >> > >> Echo wrote: > >>> Thanks a lot! > >>> > >>> I got what I want! And many useful tools! > >>> > >>> Regards, > >>> Echo > >>> > >>> > >>> "Pavel A." wrote: > >>> > >>>> Look at http://www.uwe-sieber.de/ > >>>> > >>>> Regards, > >>>> --PA > >>>> > >>>> "Echo" wrote: > >>>>> Removable devices, such as usb devices, flashmedia card, can only be safely > >>>>> removed by clicking the icon in system tray in WinXP. But how to make it > >>>>> programmatically? > >>>>> > >>>>> I tried IOCTL_STORAGE_EJECT_MEDIA, FSCTL_DISMOUNT_VOLUME, but only have > >>>>> effect in several special cases. > >>>>> > >>>>> Any advice be appreciated! > >>>>> > >>>>> >
From: Uwe Sieber on 15 Jan 2007 06:00 David J. Craig wrote: > With XP there is an option to optimize media for > speed and not safe removabililty so I am not sure it an speed optimized > drive will properly flush. I've never seen even a minimal difference in caching behavour resulting from this settings for drives with drive type DRIVE_REMOVABLE. Have you? Uwe
From: Uwe Sieber on 15 Jan 2007 06:22
Some of these PCI attached card readers appear with a drive type DRIVE_UNKNOWN. Maybe because the drive developers had no fun, time or budget to implement the removable specific stuff like IOCTL_STORAGE_EJECT_MEDIA. So, I've been wrong calling such devices 'scrap devices'. It's the fault or their drivers. Try to open the storage volume with read+write and no share access. This requires admin previleges... If this succeeds, call FlushFileBuffers, DeviceIoControl with FSCTL_LOCK_VOLUME and then with FSCTL_DISMOUNT_VOLUME. Now you can tell the user that it's save now to take out the card. Check periodically if you can read some bytes from the media - FSCTL_DISMOUNT_VOLUME again each time. As soon as it fails, the media is gone and you can close the handle. Instead of polling, waiting for GUID_IO_MEDIA_REMOVAL it the better way but I do not expect that this works with this kind of underdone driver. Uwe Echo wrote: > I mean, FlashMedia Card, such as SdCard, sometimes can't be ejected by > IOCTL_STORAGE_EJECT_MEDIA. > > Echo > > "Uwe Sieber" wrote: > >> >> What do you mean with "can't work with"? Is it one of these >> scrap devices with GetDriveType returns DRIVE_UNKNOWN for? >> >> Uwe >> >> >> Echo wrote: >>> Some are PCI attached, some are internal usb attached. I tried many. Some can >>> be ejected with IOCTL_STORAGE_EJECT_MEDIA, FSCTL_DISMOUNT_VOLUME, some >>> can't. As to current one I'm testing, it's PCI attached, and can't work with >>> IOCTL_STORAGE_EJECT_MEDIA, FSCTL_DISMOUNT_VOLUME. >>> >>> I refer to MS KB article: http://support.microsoft.com/kb/165721 when using >>> IOCTL_STORAGE_EJECT_MEDIA method. >>> >>> Thanks & Regards, >>> Echo >>> >>> "Uwe Sieber" wrote: >>> >>>> With 'SdCard' you mean a PCI attached SD card reader? Then >>>> you have luck to get it back by means of "Scan for hardware >>>> changes". It would not work that way with an internal USB >>>> card reader. >>>> Here the right way is to eject the media using >>>> IOCTL_STORAGE_EJECT_MEDIA. >>>> >>>> >>>> Uwe >>>> >>>> >>>> Echo wrote: >>>>> I tried the project, it works well with usb devices (calling >>>>> CM_Request_Device_Eject), but has problem with fixed drive such as SdCard >>>>> (calling CM_Query_And_Remove_SubTree). SdCard can be ejected, but can't be >>>>> recognized after reinsertion. I have to "Scan for hardware changes" in >>>>> Control Panel to force system to find the device. >>>>> >>>>> Thanks & Regards, >>>>> Echo >>>>> >>>>> "Uwe Sieber" wrote: >>>>> >>>>>> Some are a bit hidden in too much text... >>>>>> If you want to program it yourself, here is my demo project: >>>>>> http://www.codeproject.com/system/RemoveDriveByLetter.asp >>>>>> >>>>>> >>>>>> It uses CM_Query_And_Remove_SubTree to remove the USB device. >>>>>> But this function requires admin previleges while >>>>>> CM_Request_Device_Eject works without. No idea why. >>>>>> >>>>>> >>>>>> Uwe >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> >>>>>> Echo wrote: >>>>>>> Thanks a lot! >>>>>>> >>>>>>> I got what I want! And many useful tools! >>>>>>> >>>>>>> Regards, >>>>>>> Echo >>>>>>> >>>>>>> >>>>>>> "Pavel A." wrote: >>>>>>> >>>>>>>> Look at http://www.uwe-sieber.de/ >>>>>>>> >>>>>>>> Regards, >>>>>>>> --PA >>>>>>>> >>>>>>>> "Echo" wrote: >>>>>>>>> Removable devices, such as usb devices, flashmedia card, can only be safely >>>>>>>>> removed by clicking the icon in system tray in WinXP. But how to make it >>>>>>>>> programmatically? >>>>>>>>> >>>>>>>>> I tried IOCTL_STORAGE_EJECT_MEDIA, FSCTL_DISMOUNT_VOLUME, but only have >>>>>>>>> effect in several special cases. >>>>>>>>> >>>>>>>>> Any advice be appreciated! >>>>>>>>> >>>>>>>>> |