代码拉取完成,页面将自动刷新
见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没有被使用到。
另外对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能够被用上,代码也更"优雅"
感谢,下次进行公开仓库更新时会修复
登录 后才可以发表评论