Kernel Learning: A layered approach to discussing Linux file systems

Source: Internet
Author: User
Tags file system linux

A file system is a mechanism for organizing data and metadata on a storage device. The Linux file system interface is implemented as a layered architecture that separates the user interface layer, the file system implementation, and the driver of the operating storage device. Another way to look at a file system is to think of it as a protocol. Network protocols, such as IP, specify the meaning of the data stream that is transmitted over the Internet, and the file system gives the meaning of the data on a particular storage medium.

The Linux file system architecture is an interesting example of abstracting complex systems. By using a common set of API functions, Linux can support many kinds of file systems on many types of storage devices. For example, the Read function call can read a certain number of bytes from the specified file descriptor. The read function does not understand the type of file system, such as ext3 or NFS. It also does not understand the storage media in which the file system resides, such as ATAPI disks, SAS disks, or SATA disks. However, when you read a file by calling the Read function, the data returns normally.

Although most file system code is in the kernel, the architecture shown in Figure 1 shows the relationship between user space and the main file system-related components in the kernel.

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 call interface acts like a switch that sends system calls from user space to the appropriate endpoints in the kernel space.

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

Each file system implementation (such as ext2, JFS, and so on) exports a common set of interfaces for use by the VFS. The buffer cache caches requests between the file system and the associated block devices. For example, read-write requests to the underlying device driver are passed through the buffer cache. This allows the request to be cached, reducing the number of accesses to the physical device and speeding the access rate. Manages the buffer cache in the form of a recently Used (LRU) list. Note that you can use the Sync command to send a request in the buffer cache to the storage media (forcing all the unread data to be sent to the device driver and then to the storage device).

Linux treats all file systems as a common set of objects. These objects are super blocks (superblock), Inode, Dentry, and files. Super blocks at the root of each filesystem, the Super Block describes and maintains the state of the file system. 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 actions that can be performed on the object. Another set of structures, called dentry, are used to map the name to the Inode, and a directory cache is used to hold the most recently used Dentry. Dentry also maintains the relationship between directories and files to support 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).

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

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

Linux/include/linux/fs.h

struct File_system_type {
	const char *name;
	int fs_flags;
	Int (*GET_SB) (struct file_system_type *, int,
		       const char *, void *, struct vfsmount *);
	struct Dentry * (*mount) (struct file_system_type *, int,
		       const char *, void *);
	void (*KILL_SB) (struct super_block *);
	struct module *owner;
	struct File_system_type * next;//form list
	struct list_head fs_supers;

	struct Lock_class_key s_lock_key;
	struct Lock_class_key s_umount_key;
	struct Lock_class_key s_vfs_rename_key;

	struct Lock_class_key i_lock_key;
	struct Lock_class_key i_mutex_key;
	struct Lock_class_key i_mutex_dir_key;
	struct Lock_class_key i_alloc_sem_key;

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.