Linux file system call (1)---Mount

Source: Internet
Author: User
Tags dashed line tmp folder

List of terms:

struct Mount : mount point

struct Mountpoint: mount point Node

struct Vfsmount : Mount Item

Source file system: The file system that the user is going to mount

Destination file system: file system for mounting the source file system


first, the purpose

???? This article will introduce Linux the process of mounting the file system. From the system call Mount() function begins parsing, divided into three stages:

???? 1 , new source file system;

???? 2 , locate the destination file system mount folder;

???? 3 , attach the source file system to the Mount folder of the destination file system;

???? this article to Linux 3.10 The version number is based on the explanation.


Second, function call relationship

< Span lang= "en-us" xml:lang= "en-us" >???? Mount fs/namespace.c Span style= "font-family: ' AR PL UKai CN ';" > file, the specific definition is: syscall_ DEFINE5 (Mount,char __user *, Dev_name, Char __user *, Dir_name, char __user *,type, unsigned long, flags, void __user *, D ATA)

/span>dev_name Span style= "font-family: ' AR PL UKai CN ';" The device path is defined, di_name defines the mount folder; < Span lang= "en-us" xml:lang= "en-US" >type Defines the file system type; flags data Span style= "font-family: ' AR PL UKai CN ';" > defines some of the options content.

We focus on the first three parameters, and the latter two are not at the moment of concern.

???? description describes the basic function call relationship, L Inux The mount file system is divided into three main stages:

???? 1 , Vfs_kern_mount () responsible for creating the source file system;

???? 2 , Lock_mount () responsible for locating the mounted folder in the destination file system.

???? 3 , Graft_tree () responsible for mounting the source file system to the mounted folder on the destination file system;




Iii. Document System of Purpose

for the sake of descriptive narration, if the current system has been mounted ext2 file system (i.e., destination file system), tmp The folder will be the Mount folder of the destination file system.

"???? " Below we are going toext3file system mounts toext2of thetmpon the Mount folder, the command used isMount (/DEV/SDA1,/tmp,? ext3)(Omit theFlagsand theDatanumber of references).

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvbhvvbw93zwlsyw4=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast "/>


iv. New source file system

? ??? firstDo_mount ()->do_new_mount ()->vfs_kern_mount ( )based ontypeparameter specifies the file system type, creating a newext3file System. There is a need to focus on. Vfs_kern_mount ()->moutn_fs ( )based on the actual file system of the Super blockMountcallback hook function to populate the Super block and file system content (to simplify, the diagram simply gives the simplestext3file system, that is, only the root folder).

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvbhvvbw93zwlsyw4=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast "/>


v. Find the Mount folder and create a Mount node? ? ? ? The function of Do_mount ()->do_new_mount ()->do_add_mount ()->lock_mount () is to recursively find the last mounted folder. The code here is more difficult to understand, so the following will be described in detail.
? ? ? ? Linux agrees to mount multiple file systems on mounted folders, and subsequent mounted file systems will "overwrite" the file systems that are mounted before. For example, the Minix file system mounts to the TMP Mount folder of the Ext3 file system, the NFS file system mounts to the Minix file System/Mount folder, and finally the LS command will only be able to see the NFS file system, and Minix is "overwritten" by NFS.


? ? ? ? Of The TMP folder points to the Minix mount point with a red dashed line representing only the logical relationship, which does not actually exist for the Linux use < mount point. Mount folder > Two tuples as a hash factor form the table entry of the hash table mount_hashtable. Used to locate a file system that has been mounted. Like what. Minix mount to Ext3 's TMP folder, then Linux is based on <EXT3, tmp> two tuples form the hash table entry. and record Minix to <ext3, tmp> in the list of hash table entries. When it is necessary to find out which file system is mounted under the TMP folder of Ext3, it can find the corresponding hash table item according to <EXT3, tmp> two tuples, and then find the corresponding mounted file system Minix.




? ? ? ? With the above foundation, we look back at the function of Lock_mount (). Lock_mount () first finds the mounted Minix file system based on the current <EXT3, tmp> two tuples, and then finds the mounted NFS file system based on <minix,/> two tuples. When the last file system is found, call New_mountpoint () from the root folder of NFS to create a Mount node (due to Minix and NFS mounts to the same mounted folder tmp. So the Mount node has been created when Minxi is mounted. So, in fact, NFS shared the Minix Mount node, just the mount count of the Mount node plus 1.
? ? ? ? The following goes back to the fourth section describing the narrative, as the current filesystem only exists for the ext2 file system. therefore Lock_mount () will create a Mount node based on the Ext2 Mount folder tmp call New_mountpoint (), and attach the Mount node to the Mount folder tmp, mount Count plus 1. Finally, the Mount node is added to the mountpoint_hashtable hash table (the hash table uses the Mount folder TMP as the hash factor).




VI. Mount source file System

???? Do_mount ()->do_new_mount ()->do_add_mount ()->graft_tree ()responsible for the new source file systemext3Mount to the Mount node. Mnt_set_mountpoint ()responsible for pointing the source file system to the Mount node. Commit_tree ()responsible for the source file systemext3increased tomount_hashtablethe hash table. (Note: The parent-child relationship between the destination file system and the source file system is omitted in the illustration)

watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvbhvvbw93zwlsyw4=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast "/>


Vii. Summary

? ??? Linux mount file system is divided into three stages: Create a source file system, find the destination file system finally Mount folder and create Mount node. Finally, the source file system is associated to the Mount node.


Copyright Notice:The original works, such as non-commercial reprint, please indicate the source. If the publication is commercially reproduced, please contact the author.


Linux file system call (1)---Mount

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.