NAME
Win32::NTFS::Symlink - Support for NTFS junctions and symlinks on Windows
SYNOPSIS
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'
DESCRIPTION
This module implements symlink
and readlink
routines, as well as an junction
function, for use with NTFS file systems on Microsoft Windows.
symlink
(or ntfs_symlink
) will create an 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.
readlink
(or ntfs_readlink
) can read both NTFS symlinks and junctions.
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.)
Exports
By default, nothing is exported. There are multiple ways to import routines from this module.
Global Overrides
:global
-
This overrides the global
readlink
andsymlink
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 usingsymlink
andreadlink
already for other platforms such as Unix and Linux.
Convention Imports
:package
-
This will import
readlink
,symlink
, andjunction
into the current namespace.These can also be imported individually:
readlink
symlink
readlink
Alternative Imports
:ntfs_
-
This will import
ntfs_readlink
,ntfs_symlink
, andntfs_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-inreadlink
andsymlink
functions.These can also be imported individually:
ntfs_readlink
ntfs_symlink
ntfs_readlink
Mix and Match
- The above importations and global override options can be mixed and matched.
-
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);
NTFS Symlinks in Windows XP, 2003 Server, and 2000
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.
ACKNOWLEDGEMENTS
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.
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.
AUTHOR
Bayan Maxim <baymax@cpan.org>
COPYRIGHT AND LICENSE
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.