shithub: gefs

Download patch

ref: ce9628320fd8fb69a06190fa7f305175e12124e6
parent: 121accd306fec1870a6e06a04916bc938fa61118
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Apr 18 12:17:18 EDT 2023

ream: accept optional adm user argument

this is convenient for one-shot fs initialization

--- a/fns.h
+++ b/fns.h
@@ -10,6 +10,7 @@
 extern Gefs*	fs;
 extern int	debug;
 extern int	permissive;
+extern char*	reamuser;
 
 #define	UNPACK8(p)	(((uchar*)(p))[0])
 #define	UNPACK16(p)	((((uchar*)(p))[0]<<8)|(((uchar*)(p))[1]))
--- a/main.c
+++ b/main.c
@@ -15,6 +15,7 @@
 int	noauth;
 int	nproc;
 int	permissive;
+char	*reamuser;
 char	*srvname = "gefs";
 char	*dev;
 vlong	cachesz = 512*MiB;
@@ -144,6 +145,7 @@
 		break;
 	case 'r':
 		ream = 1;
+		reamuser = ARGF();
 		break;
 	case 'g':
 		grow = 1;
--- a/ream.c
+++ b/ream.c
@@ -13,9 +13,7 @@
 	Nreamqid,
 };
 
-char *defaultusers =
-	"-1:adm::\n"
-	"0:none::\n";
+char *defaultusers ="-1:adm::%s\n0:none::\n";
 
 static void
 fillxdir(Xdir *d, vlong qid, char *name, int type, int mode)
@@ -33,7 +31,7 @@
 }
 
 static void
-initadm(Blk *r, Blk *u)
+initadm(Blk *r, Blk *u, int nu)
 {
 	char *p, kbuf[Keymax], vbuf[Inlmax];
 	Kvp kv;
@@ -51,7 +49,7 @@
 	setval(r, &kv);
 
 	fillxdir(&d, Qadmuser, "users", QTFILE, 0664);
-	d.length = strlen(defaultusers);
+	d.length = nu;
 	if(dir2kv(Qadmroot, &d, &kv, vbuf, sizeof(vbuf)) == -1)
 		sysfatal("ream: pack users: %r");
 	setval(r, &kv);
@@ -283,10 +281,17 @@
 		sysfatal("ream: allocate root: %r");
 	holdblk(ab);
 	holdblk(ub);
+	if(reamuser != nil){
+		defaultusers = smprint(
+			"-1:adm::%s\n"
+			"0:none::\n"
+			"1:%s:%s:\n",
+			reamuser, reamuser, reamuser);
+	}
 	memcpy(ub->data, defaultusers, strlen(defaultusers));
 	finalize(ub);
 	syncblk(ub);
-	initadm(ab, ub);
+	initadm(ab, ub, strlen(defaultusers));
 	finalize(ab);
 	syncblk(ab);