diff options
Diffstat (limited to 'sysfile.c')
-rw-r--r-- | sysfile.c | 68 |
1 files changed, 33 insertions, 35 deletions
@@ -45,6 +45,20 @@ fdalloc(struct file *f) } int +sys_dup(void) +{ + struct file *f; + int fd; + + if(argfd(0, 0, &f) < 0) + return -1; + if((fd=fdalloc(f)) < 0) + return -1; + filedup(f); + return fd; +} + +int sys_read(void) { struct file *f; @@ -69,20 +83,6 @@ sys_write(void) } int -sys_dup(void) -{ - struct file *f; - int fd; - - if(argfd(0, 0, &f) < 0) - return -1; - if((fd=fdalloc(f)) < 0) - return -1; - filedup(f); - return fd; -} - -int sys_close(void) { int fd; @@ -225,17 +225,15 @@ create(char *path, short type, short major, short minor) if((ip = dirlookup(dp, name, &off)) != 0){ iunlockput(dp); ilock(ip); - if(ip->type != type || type != T_FILE){ - iunlockput(ip); - return 0; - } - return ip; - } - - if((ip = ialloc(dp->dev, type)) == 0){ - iunlockput(dp); + if(type == T_FILE && ip->type == T_FILE) + return ip; + iunlockput(ip); return 0; } + + if((ip = ialloc(dp->dev, type)) == 0) + panic("create: ialloc"); + ilock(ip); ip->major = major; ip->minor = minor; @@ -299,6 +297,18 @@ sys_open(void) } int +sys_mkdir(void) +{ + char *path; + struct inode *ip; + + if(argstr(0, &path) < 0 || (ip = create(path, T_DIR, 0, 0)) == 0) + return -1; + iunlockput(ip); + return 0; +} + +int sys_mknod(void) { struct inode *ip; @@ -316,18 +326,6 @@ sys_mknod(void) } int -sys_mkdir(void) -{ - char *path; - struct inode *ip; - - if(argstr(0, &path) < 0 || (ip = create(path, T_DIR, 0, 0)) == 0) - return -1; - iunlockput(ip); - return 0; -} - -int sys_chdir(void) { char *path; |