0

假设我想将文件系统的数据缓冲区同步到 linux 机器上的磁盘(在我的情况下是 USB 记忆棒分区)。

在搜索要执行此操作的功能时,我发现了以下内容

描述

  sync()  causes  all buffered modifications to file metadata and 
          data to be written to the underlying file sys‐
          tems.

  syncfs(int fd) is like sync(), but synchronizes just the file system 
                 containing file referred to by  the  open  file
                 descriptor fd.

但是如果文件系统上没有我可以打开和传递的文件syncfs怎么办?我可以“滥用”点文件吗?它是否出现在所有文件系统上?

是否有另一个功能可以满足我的要求?也许通过提供带有主要/次要编号或类似的设备文件?

4

2 回答 2

2

是的,我认为你可以做到这一点。文件系统的根目录将至少有一个用于根目录的 inode。您可以使用 .-file 来执行此操作。也可以使用 ls -i 查看 inode 编号。

是否有可能通过同步安装文件系统来避免您的问题?性能问题会阻碍吗?你看过重装吗?在特定情况下,这也可以同步您的文件系统。

我不知道您的应用程序是什么,但我遇到了将文件同步到具有 FAT32 文件系统的 USB 记忆棒的问题。它导致了奇怪的读写错误。我无法想象您应该同步一个空文件系统的任何其他正当理由。

于 2013-06-11T16:54:27.347 回答
0

来自 man 8 同步描述:

   "sync  writes  any  data  buffered  in  memory  out to disk.  This can include (but is not
   limited to) modified superblocks, modified inodes, and delayed reads and writes.  This 
   must be implemented by the kernel; The  sync program does nothing but exercise the sync(2)
   system call."

所以,请注意,这都是关于修改(修改的 inode、超级块等)。如果您没有任何修改,则它没有任何要同步的内容。

于 2013-06-11T16:12:31.080 回答