Monday, February 1, 2016

renaming (existing) hardlinks

Lets say,  We have two files testfile123 and testfile456
#touch testfile123
#touch testfile456

#unalias mv
#mv testfile123 testfile456

strace shows this:
access("testfile456", W_OK)             = 0
rename("testfile123", "testfile456")    = 0
Lets say, we have two hard links

#touch testfile
#ln testfile testfile_hlink1
#ln testfile testfile_hlink2

#mv testfile_hlink1 testfile_hlink2

access("test_hlink1", W_OK)             = 0
unlink("test_hlink2")                   = 0
So, in case of hardlink, rename system call itself is not called at all (as it is the same file and moving contents from one hardlink to another does not make sense).

man 2 rename :
       If  oldpath  and  newpath are existing hard links referring to the same
       file, then rename() does nothing, and returns a success status.

Thanks to Aravinda  for pointing me this.

No comments:

Post a Comment