- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
fsync 和 syncfs 有什么区别?
int syncfs(int fd);
int fsync(int fd);
fync 的联机帮助页说明如下:
fsync() transfers ("flushes") all modified in-core data of (i.e., modified buffer cache pages for) the file referred to by the file descriptor fd to the disk device (or other permanent stor‐ age device) so that all changed information can be retrieved even after the system crashed or was rebooted. This includes writing through or flushing a disk cache if present. The call blocks until the device reports that the transfer has completed. It also flushes metadata information associated with the file (see stat(2)).
syncfs 的联机帮助页说明如下:
sync() causes all buffered modifications to file metadata and data to be written to the underly‐ ing filesystems.
syncfs() is like sync(), but synchronizes just the filesystem containing file referred to by the open file descriptor fd.
对我来说两者似乎是平等的。它们正在同步文件描述符引用的文件和关联的元数据。
最佳答案
首先,fsync()
(和 sync()
)是 POSIX 标准函数,而 syncfs()
仅限 Linux。
所以可用性是一个很大的区别。
来自POSIX standard for fsync()
:
The
fsync()
function shall request that all data for the open file descriptor named byfildes
is to be transferred to the storage device associated with the file described byfildes
. The nature of the transfer is implementation-defined. Thefsync()
function shall not return until the system has completed that action or until an error is detected.
请注意,这只是一个请求。
来自 the POSIX standard for sync()
:
The
sync()
function shall cause all information in memory that updates file systems to be scheduled for writing out to all file systems.The writing, although scheduled, is not necessarily complete upon return from
sync()
.
同样,这也不是一定会发生的事情。
The Linux man page for syncfs()
(and sync()
) states
sync()
causes all pending modifications to filesystem metadata and cached file data to be written to the underlying filesystems.
syncfs()
is likesync()
, but synchronizes just the filesystem containing file referred to by the open file descriptorfd
.
请注意,函数返回的时间是未指定的。
The Linux man page for fsync()
states :
fsync()
transfers ("flushes") all modified in-core data of (i.e., modified buffer cache pages for) the file referred to by the file descriptorfd
to the disk device (or other permanent storage device) so that all changed information can be retrieved even if the system crashes or is rebooted. This includes writing through or flushing a disk cache if present. The call blocks until the device reports that the transfer has completed.As well as flushing the file data,
fsync()
also flushes the metadata information associated with the file (see inode(7)).Calling
fsync()
does not necessarily ensure that the entry in the directory containing the file has also reached disk. For that an explicitfsync()
on a file descriptor for the directory is also needed.
请注意,Linux 为 fsync()
提供的保证比为 sync()
或 syncfs()
提供的保证强得多,并且通过 POSIX 为 fsync()
和 sync()
。
总结:
fsync()
:“请将此文件的数据写入磁盘”sync()
:“将所有数据写到磁盘上”sync()
:“将所有数据写入磁盘(当你有空时?)”syncfs()
:“将与此文件相关联的文件系统的所有数据写入磁盘(当您有空时?)”fsync()
:“将此文件的所有数据和元数据写入磁盘,完成后才返回”请注意,Linux 手册页未指定 sync()
和 syncfs()
何时返回。
关于c - fsync 和 syncfs 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48171855/
新的 syncfs 系统调用是否在返回之前等待光盘写入完成,就像 fsync 的情况一样?此外,如果在修改文件后,是否为此文件描述符调用 syncfs 也会更新包含的目录条目? 最佳答案 syncfs
在我的嵌入式系统上,我想确保在关闭文件时数据已安全写入 - 如果系统报告数据已保存,用户应该能够立即切断电源。 我知道执行此操作的正确方法是在目录 (参见 this blog entry )。但是,在
fsync 和 syncfs 有什么区别? int syncfs(int fd); int fsync(int fd); fync 的联机帮助页说明如下: fsync() transfers ("fl
是否有导出 syncfs 的包在 Go 中运行?我想同步特定的文件系统。 我找到了 syscall包,但它仅导出 FSync、Fdatasync 和 Sync。 最佳答案 syncfs只是一个系统调用
根据 sync 手册页,不能保证调用 sync 后光盘会刷新其缓存:“根据标准规范(例如 POSIX.1-2001),sync() 会安排写入,但可能会在实际写入完成之前返回。但是,由于版本 1.3.
FUSE API不公开文件系统级别的 sync 调用,只是 fsync和 fsyncdir。这是否意味着当 sync 被调用时(或 FUSE 挂载点内的 syncfs),内核对所有 FUSE 挂载的所
我是一名优秀的程序员,十分优秀!