Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 6 months ago.
Force to write to opened file
Hi, First of all, thanks for your sd card file system implentation. I wonder how to make fflush work. I have to close and open file to actial write data to card. Is there any better solution for flush?
Thank you.
Question relating to:
![](/media/cache/profiles/IMG_3493.jpg.50x50_q85.jpg)
2 Answers
9 years, 6 months ago.
Hi Alexander. SDFileSystem itself doesn't use any internal buffers, but FATFileSystem and the stdio retarget layer in the mbed library might. Both of these layers sit between your stdio calls and my library. Unfortunately, I'm not terribly familiar with the way the stdio layer works... I see that there is function called _ensure() that makes sure any FATFileSystem buffers are synced using f_sync(), but I don't know the circumstances under which it may be called.
You might be better off sidestepping the stdio layer, and using the mbed C++ file API directly, which will also give you significantly better read/write performance. My official test program demonstrates how to do this. You could also use the underlying ChaN FatFs API, which is slightly faster yet.
[S'OK, I found it, will see if I can find a flush mechanism in the underlying code somewhere]
Hi Neil. I too am looking for a way to do this with you marvellous SDFileSystem. I've tried disk_sync() but that doesn't seem to do much flushing. The link to your official "test program" above seems to have become outdated: could you point me at where it is now?
posted by 31 Jul 2015Hi Rob. disk_sync() is for flushing any driver-level caches, which SDFileSystem doesn't have. Instead, I'm making sure the card is finished any internal processing by selecting and deselecting it. My official test program is here: https://developer.mbed.org/users/neilt6/code/SDFileSystem_HelloWorld/
posted by 31 Jul 2015