summaryrefslogtreecommitdiff
path: root/kernel/sysfile.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/sysfile.c
parent46744c4a13ec21e0818a49f31dbc3ad6ad592eed (diff)
downloadxv6-labs-a8305b7318e66eb33e7789072e8b91dffa0e4b93.tar.gz
xv6-labs-a8305b7318e66eb33e7789072e8b91dffa0e4b93.tar.bz2
xv6-labs-a8305b7318e66eb33e7789072e8b91dffa0e4b93.zip
FD_DEVICE
Diffstat (limited to 'kernel/sysfile.c')
-rw-r--r--kernel/sysfile.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/kernel/sysfile.c b/kernel/sysfile.c
index 83bb1ed..7788de3 100644
--- a/kernel/sysfile.c
+++ b/kernel/sysfile.c
@@ -253,7 +253,7 @@ create(char *path, short type, short major, short minor)
if((ip = dirlookup(dp, name, &off)) != 0){
iunlockput(dp);
ilock(ip);
- if(type == T_FILE && ip->type == T_FILE)
+ if(type == T_FILE && (ip->type == T_FILE || ip->type == T_DEVICE))
return ip;
iunlockput(ip);
return 0;
@@ -316,6 +316,12 @@ sys_open(void)
}
}
+ if(ip->type == T_DEVICE && (ip->major < 0 || ip->major >= NDEV)){
+ iunlockput(ip);
+ end_op();
+ return -1;
+ }
+
if((f = filealloc()) == 0 || (fd = fdalloc(f)) < 0){
if(f)
fileclose(f);
@@ -323,14 +329,21 @@ sys_open(void)
end_op();
return -1;
}
- iunlock(ip);
- end_op();
- f->type = FD_INODE;
+ if(ip->type == T_DEVICE){
+ f->type = FD_DEVICE;
+ f->major = ip->major;
+ } else {
+ f->type = FD_INODE;
+ f->off = 0;
+ }
f->ip = ip;
- f->off = 0;
f->readable = !(omode & O_WRONLY);
f->writable = (omode & O_WRONLY) || (omode & O_RDWR);
+
+ iunlock(ip);
+ end_op();
+
return fd;
}
@@ -361,7 +374,7 @@ sys_mknod(void)
if((argstr(0, path, MAXPATH)) < 0 ||
argint(1, &major) < 0 ||
argint(2, &minor) < 0 ||
- (ip = create(path, T_DEV, major, minor)) == 0){
+ (ip = create(path, T_DEVICE, major, minor)) == 0){
end_op();
return -1;
}