views:

12

answers:

1

I am writing a c# .net CF application for windows mobile 6, which does some file handling. I wanted to know if there is any built-in way to make the file handling robust against power failure. For instance, if there is a power failure while writing the file, the file contents should be intact without corruption(maybe there is loss of the data being written at the time of power loss, but not already existing data in the file). The next time the power is up, the file contents should be present as before the power failure.

Thanks in advance.

+1  A: 

In my experience with numerous industrial Windows Mobile/Windows CE devices over the years (Symbol/Motorola, Toshiba, Intermec, etc), you can't guarantee much of anything around data integrity on the local storage. After a power failure event, the data will often be partially corrupted or, more frequently, completely gone. This isn't really the fault of Windows Mobile- it's just the way the flash storage subsystems are built. They're "non-volatile" on clean power on/off, but power fail on in-progress writes is usually fatal. Our current Symbol/Moto WM6 devices get bricked and need reflashing every few weeks when someone drains the battery too far.

If you have a mostly-available network, I'd suggest offloading or augmenting your local storage with device-specific network storage where possible (eg fileshare, webservice, etc).

Bottom line: non-volatile storage on these devices is a convenience and shouldn't be trusted with important long-term storage.

nitzmahone
I second the above. The only way I have seen to prevent nand flash corruption is to add a mega capacitor so the system will have time to gracefully shutdown, but that is device specific and the OEM's responsibility.
Shaihi
Thanks for the response. But Wouldn't a mobile device power itself off just before the entire power is drained, So that it has enough power for the data stored in device flash memory to last for some time? (But this wouldn't still solve the problem as the application is still killed abruptly while shutting off.) I would assume now, with the above answer, that there should be some sort of intelligence built-in in the application to have backup files and use them if the main file is corrupt.
Vicky
It depends on the settings. Nand flash data does not require any power to last, it is a persistent storage. Even if the device shuts down gracefully when the battery is drained and you still have the rare cases of faulty batteries or pulling out the battery and so on.
Shaihi
Graceful auto-shutdown also requires that the low-battery sense is accurate- it becomes less so the older the battery gets. About half the time with our current devices (Symbol MC9090 series, <2yrs old), the entire filesystem gets zapped when the battery dies, and that's actually better than with other devices. Gotta say again that relying on the device's flash for anything beyond short-term storage is a recipe for disaster.
nitzmahone