SdFat: flush() or sync()?

I have seen both being used to ensure data is physically written onto the SD card. Is there a practical difference between the two?

The SdFat literature says

flush(): “Ensure that any bytes written to the file are saved to the SD card.”

sync(): “causes all modified data and directory fields to be written to the storage device.”

As you can see from your own quotes , yes there is a difference!


Thanks for pointing that out.

To hone my question: is either of these better for ensuring that data is physically written on the SD card, in terms of speed of execution and/or the way the file is left on the card.

As an example, I often need to eject the SD card without being able to formally close the file via the code. When I use regular flush() the file is physically written and accessible up to the last flush action.

If you look at what is affected, according to the descriptions, there are significant differences. flush() affects ONE file. sync() affects all files and directories.

Thanks PaulS, this makes more sense now.