summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkolya <kolya>2008-10-16 15:18:49 +0000
committerkolya <kolya>2008-10-16 15:18:49 +0000
commitf3e87bc838a09163f91ab79696a34f8c19386c55 (patch)
tree2f3a20b84c5eecab97be3a4208daabf17f057ba7
parente1626709d6bfcf82dc630e3ae15887e05bb3aa47 (diff)
downloadxv6-labs-f3e87bc838a09163f91ab79696a34f8c19386c55.tar.gz
xv6-labs-f3e87bc838a09163f91ab79696a34f8c19386c55.tar.bz2
xv6-labs-f3e87bc838a09163f91ab79696a34f8c19386c55.zip
make mkdir crash-safer, as noticed by many students on midterm
-rw-r--r--sysfile.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/sysfile.c b/sysfile.c
index a23b48a..ce812f5 100644
--- a/sysfile.c
+++ b/sysfile.c
@@ -237,13 +237,6 @@ create(char *path, int canexist, short type, short major, short minor)
ip->minor = minor;
ip->nlink = 1;
iupdate(ip);
-
- if(dirlink(dp, name, ip->inum) < 0){
- ip->nlink = 0;
- iunlockput(ip);
- iunlockput(dp);
- return 0;
- }
if(type == T_DIR){ // Create . and .. entries.
dp->nlink++; // for ".."
@@ -252,6 +245,17 @@ create(char *path, int canexist, short type, short major, short minor)
if(dirlink(ip, ".", ip->inum) < 0 || dirlink(ip, "..", dp->inum) < 0)
panic("create dots");
}
+
+ if(dirlink(dp, name, ip->inum) < 0){
+ dp->nlink--;
+ iupdate(dp);
+ iunlockput(dp);
+
+ ip->nlink = 0;
+ iunlockput(ip);
+ return 0;
+ }
+
iunlockput(dp);
return ip;
}