Boost logo

Boost :

From: David Sirovsky (david.sirovsky_at_[hidden])
Date: 2008-03-05 05:33:56


Hello All,

As far as I understand Boost.Filesystem assumes that there is no symbolic
link support in Windows (is_symlink() always returns false, it is
impossible to create, etc.), but only hardlinks (using the CreateHardLink
API call).

As you probably know, symlinks have been introduced in Vista (NTFS only):
the API now includes CreateSymbolicLink and a user is able to create
symlinks using mklink and see them using dir. [
http://en.wikipedia.org/wiki/NTFS_symbolic_link]<http://en.wikipedia.org/wiki/NTFS_symbolic_link>

However, creating fully functional symbolic links was quite possible already
in Windows 2000 on NTFS drives - using junction reparse points. [
http://en.wikipedia.org/wiki/NTFS_junction_point]<http://en.wikipedia.org/wiki/NTFS_junction_point>

A junction is created with 2 main API calls:

hFile = CreateFile( LinkDirectory, GENERIC_WRITE, 0,
  NULL, OPEN_EXISTING,
  FILE_FLAG_OPEN_REPARSE_POINT|FILE_FLAG_BACKUP_SEMANTICS, NULL );
. . .
DeviceIoControl( hFile, FSCTL_SET_REPARSE_POINT,
  reparseInfo,
  reparseInfo->ReparseDataLength + REPARSE_MOUNTPOINT_HEADER_SIZE,
  NULL, 0, &returnedLength, NULL )
. . .

A popular free SysInternals'
http://www.microsoft.com/technet/sysinternals/FileAndDisk/Junction.mspx tool
is usually used to create/list junctions in Win2000, XP, Vista. Its
source-code can be found here:
http://web.archive.org/web/20060106050745/www.sysinternals.com/Utilities/Junction.html
[At the Web-Archive, as the source-code has not yet been officially
re-released by Microsoft since SysInternals migration to Technet]

(There is also another pre-Vista tool - the Microsoft's
fsutil)<http://technet2.microsoft.com/windowsserver/en/library/14cb706b-2a38-48e0-a569-a7fa9ca3b3401033.mspx?mfr=true>

As far as I understand, junctions behave similar to symbolic links - they
point to specific "real" locations not only on the same drive, they can be
deleted without deleting the target, they still point to already deleted
file/directory, etc.

They are even in formal use in Windows Vista: for example, "Documents and
Settings" is no longer a directory but a junction pointing to some newly
introduced user folder; junctions are supported in the mklink tool and are
shown using dir.

Maybe it is worth considering to introduce Windows NTFS symlinks support in
Boost.FileSystem - a straightforward approach would be to use new symbolic
link API for Vista target build and junctions for 2000 and XP.

[I am sorry if this subject has already been discussed - I have not found
any posts on it]

Best Regards,

David Sirovsky.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk