Virtual file system VFS for Linux

Source: Internet
Author: User

Virtual file system, an alias virtual file system switch, is a software layer in Linux that provides a file system operation interface to user space.

The system calls that the VFS contains include open (2), stat (2), read (2), write (2), chmod (2), and so on, which are executed in the process environment. The following important data structures are the VFS (the data structures involved in the virtual file system):

1. Directory Entry Cache (dcache)

The VFS implements system calls to open (2), stat (2), chmod (2), and other similar file system calls. The parameters used in these system calls are used by VFS for the directory entry cache object search, where the directory entry cache has multiple names, such as Dentry cache or Dcache. The Dentry cache provides a quick find mechanism to quickly find specific dentry based on the path name. In particular, Dentry is present in memory and is not persisted to disk for permanent storage.

2. Inode Object

Each of the Dentry objects has a pointer to the specific Inode object. The inode is a file system object, such as a regular file (regular files), directory, FIFO (pipeline). These Inode objects exist on disk (block device file system) or memory (pseudo file system Procfs under Linux). If the Inode object exists on the disk, it needs to be loaded into memory, and when the change occurs, it needs to be saved to disk. An Inode object may have multiple Dentry objects pointing to it (because the hard-connect feature is implemented under Linux).

In order to find a specific Inode object, you need to perform a lookup operation on the inode of the parent directory. The specific lookup method is implemented by the file system that is stored in the inode, which is initialized by the specific file system. Once the VFS has a specific Dentry object, many system calls can be completed quickly, such as the stat (2) system call, which is to obtain data on the inode, according to the pointer on the dentry can quickly find the Inode object.

3. File Object

Another operation is required to open a file: An object that allocates a file structure (this is the implementation of the files descriptor on the Linux kernel side). The newly requested file object Initializes a pointer to the Dentry object and multiple file manipulation functions (such as read, write, mmap, and so on). The file data structure is placed in the document description table of the Process (descriptor table).

User-space Read, write, and so on are the user space State (userspace file descriptor) descriptor to obtain the correct file structure, and then call the file structure of the specific method. As long as the file is open, there is a corresponding Dentry object in the Linux kernel, and naturally there are inode objects for the object.

4. File system Objects (filesystem)

Registering and uninstalling a file system uses the following function call.

#include <linux/fs.h>


externintRegister_filesystem (structFile_system_type *);

      extern int struct  

The incoming parameter struct File_system_type describes the specific file system. When a command is issued that requires a file system to be mounted on a directory in your namespace, the VFS invokes the Mount method in the specific file. When the mount operation is complete, a struct Dentry object is returned, and a new Vfsmount object is created to point to the Dentry object, and the Vfsmount object is added to the mount point. So when the path resolution arrives at this directory, it jumps to the file system that the Vfsmount points to.

All mounted file systems can be observed under/proc/filesystems.

The following is the FILE_SYSTEM_TYPE structure:

struct File_system_type {

ConstChar*name;
intFs_flags;
structDentry * (*mount) (structFile_system_type *,int,
ConstChar*,void*);
void(*KILL_SB) (structSuper_block *);
structModule *owner;
structFile_system_type * NEXT;
structList_head fs_supers;
structLock_class_key S_lock_key;
structLock_class_key S_umount_key;

    };

Name: File system names, currently supported file names are "ext2", "ext3", "Ext4", "Msdos" and so on

fs_flags: Some signs, such as: Fs_requires_dev, Fs_no_dcache

Mount: An important field that requires a specific filesystem mount method when an filesystem is instantiated

5. Superblock Object

A superblock (Super Block) object represents a mounted file system.

Here is a data structure for the operation of the Super Block:

struct super_operations {

structInode * (*alloc_inode) (structSuper_block *SB);
void(*destroy_inode) (structInode *);
void(*dirty_inode) (structInode *,intFlags);
int(*write_inode) (structInode *,int);
void(*drop_inode) (structInode *);
void(*delete_inode) (structInode *);
void(*put_super) (structSuper_block *);
int(*SYNC_FS) (structSuper_block *SB,intWait);
int(*FREEZE_FS) (structSuper_block *);
int(*UNFREEZE_FS) (structSuper_block *);
int(*STATFS) (structDentry *,structKstatfs *);
int(*REMOUNT_FS) (structSuper_block *,int*,Char*);
void(*clear_inode) (structInode *);
void(*umount_begin) (structSuper_block *);
int(*show_options) (structSeq_file *,structDentry *);
ssize_t (*quota_read) (structSuper_block *,int,Char*, size_t, loff_t);
ssize_t (*quota_write) (structSuper_block *,int,ConstChar*, size_t, loff_t);
int(*nr_cached_objects) (structSuper_block *);
void(*free_cached_objects) (structSuper_block *,int);

};

All methods are not maintained by lock, which means that these methods can only be executed in the context of a process and cannot be executed in the context of an interrupt.

6. Address space object

The Address_space object is used to group and manage the page in page cache. It can be used to keep track of a file in the page cache and in a file that is mapped to a file region in the process address space.

Address space provides a number of distinctive features, such as page tracking for dirty or writeback based on the location of the page.

Further Reading:

1.Creating Linux virtual filesystems. 2002. http://lwn.net/Articles/13325/

2. A Tour of theLinux VFS by Michael K. Johnson. 1996. http://www.tldp.org/LDP/khg/HyperNews/get/fs/vfstour.html

Virtual file system VFS for Linux

Related Article

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.