fsync 的手册页说:
If the underlying hard disk has write caching enabled, then the data may not really be on permanent storage when fsync() / fdatasync() return.
有什么方法可以确保数据物理写入磁盘吗?
最佳答案
不,没有。
使用fsync
,您可以告诉操作系统将其写入磁盘,就操作系统而言,它已被写入磁盘。
如果磁盘伪造了这一点,那么不幸的是,您无法真正更改它。 使用适当的磁盘系统(即 BBU raid 设置),您可以简单地启用/禁用写入缓存来避免这种情况。
请注意,如果您指定 O_DIRECT
和 O_SYNC
标志,它应该将其写入磁盘:http://www.kernel.org/doc/man-pages/online/pages/man2/open.2.html
关于c++ - 确保 fsync 完成其工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11612165/