歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> linux系統中mount樹結構與遍歷

linux系統中mount樹結構與遍歷

日期:2017/2/28 17:48:04   编辑:Linux教程
linux中,vfsmount結構記錄掛載文件系統。其數據成員mnt_parent指向該文件系統的父文件系統, mnt_mounts是孩子文件系統的鏈頭部,mnt_child指向兄弟結點
例如 系統的根文件系統是ext3格式,在/mnt/winc /mnt/wind /mnt/wine 目錄上分別掛載三個分區(可以認為是windows下的c d e 盤)。這樣系統就為新掛載的三個文件系統分別分配了vfsmount結構,並將其 mnt_parent 指向根文件系統的vfsmount結構,通過mnt_child鏈入跟文件系統vfsmount的mnt_mounts 鏈表,初始化mnt_mounts指向自身.
內核代碼中,對一特定vfsmount為根的mount樹遍歷,用到了先根遍歷算法:
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);
}
Copyright © Linux教程網 All Rights Reserved