shithub: mq

Download patch

ref: f3e647cd3055f1e1686e5f3957d40649ad5bea1f
parent: 52b7ea043795db40d79ca7aa203cb1c75e002217
author: Ori Bernstein <[email protected]>
date: Sun Dec 10 11:06:59 EST 2023

mq: fix arm build

--- a/mq.c
+++ b/mq.c
@@ -11,7 +11,7 @@
 
 enum {
 	Qroot,
-	Maxqid,
+	Qmq,
 };
 
 enum {
@@ -63,7 +63,7 @@
 Mq	**queues;
 int	nqueues;
 vlong	maxlog = -1;
-vlong	queueid = Maxqid;
+vlong	queueid = 0;
 
 char Ebaduse[] = "invalid use of fd";
 char Einuse[] = "fid in use";
@@ -74,6 +74,10 @@
 char Ebadcmd[] = "unknown command";
 char Enomem[] = "out of memory";
 
+#define QTYPE(p)	((int)((p) & 0x3))
+#define QIDX(p)		((p)>>2)
+#define QPATH(i, t)	((i)<<2 | (t))
+
 void *
 emalloc(ulong n)
 {
@@ -208,7 +212,7 @@
 {
 	Mq *q;
 
-	switch(f->qid.path){
+	switch(QTYPE(f->qid.path)){
 	case Qroot:
 		if(strcmp(name, "..") == 0){
 			*qid = f->qid;
@@ -232,7 +236,7 @@
 void
 mqstat(Req *r)
 {
-	switch(r->fid->qid.path){
+	switch(QTYPE(r->fid->qid.path)){
 	case Qroot:
 		r->d.uid = estrdup9p("glenda");
 		r->d.gid = estrdup9p("glenda");
@@ -270,7 +274,7 @@
 	int i, o;
 
 	path = r->fid->qid.path;
-	if(path == Qroot){
+	if(QTYPE(path) == Qroot){
 		respond(r, Ebaduse);
 		return;
 	}
@@ -351,7 +355,7 @@
 	Rd *rd;
 	Mq *q;
 
-	if(r->fid->qid.path == Qroot){
+	if(QTYPE(r->fid->qid.path) == Qroot){
 		dirread9p(r, rootgen, nil);
 		respond(r, nil);
 		return;
@@ -405,9 +409,11 @@
 	q = emalloc(sizeof(Mq));
 	q->name = estrdup(r->ifcall.name);
 	q->mode = r->ifcall.mode;
-	q->qid.path = queueid++;
+	q->qid.path = QPATH(queueid, Qmq);
 	q->qid.vers = 0;
 	q->qid.type = QTFILE;
+	queueid++;
+
 	a = emalloc(sizeof(Aux));
 	a->q = q;
 	if(m == OREAD || m == ORDWR || m == OEXEC)
@@ -435,9 +441,9 @@
 	m = r->ifcall.mode & OMASK;
 	p = r->fid->qid.path;
 	a = emalloc(sizeof(Aux));
-	if(p != Qroot){
-		incref(queues[p-Maxqid]);
-		a->q = queues[p-Maxqid];
+	if(QTYPE(p) != Qroot){
+		incref(queues[QIDX(p)]);
+		a->q = queues[QIDX(p)];
 		if(m == OREAD || m == ORDWR || m == OMASK)
 			a->id = subscribe(a->q);
 		r->fid->aux = a;