summaryrefslogtreecommitdiff
path: root/sysfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysfile.c')
-rw-r--r--sysfile.c35
1 files changed, 26 insertions, 9 deletions
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;
}