0

I'm looking for a way to get a file's inode on Linux and a file identity on Windows, or any other unique file identity as cross-platform as possible and more efficient than hashing file contents. Platforms are Linux,Windows,Mac.

The purpose of this is to be able track files as efficiently as possible so the program can locate them after the user has renamed or moved them. If I have a file path + file ID and the file is not at the path, I need a way to find the new file path on all mounted volumes (or fail if it has been deleted). Hashing all files is prohibitively expensive and creates a whole bunch of new error possibilities since files are going to be updated and renamed regularly.

I'm hoping there is an existing library but haven't found anything cross-platform yet. If there is none, I'd be very grateful for help on how to use syscalls in x/sys, and to hear about any limitations inodes and file identities have.

  • 1
    "and more efficient than hashing file contents" There isn't such a thing. You can stop looking. – Volker Jan 12 '23 at 11:55
  • Are you sure? On Linux, inodes can be used that way and I've found posts for a similar API on Windows (NTFS). The problem is that there is no recent cross-platform library. But maybe you mean that there are too many edge cases to consider and it's not worth it ("been there, done it")? https://stackoverflow.com/questions/1866454/unique-file-identifier-in-windows – Eric '3ToedSloth' Jan 12 '23 at 12:05
  • 2
    Either you did not properly state your problem or inodes are of no help: If you mount two filesystems then two files might have the same inode (number) and if you copy a file from one to the other filesystem it will change its inode. (No, I have not "been here" as I do not enter fantasy land). But maybe you problem is actually narrower than you stated in the question in which case inodes might work. – Volker Jan 12 '23 at 13:00
  • Thanks, that reply was helpful. I stated my problem clearly and have nothing to change or add to it. Given what you say, inodes seem to be only part of the solution I'm looking for. "of no help" seems a bit exaggerated, though, as it is possible identify mounted filesystems. So filesystem + inode seems to be the way to go for Linux. Still looking for something more cross-platform, but perhaps I'll write a library myself. fsnotify also seems to use inodes and Windows file identities, I'll check how it works in the source code. Thanks! – Eric '3ToedSloth' Jan 12 '23 at 15:12

0 Answers0