Skip to content

Commit

Permalink
fileincref -> filedup (consistent with idup)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsc committed Aug 27, 2007
1 parent 7895178 commit 1ccff18
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ int exec(char*, char**);
// file.c
struct file* filealloc(void);
void fileclose(struct file*);
void fileincref(struct file*);
struct file* filedup(struct file*);
void fileinit(void);
int fileread(struct file*, char*, int n);
int filestat(struct file*, struct stat*);
Expand Down
7 changes: 4 additions & 3 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ filealloc(void)
}

// Increment ref count for file f.
void
fileincref(struct file *f)
struct file*
filedup(struct file *f)
{
acquire(&file_table_lock);
if(f->ref < 1 || f->type == FD_CLOSED)
panic("fileincref");
panic("filedup");
f->ref++;
release(&file_table_lock);
return f;
}

// Read from file f. Addr is kernel address.
Expand Down
7 changes: 3 additions & 4 deletions proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,9 @@ copyproc(struct proc *p)
}
memmove(np->mem, p->mem, np->sz);

for(i = 0; i < NOFILE; i++){
if((np->ofile[i] = p->ofile[i]) != 0)
fileincref(np->ofile[i]);
}
for(i = 0; i < NOFILE; i++)
if(p->ofile[i])
np->ofile[i] = filedup(p->ofile[i]);
np->cwd = idup(p->cwd);
}

Expand Down
2 changes: 1 addition & 1 deletion sysfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ sys_dup(void)
return -1;
if((fd=fdalloc(f)) < 0)
return -1;
fileincref(f);
filedup(f);
return fd;
}

Expand Down

0 comments on commit 1ccff18

Please sign in to comment.