2 Star 27 Fork 67

华中科技大学操作系统团队 / riscv-pke

 / 详情

lab4_fs中进程的fd table计数问题

待办的
创建于  
2023-02-11 23:04

见lab4_1分支的proc_file.c:49,即下面列出代码中加粗行。

proc_file_management *init_proc_file_management(void) {
  proc_file_management *pfiles = (proc_file_management *)alloc_page();
  pfiles->cwd = vfs_root_dentry; // by default, cwd is the root
  pfiles->nfiles = 0; 

  for (int fd = 0; fd < MAX_FILES; ++fd) {
    pfiles->opened_files[fd].status = FD_NONE;
     **++pfiles->nfiles;** 
  }
  sprint("FS: created a file management struct for a process.\n");
  return pfiles;
}

按照int nfiles; // the number of opened files a process has的描述,这里不应该进行计数。

这是一个trivial bug,因为nfiles没有被使用到。

评论 (3)

wsyy 创建了任务
wsyy 修改了描述
展开全部操作日志

另外对nfiles注释修改为the number of files opened by a process感觉更妥当

do_open中寻找空闲fd的部分proc_file.c:90-96

  struct file *pfile;
  for (fd = 0; fd < MAX_FILES; ++fd) {
    pfile = &(current->pfiles->opened_files[fd]);
    if (pfile->status == FD_NONE) break;
  }
  if (pfile->status != FD_NONE)  // no free entry
    panic("do_open: no file entry for current process!\n");

可以修改为

  if (current->pfiles->nfiles >= MAX_FILES) {
    panic("do_open: no file entry for current process!\n");
  }
  struct file *pfile;
  for (fd = 0; fd < MAX_FILES; ++fd) {
    pfile = &(current->pfiles->opened_files[fd]);
    if (pfile->status == FD_NONE) break;
  }

这样nfiles能够被用上,代码也更"优雅"

感谢,下次进行公开仓库更新时会修复

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
1
https://gitee.com/hustos/riscv-pke.git
git@gitee.com:hustos/riscv-pke.git
hustos
riscv-pke
riscv-pke

搜索帮助