Re: atomic file operations

Artem B. Bityuckiy
2005-03-24T10:53:23Z

Estelle HAMMACHE wrote:
> Yes, when I write that the input buffer is split it means that
> several data nodes are written to the flash - each data node
> is an independent piece of data complete with header and CRC.
> If a data node is only partly written to flash, its CRC check
> will fail so the partial data will not be taken into account
> when building the file at next mount. In this sense each data
> node is an atomic write - but JFFS2 does not guarantee that
> a write() input buffer will be written as a single data node.

But if you:

1. write only 0-PAGE_SIZE bytes;
2. do not overlap n*PAGE_SIZE borders (n is 1,2, ...)
3. do fsync after write.

then you have the guarantee that you either have written all or
nowthing. JFFS2 does guarantee that due to its implementation.

To put it differently, write by small peaces, and do not overlap page
boundaries, and do fsync, and be happy with an atomic writes :-)

Examples:
(assume PAGE_SIZE is 4K)

write 4K to offset 16K is OK
write 1 byte anywhere is OK
write 10 bytes at offset 4095 is not OK.

HTH.

--
Best Regards,
Artem B. Bityuckiy,
St.-Petersburg, Russia.