Tcl Source Code

View Ticket
Login
Ticket UUID: c8d4f01a54d7ecf819f4881fb02467ad14fc7b0c
Title: Windows: NTFS symbolic links are not supported by [file]
Type: Bug Created on: 2015-09-04 14:28:36
Submitter: anonymous Assigned to: jan.nijtmans
Subsystem: 37. File System Severity: Minor
Priority: 5 Medium Last modified: 2026-11-27 15:23:03
Status: Pending Closed by: nobody
Resolution: Fixed Closed on:
Version: 8.6.18, 9.0.5, 9.1.0
Description:
Tcl supports NTFS junctions, but not NTFS symbolic links.
[file link], [file readlink] etc. all fail with messages about not a directory.
User Comments:
dkf added on 2015-09-08 08:56:43:

Strictly, it's new functionality, but it would be nice to have.


apnadkarni added on 2016-02-25 07:47:40:
Some comments for future reference.

As of 8.6.5, file link translates to NTFS junctions for directories and hard links for files. If support for symbolic links is added, will need to decide if the [file link -symbolic] for dirs which currently uses junctions will be changed to use symbolic links instead and any backward compatibility issues that may arise.

Also, symbolic links are not supported on XP.

kjnash added on 2019-03-11 21:07:22:
Yes, it would be nice to have.

Even if the existing behaviour of [file link -symbolic $F1 $F2] for creating a link is preserved until the next major revision, it would be very useful if [file link $F1], [file isdirectory $F1], [file stat $F1] etc returned valid results for Windows symlinks created outside Tcl.

juliannoble2 added on 2024-09-22 05:31:05:
I think (just a feeling - no real evidence) these types of links - which behave more like unix symlinks are becoming more important/used.
I'm not sure of the platform differences though.

Can we add it to the list of known bugs so that it eventually gets some love?

apnadkarni added on 2025-12-28 17:57:13:

On the radar, but will trigger some subtle compatibility differences with 9.0 behavior and some limitations w.r.t. usage (compared to Unix, and stemming from Windows itself)

Advantages

  • ReFS does not support junctions but does support symbolic links
  • relative paths permitted
  • cross-volume links permitted (afaik)
  • closer compatibility with POSIX links (relative paths being the most obvious)

Disadvantages

  • Requires either admin privileges or running in developer mode. This is the biggest drawback.
  • Different behaviour from 9.0 file link on Windows but possible this might be hand waved away.

serhiy.storchaka added on 2026-10-17 10:53:34:

Still present in 8.6.18, 9.0.5 and 9.1 on Windows 11: [file readlink] fails on every real symlink, and only junctions work:

% file readlink dirlink      ;# mklink /D dirlink target
could not read link "dirlink": invalid argument
% file readlink filelink     ;# mklink filelink a.txt, or [file link -symbolic filelink a.txt]
could not read link "filelink": not a directory

So a file link that Tcl itself has created with [file link -symbolic] since 8.6.11 ([548cd945d6]) cannot be read back.

Cause, in win/tclWinFile.c: WinReadLink() returns ENOTDIR for anything that is not a directory. For directories, WinReadLinkDirectory() does have a case for symlinks, but it tests IO_REPARSE_TAG_SYMBOLIC_LINK. The SDK and mingw-w64 headers do not define that name (theirs is IO_REPARSE_TAG_SYMLINK, 0xA000000C), so the fallback #define ... IO_REPARSE_TAG_RESERVED_ZERO makes it 0. The symlink tag never matches and the function ends in EINVAL. The same function is used by TclpObjNormalizePath(), so directory symlinks in the middle of a path are not resolved by [file normalize] either. A fix needs more than the constant: symlink reparse data uses SymbolicLinkReparseBuffer (it has an extra Flags field and can hold a relative target), not MountPointReparseBuffer, and the name should be read at SubstituteNameOffset.


serhiy.storchaka added on 2026-10-18 13:54:20:

Proposed fix in branch win-readlink-symlinks: [file readlink] now reads symbolic links to files and directories. Relative targets are returned as stored, like on Unix, and \??\UNC\server\share targets as \\server\share. [file normalize] resolves directory symlinks inside a path. Tests winFile-5.1 to 5.5 (all but 5.2 and 5.4 need the right to create symbolic links).

Only reading is changed: [file link -symbolic] still creates junctions for directories, so the compatibility question about creating links remains open.


jan.nijtmans added on 2026-11-27 15:23:03:

Merged to [91dee7634c|trunk]