every iput() and namei() must be inside a transaction

This commit is contained in:
Robert Morris 2014-08-04 13:06:48 -04:00
parent 020c8e2384
commit 2c56547272
6 changed files with 145 additions and 17 deletions

View file

@ -120,10 +120,12 @@ sys_link(void)
if(argstr(0, &old) < 0 || argstr(1, &new) < 0)
return -1;
if((ip = namei(old)) == 0)
return -1;
begin_trans();
if((ip = namei(old)) == 0){
commit_trans();
return -1;
}
ilock(ip);
if(ip->type == T_DIR){
@ -186,10 +188,12 @@ sys_unlink(void)
if(argstr(0, &path) < 0)
return -1;
if((dp = nameiparent(path, name)) == 0)
return -1;
begin_trans();
if((dp = nameiparent(path, name)) == 0){
commit_trans();
return -1;
}
ilock(dp);
@ -286,18 +290,24 @@ sys_open(void)
if(argstr(0, &path) < 0 || argint(1, &omode) < 0)
return -1;
begin_trans();
if(omode & O_CREATE){
begin_trans();
ip = create(path, T_FILE, 0, 0);
commit_trans();
if(ip == 0)
if(ip == 0){
commit_trans();
return -1;
}
} else {
if((ip = namei(path)) == 0)
if((ip = namei(path)) == 0){
commit_trans();
return -1;
}
ilock(ip);
if(ip->type == T_DIR && omode != O_RDONLY){
iunlockput(ip);
commit_trans();
return -1;
}
}
@ -306,9 +316,11 @@ sys_open(void)
if(f)
fileclose(f);
iunlockput(ip);
commit_trans();
return -1;
}
iunlock(ip);
commit_trans();
f->type = FD_INODE;
f->ip = ip;
@ -361,15 +373,20 @@ sys_chdir(void)
char *path;
struct inode *ip;
if(argstr(0, &path) < 0 || (ip = namei(path)) == 0)
begin_trans();
if(argstr(0, &path) < 0 || (ip = namei(path)) == 0){
commit_trans();
return -1;
}
ilock(ip);
if(ip->type != T_DIR){
iunlockput(ip);
commit_trans();
return -1;
}
iunlock(ip);
iput(proc->cwd);
commit_trans();
proc->cwd = ip;
return 0;
}