在 Solaris 上进行同步磁盘刷新的最佳方法是什么?我想刷新所有磁盘,而不是单个文件。
Solaris(与 Linux 相对)上的 Sync() 异步工作,我正在寻找 SYNCHRONOUS sync() (完成后返回)
随之而来的问题:如何检查同步是否正确完成?我怎样才能写测试表明它已经完成?
谢谢!
你可以运行:
/usr/sbin/lockfs -af
引用lockfs 手册页:
-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.
如果你想纯粹用 C 来做,你可以使用
#include <sys/filio.h>
...
ioctl(fd, _FIOFFS, NULL);
fd 是文件系统挂载点的文件描述符(来自 /etc/mtab)。
请注意,_FIOFFS 是一个私有接口,因此可能随时消失,恕不另行通知。一种完全受支持且更强大的方法是简单地将行添加system("/usr/sbin/lockfs -af");
到您的代码中。