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

Linux虚拟文件系统--open()

[日期:2012-11-22] 来源:Linux社区  作者:vanbreaker [字体:大 中 小]

实际的扩充操作:

static int expand_fdtable(struct files_struct *files, int nr) 
    __releases(files->file_lock) 
    __acquires(files->file_lock) 
{ 
    struct fdtable *new_fdt, *cur_fdt; 
 
    spin_unlock(&files->file_lock); 
    new_fdt = alloc_fdtable(nr);//根据nr重新创建一个新的fdtable 
    spin_lock(&files->file_lock); 
    if (!new_fdt) 
        return -ENOMEM; 
    /*
    * extremely unlikely race - sysctl_nr_open decreased between the check in
    * caller and alloc_fdtable().  Cheaper to catch it here...
    */ 
    /*这里为了防止因为竞争,在alloc_fdtable调用之前systl_nr_open减小了新创建的fdtable小于nr*/ 
    if (unlikely(new_fdt->max_fds <= nr)) { 
        free_fdarr(new_fdt); 
        free_fdset(new_fdt); 
        kfree(new_fdt); 
        return -EMFILE; 
    } 
    /*
    * Check again since another task may have expanded the fd table while
    * we dropped the lock
    */ 
    cur_fdt = files_fdtable(files);//获取旧的fdtable 
    if (nr >= cur_fdt->max_fds) {//新的nr必须大于旧的fdtable的大小 
        /* Continue as planned */ 
        copy_fdtable(new_fdt, cur_fdt);//将旧的fdtable中的内容拷贝至新的fdtable 
        rcu_assign_pointer(files->fdt, new_fdt);//用新的fdtable替换旧的fdtable 
        if (cur_fdt->max_fds > NR_OPEN_DEFAULT) 
            free_fdtable(cur_fdt);//释放旧的fdtable 
    } else { 
        /* Somebody else expanded, so undo our attempt */ 
        free_fdarr(new_fdt); 
        free_fdset(new_fdt); 
        kfree(new_fdt); 
    } 
    return 1; 
}

到此为止,分配新的fd的工作完成,如果分配fd成功,接下来do_sys_open()就要通过do_filp_open()函数查找文件并执行相应的打开操作

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

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