同步没有文件的文件系统

时间:2013-06-11 15:50:40

标签: linux filesystems sync

假设我想在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的文件怎么办?我可以“滥用”点文件吗?它是否出现在所有文件系统上?

还有其他功能可以满足我的需求吗?也许通过提供具有主要/次要编号或某些此类设备的设备文件?

2 个答案:

答案 0 :(得分:2)

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

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

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

答案 1 :(得分: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,超级块等)。如果您没有任何修改,则无法进行任何同步。

相关问题