Chinaunix首页 | 论坛 | 博客
  • 博客访问: 434254
  • 博文数量: 99
  • 博客积分: 65
  • 博客等级: 民兵
  • 技术积分: 1012
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-20 16:30
个人简介

linux kernel 工程师

文章分类

全部博文(99)

文章存档

2018年(5)

2017年(12)

2016年(27)

2015年(10)

2014年(43)

2012年(2)

我的朋友

分类: LINUX

2016-12-27 19:03:21

在sys_mount的调用过程中,会调用到vfs_kern_mount
调用关系如下:
sys_mount  
    ->do_mount
        ->do_new_mount
           ->do_kern_mount
                ->vfs_kern_mount

在proc_fs中也会调用vfs_kern_mount

点击(此处)折叠或打开

  1. void __init proc_root_init(void)
  2. {
  3.     ...
  4.     proc_mnt = kern_mount_data(&proc_fs_type, &init_pid_ns);
  5.     ...
  6. }

  7. struct vfsmount *kern_mount_data(struct file_system_type *type, void *data)
  8. {
  9.     return vfs_kern_mount(type, MS_KERNMOUNT, type->name, data);
  10. }

点击(此处)折叠或打开

  1. struct vfsmount *
  2. do_kern_mount(const char *fstype, int flags, const char *name, void *data)
  3. {
  4.     struct file_system_type *type = get_fs_type(fstype);
  5.     struct vfsmount *mnt;
  6.     if (!type)
  7.         return ERR_PTR(-ENODEV);
  8.     mnt = vfs_kern_mount(type, flags, name, data);
  9.     if (!IS_ERR(mnt) && (type->fs_flags & FS_HAS_SUBTYPE) &&
  10.      !mnt->mnt_sb->s_subtype)
  11.         mnt = fs_set_subtype(mnt, fstype);
  12.     put_filesystem(type);
  13.     return mnt;
  14. }


点击(此处)折叠或打开

  1. struct vfsmount *
  2. vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
  3. {
  4.     struct vfsmount *mnt;
  5.     char *secdata = NULL;
  6.     int error;

  7.     if (!type)
  8.         return ERR_PTR(-ENODEV);
  9.     /* 分配一份vfsmount结构 */
  10.     error = -ENOMEM;
  11.     mnt = alloc_vfsmnt(name);
  12.     if (!mnt)
  13.         goto out;

  14.     if (flags & MS_KERNMOUNT)
  15.         mnt->mnt_flags = MNT_INTERNAL;

  16.     if (data && !(type->fs_flags & FS_BINARY_MOUNTDATA)) {
  17.         secdata = alloc_secdata();
  18.         if (!secdata)
  19.             goto out_mnt;

  20.         error = security_sb_copy_data(data, secdata);
  21.         if (error)
  22.             goto out_free_secdata;
  23.     }
  24.     /* 读取超级块
  25.        procfs对应的函数是proc_get_sb
  26.      */
  27.     error = type->get_sb(type, flags, name, data, mnt);
  28.     if (error < 0)
  29.         goto out_free_secdata;
  30.     BUG_ON(!mnt->mnt_sb);
  31.     WARN_ON(!mnt->mnt_sb->s_bdi);
  32.     WARN_ON(mnt->mnt_sb->s_bdi == &default_backing_dev_info);
  33.     mnt->mnt_sb->s_flags |= MS_BORN;

  34.     error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
  35.     if (error)
  36.         goto out_sb;

  37.     /*
  38.      * filesystems should never set s_maxbytes larger than MAX_LFS_FILESIZE
  39.      * but s_maxbytes was an unsigned long long for many releases. Throw
  40.      * this warning for a little while to try and catch filesystems that
  41.      * violate this rule. This warning should be either removed or
  42.      * converted to a BUG() in 2.6.34.
  43.      */
  44.     WARN((mnt->mnt_sb->s_maxbytes < 0), "%s set sb->s_maxbytes to "
  45.         "negative value (%lld)\n", type->name, mnt->mnt_sb->s_maxbytes);

  46.     mnt->mnt_mountpoint = mnt->mnt_root;
  47.     mnt->mnt_parent = mnt;
  48.     up_write(&mnt->mnt_sb->s_umount);
  49.     free_secdata(secdata);
  50.     return mnt;
  51. out_sb:
  52.     dput(mnt->mnt_root);
  53.     deactivate_locked_super(mnt->mnt_sb);
  54. out_free_secdata:
  55.     free_secdata(secdata);
  56. out_mnt:
  57.     free_vfsmnt(mnt);
  58. out:
  59.     return ERR_PTR(error);
  60. }

阅读(1146) | 评论(0) | 转发(0) |
0

上一篇:sys_mount

下一篇:proc fs

给主人留下些什么吧!~~