Hard link and symbolic link under NTFS)

Source: Internet
Author: User
Hard link and symbolic link under NTFS)

In Linux, ext2 and other file systems all have the functions of hard link and symbolic link, this function allows us to use multiple paths to access the same file or directory. For example, let/vmlinuz and/boot/vmlinuz-2.6.7-1-38 represent the same file. However, there is a difference between hard link and symbolic link ).

Hard link indicates that it and the original file name point to the same file content on the storage device. Just as the content of this file has multiple file names, each file name has an equal position. After deleting any of these files, the object content will not be deleted, and other names can be used to access the file. The object content is deleted only when the last file name pointing to the object content is deleted. That is to say, the hard link of a file is not essentially different from the original name of the file. Note that each partition may have the same storage location address, so hard link must be in the same partition as the file to be linked. In addition, the directory does not support
Hard link. Symbolic Link is also called soft link, which is similar to the shortcut. lnk file in windows. It is a separate file, and the content of this file is the path of the file it points. When a program accesses Symbolic Link, it does not access its own content, but the content of the file it points. After a file is deleted, its symbolic link cannot access the file because the file itself has been deleted. That is to say, the symbolic link of a file is totally different from the file name or content. Symbolic
Link can link any files or directory paths that can be accessed locally.

These are my understanding of hard link and symbolic link. I tried to explain these two concepts in languages that are not relevant to file systems and as easy as possible. However, if you are a software developer or system administrator or want to know more details, we strongly recommend that you read this post.

OK. The concept is clearly explained. NTFS 3.0 (NTFs version used in Windows 2000) actually supports hard link and symbolic link. Although there are no easy-to-use tools in windows, in addition, Explorer treats symbolic link very strangely.

In Windows 2000 and later versions, you can use the complex command fsutil hardlink create to create a hard link. The usage is simple:

Fsutil hardlink create <New File Name> <existing file name>

You can also use ln In GNU utilities for Win32 to create a hard link. This is the Win32 port version of some GNU tools, which is very useful. In addition
Ln can not only create hard link, but also create symbolic link (in Windows, it is the shortcut. lnk file ).

Of course, if you want to create a hard link in your own program, it is also very easy. You only need a very simple API function:

BOOL CreateHardLink(  LPCTSTR lpFileName,  LPCTSTR lpExistingFileName,  LPSECURITY_ATTRIBUTES lpSecurityAttributes);

The meaning of the first two parameters does not need to be explained. The purpose of the last parameter is reserved temporarily and must be null.

For Symbolic Link, NTFS only supports symbolic link to the directory. Microsoft calls it junction. However, for the symbolic link of the file, Microsoft also provides a solution, that is, the shortcut cut,. lnk file ). However, symbolic link and shortcuts are not at the same level. The former is the function of the underlying file system, and the latter is the function of the application layer.

In "disk management" in "Computer Management" in "Administrative Tools", we can load a volume to an empty directory on an NTFS Volume, this is to create a symbolic link named by the empty directory for the root directory of the mounted volume. You can also use the command line tool mountvol to complete this task.

Unfortunately, Windows does not provide the complete symbolic link support tool for NTFS. "Computer Management" or mountvol can only create symbolic links for the root directory of a volume, rather than for any directory. Fortunately, we can use the free command line tool junction.exe with source code provided by sysinternals to fully implement
NTFS Symbolic Link Management. Of course, Microsoft is not so inexplicable. In windwos 2000 Resource Kit, it provides the command line tool linkd.exe to complete this task. However, its function of viewing symbolic link information is not as good as junction, because it does not support wildcard and subdirectory scanning.

Note that, Explorer has a strange behavior for symbolic link. That is, there is no difference between a symbolic link in Explorer and its link directory. Deleting this symbolic link will delete all files under the link directory! The famous powerful and convenient Scalability (forgive me for using so many modifiers here, I really like TC too much .) The file management tool total commander does not have this problem.

Some basic concepts and knowledge in this article come from the following two pages:
Http://answers.google.com/answers/threadview? Id = 341355
Http://phorum.study-area.org/viewtopic.php? T = 12235

Reference: http://rainux.org/ntfs-hard-linksymbolic-link

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.