Current location - Quotes Website - Team slogan - What role does the virtual file system under Linux play?
What role does the virtual file system under Linux play?
Linux operating system

Because of the existence of virtual file system, it allows many different file systems to be saved and supports file operations across file systems. Virtual file system, namely VFS (Virtual File)

System) is a software abstraction layer in the Linux kernel. Through some data structures and methods, data can be transferred to actual file systems such as ext2 and vfat.

Provide an interface mechanism. After briefly introducing the data structure of VFS, this paper goes deep into the source code of Linux kernel with file I/O as the starting point, and traces back to sys_open and

The code structure of sys_read system calls, in the process of tracing back, clarifies the basic principle of file operation across file systems and the basis for realizing the slogan "Everything is a file".

Virtual file system

Is a set of code framework, which is between the file system and the users of a specific file system, and separates them. This design idea introduces an abstract level, that is, "the upper layer does not depend on it".

In the concrete implementation, it depends on the interface; The lower layer does not depend on the concrete implementation, but on the interface. This is the famous "dependency inversion", which can be seen everywhere in the Linux kernel.

The design of VFS framework needs to meet the following requirements:

1、? Provide a unified file and directory interface for upper users, such as? Open, read, write

2、? Define a series of unified operation "interfaces" for the specific file system at the bottom, such as file _ operations, inode _ operations, dentry _ operation, etc. The specific file system must implement these interfaces before it can be integrated into the VFS framework.

To this end, VFS needs:

1. Defines the unified concept of the file system.

2. On the basis of this concept, realize the operation interfaces provided to upper users, such as opening, reading and writing.

3. Provide a mechanism to integrate the specific file system at the bottom into the VFS framework, such as "registration" and "installation" of the file system.

VFS core concept

1, VFS manages the file system through a tree structure, and any node in the tree structure is a "directory node".

2. The tree structure has a "root node"

3.VFS knows all the necessary information of a specific file system through "super block". You must first register a specific file system with VFS. After registration, VFS can get the "superblock" of the file system.

4. A specific file system can be installed on a "directory node" and can only be used after installation.

5. The user's operation on the file is to find the "directory node" of the corresponding file through the interface of VFS, and then call the operation interface corresponding to the "directory node".