sys_mount - > do_mount -> do_new_mount -> vfs_kern_mount
vfs_kern_mount的作用就是准备好一个完整的mount结构。
vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
{
struct mount *mnt;
struct dentry *root;
if (!type)
return ERR_PTR(-ENODEV);
// alloc一个新的struct mount结构,并初始化里面一部分(如链表指针、mnt_devname等成员内容)
mnt = alloc_vfsmnt(name);
if (!mnt)
return ERR_PTR(-ENOMEM);
if (flags & MS_KERNMOUNT)
mnt->mnt.mnt_flags = MNT_INTERNAL;
// 调用具体文件系统的mount回调函数type->mount,继续挂载操作
root = mount_fs(type, flags, name, data);
if (IS_ERR(root)) {
mnt_free_id(mnt);
free_vfsmnt(mnt);
return ERR_CAST(root);
}
// 完成mnt结构的最后赋值,并返回vfsmount结构
mnt->mnt.mnt_root = root;
mnt-