[Baypiggies] File IO question

Ken Seehart ken at seehart.com
Wed Jul 26 03:54:00 CEST 2006


steve hindle wrote:
>> On 7/25/06, Ken Seehart <ken at seehart.com> wrote:
>>     
>>> 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?
>>>
>>>       
>
> Given its a binary switch - the file contents are immaterial.
> You could simply use the (non-)existance of the file as the status indicator.
>   
That was my original plan, but I was worried that it would be easier to 
corrupt a directory by interrupting file creation/deletion than it would 
be to interrupt writing a byte to a file.  I'm not certain about this 
though.
> Also,  in these situations, its common to write the indicator LAST, after all
> updates have completed normally.  So if the power fails, etc - you can
> still boot
> the original known-good copy.
>
> Steve
>   
Yes, that's the basic idea.  The pseudocode is something like this:

set indicator 1 to false
write to file 1
set indicator 1 to true
set indicator 2 to false
write to file 2
set indicator 2 to true

At boot up, the indicators tell me which file is valid, and the 
appropriate file copy is performed.

- Ken



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/baypiggies/attachments/20060725/a3bb657f/attachment.htm 


More information about the Baypiggies mailing list