My example as you notice is just an example to reproduce this problem. Andthing is these functions *never* fail - so there is nothing really a reasonto break, those prints are only informational and a proof functions return 0.
I can live with small data loss, it's obvious to loose some data on powerloss. And by small I mean few of kilobytes, but here I loose *whole* filewith many megabytes if it is not closed.
So if I understand correctly - I can open file (mode 'a'), put in there hundreds ofmegabytes calling *only* fwrite(), all of which return SUCCESS (there is not a singleerror in whole execution) but if I never call fsync() (or fclose()) and power loseoccurs I lost *whole* file, because only fsync() can update file entry on FAT?
I expected things to work like that (consider calling only fwrite() in a loop):1) on fwrite() data is copied to some internal library buffer - ok2) as data written is less than 512 bytes (or different value depending onlibrary buffer size) nothing else happens3) if buffer fills to certain threshold (like that 512 bytes) data is flushedfrom library to kernel buffers.4) when kernel buffer overflows, kernel will send data to SD card.5) after dumping data to sd card, FAT entry is updated to reflect changesAnd it appears point 5 is not done. It will be done once fclose() is called.Is this correct behaviour of stdio and writing to file?
Hello
Ensuring data has been written to disk in proper order is a typical requirement of embedded platforms.
It is not usually the case on normal desktop/server platforms, where performance and caching is more important than actual non volatile storage device access, in order to reduce IO operations and improve disk throughput.
That's why, in embedded devices, we need file systems that
ensure this device consistency as best as possible. This is
a responsibility of the filesystem, not of the C language.
That's also why FAT family filesystems (and SD cards) are a total nonsense in embedded devices where power can be shut down without any warning or backup power.
SmartFS attempts to go in this direction but I am not aware
of the offered consistency guarantees.
littlefs from mbedOS was promising in this domain by
promising atomic FS updates as well as wear leveling, but I
lack time and no one offered to reimplement it for nuttx.
Specs are available.
Sebastien
--
You received this message because you are subscribed to the Google Groups "NuttX" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nuttx+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
| Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (1) |