Linux file system call (1)---Mount

Source: Internet
Author: User
Tags dashed line

List of terms:

struct Mount : mount point

struct Mountpoint mount point Node

struct Vfsmount : Mount Item

The file system that the source file system user will mount

File system of the destination file system mounted source file system


first, the purpose

This article will introduce Linux the process of mounting a file system from a system call Mount() The function begins to parse and is divided into three stages:

1 , new source file system;

2 , find the Mount directory of the destination file system;

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

This article takes Linux 3.10 version is the basis for the explanation.


Second, function call relationship

< Span lang= "en-us" >        Mount system calls are defined in fs/namespace.c file, specifically defined as: Syscall_define5 (Mount,char __user *, Dev_name, Char __user *, Dir_name, char __user *,type, unsigned long, flags, void __u SER *, data)

< Span lang= "en-us" >         where dev_name defines the device path; di_name defines the mount directory; type flags and data Defines some of the options content. We focus on the first three parameters, the last two parameters are not currently concerned.

describes the main function call relationships, 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 mount directory in the destination file system;

3 , Graft_tree () responsible for mounting the source file system on the Mount directory of the destination file system;




Iii. Document System of Purpose

for the sake of description, we assume that the current system has been mounted ext2 file system (i.e., destination file system), tmp The directory will be the mount directory of the destination file system.

below we are going toext3file system mounts toext2of thetmpon the Mount directory, the command used isMount (/DEV/SDA1,/tmp, EXT3)(Omit theFlagsand theDataparameters).



iv. New source file system

FirstDo_mount ()->do_new_mount ()->vfs_kern_mount ( )according totypeparameter specifies the file system type, creating a newext3file System. It is important to focus on theVfs_kern_mount ()->moutn_fs ( )based on the actual file system of the Super blockMountcallback hook function, populate the Super block and file system content (to simplify, the diagram gives only the simplestext3file system, which is the root directory only).



v. Find the Mount directory and create a Mount nodeThe function of Do_mount ()->do_new_mount ()->do_add_mount ()->lock_mount () is to recursively find the final mount directory, where the code is more difficult to understand, so the following will be described in detail.
Linux allows mounting of multiple file systems on mounted directories, and later mounted file systems will "overwrite" the file systems that were mounted before. For example, the Minix file system mounts to the TMP mount directory of the Ext3 file system, the NFS file system mounts to the/mount directory of the Minix file system, and the end use of the LS command will only see the NFS file system, and Minix is "overwritten" by NFS.
Where the TMP directory points to the Minix mount point of the red dashed line only represents a logical relationship, there is no such a point of contact, Linux use < mount point, mount directory > Two tuples as a hash factor form the hash table mount_hashtable, Used to locate a file system that has been mounted. For example, Minix mounts to the TMP directory of ext3, then Linux is based on &LT;EXT3, tmp> two tuples form a hash table entry, and Minix is recorded to <ext3, tmp> the list of items in the Hashtable. When you need to find out which file system is mounted under the TMP directory of ext3, you can find the corresponding Hashtable entry according to &LT;EXT3, tmp> two tuples, and then locate the corresponding mounted file system Minix.


With the above foundation, we look back to Lock_mount () function, Lock_mount () first based on the current &LT;EXT3, tmp> Two tuples found mounted Minix file system, and then according to <minix,/> Binary finds the mounted NFS file system, and when the last file system is found, the Mount node is created according to the root directory of the NFS call New_mountpoint () (Because Minix and NFS mount to the same Mount directory TMP, so the Mount node is created when the Minxi is mounted) , so in fact NFS shared the Minix Mount node, just the mount count of the mounted nodes plus 1).
Continue with the scenario described in section Fourth below, because only the ext2 file system exists in the current file system, so Lock_mount () will create a Mount node based on EXT2 's mount directory tmp call New_mountpoint (), and point the Mount node to the Mount directory TMP, Mount Count plus 1, and finally add the Mount node to the Mountpoint_hashtable hash table (the hash table uses the Mount directory 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 systemext3added tomount_hashtablethe hash table. (Note: The parent-child relationship between the destination file system and the source file system is omitted in the illustration)



Vii. Summary

Linux The mount file system is divided into three stages: creating a source file system, locating the final mount directory of the destination file system and creating the Mount node, and finally associating the source file system to the Mount node.


Copyright Notice:original works, such as non-commercial reprint, please specify the source, such as commercial reprint publication, 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.