In-depth parsing of inode blocks and superblocks in Unix

Source: Internet
Author: User
Article Title: In-depth parsing of inode blocks and superblocks in Unix. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Although the Unix operating system is more stable than the Windwos system. However, Unix operating systems sometimes have bad temper and strike. This is mainly because inode blocks and Super blocks in Unix operating systems are at odds. What are the locations of these two blocks in the Unix operating system?

 I. inode block, the core of Unix files.

First, you must understand that any resource in the Unix operating system is managed as a file. Such as directories, optical drives, and terminal devices, are regarded as files. In this regard, all directories and hardware devices in the Unix operating system share the same attributes as common files. These attributes are stored in the inode block.

The Inode block stores all Inode nodes in a file system. That is to say, when the system creates a file (or adds a new device), the system allocates an Inode node to the file from this block. This node stores most of the attributes of this file, such as the creation and modification time. Note that two attributes are not included in the inode node, namely the file name and the node number. This is mainly because inode nodes are arranged in order, so the system kernel can use a simple algorithm to obtain the inode node number. When you use the ls command provided by the system to display file or directory information, you need to use the information in this node. To determine the Inode node of a file, the Ls command needs to find its directory, read its Inode node, and obtain the file attributes based on the inode node. Under normal circumstances, this node number will not cause any problems. However, some faults may occur due to unexpected power outages or other causes. If an inode node may have been created in the system but is not used properly, or the part number may be out of the range. These faults may cause security risks to the operating system. When an unexpected shutdown or other unexpected event occurs, it is recommended that the system engineer use The fsck system command to fix the error in the inode node.

In addition, it should be noted that an important information is stored in the inode node, that is, an array containing 13-15 pointer elements, these pointers are the address of the disk block area. These pointers are very important. The operating system uses these pointers to locate and read relevant files on the hard disk. As mentioned above, this pointer address may be incorrect due to some unexpected operations. Sometimes this can be very serious. For example, some files cannot be read. If these files are unfortunately system configuration files, the system will crash. If these pointer addresses are incorrect, the file name is still displayed in the operating system. However, if you try to open these files, the system will tell you that they cannot be opened. What if this happens? In this case, the system engineer needs to manually run The fsck command. If the file is not seriously damaged, the kernel in the operating system will establish a link for it. However, if the original file is damaged, it cannot be read again. The system creates a user to delete the file (from the hard disk ).

Because the attributes of some files (such as the creation and modification time) are stored in Inode nodes, some commands do not need to open files when obtaining these attributes. For example, if the system engineer is writing a file backup program, it needs to use the modify time in the inode node to intercept this attribute. In this case, you can use the relevant commands to directly obtain the information from the inode node without opening the corresponding file. Therefore, file backup programs in Unix operating systems are more efficient and easier to implement.

From the above analysis, we can see that inode nodes are the core of files in Unix operating systems and an intermediary between operating systems and data stored in hard disks. If this node information is incorrect, the data block stored in the hard disk is like a non-active wanderer and cannot be used by users. In addition, when we delete files, we only delete the contact. Therefore, you can use the first-line recovery tool to restore deleted files. If you need to delete a file, you need to format the hard disk (low size) or copy a large file to overwrite it. Only the data blocks stored in the hard disk will be deleted. It should be noted that shutting down the Unix operating system according to the normal Shutdown program is the best way to protect inode node information. Sudden Power outages or other accidents are the biggest killer of inode nodes.

 Ii. Super block, the heart of the file system.

If inode blocks are the core of files in Unix operating systems, they are the heart of the file system. After the Unix operating system is started, it is found that a file system cannot be used. It is likely that the super block has a problem. Why is this super block so powerful? This is mainly because the global file information is saved in the super block, such as the space used by the hard disk, the available space of the data block, and the inode node information. As an image metaphor, this super block is like an enterprise's balance sheet. What resources in a file system are recorded in this table.

After the operating system is started, the system kernel copies the content in the super block to the memory and periodically updates the content in the super block on the hard disk using the latest content in the memory. There is a time difference between this update. Therefore, the super block information in the memory and the super block information in the hard disk are usually synchronized only at a specific time during startup and shutdown; however, they are not synchronized at other times. Assuming that the super block information in the memory is not saved to the hard disk in time when the operating system encounters an unexpected host or an accident caused by power failure, the integrity of the file system will be damaged. The minor causes the loss of the just-created file system, and the minor causes the file system to crash. In this case, System Engineers often need to use the sync Command provided by the system to copy the memory content to the disk when the system fails. This process is often automatically completed by the operating system, which is precisely because the Unix operating system is more stable than the Windows operating system. When the operating system restarts, the system kernel compares the two and tags the file system clean or dirty based on their differences. This information is also stored in the super block of the file system.

It can be seen that if a super block is damaged, it will be very destructive to the file system. Otherwise, a file system cannot be mounted. Otherwise, the entire operating system will crash. In Unix operating systems, apart from using the sync command to ensure that the content on the hard disk will never be updated than the content in the memory, it also provides a very favorable measure to ensure its security. In fact, this technology has been available for a long time, but it was not used in the management of Super blocks at the beginning. This technology is similar to the disk array. The operating system saves multiple super block contents to different areas on the hard disk. When one of the Super blocks fails, the operating system automatically uses another super block. After the system runs normally, the system content replaces the faulty super block with the available super block. Therefore, unless all the Super blocks are damaged, the file system and the operating system can be mounted and started normally as long as one super block is available. This security mechanism greatly improves the security of Super blocks and the stability of Unix operating systems. Currently, most Unix operating systems (including Linux operating systems) have implemented similar security mechanisms.

[1] [2] Next page

Related Article

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.