[Study Notes] File System Structure 2

Source: Internet
Author: User

Disk File Storage

The storage of UNIX file systems is completed through the Directory and file system structure. The former stores the File hierarchy, and the latter stores the file location and content.


1. directory file

In UNIX, a directory is a special file whose content is a series of directory items, each directory item consists of a file name in the Directory and the I node number occupied by the file. You can use
-AI command to view the contents of each directory.

Directory builds a tree-like file structure system, and records the correspondence between file names and I nodes, thus setting up a bridge between file names, file attributes, and content.


2. Disk Files

The file system records the file name and its corresponding I node number through the directory, and records the information and content of the file through the I node. In fact, the I node records only the attributes of the file. the specific content of the file is stored in the data block in the Data zone, only one "disk address table" is retained on the I node to record the location where the file content is stored.

The "disk address table" consists of 13 block numbers, each of which occupies 4 bytes, representing a data block number in the data area.



The UNIX file system uses a three-level index structure to store files. It divides the "disk address table" into four parts: Direct Index address, first-level indirect index address, second-level indirect index address, and third-level indirect index address.

The UNIX file storage method is complex. When processing large files, the existence of indirect indexes leads to low disk utilization and slow data addressing, but it is very convenient to process small files, files with a length not greater than 10 KB can be directly addressable. In fact, statistics show that in UNIX, 80% is a small file, 20% is a large file, and 85% is less than 8 KB, 48% of files are smaller than 1 kb, and only 1% of files are ultra-large files.



3. Link file

Linked files include hard-link files and symbolic link files. The hard link of the created file does not occupy additional disk blocks. It adds a directory item to the directory file. Register the file name and the I node number of the linked file, and add the di_nlink (File Link count) field value to 1. The linked file is another access path of the original file, which points to the same disk area. Therefore, modifying the file through a hard Link means changing the original file itself.

When deleting a file, the file system deletes the file from the disk only when the di_nlink field of the I node is reduced by 1 and the value is 0, that is, no link points to the node.

Hard links can only be implemented in the file system. when crossing a file system link, you need to create a symbolic link, a symbolic link, and a soft link. It is similar to the shortcut in window, it is a file that occupies disk blocks and records a link to the target file. During access, the operating system first reads the link and then reads the target file.



4. Working Principle of Disk File Reading

The following uses the command "cat t1.c" as an example.

Step 1: Find the t1.c file and the corresponding I node number in the current directory file. Assume It is 1109

Step 2: Read node 1,109th from the I node table

Step 3: Read the file attributes and access permissions of node I.

Step 4: Read the disk address table in the I node and read the file content in the Data Zone according to the three-level index rules.



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.