From 1ccff18b2404e18fc889901f85b72777193c0b3f Mon Sep 17 00:00:00 2001 From: rsc Date: Mon, 27 Aug 2007 14:35:09 +0000 Subject: [PATCH] fileincref -> filedup (consistent with idup) --- defs.h | 2 +- file.c | 7 ++++--- proc.c | 7 +++---- sysfile.c | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/defs.h b/defs.h index 7af5421..b81ef31 100644 --- a/defs.h +++ b/defs.h @@ -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*); diff --git a/file.c b/file.c index 297fd1c..9bd6ece 100644 --- a/file.c +++ b/file.c @@ -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. diff --git a/proc.c b/proc.c index fb79444..776c8b4 100644 --- a/proc.c +++ b/proc.c @@ -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); } diff --git a/sysfile.c b/sysfile.c index 1182e17..712a220 100644 --- a/sysfile.c +++ b/sysfile.c @@ -83,7 +83,7 @@ sys_dup(void) return -1; if((fd=fdalloc(f)) < 0) return -1; - fileincref(f); + filedup(f); return fd; }