atomic file operations
Artem B. Bityuckiy
dedekind at yandex.ru
Thu Mar 24 05:53:16 EST 2005
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 :-)
(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.
Artem B. Bityuckiy,
More information about the linux-mtd