免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 743 | 回复: 0
打印 上一主题 下一主题

linux中mount树结构及遍历 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-04-22 11:51 |只看该作者 |倒序浏览

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);
}


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/36646/showart_283571.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP