summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2012-12-04 10:40:08 +0100
committercinap_lenrek <cinap_lenrek@gmx.de>2012-12-04 10:40:08 +0100
commitb142e2a30883e78c3c7ae40762a607cef1dd40b9 (patch)
treea529629ce0aec865ca2cbd8da67576b4ed375a67
parent98bd6364246cd1fb6344b8e9975beefdf885ce21 (diff)
devpipe: import pipe wstat() support to change permissions (import from sources)
-rw-r--r--sys/src/9/port/devpipe.c40
1 files changed, 36 insertions, 4 deletions
diff --git a/sys/src/9/port/devpipe.c b/sys/src/9/port/devpipe.c
index bea354b78..a72303dcc 100644
--- a/sys/src/9/port/devpipe.c
+++ b/sys/src/9/port/devpipe.c
@@ -14,6 +14,7 @@ struct Pipe
Pipe *next;
int ref;
ulong path;
+ long perm;
Queue *q[2];
int qref[2];
};
@@ -80,6 +81,7 @@ pipeattach(char *spec)
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 @@ pipegen(Chan *c, char*, Dirtab *tab, int ntab, int i, Dir *dp)
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 @@ pipestat(Chan *c, uchar *db, int n)
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 @@ pipestat(Chan *c, uchar *db, int n)
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 @@ Dev pipedevtab = {
pipewrite,
pipebwrite,
devremove,
- devwstat,
+ pipewstat,
};