Virtual File System (VFS), Virtual File System (vfs)

Source: Internet
Author: User

Virtual File System (VFS), Virtual File System (vfs)

Link: http://www.orlion.ga/1008/

Linux creates an abstraction layer on top of different file systems, making concepts such as files, directories, and read/write access an abstraction layer. This abstraction layer is called a Virtual File System (VFS ).

The VFS subsystem of the Linux kernel is as follows:

Each Process stores a file descriptor table in the Process Control Block (PCB). The file descriptor is the index of this table. Each table item has a pointer to an opened file, an open file is represented by a file struct in the kernel. the pointer in the file descriptor table points to the file struct.

Maintain the file Status Flag (f_flags) and current read/write position (f_pos) in the File struct ). In process 1 and process 2 both open the same file, but corresponding to different File structures, so there can be different file Status Flag and read/write locations. The file struct also has a member f_count, indicating Reference Count. If two file descriptors point to the same file struct, the Reference Count is 2. When close () when a file descriptor is used, the file struct is not released, but the reference count is reduced to 1. When a file descriptor is closed, the reference count is changed to 0, and the file struct is released. Actually close the file.

Each file structure points to a file_operations struct. The members of this struct are function pointers pointing to kernel functions that implement various file operations. For example, read a file descriptor in the user program. read enters the kernel through a system call, finds the file struct pointed to by this file descriptor, and finds the file_operations struct pointed to by the file struct, call the kernel function pointed to by the read member to complete the user request. For general files opened on the same file system, the steps and methods for file operations such as read and weite should be the same, and the called functions should be the same, therefore, the file structure of the three open files in the figure points to the same file_operation structure. It is different if the opened files are non-conventional files. Each file structure has a pointer to the dentry struct. "dentry" is the abbreviation of directory entry. Parameters passed to functions such as open and stat are a path, for example,/home/orlion/a. inode of the file needs to be found based on the path. To reduce the number of disk reads, the kernel caches the tree structure of the Directory, which is called the dentry cache. Each node is a dentry struct, and you only need to search for the dentry of each part of the path, find the home directory from the root directory/, find the orlion directory, and find file. The dentry cache only saves the recently accessed directory items. If the directory items to be searched are not found in the cache, they must be read from the disk to the memory.

Each dentry structure has a pointer pointing to the inode structure. The inode struct stores the Information read from the disk inode. There are two dentry, indicating/home/akaedu/a and/home/akaedu/B respectively. They all point to the same inode, indicating that the two files are hard links. Inode struct stores the inode read information from the disk partition, such as the owner, file size, file type, and permission bit. Each inode structure has a pointer to the inode_operations struct, which also points to some kernel functions that complete file directory operations. Unlike file_operations, inode_operations points to functions that affect the layout of files and directories, such as adding and deleting files and directories, and tracking symbolic links, inode structs belonging to the same file system can point to the same inode_operation struct.

The inode struct has a pointer to the super_block struct. The super_block struct stores the Information read from the ultra-fast disk partition, such as the file system type and block size. The s_root Member of the super_block struct is a pointer to dentry, indicating where the root directory of the file system is mounted.

The structures file, dentry, inode, and super_block constitute the core concepts of VFS.

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.