上文我们说到了mount系统调用(简称sys_mount),下面我们就从sys_mount开始往下分析mount的过程
sys_mount - > do_mount
do_mount函数也在namespace.c里可以找到,如下:
long do_mount(const char *dev_name, const char *dir_name,
const char *type_page, unsigned long flags, void *data_page)
{
struct path path;
int retval = 0;
int mnt_flags = 0;
/* Discard magic */
if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
flags &= ~MS_MGC_MSK;
/* Basic sanity checks */
if (!dir_name || !*dir_name || !memchr(dir_name, 0, PAGE_SIZE))
return -EINVAL;
if (data_page)
((char *)data_page)[PAGE_SIZE - 1] = 0;
// 把mountpoint解释成path内核结构,这里是路径名解析的过程
// 调用do_path_lookup。关于路径名解析我们后面再说
/* ... and get the mountpoint */
retval = kern_path(dir_name, LOOKUP_FOLLOW, &path);
if (retval)
return retval;
retval = security_sb_mount(dev_name, &path,
type_page, flags, data_page);
if (!retval && !may_mount())
retval = -EPERM;
if (re

本文详细分析了Linux系统中mount过程,尤其是do_mount和do_new_mount函数。do_mount主要负责解析路径和flags,而do_new_mount则涉及查找文件系统类型并执行挂载操作,构建vfsmount信息,最终加入全局文件系统树。通过这些步骤,系统能完成新文件系统的挂载。
最低0.47元/天 解锁文章
5053

被折叠的 条评论
为什么被折叠?



