summaryrefslogtreecommitdiff
path: root/kernel/file.c
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2019-06-13 10:29:27 -0400
committerRobert Morris <[email protected]>2019-06-13 10:29:27 -0400
commita8305b7318e66eb33e7789072e8b91dffa0e4b93 (patch)
tree080bae6010159b083d86411fcd05438e19ca5515 /kernel/file.c
parent46744c4a13ec21e0818a49f31dbc3ad6ad592eed (diff)
downloadxv6-labs-a8305b7318e66eb33e7789072e8b91dffa0e4b93.tar.gz
xv6-labs-a8305b7318e66eb33e7789072e8b91dffa0e4b93.tar.bz2
xv6-labs-a8305b7318e66eb33e7789072e8b91dffa0e4b93.zip
FD_DEVICE
Diffstat (limited to 'kernel/file.c')
-rw-r--r--kernel/file.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/kernel/file.c b/kernel/file.c
index 6f27f22..f330cf1 100644
--- a/kernel/file.c
+++ b/kernel/file.c
@@ -73,9 +73,9 @@ fileclose(struct file *f)
f->type = FD_NONE;
release(&ftable.lock);
- if(ff.type == FD_PIPE)
+ if(ff.type == FD_PIPE){
pipeclose(ff.pipe, ff.writable);
- else if(ff.type == FD_INODE){
+ } else if(ff.type == FD_INODE || ff.type == FD_DEVICE){
begin_op();
iput(ff.ip);
end_op();
@@ -90,7 +90,7 @@ filestat(struct file *f, uint64 addr)
struct proc *p = myproc();
struct stat st;
- if(f->type == FD_INODE){
+ if(f->type == FD_INODE || f->type == FD_DEVICE){
ilock(f->ip);
stati(f->ip, &st);
iunlock(f->ip);
@@ -113,6 +113,8 @@ fileread(struct file *f, uint64 addr, int n)
if(f->type == FD_PIPE){
r = piperead(f->pipe, addr, n);
+ } else if(f->type == FD_DEVICE){
+ r = devsw[f->major].read(1, addr, n);
} else if(f->type == FD_INODE){
ilock(f->ip);
if((r = readi(f->ip, 1, addr, f->off, n)) > 0)
@@ -138,6 +140,8 @@ filewrite(struct file *f, uint64 addr, int n)
if(f->type == FD_PIPE){
ret = pipewrite(f->pipe, addr, n);
+ } else if(f->type == FD_DEVICE){
+ ret = devsw[f->major].write(1, addr, n);
} else if(f->type == FD_INODE){
// write a few blocks at a time to avoid exceeding
// the maximum log transaction size, including