git: 9front

Download patch

ref: b0134a4b24585b911c8bd34db1a1dd7f37d12331
parent: 9fffcf8abef5c21b81357a16d46266d8a6fc8a21
author: cinap_lenrek <cinap_lenrek@gmx.de>
date: Tue Dec 4 05:40:08 EST 2012

devpipe: import pipe wstat() support to change permissions (import from sources)

--- a/sys/src/9/port/devpipe.c
+++ b/sys/src/9/port/devpipe.c
@@ -14,6 +14,7 @@
 	Pipe	*next;
 	int	ref;
 	ulong	path;
+	long	perm;
 	Queue	*q[2];
 	int	qref[2];
 };
@@ -80,6 +81,7 @@
 	lock(&pipealloc);
 	p->path = ++pipealloc.path;
 	unlock(&pipealloc);
+	p->perm = pipedir[Qdata0].perm;
 
 	mkqid(&c->qid, NETQID(2*p->path, Qdir), 0, QTDIR);
 	c->aux = p;
@@ -116,7 +118,7 @@
 		break;
 	}
 	mkqid(&q, NETQID(NETID(c->qid.path), tab->qid.path), 0, QTFILE);
-	devdir(c, q, tab->name, len, eve, tab->perm, dp);
+	devdir(c, q, tab->name, len, eve, p->perm, dp);
 	return 1;
 }
 
@@ -161,10 +163,10 @@
 		devdir(c, c->qid, ".", 0, eve, DMDIR|0555, &dir);
 		break;
 	case Qdata0:
-		devdir(c, c->qid, "data", qlen(p->q[0]), eve, 0600, &dir);
+		devdir(c, c->qid, "data", qlen(p->q[0]), eve, p->perm, &dir);
 		break;
 	case Qdata1:
-		devdir(c, c->qid, "data1", qlen(p->q[1]), eve, 0600, &dir);
+		devdir(c, c->qid, "data1", qlen(p->q[1]), eve, p->perm, &dir);
 		break;
 	default:
 		panic("pipestat");
@@ -175,6 +177,36 @@
 	return n;
 }
 
+static int
+pipewstat(Chan* c, uchar* db, int n)
+{
+	int m;
+	Dir *dir;
+	Pipe *p;
+
+	p = c->aux;
+	if(strcmp(up->user, eve) != 0)
+		error(Eperm);
+	if(NETTYPE(c->qid.path) == Qdir)
+		error(Eisdir);
+
+	dir = smalloc(sizeof(Dir)+n);
+	if(waserror()){
+		free(dir);
+		nexterror();
+	}
+	m = convM2D(db, n, &dir[0], (char*)&dir[1]);
+	if(m == 0)
+		error(Eshortstat);
+	if(!emptystr(dir[0].uid))
+		error("can't change owner");
+	if(dir[0].mode != ~0UL)
+		p->perm = dir[0].mode;
+	poperror();
+	free(dir);
+	return m;
+}
+
 /*
  *  if the stream doesn't exist, create it
  */
@@ -387,5 +419,5 @@
 	pipewrite,
 	pipebwrite,
 	devremove,
-	devwstat,
+	pipewstat,
 };
--