summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'file.c')
-rw-r--r--file.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/file.c b/file.c
index 981d474..297fd1c 100644
--- a/file.c
+++ b/file.c
@@ -56,17 +56,16 @@ int
fileread(struct file *f, char *addr, int n)
{
int r;
- struct inode *ip;
if(f->readable == 0)
return -1;
if(f->type == FD_PIPE)
return pipe_read(f->pipe, addr, n);
if(f->type == FD_INODE){
- ip = ilock(f->ip);
- if((r = readi(ip, addr, f->off, n)) > 0)
+ ilock(f->ip);
+ if((r = readi(f->ip, addr, f->off, n)) > 0)
f->off += r;
- iunlock(ip);
+ iunlock(f->ip);
return r;
}
panic("fileread");
@@ -77,17 +76,16 @@ int
filewrite(struct file *f, char *addr, int n)
{
int r;
- struct inode *ip;
if(f->writable == 0)
return -1;
if(f->type == FD_PIPE)
return pipe_write(f->pipe, addr, n);
if(f->type == FD_INODE){
- ip = ilock(f->ip);
- if((r = writei(ip, addr, f->off, n)) > 0)
+ ilock(f->ip);
+ if((r = writei(f->ip, addr, f->off, n)) > 0)
f->off += r;
- iunlock(ip);
+ iunlock(f->ip);
return r;
}
panic("filewrite");
@@ -97,12 +95,10 @@ filewrite(struct file *f, char *addr, int n)
int
filestat(struct file *f, struct stat *st)
{
- struct inode *ip;
-
if(f->type == FD_INODE){
- ip = ilock(f->ip);
- stati(ip, st);
- iunlock(ip);
+ ilock(f->ip);
+ stati(f->ip, st);
+ iunlock(f->ip);
return 0;
}
return -1;