0

What i mean to "uniqueness" here also concerns about the time.

  • Every time a file created on file system, there's a unique file.
  • Files in same directory with same name but appears in different time stage are different.
  • Definition to "unique" has nothing to do with file content.

Firstly, i use inode to identify a file, files with different inode are different, a file alway have a fixed inode within it's lifecycle even it's been moved and touched.

BUT, the inode may be reused by the OS. If file A.txt has inode 22345, if i delete A.txt and create B.txt, B.txt MAY have in ode 22345.

What if there's creation-time for files? So that I can use inode+creation-time to identify a file in the file system's history. But linux didn't offer that.

I also try inode+file_md5, but what if A.txt and B.txt have same con ten?

So, do you have any ideas?

=========== edit ===========

My scenario is a kind of log file collecting. In a logging directory, log files maybe created, moved and deleted. We use mapping from file offset to timestamp to do some "check point" like work. So how to defile the "file" mentioned just now?

4

1 回答 1

4

通常除了 inode 编号之外,还比较设备编号,因为两个不同文件系统上的两个文件可能具有相同的 inode 编号。

无论如何,比较 inode/dev 编号是回答“这两个文件描述符是否引用同一个文件?”问题的一种方法。请注意问题中使用“文件描述符”而不是“路径”,如果在其中的 stat()' 之后和比较 inode/dev 编号之前随后删除了路径,则可以避免竞争。正如您自己指出的那样,只有当它们具有活动引用(路径和/或它们被某个进程打开)时,inode 编号才能保证是唯一的。

在您的情况下,我想一种解决方案是跟踪您感兴趣的文件的 inode/dev 编号,如果文件被删除,则从列表中删除。虽然我不确定你真正想要完成什么。

于 2012-11-01T07:30:51.307 回答