Hello asfj,
NTFS 5.0 supports what they call junctions, which are similar to
symbolic links, on an NTFS filesystem. They also allow hard links,
which are essentially the same as hard links in Unix.
A hard link creates a new directory entry for an existing file. The
hard link must reference a file on the same volume as itself.
Junctions, or soft links, are used to link to a directory rather than
a file. Junctions can reference a directory on a different volume on
the same computer, but not a directory located on a shared volume from
another computer. (See reference 1.)
While this functionality isn't very well-documented or accessible,
there is an example of this in the Computer Management MMC snap-in
(found under Administrative Tools on WinXP) under Disk Management.
You can map a volume to a directory within an existing file structure,
rather than giving it its own volume drive letter. This creates a
junction from the directory to the root of that volume.
Unfortunately, since junctions work only with directories, this may
not be the full functionality you're looking for. Also, support for
junctions in Explorer is sketchy. Deleting junction points behaves
oddly, as well as attempting to delete folders within a directory
accessed through a junction point. (See reference 2, scroll to
"Observed Effects".)
If you still want to use junctions, you have to use an undocumented
feature of the API. Fortunately, Mike Nordell at The Code Project had
the decency to not only figure out how to use the undocumented API
access to junction points, but explain his solution and how he came to
find it. (See reference 3.) You can skip straight to his solution,
implemented in VC6 on Win2000, at the following URL, but his
description of what he had to go through to figure this out is worth
reading. (I'll leave it to you to browse there for the code, rather
than pasting it here, as it's fairly large and ugly.)
http://www.codeproject.com/w2k/junctionpoints.asp?df=100&forumid=75&exp=0&select=354644#The_Solution
If you want to link to individual files, you're restricted to using
hard links in NTFS. A hard link can be created using the
CreateHardLink function. MSDN documentation for the function can be
found at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/createhardlink.asp
An example usage, as seen there, looks like this:
fCreatedLink = CreateHardLink( pszNewLinkName,
pszExistingFileName,
NULL);
if (!fCreatedLink)
// handle error condition
The first two parameters of the function are fairly self-explanatory
in this example. The third parameter is "lpSecurityAttributes", which
is reserved and must be NULL when used.
I've also found some utilities for managing junctions, and have listed
URLs to them below. You might want to use these to experiment with
how well junctions work under Windows before spending time
implementing and using them in your own code.
I could not yet find any indication whether junctions are supported or
not under various Unix / Linux implementations of NTFS. They are a
part of the NTFS 5.0 specification, rather than a software-level
implementation like shortcuts, so a full support for the NTFS 5.0
filesystem should include them, but that's not exactly a guarantee
that such support is already available. If you need further research
done on this point, let me know via a clarification and I will look
into it further.
I hope this answers your question! Have a good day,
- josh_g
Search strategies used:
windows symbolic link
junctions windows
hard link junction unix
Software utilities for using junctions:
Junction Link Magic
http://www.rekenwonder.com/linkmagic.htm
Junction
http://www.sysinternals.com/ntw2k/source/misc.shtml#junction
Other References:
1. MSDN
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/file_and_directory_linking.asp
2. TheFreeDictionary encyclopedia: NTFS junction point
http://encyclopedia.thefreedictionary.com/NTFS%20Junction%20point
3. The Code Project - Windows 2000 Junction Points
http://www.codeproject.com/w2k/junctionpoints.asp?df=100&forumid=75&exp=0&select=354644
4. Symbolic Link On Windows
http://c2.com/cgi/wiki?SymbolicLinkOnWindows |