LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (http://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   sync( ) problem on SD card (http://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/sync-problem-on-sd-card-4175449708/)

5883 02-11-2013 02:05 PM

sync( ) problem on SD card
 
Hi we have a customer designed arm9 board,
it has a software reset button.

when i press it, it'll trigger a configuration backup function,
which will save all my running configuration from ram disk to SD/EMMC card, using "cp" command.

In the end of the cp commands, i run "sync()" to make sure all stuff put back to SD or EMMC. Then board reboots.

Now after i reboot, i copy my original config from SD/EMMC to ram disk.
Every once a while it says inode problem, asking me to run e2fsck.
If i put several sync() in the code back to back, problem happens less but still happens.

my guess is it didn't write info to SD/EMMC completely during soft reset.
so how to make sure sync() can really flush info to the SD ?

Any help appreciated.

smallpond 02-11-2013 02:49 PM

If you run sync from the command line, it waits for all writes to disk before it returns.

If you run the sync() C library procedure, then according to the documentation:
Quote:

sync() schedules the writes, but may return before the actual writing is done.
You probably want to call fsync.

5883 02-11-2013 03:59 PM

thanks for reply 1st,
check code again, we are doing system call actually,
system("sync");

my understanding is system() will guarantee "sync" completes and then return back.
system() executes a command specified in command by calling /bin/sh -c command, and returns after the command has been completed.




Quote:

Originally Posted by smallpond (Post 4889383)
If you run sync from the command line, it waits for all writes to disk before it returns.

If you run the sync() C library procedure, then according to the documentation:

You probably want to call fsync.


rknichols 02-11-2013 08:07 PM

If the filesystem is still mounted read/write there is no assurance that the filesystem metadata has been written to the device. If the filesystem cannot be unmounted, you should at least remount it read-only before rebooting.


All times are GMT -5. The time now is 09:26 PM.