linux-2.6.34源碼
1.核心啟動調用start_kernel函數進行初始化。
asmlinkage void __init start_kernel(void) //init\Main.c:528
{
buffer_init();
key_init();
security_init();
vfs_caches_init(totalram_pages);//678行,vfs初始化
signals_init();
}
2.start_kernel調用vfs_caches_init對vfs進行初始化。//fs\Dcach.c:2354行
void __init vfs_caches_init(unsigned long mempages)
{
.......
dcache_init();
inode_init();
files_init(mempages);
mnt_init(); //mnt初始化
bdev_cache_init();
chrdev_init();
}
3.在vfs_caches_init調用fs\namespace.c 2321行的mnt_init函數void __init mnt_init(void)
{
init_rootfs(); //初始化rootfs檔案系統
init_mount_tree(); //初始化載入樹
}
4. fs\ramfs第308行的init_rootfs函數初始化rootfs檔案系統int __init init_rootfs(void)
{
int err;
err = bdi_init(&ramfs_backing_dev_info);
if (err)
return err;
err = register_filesystem(&rootfs_fs_type);//註冊rootfs檔案系統
if (err)
bdi_destroy(&ramfs_backing_dev_info);
return err;
}
rootfs檔案系統資訊fs\ramfs第289行 static struct file_system_type rootfs_fs_type = {
.name = "rootfs",
.get_sb = rootfs_get_sb,
.kill_sb = kill_litter_super,
};
5.調用register_filesystem函數將rootfs註冊到file_systems檔案系統中。//fs\Filesystem.c第69行。
int register_filesystem(struct file_system_type * fs)
{
int res = 0;
struct file_system_type ** p;
BUG_ON(strchr(fs->name, '.'));
if (fs->next)
return -EBUSY;
INIT_LIST_HEAD(&fs->fs_supers);
write_lock(&file_systems_lock);
p = find_filesystem(fs->name, strlen(fs->name));//尋找到檔案系統載入位置
if (*p)
res = -EBUSY;
else
*p = fs;
write_unlock(&file_systems_lock);
return res;
}
file_systems變數是所有檔案系統鏈表的頭指標。通過以上過程rootfs_fs_type就加入到了file_systems鏈表頭的file_system_type類型的鏈表中。可以通過file_systems指標遍曆這個鏈表,得到特定的檔案系統file_system_type 指標。