Power-Cycle Processing by Block Device Drivers

The Windows CE power management protocol supports power cycles that are transparent to applications. Therefore, it is important that block device drivers handle the POWER_DOWN and POWER_UP system messages efficiently.

Like all device drivers, block device drivers must limit themselves to minimal, very fast processing of the POWER_DOWN message. To accomplish this, they should save any volatile state information in RAM, set a flag to indicate that power is about to be turned off, and exit. POWER_ON processing is exactly like the processing for a regular card removal that is followed by an insertion. When power resumes, the PC Card Socket driver issues a card-removal notification for all sockets with inserted cards. Next, it checks the socket status and issues card-insertion notices for each socket with a card. Finally, the Device Manager launches its detection sequence and loads the appropriate driver for each card.

Block device drivers must detect whether they are being loaded either in response to a POWER_ON message or because a block device was disconnected from, and then reconnected to the system. This is important because the driver should preserve state information for any handles held by applications to files stored in the linear flash memory device across simple power cycles. However, if the block device is removed and replaced with a different card, any open file handles should be closed.

The following table shows how open file handles should be treated during POWER_UP processing.

Transition
Preserve open file handles
Simple power cycle. Yes.
Block device removed and subsequently re-inserted. Yes, if it is possible to detect that the contents of the device have not changed.
Block device removed and replaced with a different device. No.