shithub: unionfs

Download patch

ref: 7479818ad25599c69b879cc8825aeb0e90f124b3
parent: db287775ae9de502690e87ffaab5baeed76ecf46
author: kvik <kvik@a-b.xyz>
date: Wed May 15 15:35:49 EDT 2019

implement global Fil* root

this simplifies one tricky part of walking backwards

--- a/unionfs.c
+++ b/unionfs.c
@@ -53,6 +53,7 @@
 Union *unionlist = &u0;
 uvlong qidnext;
 Qidmap *qidmap[Nqidmap];
+Fil *root;
 
 void*
 emalloc(ulong sz)
@@ -218,6 +219,8 @@
 void
 filefree(Fil *f)
 {
+	if(f == root)
+		return;
 	if(decref(f))
 		return;
 //	qidfree(f->qmap);
@@ -285,19 +288,19 @@
 }
 
 void
-fsattach(Req *r)
+initroot(void)
 {
+	char *user;
 	Dir d;
-	Fil *root;
-	Fstate *st;
 	
 	nulldir(&d);
 	d.qid = (Qid){0, 0, QTDIR};
 	d.name = ".";
 	d.mode = 0777|DMDIR;
-	d.uid = r->fid->uid;
-	d.gid = r->fid->uid;
-	d.muid = r->fid->uid;
+	user = getuser();
+	d.uid = user;
+	d.gid = user;
+	d.muid = user;
 	d.mtime = time(0);
 	d.atime = time(0);
 	d.length = 0;
@@ -305,10 +308,14 @@
 	root = filenew(&d);
 	root->fspath = estrdup(d.name);
 	root->path = estrdup(d.name);
+}
+
+void
+fsattach(Req *r)
+{
+	Fstate *st;
 	
 	st = fstatenew(root);
-	decref(root);
-
 	r->fid->aux = st;
 	r->fid->qid = root->qid;
 	r->ofcall.qid = root->qid;
@@ -326,7 +333,7 @@
 	
 	if(strcmp(name, "..") == 0){
 		if((s = strrchr(p->fspath, '/')) == nil)
-			return p;
+			return root;
 		*s = 0;
 		name = "";
 	}
@@ -716,6 +723,7 @@
 	if(c == 0)
 		unionlist->next->create = 1;
 	
+	initroot();
 	postmountsrv(&fs, srv, mtpt, mflag);
 	
 	exits(nil);