Why don't hard link destinations on Windows Server 2003 immediately show the proper file size and last modified time?

1

1

I wanted to create hardlinks to files on Windows Server 2003 and I stumbled upon the superuser question hardlinks on ntfs with windows. I tried mklink as one of the answers suggested and found that mklink isn't a standalone program but rather part of the cmd.exe command shell but was not implemented until later versions of the operating system.

I then tried the fsutil hardlink command and created the hard link as follows:

fsutil hardlink create c:\testfile.txt c:\temp\testfile.txt

which created the hardlink c:\testfile.txt pointing to c:\temp\testfile.txt.

When I edit c:\testfile.txt I notice that the file size and last modified time of c:\temp\testfile.txt would not immediately match; it would take a few minutes until it matched. Why would this be?

Also I noticed that when I do a "dir" or look at the link in Explorer that there is no indication it is a hard link. How do you subsequently know?

Secondarily: Before trying fsutil I tried linkd.exe which is part of the Windows Server 2003 resource kit. It appeared to create the link just fine but I would receive "Access Denied" whenever trying to edit the link. Any ideas why?

Howiecamp

Posted 2013-03-04T21:31:08.823

Reputation: 1 438

Answers

2

I can only answer the second of your questions at the moment.

A hard link looks to the OS as though it were the original file. That is intentional, if you delete a hard link for example, it deletes the original file as well. That is by design. So there is no easy way of detecting that it is a link at least visually in Windows Explorer.

UPDATE: Many thanks to @Vedran for correcting me & giving a much better explanation of hardlinks on NTFS. Also for reminding me that I shouldn't assume that what used to be true may not still be true.

"they are all the original. Different filenames pointing to the same bits of data. When there is noone pointing at that data anymore, only then it can be considered as free space."

Under newer versions of Windows at least, hard links are clearly indicated in Windows Explorer as links.

As an aside, the excellent LinkShell Extension is very helpful for creating different type of link and junction from Windows Explorer.

Julian Knight

Posted 2013-03-04T21:31:08.823

Reputation: 13 389

You make an interesting point. It just occurred to me that while of course the file system knows that a hardlink exists (fsutil hardlink list will show them), Explorer probably needs a shell extension which would indicate this. I'm still surprised that the existence of the hard link isn't shown by default since even though the link looks like it's the original file, there's still a "connection" between that file and the destination one. – Howiecamp – 2013-03-04T22:24:18.733

Hard links are dangerous! Use softlinks if possible as they are more obvious. Of course, they don't work everywhere. For an extension to help with links, try LinkShellExtension. I use it all the time. – Julian Knight – 2013-03-04T22:33:23.373

@Howiecamp every hardlink is the original file, all of them just happen to point to the same blocks of data. – Vedran – 2014-01-15T14:16:04.607

Only if you delete all hardlinks the data will be deleted. – Vedran – 2014-01-15T14:17:38.277

@Vedran: Really? I rarely use them myself but I seem to remember that last time I tried, deleting one deletes them all. How can you tell which is the original without digging through the technical details of the filing system? I must do some testing - or maybe life is just too short! – Julian Knight – 2014-01-17T15:50:19.087

@Julian Knight no, they are all the original. Different filenames pointing to the same bits of data. When there is noone pointing at that data anymore, only then it can be considered as free space. – Vedran – 2014-01-22T13:24:16.967

Well, just goes to show that some things get badly mixed up in this old head. I've just tried it and you are, of course, absolutely correct. I'll correct my answer. – Julian Knight – 2014-01-24T12:14:42.153