Win32::NTFS::Symlink - Support for NTFS junctions and symlinks on Windows
use Win32::NTFS::Symlink qw(:global junction); # Create NTFS symlinks. symlink 'D:\dir1' => 'D:\symlink_to_dir1'; # To a directory. symlink 'D:\file1.txt' => 'D:\symlink_to_file1.txt'; # To a file. # Creates an NTFS directory junction. junction 'D:\dir1' => 'D:\junction_to_dir1'; say readlink 'D:\symlink_to_dir1'; # 'D:\dir1' say readlink 'D:\symlink_to_file1.txt'; # 'D:\file1.txt' say readlink 'D:\junction_to_dir1'; # 'D:\dir1'
This module implements symlink and readlink routines, as well as an junction function, for use with NTFS file systems on Microsoft Windows.
symlink
readlink
junction
symlink (or ntfs_symlink) will create an NTFS symlink.
ntfs_symlink
(For Windows XP, 2003 Server, or 2000, see section "NTFS Symlinks in Windows XP, 2003 Server, and 2000" below.)
junction (or ntfs_junction) will create an NTFS directory junction.
ntfs_junction
readlink (or ntfs_readlink) can read both NTFS symlinks and junctions.
ntfs_readlink
Note: While NTFS symlink targets can be either relative or absolute, readlink on a junction will always return an absolute path. This is simply how they are stored in the file system (reparse point.)
By default, nothing is exported. There are multiple ways to import routines from this module.
:global
This overrides the global readlink and symlink built-in functions. This can be useful to "fix" other modules that use these routines that would normally not be able to function correctly on Windows.
You can also choose to override each one individually:
global_readlink
global_symlink
Note: There is currently no global override for junction, as there doesn't exist a built-in function, since junctions are NTFS and Windows/NT specific, and so there aren't existing modules making use of it in the same way as those using symlink and readlink already for other platforms such as Unix and Linux.
:package
This will import readlink, symlink, and junction into the current namespace.
These can also be imported individually:
:ntfs_
This will import ntfs_readlink, ntfs_symlink, and ntfs_junction into the current namespace. This can be useful to prevent conflicts with existing sub routines with the same names, or if when it is undesired to override the built-in readlink and symlink functions.
For example:
# Override the global built-in readlink() and symlink(), and # import ntfs_junction() use Win32::NTFS::Symlink qw(:global ntfs_junction);
Another example:
# Override global built-in readlink() only, and import ntfs_symlink() # Since neither junction nor ntfs_junction are imported, it must be fully # qualified in order to be used, as either # Win32::NTFS::Symlink::junction() or Win32::NTFS::Symlink::ntfs_junction() use Win32::NTFS::Symlink qw(global_readlink ntfs_symlink);
For proper NTFS symlink support in Windows XP, 2003 Server, and 2000 (NT 5.x), a driver is needed to enable support, to expose the existing functionality to the user-land level so it can be accessed by programs such as this one.
The driver and it's source code can be obtained from http://schinagl.priv.at/nt/ln/ln.html (at the bottom.)
Note that this is only required for full symlink support. Junctions, on the other hand do not require this, since that part of the NTFS reparse mechanism is already exposed to the user-land level.
This isn't needed if you are using Vista or Server 2008 R1 (NT 6.0), or later.
I originally set out to fix Win32::Symlink, whose symlink() and readlink implementations (ironically) only worked with NTFS junctions, without any support for NTFS symlinks.
symlink()
I ended up creating a fresh new module to properly implement symlink as well as junction, and a readlink that could read either one.
So even though I ended up not using much of anything from Win32::Symlink, I still want to acknowledge Audrey Tang <cpan@audreyt.org> for the inspiration, as well as http://schinagl.priv.at/nt/ln/ln.html whose source code relating to the ln utility that helped greatly in figuring out how to properly work with NTFS reparse points.
Bayan Maxim <baymax@cpan.org>
Copyright (C) 2018 by Bayan Maxim
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
To install Win32::NTFS::Symlink, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Win32::NTFS::Symlink
CPAN shell
perl -MCPAN -e shell install Win32::NTFS::Symlink
For more information on module installation, please visit the detailed CPAN module installation guide.