UNIX File System

Source: Internet
Author: User

The Unix File System has multiple implementations. The following describes the UFS (Unix File System) based on BSD ).

Generally, a hard disk is divided into multiple partitions. Each partition can contain a file system. The structure of the file system is generally as follows:

Auto-lifting block | super block | cylindrical group 0 | cylindrical group 1 | ...... | Cylindrical group N

The structure of the cylindrical Group I is as follows:

Super block copy | configuration information | I-node diagram | block bitmap | I-node block | directory block and data block

Among them, the I-node block stores many I nodes, and one I node corresponds to one file. I node is a fixed-length record item, and the relevant information of the file is basically stored in I-node. When partitioning Linux, you can set the percentage of I-node blocks in the partition size. The default value seems to be 5%. If there are many small files on the disk, you may need to set a relatively large I-node block to make full use of the disk space.

The (I-node number, file name) ing is stored in the directory block or directory item of the directory file. Based on this, an I-node in the I-node block can be found, the I-node stores the file information: file owner, file type, file access limit, file length, pointer of the data block occupied by the file (which may have multiple), etc, then you can access the data blocks on the disk that store the file content.

In the same directory block or multiple directory blocks, multiple I-node numbers (I-node numbers, file names) can be mapped to the same I-node number, and the file names are different, that is, point to the same I-node, which means that the file names in multiple paths can point to the same file on the disk. Each I-node has a reference count, and its value is the number of directory items pointing to this I-node. The data block occupied by the file is deleted only when the link count is reduced to 0. This type of link is called hard link. This is why the function for deleting a directory item is called unlink rather than Delete. This is why the "unlink to a file" operation does not always "Release the disk block occupied by the file ".

It is related to the symbol link. A symbolic link is actually a file. the actual content of the file (the content in the data block) stores the file path pointed to by the symbolic link. In I-node, the file type of the symbolic link is s_iflnk, and the system knows that this is a symbolic link.

The file system of each partition numbers their I-nodes, which does not affect each other. Therefore, one directory item cannot direct to the I-node of another file system. This is why ln commands cannot span the file system.

For the directory, because the directory file contains the current directory "." And parent directory ".". Therefore, the I-node of mydir in a directory file has (2 + n) link count: In the parent directory file (I-node number, mydir), In the mydir file (I-node number, current directory ". "), n sub-directory files (I-node number, parent directory ".. ").


The kernel uses three data structures to indicate opened files:

(1) Each process has an open file descriptor table in the process table. The content of each item in the table is (file descriptor,Pointer to a file entry in the file table)

(2) The kernel maintains an open file table for all opened files. The content of each entry is: (File status mark, current file offset,Pointer to the file V-node)

(3) Each opened file (the device is also a file) has a V-node structure. The V-node contains the file I-node information, this information is read from the disk when the file is opened, so the file information can be quickly accessed.

Do you see the association above? Open a file descriptor table in a process --> open a file table --> V-node --> I-node. Find the I-node of the file to access the file content.

The V-node structure is created to support multiple file system types on a computer system. Sun calls this file system virtual file system, the I-node information irrelevant to the file system type is divided into v-node. Linux does not divide the relevant data structures into I-node and V-node, but uses an I-node (General I-node structure) independent of the file system) and an I-node dependent on the file system. HoweverArticleLinux General I-node is still called vnode.

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.