-   Linux - Software (
-   -   power failure interrupt (

yantai 06-04-2007 09:36 AM

power failure interrupt
I am doing writing to a flash (NVM). This writing should be protected from power failure/system crash, which means that an "emergency rescue" function should be provided during the writing. Is it possible to implement this function through signal catch? and is "sigpwr" the right signal for power failure? Please advice ASAP.

dracolich 06-04-2007 03:12 PM

How would you write code to detect a power failure before it happens? I would get a battery back-up for protection at the hardware level. And if you're concerned about a system crash before the write is complete wait until it's finished before opening more programs.

It should also be mentioned that to further protect your flash storage device you should unmount it before any crash or outage occurs to further prevent data loss.

yantai 06-05-2007 07:01 AM

write to flash during power down
Well, I really should say "power down" rather than "power failure" mistake.

Here is what I am doing -

To change the data stored in flash, it's first copied to ram buffer, after the data in the ram is changed, it copied back to flash.

HW/SW faults may cause system to power down. And it could happen when changing the data modified is still in ram buffer, or in the procedure writing back to the flash.
The code tries to save all those data in the ram buffer or carry on the writing back flash procedure even during powering down. I guess that powering down operation may force the operation on the files to stop. I would like this "force" operation wait until I finish the backup of the current RAM data or finish the write back flash operation.

How the codes to communicate with powering down event? Is there any API available that I can send message to the system to demand "powering down pending" and then after susccesful write to flash I can send "power down is OK" to the system?

dracolich 06-05-2007 07:59 AM

You haven't specified what distro you're using, but with Slackware I've never had that be a problem. If there's a write to flash pending when I tell it to shutdown it completes the write during shutdown - unless it's a hard crash instead of a "power down". If you're afraid of a hardware or software event causing shutdown wait for the write to finish before doing anything that might cause such an event. And try not to use ndiswrapper for wifi since it can be unpredictable.

Oh, to avoid losing the data this is what I do and what I suggest to everyone I meet - keep backups. Copy to a place on the hard disk first, then from there to flash.

yantai 06-06-2007 04:40 AM

It is not a slackware distro. I downloaded linux kernel from linux kernel website. And other packages (such as busybox, mplayer etc.) from different websites.

The powerdown is not supposed to be a normal powerdown. Rather it is casued by HW/SW faults. And I am not supposed to know what exact HW/SW events they are. What I need is to be aware that the system is "powering down" and started write whatever changes in the buffer to flash. I don't know how to catch "powering down" event though, would it be possible from power management? And what power management package provides such a API so that the user can catch "powering down" message and then send "pending" message back?

The system is "diskless" - there is no hard disk available :(

All times are GMT -5. The time now is 11:49 PM.