diff options
author | rtm <rtm> | 2006-07-01 21:26:01 +0000 |
---|---|---|
committer | rtm <rtm> | 2006-07-01 21:26:01 +0000 |
commit | 8b4e2a08febc8b957b44732dbc7da831479a0005 (patch) | |
tree | 46c3b079ec65f0efbd1f3b603f1b11a3ae09e56d /fd.c | |
parent | f7cea12b38a86e9b37fa5bc635310d3f85e5f8db (diff) | |
download | xv6-labs-8b4e2a08febc8b957b44732dbc7da831479a0005.tar.gz xv6-labs-8b4e2a08febc8b957b44732dbc7da831479a0005.tar.bz2 xv6-labs-8b4e2a08febc8b957b44732dbc7da831479a0005.zip |
swtch saves callee-saved registers
swtch idles on per-CPU stack, not on calling process's stack
fix pipe bugs
usertest.c tests pipes, fork, exit, close
Diffstat (limited to 'fd.c')
-rw-r--r-- | fd.c | 30 |
1 files changed, 17 insertions, 13 deletions
@@ -37,19 +37,6 @@ fd_alloc() return 0; } -void -fd_close(struct fd *fd) -{ - if(fd->type == FD_CLOSED || fd->count <= 0) - panic("fd_close"); - fd->count -= 1; - if(fd->count == 0){ - if(fd->type == FD_PIPE) - pipe_close(fd->pipe, fd->writeable); - fd->type = FD_CLOSED; - } -} - /* * addr is a kernel address, pointing into some process's p->mem. */ @@ -78,3 +65,20 @@ fd_read(struct fd *fd, char *addr, int n) return -1; } } + +void +fd_close(struct fd *fd) +{ + if(fd->count < 1 || fd->type == FD_CLOSED) + panic("fd_close"); + fd->count -= 1; + + if(fd->count == 0){ + if(fd->type == FD_PIPE){ + pipe_close(fd->pipe, fd->writeable); + } else { + panic("fd_close"); + } + fd->type = FD_CLOSED; + } +} |