[Baypiggies] File IO question
Ken Seehart
ken at seehart.com
Tue Jul 25 14:09:50 CEST 2006
I am writing a linux embedded application that writes to a FLASH disk.
It needs to reliably recover from a power down at any time. So I have
implemented a tandem file writing scheme to ensure that an uncorrupted
version of the data file exists. I am using shelve for my pair of
tandem data files because it is sufficient for my needs. I use a pair
of single byte binary files to record the status of the data files.
My question is this: If I write a single byte to a file that contains
exactly one byte, can I be sure that a power outage during the write
will not render the file unreadable?
f = open("valid", "w")
f.write('\1');
f.close();
...
f = open("valid", "w")
f.write('\0');
f.close();
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?
- Ken
More information about the Baypiggies
mailing list