Mount tree structure and traversal in linux

Source: Internet
Author: User
In linux, mount tree structure and traversal-Linux general technology-Linux programming and kernel information. The following is a detailed description. In linux, The vfsmount structure record is mounted to the file system. Its data member mnt_parent points to the parent File System of the file system, mnt_mounts is the head of the Child file system chain, mnt_child points to the sibling Node

For example, the system's root file system is in the ext3 format, mount three partitions in the/mnt/winc/mnt/wind/mnt/wine directory (which can be considered as a c d e disk in windows ). In this way, the system allocates a vfsmount structure for the three newly mounted file systems, points the mnt_parent to the vfsmount structure of the root file system, and links it to the mnt_mounts linked list of the file system vfsmount through mnt_child, initialize mnt_mounts to point to itself.

In the kernel code, the first root traversal algorithm is used to traverse the mount tree with a specific vfsmount as the root:

Static struct vfsmount * next_mnt (struct vfsmount * p, struct vfsmount * root)
{

Struct list_head * next = p-> mnt_mounts.next;
If (next ==& p-> mnt_mounts ){
While (1 ){
If (p = root)
Return NULL;
Next = p-> mnt_child.next;
If (next! = & P-> mnt_parent-> mnt_mounts)
Break;
P = p-> mnt_parent;
}
}
Return list_entry (next, struct vfsmount, mnt_child );
}

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.