NTFS links are the
abstraction
Abstraction is a process where general rules and concepts are derived from the use and classifying of specific examples, literal (reality, real or Abstract and concrete, concrete) signifiers, first principles, or other methods.
"An abstraction" ...
used in the
NTFS
NT File System (NTFS) (commonly called ''New Technology File System'') is a proprietary journaling file system developed by Microsoft in the 1990s.
It was developed to overcome scalability, security and other limitations with File Allocation Tabl ...
file system—the default file system for all
Microsoft Windows
Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
versions belonging to the
Windows NT family
Windows NT is a proprietary graphical operating system produced by Microsoft as part of its Windows product line, the first version of which, Windows NT 3.1, was released on July 27, 1993. Originally made for the workstation, office, and ser ...
—to associate
pathname
A path (or filepath, file path, pathname, or similar) is a text string that uniquely specifies an item in a hierarchical file system. Generally, a path is composed of directory names, special directory specifiers and optionally a filename, sepa ...
s and certain kinds of
metadata
Metadata (or metainformation) is "data that provides information about other data", but not the content of the data itself, such as the text of a message or the image itself. There are many distinct types of metadata, including:
* Descriptive ...
, with entries in the NTFS
Master File Table (MFT). NTFS broadly adopts a pattern akin to typical
Unix file systems in the way it stores and references file data and metadata; the most significant difference is that in NTFS, the MFT "takes the place of"
inodes, fulfilling most of the functions which inodes fulfill in a typical Unix filesystem.
In NTFS, an entity in the filesystem fundamentally exists as: a record stored in the MFT of an NTFS volume, the MFT being the core
database
In computing, a database is an organized collection of data or a type of data store based on the use of a database management system (DBMS), the software that interacts with end users, applications, and the database itself to capture and a ...
of the NTFS filesystem; and, any attributes and
NTFS streams associated with said record. A link in NTFS is ''itself'' a record, stored in the MFT, which "points" to ''another'' MFT record: the ''target'' of the link. Links are the file "entries" in the volume's hierarchical
file tree: an NTFS
pathname
A path (or filepath, file path, pathname, or similar) is a text string that uniquely specifies an item in a hierarchical file system. Generally, a path is composed of directory names, special directory specifiers and optionally a filename, sepa ...
such as or is a link. If the volume containing said pathnames were mapped to in a Windows system, these could be referenced as and . (Compare and contrast with typical Unix file systems, where a link is an entry in a directory—directories themselves being just a type of file stored in the filesystem—pointing either to another link, or to an inode.)
Types of links
NTFS has four types of links. These map relatively closely to the generic
hard link
In computing, a hard link is a directory entry (in a Directory (computing), directory-based file system) that associates a name with a Computer file, file. Thus, each file must have at least one hard link. Creating additional hard links for a fil ...
and
soft link concepts which modern file systems tend to follow.
Hard links
Hard links
Hard means something that is difficult to do. It may also refer to:
* Hardness, resistance of physical materials to deformation or fracture
* Hard water, water with high mineral content
Arts and entertainment
* Hard (TV series), ''Hard'' (TV ser ...
are typical in behavior. A hard link "points" to an MFT record. That ''target'' record will be the record for a "regular" file, such as a
text file
A text file (sometimes spelled textfile; an old alternative name is flat file) is a kind of computer file that is structured as a sequence of lines of electronic text. A text file exists stored as data within a computer file system.
In ope ...
or
executable
In computer science, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, causes a computer "to perform indicated tasks according to encoded instruction (computer science), in ...
(assuming the NTFS volume is in a normal "healthy" state). Compare with a typical
Unix file system
The Unix file system (UFS) is a family of file systems supported by many Unix and Unix-like operating systems. It is a distant descendant of the original filesystem used by Version 7 Unix.
Design
A UFS volume is composed of the followin ...
, where a hard link points to an
inode
An inode (index node) is a data structure in a Unix-style file system that describes a file-system object such as a file or a directory. Each inode stores the attributes and disk block locations of the object's data. File-system object attribu ...
. As in such file systems, an NTFS hard link cannot point to a directory.
A typical new file creation event on an NTFS volume, then, simply involves NTFS allocating and creating one new MFT record, for storing the new file entity's file
metadata
Metadata (or metainformation) is "data that provides information about other data", but not the content of the data itself, such as the text of a message or the image itself. There are many distinct types of metadata, including:
* Descriptive ...
—including, about any of the data clusters assigned to the file, and the file's data streams; one MFT record for a hard link which points to the first newly-created MFT record as its ''target''; storing a reference to the hard link in a directory file; and setting the
reference count
In computer science, reference counting is a programming technique of storing the number of Reference (computer science), references, Pointer (computer programming), pointers, or Handle (computing), handles to a resource, such as an object, a bl ...
of both these MFT records to. Any
file name
A filename or file name is a name used to uniquely identify a computer file in a file system. Different file systems impose different restrictions on filename lengths.
A filename may (depending on the file system) include:
* name – base ...
provided as part of the file creation event is stored in the hard link. An MFT record can be the target of up to 1024 hard links; each time a new hard link is successfully created, targeting a previously extant MFT record, the target's reference count is incremented.
Symmetrically, the immediate tasks performed by NTFS in a typical
file deletion
File deletion is the removal of a file from a computer's file system.
All operating systems include commands for deleting files ( rm on Unix and Linux, era in CP/M and DR-DOS, del/erase in MS-DOS/ PC DOS, DR-DOS, Microsoft Windows etc.). Fil ...
event, when deleting a hard link, are simply: removing the reference to the link from the directory file containing it (the root directory, if applicable); and decrementing by the reference counts of the MFT record targeted by the link, and, of the entry containing the hard link ''itself''. Any MFT record which now has a refcount of , is now in the "deleted" state: all its associated resources are considered "free" by NTFS, to be freely overwritten and used as needed.
Junction points
Junction points are
NTFS reparse points and operate similarly to
symbolic links in Unix or Linux, but are only defined for directories, and may only be absolute paths on local filesystems (as opposed to remote filesystems being accessed). They are created and behave in a similar way to hard links, except that if the target directory is renamed, moved, or deleted, the link will no longer be valid.
*
NTFS volume mount points
Symbolic links
Symbolic link
In computing, a symbolic link (also symlink or soft link) is a file whose purpose is to point to a file or directory (called the "target") by specifying a path thereto.
Symbolic links are supported by POSIX and by most Unix-like operating syste ...
s are
reparse points which operate similarly to Junction Points, or symbolic links in Unix or Linux, and accept relative paths and paths to files as well as directories. Support for directory and UNC paths were added in NTFS 3.1.
All NTFS links are intended to be transparent to applications. This means that the application accessing a link will be seamlessly redirected by the file system driver, and no special handling is needed. To users, they appear as normal directories or files. This also leads to an aliasing effect: writes to a link will pass the write to the underlying, linked file or
MFT entry.
Symbolic links contain the path to the linked directory or file, and a tag identifying the driver which implements the behaviour. Because they record the path, they can link to files on other volumes or even remote files. However this also means that if the referenced file is deleted or renamed, the link becomes invalid, and if the referenced file or directory is replaced with another, the link will now refer to the new file or directory.
Shortcut files
An NTFS symbolic link is not the same as a
Windows shortcut file, which is a regular file. The latter may be created on any filesystem (such as the earlier
FAT32
File Allocation Table (FAT) is a file system developed for personal computers and was the default file system for the MS-DOS and Windows 9x operating systems. Originally developed in 1977 for use on floppy disks, it was adapted for use on ...
), may contain metadata (such as an icon to display when the shortcut is viewed in Remove links), and is not transparent to applications.
Implementations of unix-like environments for Windows such as
Cygwin
Cygwin ( ) is a free and open-source Unix-like environment and command-line interface (CLI) for Microsoft Windows. The project also provides a software repository containing open-source packages. Cygwin allows source code for Unix-like operati ...
and
Mingw
MinGW ("Minimalist GNU for Windows"), formerly mingw32, is a free and open source software development environment to create Microsoft Windows applications.
MinGW includes a port of the GNU Compiler Collection (GCC), GNU Binutils for Windows ...
can use shortcut files to emulate symbolic links where the host operating system does not support them, if configured to do so.
Examples of use
Built-in uses
* Windows Component Store (
WinSxS
Side-by-side assembly (SxS, or WinSxS on Microsoft Windows) technology is a standard for executable files in Windows 98 Second Edition, Windows 2000, and later versions of Windows that attempts to alleviate problems (collectively known as " DLL H ...
) use hard links to keep track of different versions of
DLLs stored on the hard disk drive.
* Basic installations of
Windows Server 2008
Windows Server 2008, codenamed "Longhorn Server" (alternatives: "Windows Vista Server" or "Windows Server Vista"), is the seventh major version of the Windows NT operating system produced by Microsoft to be released under the Windows Server b ...
used symlinks for \Users\All Users\ → \ProgramData\ redirection.
* Since
Windows Vista
Windows Vista is a major release of the Windows NT operating system developed by Microsoft. It was the direct successor to Windows XP, released five years earlier, which was then the longest time span between successive releases of Microsoft W ...
, all versions of Windows have used a specific scheme of built-in directories and utilize hidden junctions to maintain
backward compatibility
In telecommunications and computing, backward compatibility (or backwards compatibility) is a property of an operating system, software, real-world product, or technology that allows for interoperability with an older legacy system, or with Input ...
with Windows XP and older. Examples of these junctions are:
**
C:\Documents and Settings
pointing to
C:\Users
**
%USERPROFILE%\Application Data
pointing to
%USERPROFILE%\AppData\Roaming
**
%USERPROFILE%\My Documents\My Pictures
pointing to
%USERPROFILE%\Pictures
Program redirection
By setting a junction point that points to a directory containing a particular version of a piece of software, it may be possible to add another version of the software and redirect the junction point to point to the version desired.
Saving storage space
The contents of a junction use almost no storage space (they simply point to the original directory). If an administrator needs to have multiple points of entry to a large directory, junction points can be an effective solution. Junction points should not be confused with a ''copy'' of something as junctions simply point to the original. If directories need to be modified separately a junction cannot be used as it does not provide a distinct copy of the directory or files within.
Likewise, symbolic links and hard links are useful for merging the contents of individual files.
Circumventing predefined paths
Since reinstalling Windows (or installing a new version) often requires deleting the contents of the
C:
drive, it is advantageous to create multiple
partitions so only one partition needs to be deleted during the installation. However, some programs don't let the user choose the installation directory, or install some of their files to the
C:
drive even when they are installed to a different drive. By creating a junction point, the program can be tricked into installing to a different directory.
Command-line tools
Windows comes with several tools capable of creating and manipulating NTFS links.
*
PowerShell
PowerShell is a shell program developed by Microsoft for task automation and configuration management. As is typical for a shell, it provides a command-line interpreter for interactive use and a script interpreter for automation via a langu ...
: The
New-Item
cmdlet of
Windows PowerShell
PowerShell is a shell program developed by Microsoft for task automation and configuration management. As is typical for a shell, it provides a command-line interpreter for interactive use and a script interpreter for automation via a langua ...
that can create empty files, folders, junctions, and hard links. In PowerShell 5.0 and later, it can create symbolic links as well. The
Get-Item
and
Get-ChildItem
cmdlets can be used to interrogate file system objects, and if they are NTFS links, find information about them. The
Remove-Item
cmdlet can remove said items, although there has been a record of a bug preventing this cmdlet from working properly.
*
Windows Command Prompt
cmd.exe, a.k.a. Command Prompt, is a shell (computing), shell computer program, program on later versions of Windows (Windows NT, NT and Windows CE, CE families), OS/2,, eComStation, ArcaOS, and ReactOS. In some versions of Windows (Windows C ...
: Starting with Windows Vista and Windows Server 2008, the
mklink
internal command can create junctions, hard links, and symbolic links.
This command is also available in
ReactOS
ReactOS is a Free and open-source software, free and open-source operating system for i586/amd64 personal computers that is intended to be binary-code compatibility, binary-compatible with computer programs and device drivers developed for Wind ...
. In addition, the venerable
dir
command can display and filter junction points via the
/aL
switch. Finally, the
rd
command (also known as
rmdir
) can delete junction points.
* fsutil.exe: A command-line utility introduced with
Windows 2000
Windows 2000 is a major release of the Windows NT operating system developed by Microsoft, targeting the server and business markets. It is the direct successor to Windows NT 4.0, and was Software release life cycle#Release to manufacturing (RT ...
. Its
hardlink
sub-command can make hard links or list hard links associated with a file. Another sub-command,
reparsepoint
, can query or delete
reparse points, the file system objects that make up junction points, hard links, and symbolic links.
In addition, the following utilities can create NTFS links, even though they don't come with Windows.
* : It is a component of the
Resource Kit Resource Kit is a term used by Microsoft for a set of software resources and documentation released for their software products, but which is not part of that product. Resource kits offer supplementary resources such as technical guidance, compatibi ...
for
Windows 2000
Windows 2000 is a major release of the Windows NT operating system developed by Microsoft, targeting the server and business markets. It is the direct successor to Windows NT 4.0, and was Software release life cycle#Release to manufacturing (RT ...
and
Windows Server 2003
Windows Server 2003, codenamed "Whistler Server", is the sixth major version of the Windows NT operating system produced by Microsoft and the first server version to be released under the Windows Server brand name. It is part of the Windows NT ...
. It can make junction points.
* junction: A free command-line utility from Microsoft, it can create or delete junctions.
* PowerShell Community Extensions (PSCX): Hosted on Microsoft PowerShell Gallery, this module adds several cmdlets for dealing with NTFS links, including: New-Hardlink, New-Junction, Get-ReparsePoint, Remove-ReparsePoint, and New-Symlink.
APIs
To create hard links, apps may use th
function of
Windows API
The Windows API, informally WinAPI, is the foundational application programming interface (API) that allows a computer program to access the features of the Microsoft Windows operating system in which the program is running. Programs can acces ...
. All versions of the
Windows NT family
Windows NT is a proprietary graphical operating system produced by Microsoft as part of its Windows product line, the first version of which, Windows NT 3.1, was released on July 27, 1993. Originally made for the workstation, office, and ser ...
can us
to determine the number of hard links associated with a file. There can be up to 1024 links associated with an MFT entry. Similarly, th
function can create symbolic links. Junctions are more complex to create, they require manual
reparse point information filling. Junctions are defined for directories only: although the API does not fail when one creates a junction pointing to a file, the junction will not be interpreted successfully when used later.
Junctions and symbolic links pointing to directories can be removed wit
Hazards
Consistency
Symbolic links and NTFS junctions can point to non-existent targets because the operating system does not continuously ensure that the target exists.
Additional hazards lurk in the use of NTFS directory junctions that:
* include links that refer to their own parent folders, such as creating hard link
X:\path\to\parent
which points to either
X:\path\
or
X:\path\to\
, or
* specify targets by using volume drive letters, such as
X:
, in
X:\some\path\
.
Recursive structure
The problem in the first case is that it creates recursive paths, which further implies infinite recursion in the directory structure. By introducing reentrancy, the presence of one or more directory junctions changes the structure of the file system from a simple
proper tree into a
directed graph, but recursive linking further complicates the graph-theoretical character from
acyclic to cyclic. Since the same files and directories can now be encountered through multiple paths, applications which traverse reentrant or recursive structures naively may give incorrect or incoherent results, or may never terminate. Worse, if recursively ''deleting'', such programs may attempt to delete a parent of the directory it is currently traversing.
Note that both of the conditions listed above exist in the system of hard links established on the
C:
drive in the default Windows setup. For example, every
Windows 10
Windows 10 is a major release of Microsoft's Windows NT operating system. The successor to Windows 8.1, it was Software release cycle#Release to manufacturing (RTM), released to manufacturing on July 15, 2015, and later to retail on July 2 ...
installation defines the recursive path:
C:\ProgramData\
C:\ProgramData\Application Data\
C:\ProgramData\Application Data\Application Data\
C:\ProgramData\Application Data\Application Data\Application Data\
C:\ProgramData\Application Data\Application Data\Application Data\Application Data\
C:\ProgramData\Application Data\Application Data\Application Data\Application Data\Application Data\ ...
Each additional path name in this seemingly infinite set is an actual valid Windows path which refers to the same location. In practice, path names are limited by the 260-character DOS path limit (or newer 32,767 character limit), but truncation may result in incomplete or invalid path and file names. Whenever a copy of a Windows installation is archived, with directory junctions intact, to another volume on the same—or worse—''another'' computer, the archived copy may still incorporate active folders from the running installation. For example, depending on the method used for copying, a backup copy of a Windows drive
X:\archive\...
will include a hard link called
X:\archive\Users\USERNAME\My Documents
which still points to folder
C:\Users\USERNAME\Documents\
in the current, active installation.
Cross-volume traversal
The second form of deferred target mis-referral, while conceptually simpler, can have more severe consequences. When a self-consistent volume or directory structure containing hard links which use volume drive-letter path names is copied or moved to another volume (or when the drive letter of a volume is reassigned by some other means), such links may no longer point to the corresponding target ''in the copied structure''. Again the results depend on the software that was used for copying; while some programs may intercede by modifying any fully subsumed hard links in the copy in order to preserve structural consistency, others may ignore, copy exactly, or even traverse into hard links, copying their contents.
The serious problems occur if hard links are copied exactly such that they become, in the new copy, cross-volume hard links which still point to original files and folders on the source volume. Unintentional cross-volume hard links, such as hard links in an "archive" folder which still point to locations on the original volume (according to drive letter), are catastrophes waiting to happen. For example, deleting what is much later presumed to be an unused archive directory on a disused backup volume may result in deleting current, active user data or system files.
A preventative measure for the drive-letter hazard is to use volume GUID path syntax, rather than paths containing volume drive letters, when specifying the target path for a directory junction. For example, consider creating an alias for
X:\Some\Other\Path
at
X:\Some\Path\Foo
:
As described above, if the folder structure that contains the resulting link is moved to a disk with a drive letter other than
X:
, or if the letter is changed on drive
X:
itself, the data content at the target location is vulnerable to accidental corruption or malicious abuse. A more resilient version of this link can partially mitigate this risk by referencing the target volume by its GUID identifier value (which can be discovered by running the
fsutil volume list
command).
Doing so ensures that the junction will remain valid if drive letter
X:
is changed by any means.
As for a proactive means of avoiding directory junction disasters, the command
dir /AL /S /B "X:\Some\Path"
can be used to obtain, for careful analysis prior to committing any irreversible file system alterations, a list of all hard links "below" a certain file system location. While by definition every link in the resulting list has a path name that starts with
X:\Some\Path\
, if any of those hard links contains a target which is not subsumed by
X:\Some\Path
, then the specified scope has been escaped, and the starting directory you specified is not fully-subsuming. Extra caution may be indicated in this case, since the specified directory includes files and directories which reside on other physical volumes, or whose own parent-traversal-to-root does not include the specified directory.
Limitations
Privilege requirements
The default security settings in Windows disallow non-elevated administrators and all non-administrators from creating symbolic links but not junctions. This behavior can be changed running "secpol.msc", the Local Security Policy management console (under: Security Settings\Local Policies\User Rights Assignment\Create symbolic links). It can be worked around by starting
cmd.exe
cmd.exe, a.k.a. Command Prompt, is a shell program on later versions of Windows ( NT and CE families), OS/2,, eComStation, ArcaOS, and ReactOS. In some versions of Windows ( CE .NET 4.2, CE 5.0 and Embedded CE 6.0) it is referred to as ...
with ''Run as administrator'' option or the
runas
In computing, runas (a compound word, from “run as”) is a command in the Microsoft Windows line of operating systems that allows a user to run specific tools and programs under a different username to the one that was used to logon to a comp ...
command. Starting with Windows 10 Insiders build 14972 the requirement for elevated administrator privileges was removed in Windows "Developer Mode", allowing symlinks to be created without needing to elevate the console as administrator. At the API level, a flag is supplied for this purpose.
Boot time
The
Windows startup process
The booting process of Microsoft Windows varies between different releases.
DOS-based Windows Windows 1.x/2.x
In Windows versions 1.01 to Windows 2.11, the system was loaded when WIN.COM was executed within MS-DOS. It then loaded WIN100.BIN ...
does not support junction points, so it is impossible to redirect certain system folders:
* \Windows
* \Windows\System32
* \Windows\System32\Config
Other critical system boot files, such as The sleep image file
hiberfil.sys
, also do not support redirection.
System-defined locations
It is technically possible to redirect the following non-critical system folder locations:
* \Users
* \Documents and Settings
* \ProgramData
* \Program Files
* \Program Files (x86)
Doing this may lead to long-term Windows reliability or compatibility issues. Creating junctions for
\Users
and
\ProgramData
pointing to another drive is not recommended as it breaks updates and Windows Store Apps.
Creating junctions for \Users, \ProgramData,
\Program Files
or
\Program Files (x86)
pointing to other locations breaks installation or upgrade of Windows.
Creating junctions for
\Program Files
or
\Program Files (x86)
pointing to another drive breaks Windows'
Component Based Servicing which hardlinks files from its repository \Windows\SxS to their installation directory.
Windows installer
Windows Installer
Windows Installer (msiexec.exe, previously known as Microsoft Installer, List of Microsoft codenames, codename Darwin) is a software component and application programming interface (API) of Microsoft Windows used for the Installation (computer ...
does not fully support symbolic links. Redirecting
\Windows\Installer
will cause most .msi-based Windows installers to fail with error 2755 and/or error 1632.
Symbolic link support in Windows XP
Since Windows XP uses the same NTFS format version as later releases, it's feasible to enable symbolic links support in it. For using NTFS symbolic links under Windows 2000 and XP, a third-party driver exists that does it by installing itself as a file system filter.
History
Symbolic links to directories or volumes, called
junction points and mount points, were introduced with NTFS 3.0 that shipped with Windows 2000. From NTFS 3.1 onwards, symbolic links can be created for any kind of file system object. NTFS 3.1 was introduced together with
Windows XP
Windows XP is a major release of Microsoft's Windows NT operating system. It was released to manufacturing on August 24, 2001, and later to retail on October 25, 2001. It is a direct successor to Windows 2000 for high-end and business users a ...
, but the functionality was not made available (through ntfs.sys) to user mode applications. Third-party filter drivers such as Masatoshi Kimura's opensource
senable
driver could however be installed to make the feature available in user mode as well. The ntfs.sys released with
Windows Vista
Windows Vista is a major release of the Windows NT operating system developed by Microsoft. It was the direct successor to Windows XP, released five years earlier, which was then the longest time span between successive releases of Microsoft W ...
made the functionality available to user mode applications by default.
Since NTFS 3.1, a symbolic link can also point to a file or remote
SMB network path. While NTFS junction points support only absolute paths on local drives, the NTFS symbolic links allow linking using relative paths. Additionally, the NTFS symbolic link implementation provides full support for cross-filesystem links. However, the functionality enabling cross-host symbolic links requires that the remote system also support them, which effectively limits their support to Windows Vista and later Windows operating systems.
See also
*
NTFS volume mount point
*
NTFS reparse point
*
Symbolic link
In computing, a symbolic link (also symlink or soft link) is a file whose purpose is to point to a file or directory (called the "target") by specifying a path thereto.
Symbolic links are supported by POSIX and by most Unix-like operating syste ...
*
File shortcut
In computing, a file shortcut is a handle in a user interface that allows the user to find a file or resource located in a different directory or folder from the place where the shortcut is located. Similarly, an Internet shortcut allows the us ...
References
External links
Documentation for NTFS symbolic links on MSDNCreateSymbolicLink function in the Win32 APIfsutilhardlink create
- creates a hard link
In computing, a hard link is a directory entry (in a Directory (computing), directory-based file system) that associates a name with a Computer file, file. Thus, each file must have at least one hard link. Creating additional hard links for a fil ...
(Windows 2000
Windows 2000 is a major release of the Windows NT operating system developed by Microsoft, targeting the server and business markets. It is the direct successor to Windows NT 4.0, and was Software release life cycle#Release to manufacturing (RT ...
and later)
Microsoft Knowledge Base Article
– 'How to Create and Manipulate NTFS Junction Points'
archived version
Junction
command line utility from Microsoft TechNet
Codeproject Article
– discussion on the source code of a junction point utility, aimed at programmers
PC Mag Article
about adding any directory to the start menu (allowing a preview within the startmenu as a submenu).
{{Computer files
Disk file systems
Windows disk file systems
Windows administration
pl:Dowiązanie symboliczne