WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: fsync won't work if i don't call sync  (Read 1963 times)

Offline mbertrand

  • Full Member
  • ***
  • Posts: 225
fsync won't work if i don't call sync
« on: January 09, 2013, 11:06:40 AM »
We use TC on what we call controllers. These are small industrial computers. There is a program built in QT that does control and logs and more. It has a usb port on the front and this is the only way the user (customer ) can get files from the controller.
The user does not have to mount it and does not even know that concept. We are auto mounting it when user inserts the usb stick.
User never sees the terminal only our program!

For example user can export log files from the controller to usb stick. I'm relatively new to Linux and just realized that file i/o is buffered and fsync need to be explicitly called to have buffered data written to disk write away. So after each file is copied I call fsync but nothing is writen until a call sync(). But calling sync() does not seem to be needed according to documentation and it is not needed when I run my program on my Ubuntu desktop. What am I missing?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11502
Re: fsync won't work if i don't call sync
« Reply #1 on: January 09, 2013, 03:33:40 PM »
Hi mbertrand
That's not much to go on, but I'll give it a shot. Are you checking the return value of  fsync  to see that actually
reports success? Also:
Quote
Calling fsync() does not necessarily ensure that the entry in the directory containing the file has also reached disk. For that an explicit fsync() on a file descriptor for the directory is also needed.
from:
http://linux.die.net/man/2/fsync
It might be simpler to just copy the files and then then call umount, which should sync the file system on the
device for you.