Hard Links Aren’t The Same As Shortcuts

I was recently pointed to this interesting article/blog on TechRepublic, which talks about the WinSxS folder in Windows Vista.

Mr. Detwiler quotes Joseph Conway, Senior Support Escalation Engineer at Microsoft, as saying that other files in the system are hard links to files in the WinSxS folder, and Michael Beck, a Microsoft program manager, as saying that the files in the WinSxS folder are hard links to files elsewhere in the system.  Bill then adds: “Luckily, this dichotomy has no impact on our efforts to reduce the size of the WinSxS folder.”

In fact, there is no dichotomy: the two statements are just different ways of saying the same thing, because hard links are symmetric – when you create a hard link, what you are really doing you are creating a second directory entry for an existing file.  This directory entry is otherwise perfectly normal, and there is no difference between it and the original one.  In fact, there isn’t even any way to tell for sure which one (if either) is the original!

As a concrete if contrived example, suppose we wanted to create a single file but put it in two folders, c:\fred and c:\joe.  We could create the file in c:\fred and then put a hard link in c:\joe; we could create the file in c:\joe and put a hard link in c:\fred; or we could create the file in c:\alice, put hard links in both c:\fred and c:\joe, and then delete the original link from c:\alice.  (Note that when you “delete” a file with more than one directory entry, only the directory entry is removed.)

The key point here is that it doesn’t make any difference which of these options we choose, as the end result is exactly the same.  So whether we then say “the file in c:\fred is a hard link to the file in c:\joe” or “the file in c:\joe is a hard link to the file in c:\fred” is entirely a matter of taste, as both statements are equally valid.  Strictly speaking, all either statement means is that c:\fred\myfile and c:\joe\alsomyfile are two different names for the same file.

Incidentally, this is also true of hard links in Unix file systems.  In either case, hard links should not be confused with symbolic links (reparse points in NTFS) or with Windows Explorer shortcuts, both of which are quite distinct from their targets.

Advertisements

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: