LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 627|回复: 2

Linux文件系统的一个菜鸟问题

[复制链接]
发表于 2005-9-2 17:13:11 | 显示全部楼层 |阅读模式
正在学习中,有点弱,提个问题:
在task_struct中有个指针,指向一个files_struct结构,表示进程已打开文件的一些信息。在files_struct中的主体部分就是一个file结构数组,代表已打开的具体文件。

  1. struct files_struct {
  2.         ......
  3.         struct file * fd_array[NR_OPEN_DEFAULT];
  4. };
复制代码

每打开一个文件,进程就会通过"已打开文件号"fid来访问这个文件,而fid实际上就是相应file结构在上述数组中的下标,我想问问这个fid是否就是用户空间使用的文件描述符呢?如果不是,这两者有什么关系么?
发表于 2005-9-2 20:54:50 | 显示全部楼层

  1. struct file fastcall *fget(unsigned int fd)
  2. {
  3.         struct file *file;
  4.         struct files_struct *files = current->files;

  5.         spin_lock(&files->file_lock);
  6.         file = fcheck_files(files, fd);
  7.         if (file)
  8.                 get_file(file);
  9.         spin_unlock(&files->file_lock);
  10.         return file;
  11. }
复制代码


  1. static inline struct file * fcheck_files(struct files_struct *files, unsigned int fd)
  2. {
  3.         struct file * file = NULL;

  4.         if (fd < files->max_fds)
  5.                 file = files->fd[fd];
  6.         return file;
  7. }
复制代码


从上面的代码可以看出是相对应的。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-9-3 16:25:44 | 显示全部楼层
多谢~~
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表