版權聲明:本文為部落客原創文章,未經部落客允許不得轉載。 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