LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 02-11-2013, 02:05 PM   #1
5883
Member
 
Registered: Aug 2004
Posts: 173

Rep: Reputation: 0
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.

Last edited by 5883; 02-11-2013 at 02:07 PM.
 
Old 02-11-2013, 02:49 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: Fedora
Posts: 4,153

Rep: Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265Reputation: 1265
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.
 
Old 02-11-2013, 03:59 PM   #3
5883
Member
 
Registered: Aug 2004
Posts: 173

Original Poster
Rep: Reputation: 0
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 View Post
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.
 
Old 02-11-2013, 08:07 PM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,783

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Unplugging a memory card after sync command. stf92 Linux - Newbie 4 02-24-2012 08:54 PM
sync out of range problem- can anyone help me pragna26 Fedora 1 11-04-2006 09:11 AM
Wireless Network Card Sync with Browser. areswargod03 Linux - Wireless Networking 3 03-04-2006 10:59 AM
Sync Out of Range Problem Eurytus Linux - Newbie 8 08-09-2004 02:26 AM
Frame Relay and HDLC Sync card vvlada Linux - Networking 5 03-31-2001 12:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration