From 2c56547272e43b483d560a61692f1e24926a82fb Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Mon, 4 Aug 2014 13:06:48 -0400 Subject: every iput() and namei() must be inside a transaction --- sysfile.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'sysfile.c') diff --git a/sysfile.c b/sysfile.c index 64f2b33..095fca7 100644 --- a/sysfile.c +++ b/sysfile.c @@ -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; } -- cgit v1.2.3