Linux Virtual file System Vfs__linux

Source: Internet
Author: User
Tags file copy


Perfect coexistence with other systems is one of the successes of Linux, where Linux can transparently mount disks or partitions in other system file formats, such as Windows FAT32, NTFS, and so forth;


Linux uses the virtual filesystem Switch to support multiple types of file systems.
The idea of VFS is to store different types of file system information in the kernel, and each operation supported by all Linux file systems has a domain that corresponds to the kernel replacing the domain with a specific file system when read, write, or other function calls.
If Ext4_file_open represents a EXT4 file open operation, Ntfs_file_open represents an NTFS file open operation; domain open represents file-open operations for all file systems, replacing open to Ext4_file_ when opening EXT4 file system files Open, when you open the NTFS file system file, replace Open with Ntfs_file_open, which enables a unified interface open to file files with different format file systems.

I.vfs function
VFS provides a unified interface for different file systems, separating file system-related system calls from specific file system operations, and systems calling files that manipulate specific file systems through VFS.

For example, use the following command:

$ cp/floppy/test/tmp/test

/floppy is the mount point for the MS-DOS disk,/tmp is the EXT2 directory, because the VFS is the abstraction layer between the system call (application) and the file system implementation, so the CP does not need to know the file system type of/floppy/test and/tmp/test and only interacts with the VFS.
The VFS functions as shown in the file copy process:

I. Common file model
VFS uses a common file model to represent all file systems, and all file system implementations must convert their physical structure to the VFS common file model.
For example, the common file model treats a directory as a file of system files and directories, but some non-UNIX file systems use FAT to store files in the directory tree, which are not files; In order to follow the common file model, The FAT based file system must construct the corresponding files for the directory (these files exist only in kernel memory).

The kernel cannot hard-code a function to handle operations such as READ,IOCTL, and it must use pointers to the corresponding functions of the specific file system to implement these operations.
If the system calls read, the kernel invokes Sys_read, which in turn invokes the read operation of file, File->f_op->read (...), and F_op is the pointer to a specific file system file operation, so that the file can be manipulated using a unified file system interface.
In some cases, VFS can do file operations on its own without relying on the underlying specific file system; If you close open files, VFS simply frees up the file object in memory without requiring disk file manipulation, and Lseek simply changes the pointer in the file object and does not require disk file manipulation. Therefore, the VFS can be used as a common file system, and the VFS will use the specific file system if necessary.

The common file model can be regarded as object-oriented, and the object-oriented programming is realized by using the structure with data and function pointers.
The common file model mainly has the following object types:
Superblock: Save mounted file system information; disk-based file system, Superblock usually corresponds to the file system control block on the disk
Dentry: Stores the information associated with a directory entry and file; a disk-based file system that saves that information in different ways
Inode: The information to save the file; a disk-based file system where the inode usually corresponds to a file control block; Each inode has a unique inode number that identifies the file on the file system.
File: Saves interaction information between processes and open files; file objects are only available in kernel memory when the process opens the files
The following diagram illustrates the relationships between these objects when the process is manipulating files:

Three processes open the same file, and two hard connections point to the file (two directory entries point to the file), where two processes use one of the hard connections, and the other process uses another hard connection.
Each process uses its own file object, 2 Hard connections use 2 Dentry objects, 2 dentry use the same inode;inode to identify the superblock, and the disk files are identified with Superblock.

II. Cache acceleration
In addition to providing a unified file system interface, VFS also plays an important role in system performance.
1. Place the most recently used Dentry object in the Dentry cache to speed up the search of files;
2. Save the contents of the file in the page cache to speed up file operation;

Ii. VFS Data structure
The VFS object is stored in the corresponding data structure, contains both object attributes and object method list pointers, and the kernel dynamically modifies object method list pointers to implement the object polymorphism.
The following figure is the main object structure involved in the VFS and the relationship between them:

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.