Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Detecting whether two pathes refer to the same file

by ambrus (Abbot)
on Sep 10, 2010 at 09:37 UTC ( [id://859613]=note: print w/replies, xml ) Need Help??


in reply to Detecting whether two pathes refer to the same file

The inode number alone is not enough, you also have to compare the device number from stat, because the inode numbers are unique only within each filesystem.

The dev-inode pair usually identifies the file uniquely, but of course there are some caveats.

  • Perls are normally compiled with 64-bit file access, and you might need that for this trick too, because it makes inode numbers wider.
  • Device numbers might not be constant over a reboot. (They often are, but not always.)
  • Under linux, if you see a file through a bind mount, it gets the same device-inode pair as the file on the original mount, so it's possible to have two file names that refer to the same underlying file but one of them is read-only.
  • Probably more stuff I don't know about.
  • Comment on Re: Detecting whether two pathes refer to the same file

Replies are listed 'Best First'.
Re^2: Detecting whether two pathes refer to the same file
by rovf (Priest) on Sep 10, 2010 at 09:50 UTC
    Thank you for the quick reply!
    Perls are normally compiled with 64-bit file access, and you might need that for this trick too, because it makes inode numbers wider.
    In what way could this affect me? I just have to compare the inode numbers (and device numbers, as you pointed out), as they are returned from stat,isn't it?
    Device numbers might not be constant over a reboot.
    As I apply the call to stat to both variables in succession, there is no possibility to be interrupted by a reboot.

    -- 
    Ronald Fischer <ynnor@mm.st>
      In what way could this affect me? I just have to compare the inode numbers (and device numbers, as you pointed out), as they are returned from stat,isn't it?

      If your perl doesn't support 64 bits inodes, stat will fail in weird ways; in the worst case, it could return erroneous inodes and wrongly state different files as the same.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://859613]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2024-04-19 08:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found