What is the best way to do synchronous disk flush on Solaris? I want to flush all disk, not a single file.
Sync() on Solaris (opposite to Linux) works ASYNCHRONOUSLY, I'm looking for SYNCHRONOUS sync() (it returns when it's done)
Consequent question: how to check sync is done properly? How can I write test showing it's done?
Thanks!
You can run:
/usr/sbin/lockfs -af
Quoting lockfs manual page:
-f
Force a synchronous flush of all data that is dirty at the time fsflush is run to its backing store for the named file system (or for all file systems.) It is a more reliable method than using sync(1M) because it does not return until all possible data has been pushed.
If you want to do it purely in C, you might use
#include <sys/filio.h>
...
ioctl(fd, _FIOFFS, NULL);
with fd being a file descriptor to the file system mount point (from /etc/mtab).
Beware though that _FIOFFS is a private interface so might disappear at any time without notice. A fully supported and more robust way would be to simply add the line system("/usr/sbin/lockfs -af"); to your code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With