Linux核心VFS—rootfs檔案系統載入

來源:互聯網
上載者:User
 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 指標。

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.