diff options
author | Robert Morris <[email protected]> | 2014-08-04 13:06:48 -0400 |
---|---|---|
committer | Robert Morris <[email protected]> | 2014-08-04 13:06:48 -0400 |
commit | 2c56547272e43b483d560a61692f1e24926a82fb (patch) | |
tree | 514014c69ff9cfe2a67159b9a3f514a3a619aea6 /sysfile.c | |
parent | 020c8e2384877ffc13579f633ac3c723f80baf8c (diff) | |
download | xv6-labs-2c56547272e43b483d560a61692f1e24926a82fb.tar.gz xv6-labs-2c56547272e43b483d560a61692f1e24926a82fb.tar.bz2 xv6-labs-2c56547272e43b483d560a61692f1e24926a82fb.zip |
every iput() and namei() must be inside a transaction
Diffstat (limited to 'sysfile.c')
-rw-r--r-- | sysfile.c | 35 |
1 files changed, 26 insertions, 9 deletions
@@ -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; } |