Can inode and crtime be used as a unique file identifier?

后端 未结 3 1988
后悔当初
后悔当初 2020-12-31 06:43

I have a file indexing database on Linux. Currently I use file path as an identifier. But if a file is moved/renamed, its path is changed and I cannot match

3条回答
  •  甜味超标
    2020-12-31 07:14

    • {device_nr,inode_nr} are a unique identifier for an inode within a system
    • moving a file to a different directory does not change its inode_nr
    • the linux inotify interface enables you to monitor changes to inodes (either files or directories)

    Extra notes:

    • moving files across filesystems is handled differently. (it is infact copy+delete)
    • networked filesystems (or a mounted NTFS) can not always guarantee the stability of inodenumbers
    • Microsoft is not a unix vendor, its documentation does not cover Unix or its filesystems, and should be ignored (except for NTFS's internals)

    Extra text: the old Unix adagium "everything is a file" should in fact be: "everything is an inode". The inode carries all the metainformation about a file (or directory, or a special file) except the name. The filename is in fact only a directory entry that happens to link to the particular inode. Moving a file implies: creating a new link to the same inode, end deleting the old directory entry that linked to it. The inode metatata can be obtained by the stat() and fstat() ,and lstat() system calls.

提交回复
热议问题