版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/feilengcui008/article/details/48420871
1.根文件系统的挂载
- mount_root[init/do_mounts.c]
- create_dev(“/dev/root”, ROOT_DEV) ==> how to do this
- sys_unlink(“/dev/root”)
- sys_mknod(“/dev/root”,…)
- mount_block_root(“/dev/root”, flags)
- get_fs_names -> copy root_fs_names
- do_mount_root ==> 调用系统调用sys_mount,sys_chdir(“/root”),为当 前进程current->fs.pwd.dentry设置挂载返回的root dentry
- sys_mount ==>进入系统调用
- create_dev(“/dev/root”, ROOT_DEV) ==> how to do this
2.进入系统调用的挂载,也是用户态挂载文件系统的入口
- sys_mount[fs/namespace.c]
- copy_mount_string
- copy_mount_options
- do_mount
- user_path(dirname, &path) -> path_lookupat ==> 获取挂载路径的struct path,查找路径是很复杂的过程:)
- do_remount
- do_loopback
- do_change_type
- do_move_mount
- do_new_mount ==> 构建虚拟挂载点vsfmount,检查设置namespace
- get_fs_type ==> 在file_systems查找传入的文件系统类型
- vfs_kernel_mount ==> 调用具体文件系统的mount,并将返回的root dentry与分配的vfsmount挂接
- alloc_vfsmnt ==> 从slob中分配虚拟挂载点struct vfsmount
- root = mount_fs
- type->mount ==> 调用具体文件系统的mount,返回root dentry
- 设置vfsmount结构内容
3.进入具体文件系统类型的mount,此处以ext2为例分析
-
模块初始化时
- init_inodecache分配slab作为inode的cache
- register_filesystem加入模块全局变量file_systems
-
struct file_system_type ext2_fs_type
- ext2_mount
- mount_bdev ==> 传入ext2_fill_super,返回root dentry
- blkdev_get_by_path ==> 通过设备节点路径名构造block_device结构
- sget ==> 获取或分配super block结构体,并将bdev绑定到sb上
- fill_super ==> 填充super block
- sb_bread ==> 读取super block的count块到buffer head,先查找lru缓存
- __find_get_clock_slow ==> 根据bdev中的inode及inode中的i_mapping信息将page cache读到buffer head里
- sb_bread ==> 读取super block的count块到buffer head,先查找lru缓存
- mount_bdev ==> 传入ext2_fill_super,返回root dentry
- kill_block_super
- ext2_mount