From e47e366450cb6a99f5c845ac6a77d14156ee0e3b Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Mon, 19 Mar 1990 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1990-03-19 --- gnot/devdk.c | 46 +++++++++++++++++++++++++++++++++------------- port/devdk.c | 46 +++++++++++++++++++++++++++++++++------------- port/devlance.c | 2 +- 3 files changed, 67 insertions(+), 27 deletions(-) diff --git a/gnot/devdk.c b/gnot/devdk.c index 047b73b095d2412b770f2a1fe2716e5646f47f3d..f0db2a6c82e96b978e80f0bcc1505fd11e590be8 100644 --- a/gnot/devdk.c +++ b/gnot/devdk.c @@ -644,7 +644,14 @@ dkopen(Chan *c, int omode) Dk *dp; int line; - if(c->qid == Dcloneqid){ + if(c->qid & CHDIR){ + /* + * directories are read only + */ + if(omode != OREAD) + error(0, Ebadarg); + } else switch(STREAMTYPE(c->qid)){ + case Dcloneqid: /* * get an unused device and open it's control file */ @@ -665,7 +672,8 @@ dkopen(Chan *c, int omode) error(0, Enodev); streamopen(c, &dkinfo); pushq(c->stream, &urpinfo); - } else if(STREAMTYPE(c->qid) == Dlistenqid){ + break; + case Dlistenqid: /* * listen for a call and open the control file for the * channel on which the call arrived. @@ -675,13 +683,25 @@ dkopen(Chan *c, int omode) streamopen(c, &dkinfo); pushq(c->stream, &urpinfo); dkwindow(c); - } else if(c->qid != CHDIR){ + break; + case Daddrqid: + case Draddrqid: + case Duserqid: + case Dotherqid: + /* + * read only files + */ + if(omode != OREAD) + error(0, Ebadarg); + break; + default: /* * open whatever c points to, make sure it has an urp */ streamopen(c, &dkinfo); if(strcmp(c->stream->procq->next->info->name, "urp")!=0) pushq(c->stream, &urpinfo); + break; } c->mode = openmode(omode); @@ -702,7 +722,7 @@ dkclose(Chan *c) Dk *dp; /* real closing happens in lancestclose */ - if(c->qid != CHDIR) + if(c->stream) streamclose(c); dp = &dk[c->dev]; @@ -714,17 +734,20 @@ dkclose(Chan *c) long dkread(Chan *c, void *a, long n) { - int t; Line *lp; - t = STREAMTYPE(c->qid); - if(t>=Slowqid || t==Dlineqid) + if(c->stream) return streamread(c, a, n); - if(c->qid == CHDIR) - return devdirread(c, a, n, dkdir, dk[c->dev].lines, devgen); + + if(c->qid & CHDIR){ + if(c->qid == CHDIR) + return devdirread(c, a, n, dkdir, dk[c->dev].lines, devgen); + else + return devdirread(c, a, n, dksubdir, Nsubdir, streamgen); + } lp = &dk[c->dev].line[STREAMID(c->qid)]; - switch(t){ + switch(STREAMTYPE(c->qid)){ case Daddrqid: return stringread(c, a, n, lp->addr); case Draddrqid: @@ -782,9 +805,6 @@ dkwrite(Chan *c, void *a, long n) return n; } - if(t >= Slowqid) - return streamwrite(c, a, n, 0); - error(0, Eperm); } diff --git a/port/devdk.c b/port/devdk.c index 047b73b095d2412b770f2a1fe2716e5646f47f3d..f0db2a6c82e96b978e80f0bcc1505fd11e590be8 100644 --- a/port/devdk.c +++ b/port/devdk.c @@ -644,7 +644,14 @@ dkopen(Chan *c, int omode) Dk *dp; int line; - if(c->qid == Dcloneqid){ + if(c->qid & CHDIR){ + /* + * directories are read only + */ + if(omode != OREAD) + error(0, Ebadarg); + } else switch(STREAMTYPE(c->qid)){ + case Dcloneqid: /* * get an unused device and open it's control file */ @@ -665,7 +672,8 @@ dkopen(Chan *c, int omode) error(0, Enodev); streamopen(c, &dkinfo); pushq(c->stream, &urpinfo); - } else if(STREAMTYPE(c->qid) == Dlistenqid){ + break; + case Dlistenqid: /* * listen for a call and open the control file for the * channel on which the call arrived. @@ -675,13 +683,25 @@ dkopen(Chan *c, int omode) streamopen(c, &dkinfo); pushq(c->stream, &urpinfo); dkwindow(c); - } else if(c->qid != CHDIR){ + break; + case Daddrqid: + case Draddrqid: + case Duserqid: + case Dotherqid: + /* + * read only files + */ + if(omode != OREAD) + error(0, Ebadarg); + break; + default: /* * open whatever c points to, make sure it has an urp */ streamopen(c, &dkinfo); if(strcmp(c->stream->procq->next->info->name, "urp")!=0) pushq(c->stream, &urpinfo); + break; } c->mode = openmode(omode); @@ -702,7 +722,7 @@ dkclose(Chan *c) Dk *dp; /* real closing happens in lancestclose */ - if(c->qid != CHDIR) + if(c->stream) streamclose(c); dp = &dk[c->dev]; @@ -714,17 +734,20 @@ dkclose(Chan *c) long dkread(Chan *c, void *a, long n) { - int t; Line *lp; - t = STREAMTYPE(c->qid); - if(t>=Slowqid || t==Dlineqid) + if(c->stream) return streamread(c, a, n); - if(c->qid == CHDIR) - return devdirread(c, a, n, dkdir, dk[c->dev].lines, devgen); + + if(c->qid & CHDIR){ + if(c->qid == CHDIR) + return devdirread(c, a, n, dkdir, dk[c->dev].lines, devgen); + else + return devdirread(c, a, n, dksubdir, Nsubdir, streamgen); + } lp = &dk[c->dev].line[STREAMID(c->qid)]; - switch(t){ + switch(STREAMTYPE(c->qid)){ case Daddrqid: return stringread(c, a, n, lp->addr); case Draddrqid: @@ -782,9 +805,6 @@ dkwrite(Chan *c, void *a, long n) return n; } - if(t >= Slowqid) - return streamwrite(c, a, n, 0); - error(0, Eperm); } diff --git a/port/devlance.c b/port/devlance.c index b50c957250c78a8b407556e43d9bf23e6338a2b0..e92a08218d64f8382edb7c06fb2d979715e74ffc 100644 --- a/port/devlance.c +++ b/port/devlance.c @@ -605,7 +605,7 @@ lancewalk(Chan *c, char *name) void lancestat(Chan *c, char *dp) { - if(c->qid == CHDIR) + if(c->qid==CHDIR || c->qid==Ltraceqid) devstat(c, dp, lancedir, Ndir, devgen); else devstat(c, dp, 0, 0, streamgen);