shithub: ext4srv

Download patch

ref: d81e6dbca628a7a568aa662d442f49fe00ca6955
parent: 268054fa0999ee700bfdc5bababd66a1e227f992
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Sep 9 18:26:59 EDT 2021

add optional uid value to -R to choose "top" owner; set group to the user on create

--- a/ext4srv.c
+++ b/ext4srv.c
@@ -28,8 +28,6 @@
 enum {
 	Adir,
 	Afile,
-
-	Root = 0,
 };
 
 static Opts opts = {
@@ -44,6 +42,7 @@
 	.inodesz = 256,
 	.ninode = 0,
 };
+static u32int Root;
 static u8int zero[65536];
 static char Eperm[] = "permission denied";
 static char *srvname;
@@ -288,8 +287,8 @@
 static void
 rcreate(Req *r)
 {
-	struct ext4_inode inode;
 	u32int perm, dirperm, t;
+	struct ext4_inode inode;
 	char *s, *err, *q;
 	int mkdir, res;
 	Aux *a;
@@ -360,7 +359,7 @@
 
 	if((res = ext4_mode_set(s, perm)) != 0)
 		goto ext4errorrm;
-	ext4_owner_set(s, a->uid, ext4_inode_get_gid(&inode));
+	ext4_owner_set(s, a->uid, a->uid);
 
 	r->fid->qid.path = a->p->qidmask.path | a->file->inode;
 	r->fid->qid.vers = 0;
@@ -933,7 +932,7 @@
 static void
 usage(void)
 {
-	fprint(2, "usage: %s [-C] [-R] [-g GROUPFILE] [-l resolve] [-s SRVNAME]\n", argv0);
+	fprint(2, "usage: %s [-C] [-R [uid]] [-g GROUPFILE] [-l resolve] [-s SRVNAME]\n", argv0);
 	fprint(2, "mkfs:  %s -M (2|3|4) [-L LABEL] [-b BLKSIZE] [-N NUMINODES] [-I INODESZ] DEVICE\n", argv0);
 	threadexitsall("usage");
 }
@@ -953,7 +952,7 @@
 void
 threadmain(int argc, char **argv)
 {
-	char *gr;
+	char *gr, *uid;
 	vlong sz;
 	int f;
 
@@ -993,6 +992,8 @@
 		goto nomkfs;
 	case 'R':
 		opts.asroot = 1;
+		if((uid = ARGF()) != nil)
+			Root = atoll(uid);
 		goto nomkfs;
 
 	case 'M':