UBIFS sync question

Jamie Lokier jamie at shareable.org
Thu Oct 2 08:55:32 EDT 2008


Artem Bityutskiy wrote:
> However, if you open a file, and just add few lines to it, then it
> should not become empty after reboot. You should just loose whole or
> part of new data.
> 
> I think you actually truncate the file, then re-write it, instead of
> appending. This often happens in case of shell scripts - shell commands
> like truncating files.

Generally when updating a file, then I write a new file under a
temporary name in the same directory, then fsync() the new file, then
rename() it over the original file, then fsync() the containing
directory.

That should be safe for any change to the file contents.  After boot
during this process, you should see the old contents or the new
contents, nothing else.  After the second fsync(), you should be
confident that any subsequent boot will always see the new contents.

O_APPEND should be ok too and is essential for log files, but there's
always a danger than after a boot in the middle of the update, you'll
see half the write.

-- Jamie



More information about the linux-mtd mailing list