On our (4.2) platform, we programmatically load/unload (dismount) the
\Storage Card and the ATADISK driver, based on the state of a switch on
our CompactFlash card door.
Most of the time, this works fine. However, it seems that if I unload,
then reload in quick succession (caused by someone opening then closing
the card door), then the \Storage Card filesystem doesn't always
reappear, even though ATADISK gets reloaded.
The unload sequence we follow is:
1. DismountStore() to dismount DSK1: (we have the reg configured so that
\Storage Card is always DSK1:). We don't (currently) wait for any
notification that the store has unloaded.
2. DeactivateDevice() for ATADISK.
3. Wait for a BLOCK_DRIVER_GUID notification that tells us that DSK1:
(ATADISK driver) has been removed.
4. Unload sequence is now complete, and we allow reloading (eg if the
door closes again).
The load sequence is:
1. ActivateDeviceEx() for ATADISK.
2. When ATADISK load is complete, it sends a BLOCK_DRIVER_GUID
notification, for the benefit of Storage Manager.
3. Storage Manager loads a FAT filesystem for each partition (we have
only one normally).
4. We wait for notification (FindFirstChangeNotification() for root
directory changes) that the \Storage Card directory has appeared.
5. Sequence complete - filesystem is now ready to use.
This all works nicely, as long as we don't unload, then reload too
quickly. If we do, the (re)load sequence fails at step 3 above.
What seems to happen (based on stepping through the code with the
debugger) is that Storage Manager's PnP thread receives the
BLOCK_DRIVER_GUID attach notification, and calls its MountStore()
function. That function then searches through its list of stores, and
finds a matching one that it marked as detached. It therefore marks it
as attached again (rather than its more usual call to AddStore()), and
then returns (without sending a STORE_MOUNT_GUID attach notification -
perhaps that is significant?).
In any case, the end result is that the \Storage Card filesystem doesn't
seem to be reloaded, as I don't get a filesystem notification for it (or
a STORE_MOUNT_GUID PnP notification - I've tried that approach too), and
I can't see it with the remote file viewer, or from an application.
Does anyone have any idea what might be going on here? Better still, how
can I get it to work (ie to always load the filesystem when ATADISK (re)
loads up)?