[Baypiggies] File IO question

Monte Davidoff davidoff56 at alluvialsw.com
Tue Jul 25 19:32:11 CEST 2006


Ken Seehart wrote:
> 
> In other words, if the file initially contains a 0 or 1, and the above 
> code is executed repeatedly, can I be sure that my file will contain a 0 
> or 1 if the power is shut off at a random time during execution?

You need to ensure that the OS file buffers are written to disk -- 
closing the file is not sufficient.  I suggest something along these lines:

1. Write new data file.
2. Invoke /bin/sync to ensure the new data file is written to disk, if 
shelve did not take care of this already.
3. Using Steve Hindle's suggestion, update the status indicator in the 
file system.
4. Invoke /bin/sync again to ensure that the status indicator changes 
are written to disk.

I'm also working on an embedded Linux application that writes to a flash 
drive.  To get journaling, I've used XFS on the flash drive, although I 
have not tried JFFS2.

Monte


More information about the Baypiggies mailing list