I tried to use fsync to write some file to SD card ASAP. However fsync does not actually block before the file is physically written to the SD card. It seems to take about 5-6 seconds before the data is actually on the SD card. However mount the file system (I tried ext3, ext4) with commit = 1 or sync option does seem to work, the data is safe after reboot in 1 second. My question is that is there anyway to achieve flushing without resort to partition wide solution? I'm using linux kernel 2.6.37. Thank you
Asked
Active
Viewed 794 times
0
-
Are you sure it's not working on ext3 neither? See ext4 issue [Data Loss with Applications that do not use fsync() correctly](https://www.thomas-krenn.com/en/wiki/Ext4_Filesystem#Data_Loss_with_Applications_that_do_not_use_fsync.28.29_correctly). – pevik May 11 '15 at 13:13
1 Answers
0
If you want to be sure the content is written on the SD card, you should call blockdev with --flushbufs before exiting the program. If you want to benchmark the writing process, you can call this after every write.
/sbin/blockdev --flushbufs $dev

Gipsz Jakab
- 433
- 3
- 9