From 7f9649d9350ed15e5e4755243cf152dd40bf817f Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sun, 23 Jun 2002 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 2002-06-23 --- port/devcap.c | 73 ++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/port/devcap.c b/port/devcap.c index 3094705e1aad474fee6c30170051e1e642d5681e..ceb3278c89760b0b6917781f6e2678ac6808d752 100644 --- a/port/devcap.c +++ b/port/devcap.c @@ -29,7 +29,6 @@ struct Caphash struct { QLock; - int opens; Caphash *first; int nhash; } capalloc; @@ -41,13 +40,14 @@ enum Quse, }; +/* caphash must be last */ Dirtab capdir[] = { ".", {Qdir,0,QTDIR}, 0, DMDIR|0500, - "caphash", {Qhash}, 0, 0200, "capuse", {Quse}, 0, 0222, + "caphash", {Qhash}, 0, 0200, }; -#define NCAPDIR 3 +int ncapdir = nelem(capdir); static Chan* capattach(char *spec) @@ -58,13 +58,23 @@ capattach(char *spec) static Walkqid* capwalk(Chan *c, Chan *nc, char **name, int nname) { - return devwalk(c, nc, name, nname, capdir, NCAPDIR, devgen); + return devwalk(c, nc, name, nname, capdir, ncapdir, devgen); +} + +static void +capremove(Chan *c) +{ + if(iseve() && c->qid.path == Qhash) + ncapdir = nelem(capdir)-1; + else + error(Eperm); } + static int capstat(Chan *c, uchar *db, int n) { - return devstat(c, db, n, capdir, NCAPDIR, devgen); + return devstat(c, db, n, capdir, ncapdir, devgen); } /* @@ -86,20 +96,13 @@ capopen(Chan *c, int omode) qunlock(&capalloc); nexterror(); } - qlock(&capalloc); switch((ulong)c->qid.path){ case Qhash: if(!iseve()) error(Eperm); - if(capalloc.opens > 0){ - qunlock(&capalloc); - error("exclusive use"); - } - capalloc.opens++; break; } poperror(); - qunlock(&capalloc); c->mode = openmode(omode); c->flag |= COPEN; @@ -164,14 +167,8 @@ addcap(uchar *hash) } static void -capclose(Chan *c) +capclose(Chan*) { - if(c->flag & COPEN) - if(c->qid.path == Qhash){ - qlock(&capalloc); - capalloc.opens--; - qunlock(&capalloc); - } } static long @@ -179,7 +176,7 @@ capread(Chan *c, void *va, long n, vlong) { switch((ulong)c->qid.path){ case Qdir: - return devdirread(c, va, n, capdir, nelem(capdir), devgen); + return devdirread(c, va, n, capdir, ncapdir, devgen); default: error(Eperm); @@ -258,22 +255,22 @@ capwrite(Chan *c, void *va, long n, vlong) } Dev capdevtab = { - L'¤', - "cap", - - devreset, - devinit, - devshutdown, - capattach, - capwalk, - capstat, - capopen, - devcreate, - capclose, - capread, - devbread, - capwrite, - devbwrite, - devremove, - devwstat, +.dc= L'¤', +.name= "cap", + +.reset= devreset, +.init= devinit, +.shutdown= devshutdown, +.attach= capattach, +.walk= capwalk, +.stat= capstat, +.open= capopen, +.create= devcreate, +.close= capclose, +.read= capread, +.bread= devbread, +.write= capwrite, +.bwrite= devbwrite, +.remove= capremove, +.wstat= devwstat, };