Linux file system architecture and Virtual file system (VFS)

Source: Internet
Author: User

Figure 1. Architecture of Linux File system components

The user space contains applications (for example, the users of the file system) and the GNU C Library (GLIBC), which provide a user interface for file system calls (open, read, write, and close). The system invocation interface acts like a switch that sends system calls from the user space to the appropriate endpoints in the kernel space.

VFS is the primary interface for the underlying file system. This component exports a set of interfaces and then abstracts them into individual file systems, and the behavior of individual file systems can vary greatly. There are two caches (Inode and Dentry) for file system objects. They cache recently used file system objects.

  sync   The command sends the request in the buffer cache to the storage media (forcing all the uncommitted data to be sent to the device driver, which is then sent to the storage device).

What is a block device?
Block devices are devices that send and receive data in blocks, such as disk sectors, that support features such as Buffering and random access (without having to read blocks sequentially, but to access any block at any time). Block devices include hard disks, CD-ROM, and RAM disks. In contrast to a block device, a character device has no media that can be physically addressed. Character devices, including serial ports and tape devices, can read data from these devices in a verbatim manner.

This is the top-level scenario for VFS and file system components. Now, discuss the main structure of implementing this subsystem.

Main structure

Linux treats all file systems in the perspective of a common set of objects. These objects are super blocks (superblock), Inode, Dentry, and files. The super Block describes and maintains the state of the file system on the root of each filesystem. Each object (file or directory) that is managed in the file system is represented as an inode in Linux. The inode contains all the metadata that is required to manage the objects in the file system, including the operations that can be performed on the object. Another set of structures, called dentry, is used to implement mappings between names and Inode, and a directory cache is used to hold the most recently used Dentry. Dentry also maintains the relationship between directories and files, which supports moving through the file system. Finally, the VFS file represents an open file (the state of the open file is saved, such as the write offset, and so on).

Virtual file system Layer

The VFS acts as the root layer of the file system interface. The VFS records the currently supported file systems and the currently mounted file systems.

You can use a set of registration functions to dynamically add or remove file systems in Linux. The kernel saves a list of currently supported file systems, which can be viewed in user space through the/proc file system. This virtual file also displays the devices that are currently associated with these file systems. The method of adding a new file system to Linux is called register_filesystem . The parameter of this function defines a reference to a file system structure () that defines the name of the file_system_type file system, a set of properties, and two super-block functions. You can also unregister the file system.

When registering a new file system, the file system and its related information are added to the File_systems list (see Figures 2 and linux/include/linux/mount.h). This list defines the file systems that can be supported. cat /proc/filesystems You can view this list by typing it on the command line.


Figure 2. File systems registered to the kernel

Another structure maintained in the VFS is the mounted file system (see Figure 3). This structure provides the currently mounted file system (see LINUX/INCLUDE/LINUX/FS.H). It links the Super block structure discussed below.


Figure 3. List of mounted file systems

Super Block

The super block structure represents a file system. It contains the information required to manage the file system, including file system names (such as ext2), file system size and status, block device references and metadata information (such as free lists, and so on). A super block is typically stored on a storage medium, but it can be created in real time if the Super block does not exist. You can find the Super block structure in the./linux/include/linux/fs.h (see Figure 4).


strong> Figure 4. Super block structure and inode operation  
 

  alloc_inode   destroy_inode   delete inode. Can be used   read_inode   and write_inode   Read and write Inode, with   sync_fs   Perform file system synchronization. You can find   in./linux/include/linux/fs.h, super_operations   structure. Each file system provides its own Inode method, which implements the operation and provides a common abstraction to the VFS layer.

Inode and Dentry

The inode represents an object in the file system that has a unique identifier. Each file system provides a way to map file names to unique inode identifiers and Inode references. Figure 5 shows a portion of the inode structure and two related structures. Please pay special attention inode_operations and file_operations . These structures represent the operations that can be performed on this inode. inode_operations defines the operations that are performed directly on the Inode, and file_operations defines the methods associated with files and directories (standard system calls).


Figure 5. Inode structure and associated operations

The inode and the directory cache each hold the most recently used Inode and Dentry. Note that for each inode in the inode cache, there is a corresponding dentry in the directory cache. Can be found inode and dentry structured in./linux/include/linux/fs.h.

Buffer cache

In addition to the individual file system implementations (which can be found in./linux/fs), the bottom of the file system layer is the buffer cache. This component tracks read and write requests from the file system implementation and physical devices (through device drivers). To improve efficiency, Linux caches requests to avoid sending all requests to physical devices. The most recently used buffers (pages) are cached in the cache, which can be quickly provided to individual file systems.

Linux file system architecture and Virtual file system (VFS)

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.