]> Devi Nivas Git - cs3210-lab0.git/commitdiff
Shorten sys_unlink a little; create now fits in column
authorAustin Clements <amdragon@mit.edu>
Fri, 2 Sep 2011 19:20:27 +0000 (15:20 -0400)
committerAustin Clements <amdragon@mit.edu>
Fri, 2 Sep 2011 19:20:27 +0000 (15:20 -0400)
sysfile.c

index c9d35944330e8b7025c3fbf27ca99fc2cbf76988..9de3d86c7a766b7d92b756c2300d918066ed9322 100644 (file)
--- a/sysfile.c
+++ b/sysfile.c
@@ -188,26 +188,18 @@ sys_unlink(void)
   ilock(dp);
 
   // Cannot unlink "." or "..".
-  if(namecmp(name, ".") == 0 || namecmp(name, "..") == 0){
-    iunlockput(dp);
-    commit_trans();
-    return -1;
-  }
+  if(namecmp(name, ".") == 0 || namecmp(name, "..") == 0)
+    goto bad;
 
-  if((ip = dirlookup(dp, name, &off)) == 0){
-    iunlockput(dp);
-    commit_trans();
-    return -1;
-  }
+  if((ip = dirlookup(dp, name, &off)) == 0)
+    goto bad;
   ilock(ip);
 
   if(ip->nlink < 1)
     panic("unlink: nlink < 1");
   if(ip->type == T_DIR && !isdirempty(ip)){
     iunlockput(ip);
-    iunlockput(dp);
-    commit_trans();
-    return -1;
+    goto bad;
   }
 
   memset(&de, 0, sizeof(de));
@@ -226,6 +218,11 @@ sys_unlink(void)
   commit_trans();
 
   return 0;
+
+bad:
+  iunlockput(dp);
+  commit_trans();
+  return -1;
 }
 
 static struct inode*