Linux File System Architecture

Source: Internet
Author: User

The Linux File System is composed of several trees and linked list structures. As we all know, all directories and files constitute a visual "one tree, there is a mount linked list behind this "one" tree. If every file system is a tree (in fact, this is the case ), this linked list links many trees into the "one" tree. Therefore, the Linux File System is composed of many trees which are linked together by mounting the linked list, for example,/tmp/My is a directory with the file file1, And we can mount a disk partition D to this directory, in this case, the files under/tmp are the files under disk partition D. This model can also be used to implement non-storage file systems or even any file systems, such as procfs, sysfs, tmpfs, and so on. Mount any file system to any directory of the mounted file system. These file systems can be mounted on disks, on networks, and in memory, in your mind, it seems that such a file system can be infinitely expanded.
At the bottom layer, Linux maintains the concept of a disk inode, which represents an actual file. At the previous layer, Linux maintains the memory inode, it allows the operating system to provide user interfaces to operate disk inode. The memory inode corresponds to the disk inode, in the VFS layer, disk inode in different formats of different file systems are unified into the same memory inode. In this way, the interfaces provided above are unified. Before the interfaces are unified, the data structure must be unified first. The concept of directory item dentry is related to memory inode. It is bound to one and only one memory inode, but allows multiple dentry to bind the same memory inode, in fact, it is the kernel entity of each file we see when using the operating system. Since the multi-to-one relationship between dentry and inode is allowed, the operating system can easily implement concepts such as links. In this sense, dentry is not at the same level as the memory inode. inode indicates the nature of the file, dentry indicates the file interface in the operating system sense.
UNIX is the first to implement VFS. in UNIX, inode becomes a vnode in memory. This name may sound better. The implementation of this VFS in Linux is more complicated. Its essence is the memory inode data structure, and the file_operations operation function set is provided based on the data structure, how are these data structures combined? When are they combined? If you want to figure it out, you need to start from the origin, so the sys_open System Call will inevitably link all of this. If sys_open is not enough, as a file system, sys_mount determines the basic template of the file system, such as the super_block structure. Because sys_mount still needs to use sys_open, sys_open is of course the top priority. The outline of open is a two-tier loop, and the external path is resolved cyclically. The inner loop searches for the next element in the specific path to be open. The path elements are separated. Before further processing the next path element, you must set the current dentry to the root directory of the file system mounted at the top layer of the current directory, which is implemented by follow_mount in Linux, in this way, all the original contents in the mounted directory are hidden. The original tree still exists, but a new root is generated on this node, then the new root is extended into a tree, and any tree node can grow out of a new root, and then recursively grow a new tree.
Each mounted file system in the system has a super block, which is the metadata of the file system. The Super blocks of all similar file systems are linked into a linked list, under the guidance of the super block callback function, the system module can support a variety of file systems. There is also a mount table in the system, which is actually a mount tree. Many kernel entities are connected to different data structures at the same time, so that different data structures can be used in different scenarios, for example, vm_area_struct is connected to both the linked list and the red tree. Each entry in the Mount table indicates a mount, which contains the super block information of a mounted file system, and the dentry corresponding to the inode of the mount point, the dentry and device number corresponding to inode of the file system root.
Each mounted file system has a root, that is, "/", which is a special directory. Generally, each type of file system assigns a fixed memory inode number to this root, then assign a unique inode number within the Mount range for the subsequent mount file system. Therefore, the inode number of files in the file system of different mount points will be the same. Note, generally, do not mention the unique disk inode or not, because not every file system has the disk inode concept, unix/Linux only allows many file systems to be "adapted" to the memory inode (vnode) for VFS. For example, NTFS does not have the concept of inode, when an NTFS partition is mounted on Linux, the NTFS module of the kernel loads the metadata of the NTFS file to the memory inode. This is the application of the adapter mode in the Linux kernel.

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.