More on Vista Reparse Points
Vista upgrades NTFS to include some shiny new features, one is Transactional NTFS or "TxF". That means there's a Resource Manager for NTFS so you can batch up a whole transaction worth of file writes and if any of them go wrong - rollback. I'm having a little trouble with Transactional NTFS right now because the resource manager is shutting down because I need to run chkdsk /f on my drive and I can't, but that's a story for another day.
Philip left a comment in my recent post on improvements in junctions/reparse points/symbolic links in Vista. He said "Have you tried using the new Vista symbolic directory link support available in the command line program "mklink /d". I have successfully used it cross-drive for other directories,though I haven't tested it in your scenario."
Soinks! That's what I get for not keeping up with Junfeng Zhang's excellent blog.
Postulate: Symlink is to Junction in Windows as Symlink is to Hardlink in Unix.
Symlinks can span volumes (wicked useful) and you can also Symlink to UNC paths. Woof. Notice the Command Prompt Screenshot at Right. In this example "My Documents" is a Symlink to another drive, while Junction points locally.
I am still a little unclear about the difference. As I understand it, junctions are "reparse points" and support links to local files and directories while symlinks are built into the NTFS file system at the Kernel level and support spanning drives. Perhaps Mark Russinovich will jump in here and explain.
Here's my DOS prompt removing my non-working junction and using the new MKLINK to get My Documents onto another drive.
C:\Users\Scott>mklink
Creates a symbolic link.
MKLINK [[/D] | [/H] | [/J]] Link Target
/D Creates a directory symbolic link. Default is a file
symbolic link.
/H Creates a hard link instead of a symbolic link.
/J Creates a Directory Junction.
Link specifies the new symbolic link name.
Target specifies the path (relative or absolute) that the new link
refers to.
C:\Users\Scott>junction "My Documents"
Junction v1.04 - Windows junction creator and reparse point viewer
Copyright (C) 2000-2005 Mark Russinovich
Systems Internals - http://www.sysinternals.com
C:\Users\Scott\My Documents: JUNCTION
Substitute Name: D:\Scott\My Documents
C:\Users\Scott>mklink /d "My Documents" "d:\Scott\My Documents"
Cannot create a file when that file already exists.
C:\Users\Scott
>junction /d "My Documents"
Junction v1.04 - Windows junction creator and reparse point viewer
Copyright (C) 2000-2005 Mark Russinovich
Systems Internals - http://www.sysinternals.com
Deleted My Documents.
C:\Users\Scott>mklink /d "My Documents" "d:\Scott\My Documents"
symbolic link created for My Documents <<===>> d:\Scott\My Documents
C:\Users\Scott>junction "My Documents"
Junction v1.04 - Windows junction creator and reparse point viewer
Copyright (C) 2000-2005 Mark Russinovich
Systems Internals - http://www.sysinternals.com
C:\Users\Scott\My Documents: UNKNOWN MICROSOFT REPARSE POINT
C:\Users\Scott>dir "My Documents"
Volume in drive C is 70 GIGS - SYSTEM
Volume Serial Number is 88F3-D225
Directory of C:\Users\Scott\My Documents
10/02/2006 09:42 PM <DIR> .
10/02/2006 09:42 PM <DIR> ..
04/23/2005 07:02 PM 37,758 0764576100.01._SCLZZZZZZZ_.jpg
...lots of files here...
...snip...I was able to CD over to another drive transparently...
Turns out I was (half) wrong when I said that Explorer doesn't know about Junctions. It knows enough about Junctions to show the shortcut icon, but that's about it. However, Explorer DOES know enough about Symlinks to show the Target (pointed to) directory in the Properties dialog. Nice.
In Vista, all kinds of things have been moved, and are now using Junctions to point to the new locations:
Was | Now |
---|---|
Application Data | AppData\Roaming |
Cookies | \AppData\Roaming\Microsoft\Windows\Cookies |
Local Settings | \AppData\Local |
My Documents | \Documents |
NetHood | \AppData\Roaming\Microsoft\Windows\Network Shortcuts |
PrintHood | \AppData\Roaming\Microsoft\Windows\Printer Shortcuts |
Recent | \AppData\Roaming\Microsoft\Windows\Recent |
SendTo | \AppData\Roaming\Microsoft\Windows\SendTo |
Start Menu | \AppData\Roaming\Microsoft\Windows\Start Menu |
Templates | \AppData\Roaming\Microsoft\Windows\Templates |
Interesting stuff, I say.
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
About Newsletter
Based on reading, operations on the junction transparently treat it as the target directory itself. This has several implications.
So deleting a junction will affect the target directory.
But deleting a symbolic link just deletes the link itself.
(However, this is not always true, it depends on the utility awareness)
The access controls on UNIX symbolic link itself is ignored; only the target is relevant.
But those on both the source and target of a junction are important.
The size reported by a symbolic link is actually the same as the number of characters in the path to which it points to, as if the symbolic link is a file with the name of the destination path stored in it.
IMHO, it's in this interopability where the real power lies with TxF. Also, keep in mind that transactions in TxF have full ACID semantics as well...
I am guessing that the tool you use "junction.exe" doesn't cross volumes.
However, if you use linkd.exe, you can create a junction to a different drive.
Junctions are more like symbolic links, because they refer to a path that may not exist and could be in a different drive.
I've also found something quite baffling...
I have both of my "Music" & "Pictures" moved to my other hard disk having my older Pictures & Music. (I moved them via the Location tab of the property dialog of these "Special" folders reached via right clicking them in the Start Menu.)
I cannot understand why under Explorer the original/older folders appear to have the Vista name & icon of "Music" & "Pictures" when in fact they are still iMAGES & MUSiK when I list them using the DIR command. I've scratched my head for too long thinking maybe it's some undocumented MKLINK magic. But here's where it get's even more strange. I still see a "Pictures" & a "Music" in my user folder (which point to my older folders by the way, as expected) but they JUST DON'T SHOW UP in a DIR listing!!! I tried everything like the /ADHSL switch but "Pictures" and "Music" are nowhere to be found.
I hope you can shed some light on it. I know there is no such thing as a virtual folder (set apart junctions or symlinks) in Vista. This feature; if that's the way it was supposed to behave (as in the minds of the Vista team during the Longhorn days) it was supposedly cut from Vista. Then what do these 2 folders qualify as? :) (Reminds me of the silly sentence ending with a preposition joke!)
Comments are closed.
There are a couple new links that mklink supports, that are designed to behave similarly to UNIX:
Hard Links -- works only on files (direct link - reference count scheme) in same volume
Symbolic Links - works on both files and directories (link by name - can be broken) across volumes
Postulate should be:
Symbolic link in NTFS is same as symbolic link in UNIX.
Hard link in NTFS is same as hard link in UNIX.
Junction is similar to symbol links for directories only.
Symbolic links are the only links that work on both files and directories.
Symlinks and hardlinks have the same POSIX semantics as in UNIX. Junctions behave like classical NTFS using reparse points. (Symbolic links might also be based on reparse points)
Note: MKLINK supports options to create all three types of links