Why hard links to Linux cannot be linked to a directory

Source: Internet
Author: User
Tags parent directory

The directory file in Linux is a special file, where the data is an associative list, like a map in C + +, or dict in Python, save each file name (including subdirectories, all files in Linux!). ) to the inode mapping. The Inode essence is a pointer to the various property information of the file.

Hard links are actually equivalent words of "catalog items", which at first glance are inconsistent with our perceptions. We often think that "hard links create an additional directory entry for an existing object", but the most common use of hard links is another scenario, when an object is created for the first time, it is necessary to create a directory entry for the object, which is actually creating a hard link! This is the establishment of a hard link can not only achieve from 1 to 2 of the transformation, more adept at achieving a change from scratch!

When a directory is created, its internal file data, which is the catalog item, is created in two directories, i.e. "." and ".". “.” Point to current directory, "..." Point to the parent directory, which is actually two hard links! , so the number of hard links per directory is at least 2! root directory "/" Parent directory "..." is itself, the other directory does not allow its parent directory to be itself. During traversal of the directory tree, loops cannot be detected without tracking the inode number that is traversed. Although the ".." Point to the parent directory, but this is handled separately when the kernel traverses the directory. If other subdirectories are allowed to link to the parent directory, it can cause loops, which is prone to errors.

Why hard links to Linux cannot be linked to a directory

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.