rearrangements and cleanup for text

This commit is contained in:
Russ Cox 2009-07-11 19:26:01 -07:00
parent 2de1c550ca
commit f9a06440ab
4 changed files with 102 additions and 107 deletions

View file

@ -44,6 +44,20 @@ fdalloc(struct file *f)
return -1;
}
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)
{
@ -68,20 +82,6 @@ sys_write(void)
return filewrite(f, p, n);
}
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)
{
@ -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;
@ -298,6 +296,18 @@ sys_open(void)
return fd;
}
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)
{
@ -315,18 +325,6 @@ sys_mknod(void)
return 0;
}
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)
{