One of the Virtual File Systems

Source: Internet
Author: User

1. Universal File System Interface
As the kernel subsystem, the Virtual File System (VFS) provides interfaces related to file systems for user space programs. All file systems in the system depend not only on the coexistence of VFS, but also on the Coordination of VFS systems. Through VFS, programs can use standard UNIX file systems to read and write different file systems on different media.

 

2. File System Abstraction Layer
This generic interface is used to operate on all types of file systems because the kernel creates an abstraction layer on its underlying file system interface. This abstraction layer supports various file systems in Linux, even though they have many differences in functionality and behavior. To support multiple file systems, VFS provides a general file system model that includes common functions and behaviors of file systems that we can think of, originating from Unix-style file systems.
The VFS abstraction layer connects various file systems because it defines the basic and conceptual interfaces and data structures supported by all file systems.

 

3. UNIX File System
UNIX uses four traditional abstract concepts related to file systems: files, directory items, index nodes, and decoration.
Common Operations on a file system include creating, deleting, and installing a file system. In UNIX, the file system is installed on a specific installation point, which is called a namespace in the global hierarchy, all installed file systems appear in the system as the branches of the root file system tree.
A file can be viewed as an ordered byte string. The first character in the byte string is the file header, and the last character is the end of the file. Typical file operations include reading, writing, creating, and operating.
Files are organized through directories. A file directory is like a folder used to hold related files. Because directories can also contain subdirectories, directories can be nested to form file paths. Each part of the path is called a directory entry. For example, "/home/wzhwho/wuwu" is an example of a file path. The root directory is/, and the home, wzhwho, and wuwu directories are directory entries. They are collectively referred to as Directory items. In UNIX, the directory is a common file, and VFS treats the directory as a file, so you can perform the same operations on the directory as the file.
The UNIX system distinguishes the relevant information of a file from the file itself, such as Access Control, size, owner, creation time, and other file-related information, called the metadata of a file, it is stored in a separate data structure, which is called an index node (inode ).
All this information is closely integrated with the control information of the file system. The control information of the file system is stored in the super fast State. The super block is a data structure containing the information of the file system.
UNIX file systems are also implemented according to the above concepts in their physical disk layout. For example, on a hard disk, the file information is stored in a separate block as an index node, and the control information is stored in the super block of the disk.

 

4. VFS object and its Data Structure
VFS actually uses an object-oriented design idea and uses a cluster of data structures to represent common file objects. VFS mainly has four object types:
1) super block object, which represents an installed system
2) index the Node object, which represents a file
3) Directory item object, which represents a directory item and is an integral part of the path
4) file object, which represents the file opened by the Process
Each primary object contains an operation object. These operation objects describe the methods that the kernel can use for primary objects. The main operation objects are as follows:
1) super_operations object: contains the methods that the kernel can call for a specific file system, such as read_inode and sync_fs.
2) inode_operations object: contains the kernel's methods for calling specific files, such as create and link methods.
3) dentry_operations object: contains the methods that the kernel can call for a specific directory system, such as d_compare and d_delete.
4) file_operations object: contains the methods that the process can call to open files, such as read and write methods.

 

4.1. Super block object
All file systems must implement Super blocks. This object is used to store information of a specific file system, usually corresponding to the file system super block or file system control block stored in a specific disk sector. For non-disk-based file systems (memory-based file systems, such as sysfs), they will create Super blocks in use and save them to the memory.
A super block object is represented by a super_block struct and is defined in <Linux/fs. h>. Code for creating, managing, and destroying a super block object is located in file fs/super. C. Super block objects are created and initialized using the alloc_super () function. During file system installation, the kernel will call this function to read the file system superblock from the disk and fill in its information to the super block object in the memory.
The most important field in a super block object is s_op, which points to the super block operation function table. The superblock operation function table is represented by the super_operations struct and is defined in <Linux/fs. h>.
For example, if a file system needs to write its own super block, it needs to call:
Sb-> s_op-> write_super (SB );
Note: although the write_super method comes from the super block, you must pass the super block as a parameter during calling. This is because the C language lacks object-oriented support.

 

4.2. Index Node object
The index Node object contains all the information required by the kernel for operating files or directories. For Unix-style file systems, this information can be directly read from the disk index node.
The index Node object is represented by an inode struct and is defined in the <Linux/fs. h> file. An index node represents a file in the file system. It allows devices or special files such as pipelines. The index node is created in the memory only when files are accessed.
The inode_operations object in the index Node object is very important because it describes all the methods that VFS uses to operate on the index Node object.

 

 

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.