提交 1ccff18b 创建 作者: rsc's avatar rsc

fileincref -> filedup (consistent with idup)

上级 7895178d
...@@ -28,7 +28,7 @@ int exec(char*, char**); ...@@ -28,7 +28,7 @@ int exec(char*, char**);
// file.c // file.c
struct file* filealloc(void); struct file* filealloc(void);
void fileclose(struct file*); void fileclose(struct file*);
void fileincref(struct file*); struct file* filedup(struct file*);
void fileinit(void); void fileinit(void);
int fileread(struct file*, char*, int n); int fileread(struct file*, char*, int n);
int filestat(struct file*, struct stat*); int filestat(struct file*, struct stat*);
......
...@@ -41,14 +41,15 @@ filealloc(void) ...@@ -41,14 +41,15 @@ filealloc(void)
} }
// Increment ref count for file f. // Increment ref count for file f.
void struct file*
fileincref(struct file *f) filedup(struct file *f)
{ {
acquire(&file_table_lock); acquire(&file_table_lock);
if(f->ref < 1 || f->type == FD_CLOSED) if(f->ref < 1 || f->type == FD_CLOSED)
panic("fileincref"); panic("filedup");
f->ref++; f->ref++;
release(&file_table_lock); release(&file_table_lock);
return f;
} }
// Read from file f. Addr is kernel address. // Read from file f. Addr is kernel address.
......
...@@ -129,10 +129,9 @@ copyproc(struct proc *p) ...@@ -129,10 +129,9 @@ copyproc(struct proc *p)
} }
memmove(np->mem, p->mem, np->sz); memmove(np->mem, p->mem, np->sz);
for(i = 0; i < NOFILE; i++){ for(i = 0; i < NOFILE; i++)
if((np->ofile[i] = p->ofile[i]) != 0) if(p->ofile[i])
fileincref(np->ofile[i]); np->ofile[i] = filedup(p->ofile[i]);
}
np->cwd = idup(p->cwd); np->cwd = idup(p->cwd);
} }
......
...@@ -83,7 +83,7 @@ sys_dup(void) ...@@ -83,7 +83,7 @@ sys_dup(void)
return -1; return -1;
if((fd=fdalloc(f)) < 0) if((fd=fdalloc(f)) < 0)
return -1; return -1;
fileincref(f); filedup(f);
return fd; return fd;
} }
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论