shithub: gefs

Download patch

ref: 6fca09557ed08a206345c9c113a55d1d49564107
parent: d164aa7714b3a0f679bcacffb9a716a57cb7c0cb
author: Ori Bernstein <ori@eigenstate.org>
date: Wed May 10 00:36:26 EDT 2023

fs: clean up create error handling

--- a/error.c
+++ b/error.c
@@ -67,7 +67,6 @@
 //char Eauth2[]		= "read/write -- authentication unimplemented";
 //char Etoolong[]	= "name too long";
 //char Efidinuse[]	= "fid in use";
-//char Econvert[]	= "protocol botch";
 //char Eversion[]	= "version conversion";
 //char Eauthnone[]	= "auth -- user 'none' requires no authentication";
 //char Eauthdisabled[]	= "auth -- authentication disabled";	/* development */
--- a/fs.c
+++ b/fs.c
@@ -1472,17 +1472,19 @@
 		rerror(m, Enofid);
 		return;
 	}
+	lock(f);
+	if(f->mode != -1){
+		e = Einuse;
+		goto Fiderr;
+	}
 	if(m->perm & (DMMOUNT|DMAUTH)){
-		rerror(m, "unknown permission");
-		putfid(f);
-		return;
+		e = Ebotch;
+		goto Fiderr;
 	}
 	de = f->dent;
-
 	if(walk1(f->mnt->root, f->qpath, m->name, &old, &oldlen) == 0){
-		rerror(m, Eexist);
-		putfid(f);
-		return;
+		e = Eexist;
+		goto Fiderr;
 	}
 
 	rlock(de);
@@ -1489,8 +1491,7 @@
 	if(fsaccess(f, de->mode, de->uid, de->gid, DMWRITE) == -1){
 		rerror(m, Eperm);
 		runlock(de);
-		putfid(f);
-		return;
+		goto Fiderr;
 	}
 
 	d.gid = de->gid;
@@ -1542,36 +1543,29 @@
 	}
 	if((e = upsert(f->mnt, mb, nm)) != nil){
 		rerror(m, e);
-		putfid(f);
-		return;
+		goto Fiderr;
 	}
 
-	lock(f);
 	de = getdent(f->qpath, &d);
 	if(de == nil){
 		rerror(m, Enomem);
-		putfid(f);
-		return;
+		goto Fiderr;
 	}
-
-	if(f->mode != -1){
-		unlock(f);
-		clunkdent(de);
-		rerror(m, Einuse);
-		putfid(f);
-		return;
-	}
 	f->mode = mode2bits(m->mode);
 	f->pqpath = f->qpath;
 	f->qpath = d.qid.path;
 	f->dent = de;
-	unlock(f);
 
 	r.type = Rcreate;
 	r.qid = d.qid;
 	r.iounit = f->iounit;
-	respond(m, &r);
+Fiderr:
+	unlock(f);
 	putfid(f);
+	if(e == nil)
+		respond(m, &r);
+	else
+		rerror(m, e);
 }
 
 static char*