Symbolic Links Redux

10/9/2006 7:52:10 AM

Symbolic Links Redux

There's been some confusion as to whether symbolic links are based on reparse points from my last post on symbolic links in Vista. Symbolic links are reparse points, too, not just junctions. Reparse points are an extension mechanism in NTFS for both files and directories, not just directories. They are also used by Windows for volume mount points and files archived by Remote Storage Server. Third-party applications can create their own reparse points to extend the file system, which is how the acquired Windows Services for Unix originally implemented symbolic links.

There's a definitive answer to this by using the "fsutil reparsepoint" command in Windows XP. This is a directory containing two symbolic links and a junction points:

c:\test>dir
Volume in drive C has no label.
Volume Serial Number is 1C59-71F8

Directory of c:\test

10/09/2006 07:32 AM <DIR> .
10/09/2006 07:32 AM <DIR> ..
10/03/2006 06:00 PM <DIR> dest
10/03/2006 05:52 PM <JUNCTION> junction [c:\test\dest]
10/09/2006 07:22 AM <SYMLINK> symlink.txt [test.txt]
10/03/2006 05:51 PM <SYMLINKD> symlinkd [dest]
10/03/2006 05:52 PM 0 test.txt
2 File(s) 0 bytes
5 Dir(s) 5,580,132,352 bytes free

This is the contents of a reparse point for a symbolic link to a directory.

c:\test>fsutil reparsepoint query symlinkd
Reparse Tag Value : 0xa000000c
Tag value: Microsoft
Tag value: Name Surrogate
Tag value: Symbolic Link

Reparse Data Length: 0x0000001c
Reparse Data:
0000: 08 00 08 00 00 00 08 00 01 00 00 00 64 00 65 00 ............d.e.
0010: 73 00 74 00 64 00 65 00 73 00 74 00 s.t.d.e.s.t.

This is the content for a junction.

c:\test>fsutil reparsepoint query junction
Reparse Tag Value : 0xa0000003
Tag value: Microsoft
Tag value: Name Surrogate
Tag value: Mount Point
Substitue Name offset: 0
Substitue Name length: 32
Print Name offset: 34
Print Name Length: 24
Substitute Name: \??\c:\test\dest
Print Name: c:\test\dest

Reparse Data Length: 0x00000044
Reparse Data:
0000: 00 00 20 00 22 00 18 00 5c 00 3f 00 3f 00 5c 00 .. ."...\.?.?.\.
0010: 63 00 3a 00 5c 00 74 00 65 00 73 00 74 00 5c 00 c.:.\.t.e.s.t.\.
0020: 64 00 65 00 73 00 74 00 00 00 63 00 3a 00 5c 00 d.e.s.t...c.:.\.
0030: 74 00 65 00 73 00 74 00 5c 00 64 00 65 00 73 00 t.e.s.t.\.d.e.s.
0040: 74 00 00 00 t...

This is the content for a file symbol link.

c:\test>fsutil reparsepoint query symlink.txt
Reparse Tag Value : 0xa000000c
Tag value: Microsoft
Tag value: Name Surrogate
Tag value: Symbolic Link

Reparse Data Length: 0x0000002c
Reparse Data:
0000: 10 00 10 00 00 00 10 00 01 00 00 00 74 00 65 00 ............t.e.
0010: 73 00 74 00 2e 00 74 00 78 00 74 00 74 00 65 00 s.t...t.x.t.t.e.
0020: 73 00 74 00 2e 00 74 00 78 00 74 00 s.t...t.x.t.

I have also noticed the misuse of the words "hard link" on other blog posts. This is from the Microsoft site.

A hard link is a directory entry for a file. Every file can be considered to have at least one hard link. On NTFS volumes, each file can have multiple hard links, and thus a single file can appear in many directories (or even in the same directory with different names). Because all of the links reference the same file, programs can open any of the links and modify the file. A file is deleted from the file system only after all links to it have been deleted. After you create a hard link, programs can use it like any other file name.

A hard link is identical to the same concept in UNIX and refers only to files. It's not technically impossible to have hard directory links; NTFS just wasn't designed that way. A hard link is a peer of the original file; the original file could also be seen as a hard link to the new file.

One last point, I used linkd.exe from the Windows Resource Kit; junction.exe appears to have limitations constructing junctions on other drives.

Comments

 

Navigation

Categories

About

Net Undocumented is a blog about the internals of .NET including Xamarin implementations. Other topics include managed and web languages (C#, C++, Javascript), computer science theory, software engineering and software entrepreneurship.

Social Media