手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux虚拟文件系统(内核初始化<二>)

[日期:2012-02-09] 来源:Linux社区  作者:bullbat [字体: ]

3,注册文件描述符表释放函数

[cpp]
  1. /*文件描述符表*/  
  2. struct fdtable {  
  3.     unsigned int max_fds;/*进程能够处理的最大file结构*/  
  4.     struct file ** fd;/*所有打开文件信息*//* current fd array */  
  5.     fd_set *close_on_exec;/*exec系统调用被关闭的所有文件集合*/  
  6.     fd_set *open_fds;/*当前打开的所有文件集合*/  
  7.     struct rcu_head rcu;  
  8.     struct fdtable *next;  
  9. };  

Start_kernel()->vfs_caches_init()->files_init()->files_defer_init()->fdtable_defer_list_init()->INIT_WORK(&fddef->wq, free_fdtable_work);

[cpp]
  1. static void free_fdtable_work(struct work_struct *work)  
  2. {  
  3.     struct fdtable_defer *f =  
  4.         container_of(work, struct fdtable_defer, wq);  
  5.     struct fdtable *fdt;  
  6.   
  7.     spin_lock_bh(&f->lock);  
  8.     fdt = f->next;  
  9.     f->next = NULL;  
  10.     spin_unlock_bh(&f->lock);  
  11.     while(fdt) {/*释放工作*/  
  12.         struct fdtable *next = fdt->next;  
  13.         vfree(fdt->fd);  
  14.         free_fdset(fdt);  
  15.         kfree(fdt);  
  16.         fdt = next;  
  17.     }  
  18. }  

4.sysfs文件系统初始化

Start_kernel()->vfs_caches_init()->mnt_init()->sysfs_init()

[cpp]
  1. int __init sysfs_init(void)  
  2. {  
  3.     int err = -ENOMEM;  
  4.   
  5.     sysfs_dir_cachep = kmem_cache_create("sysfs_dir_cache",  
  6.                           sizeof(struct sysfs_dirent),  
  7.                           0, 0, NULL);  
  8.     if (!sysfs_dir_cachep)  
  9.         goto out;  
  10.     /*初始化sysfs的backing_dev_info结构*/  
  11.     err = sysfs_inode_init();  
  12.     if (err)  
  13.         goto out_err;  
  14.     /*注册文件系统*/  
  15.     err = register_filesystem(&sysfs_fs_type);  
  16.     if (!err) {  
  17.         /*创建sysfs mount*/  
  18.         sysfs_mount = kern_mount(&sysfs_fs_type);  
  19.         if (IS_ERR(sysfs_mount)) {  
  20.             printk(KERN_ERR "sysfs: could not mount!\n");  
  21.             err = PTR_ERR(sysfs_mount);  
  22.             sysfs_mount = NULL;  
  23.             unregister_filesystem(&sysfs_fs_type);  
  24.             goto out_err;  
  25.         }  
  26.     } else  
  27.         goto out_err;  
  28. out:  
  29.     return err;  
  30. out_err:  
  31.     kmem_cache_destroy(sysfs_dir_cachep);  
  32.     sysfs_dir_cachep = NULL;  
  33.     goto out;  
  34. }  
linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款