From 50e514be986e4d5b136879d1221b721b17493a78 Mon Sep 17 00:00:00 2001 From: rsc Date: Wed, 6 Sep 2006 18:43:45 +0000 Subject: [PATCH] fd_* => file_* --- defs.h | 16 ++++++++-------- file.c | 26 +++++++++++++------------- main.c | 2 +- pipe.c | 8 ++++---- proc.c | 4 ++-- sysfile.c | 26 +++++++++++++------------- 6 files changed, 41 insertions(+), 41 deletions(-) diff --git a/defs.h b/defs.h index 1491a8e..e05782d 100644 --- a/defs.h +++ b/defs.h @@ -92,14 +92,14 @@ int pipe_read(struct pipe*, char*, int); // fd.c struct stat; -void fd_init(void); -int fd_ualloc(void); -struct file* fd_alloc(void); -void fd_close(struct file*); -int fd_read(struct file*, char*, int n); -int fd_write(struct file*, char*, int n); -int fd_stat(struct file*, struct stat*); -void fd_incref(struct file*); +void fileinit(void); +int fdalloc(void); +struct file* filealloc(void); +void fileclose(struct file*); +int fileread(struct file*, char*, int n); +int filewrite(struct file*, char*, int n); +int filestat(struct file*, struct stat*); +void fileincref(struct file*); // ide.c void ide_init(void); diff --git a/file.c b/file.c index fd04383..29f07cc 100644 --- a/file.c +++ b/file.c @@ -17,14 +17,14 @@ struct devsw devsw[NDEV]; struct file file[NFILE]; void -fd_init(void) +fileinit(void) { initlock(&fd_table_lock, "fd_table"); } // Allocate a file descriptor number for curproc. int -fd_ualloc(void) +fdalloc(void) { int fd; struct proc *p = curproc[cpu()]; @@ -36,7 +36,7 @@ fd_ualloc(void) // Allocate a file descriptor structure struct file* -fd_alloc(void) +filealloc(void) { int i; @@ -56,7 +56,7 @@ fd_alloc(void) // Write to file descriptor; // addr is a kernel address, pointing into some process's p->mem. int -fd_write(struct file *fd, char *addr, int n) +filewrite(struct file *fd, char *addr, int n) { if(fd->writable == 0) return -1; @@ -71,14 +71,14 @@ fd_write(struct file *fd, char *addr, int n) iunlock(fd->ip); return r; } else { - panic("fd_write"); + panic("filewrite"); return -1; } } // Read from file descriptor. int -fd_read(struct file *fd, char *addr, int n) +fileread(struct file *fd, char *addr, int n) { if(fd->readable == 0) return -1; @@ -92,19 +92,19 @@ fd_read(struct file *fd, char *addr, int n) iunlock(fd->ip); return cc; } else { - panic("fd_read"); + panic("fileread"); return -1; } } // Close file descriptor. void -fd_close(struct file *fd) +fileclose(struct file *fd) { acquire(&fd_table_lock); if(fd->ref < 1 || fd->type == FD_CLOSED) - panic("fd_close"); + panic("fileclose"); if(--fd->ref == 0){ struct file dummy = *fd; @@ -118,7 +118,7 @@ fd_close(struct file *fd) } else if(dummy.type == FD_FILE){ idecref(dummy.ip); } else { - panic("fd_close"); + panic("fileclose"); } } else { release(&fd_table_lock); @@ -127,7 +127,7 @@ fd_close(struct file *fd) // Get metadata about file descriptor. int -fd_stat(struct file *fd, struct stat *st) +filestat(struct file *fd, struct stat *st) { if(fd->type == FD_FILE){ ilock(fd->ip); @@ -140,11 +140,11 @@ fd_stat(struct file *fd, struct stat *st) // Increment file descriptor reference count. void -fd_incref(struct file *fd) +fileincref(struct file *fd) { acquire(&fd_table_lock); if(fd->ref < 1 || fd->type == FD_CLOSED) - panic("fd_incref"); + panic("fileincref"); fd->ref++; release(&fd_table_lock); } diff --git a/main.c b/main.c index f6a8ab9..dba8bdd 100644 --- a/main.c +++ b/main.c @@ -49,7 +49,7 @@ main0(void) kinit(); // physical memory allocator tvinit(); // trap vectors idtinit(); // this CPU's interrupt descriptor table - fd_init(); + fileinit(); iinit(); // i-node table // initialize process 0 diff --git a/pipe.c b/pipe.c index 3b2f6b8..82eaeeb 100644 --- a/pipe.c +++ b/pipe.c @@ -24,9 +24,9 @@ pipe_alloc(struct file **fd1, struct file **fd2) *fd1 = *fd2 = 0; struct pipe *p = 0; - if((*fd1 = fd_alloc()) == 0) + if((*fd1 = filealloc()) == 0) goto oops; - if((*fd2 = fd_alloc()) == 0) + if((*fd2 = filealloc()) == 0) goto oops; if((p = (struct pipe*) kalloc(PAGE)) == 0) goto oops; @@ -49,11 +49,11 @@ pipe_alloc(struct file **fd1, struct file **fd2) kfree((char*) p, PAGE); if(*fd1){ (*fd1)->type = FD_NONE; - fd_close(*fd1); + fileclose(*fd1); } if(*fd2){ (*fd2)->type = FD_NONE; - fd_close(*fd2); + fileclose(*fd2); } return -1; } diff --git a/proc.c b/proc.c index 34b353b..8aa1ff1 100644 --- a/proc.c +++ b/proc.c @@ -127,7 +127,7 @@ copyproc(struct proc *p) for(i = 0; i < NOFILE; i++){ np->ofile[i] = p->ofile[i]; if(np->ofile[i]) - fd_incref(np->ofile[i]); + fileincref(np->ofile[i]); } np->cwd = p->cwd; @@ -329,7 +329,7 @@ proc_exit(void) // Close all open files. for(fd = 0; fd < NOFILE; fd++){ if(cp->ofile[fd]){ - fd_close(cp->ofile[fd]); + fileclose(cp->ofile[fd]); cp->ofile[fd] = 0; } } diff --git a/sysfile.c b/sysfile.c index d0c7afa..ea75a41 100644 --- a/sysfile.c +++ b/sysfile.c @@ -25,10 +25,10 @@ sys_pipe(void) if(pipe_alloc(&rfd, &wfd) < 0) goto oops; - if((f1 = fd_ualloc()) < 0) + if((f1 = fdalloc()) < 0) goto oops; p->ofile[f1] = rfd; - if((f2 = fd_ualloc()) < 0) + if((f2 = fdalloc()) < 0) goto oops; p->ofile[f2] = wfd; if(fetcharg(0, &fdp) < 0) @@ -41,9 +41,9 @@ sys_pipe(void) oops: if(rfd) - fd_close(rfd); + fileclose(rfd); if(wfd) - fd_close(wfd); + fileclose(wfd); if(f1 >= 0) p->ofile[f1] = 0; if(f2 >= 0) @@ -67,7 +67,7 @@ sys_write(void) if(addr + n > p->sz) return -1; - ret = fd_write(p->ofile[fd], p->mem + addr, n); + ret = filewrite(p->ofile[fd], p->mem + addr, n); return ret; } @@ -86,7 +86,7 @@ sys_read(void) return -1; if(addr + n > p->sz) return -1; - ret = fd_read(p->ofile[fd], p->mem + addr, n); + ret = fileread(p->ofile[fd], p->mem + addr, n); return ret; } @@ -102,7 +102,7 @@ sys_close(void) return -1; if(p->ofile[fd] == 0) return -1; - fd_close(p->ofile[fd]); + fileclose(p->ofile[fd]); p->ofile[fd] = 0; return 0; } @@ -146,13 +146,13 @@ sys_open(void) return -1; } - if((fd = fd_alloc()) == 0){ + if((fd = filealloc()) == 0){ iput(ip); return -1; } - if((ufd = fd_ualloc()) < 0){ + if((ufd = fdalloc()) < 0){ iput(ip); - fd_close(fd); + fileclose(fd); return -1; } @@ -310,7 +310,7 @@ sys_fstat(void) return -1; if(addr + sizeof(struct stat) > cp->sz) return -1; - r = fd_stat(cp->ofile[fd], (struct stat*)(cp->mem + addr)); + r = filestat(cp->ofile[fd], (struct stat*)(cp->mem + addr)); return r; } @@ -326,10 +326,10 @@ sys_dup(void) return -1; if(cp->ofile[fd] == 0) return -1; - if((ufd1 = fd_ualloc()) < 0) + if((ufd1 = fdalloc()) < 0) return -1; cp->ofile[ufd1] = cp->ofile[fd]; - fd_incref(cp->ofile[ufd1]); + fileincref(cp->ofile[ufd1]); return ufd1; }