From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 21523 invoked from network); 18 Jul 2022 10:58:33 -0000 Received: from 9front.inri.net (168.235.81.73) by inbox.vuxu.org with ESMTPUTF8; 18 Jul 2022 10:58:33 -0000 Received: from asquith.prosimetrum.com ([125.236.209.157]) by 9front; Mon Jul 18 06:56:43 -0400 2022 Message-ID: Date: Mon, 18 Jul 2022 22:56:00 +1200 From: umbraticus@prosimetrum.com To: 9front@9front.org MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: ACPI over ORM base self-signing frontend Subject: [9front] plumber: allow create Reply-To: 9front@9front.org Precedence: bulk This patch allows new plumb ports to be create()ed. Currently you can add a new port by doing: echo plumb to myport >> /mnt/plumb/rules so this is basically a convenience, though one which seems to be anticipated by /sys/src/libplumb/mesg.c:/creating This means that even if you run: plumber -p /dev/mordor you can start a rio with page, sam, zuke and see their ports appear in /mnt/plumb, then eg. plumb -d image /cat.jpg It may also be useful for some kinds of adhoc shenanigans, eg. touch /mnt/plumb/bcast; then, in a bunch of windows: /dev/null){ read -c `{read} echo } and plumb -d bcast 'hello all', or something. umbraticus diff d4eb08a86007787b046221fa6c76788fbec1f597 uncommitted --- a/sys/src/cmd/plumb/fsys.c +++ b/sys/src/cmd/plumb/fsys.c @@ -87,16 +87,15 @@ Qrules = 1, Qsend = 2, Qport = 3, - NQID = Qport }; static Dirtab dir[NDIR] = { - { ".", QTDIR, Qdir, 0500|DMDIR }, + { ".", QTDIR, Qdir, 0700|DMDIR }, { "rules", QTFILE, Qrules, 0600 }, { "send", QTFILE, Qsend, 0200 }, }; -static int ndir = NQID; +static int ndir = Qport; static int srvfd; static int mntfd; @@ -157,19 +156,19 @@ /* * Add new port. A no-op if port already exists or is the null string */ -void +uvlong addport(char *port) { int i; if(port == nil) - return; - for(i=NQID; itype] == nil) fsysrespond(t, buf, Ebadfcall); else{ - if(t->type==Tversion || t->type==Tauth) + if(t->type==Tversion || t->type==Tauth + || t->type==Tflush || t->type==Tremove + || t->type==Twstat) f = nil; else f = newfid(t->fid); @@ -545,7 +547,7 @@ err = startup(rs, e); plumbfree(m); }else - for(i=NQID; idst, dir[i].name) == 0){ if(dir[i].nopen == 0){ err = startup(rs, e); @@ -620,7 +622,7 @@ int i; qlock(&queue); - for(i=NQID; ioldtag); qunlock(&queue); fsysrespond(t, buf, nil); @@ -774,9 +776,31 @@ } static Fcall* -fsyscreate(Fcall *t, uchar *buf, Fid*) +fsyscreate(Fcall *t, uchar *buf, Fid *f) { - fsysrespond(t, buf, Eperm); + int mode; + mode = t->mode; + if(t->perm & DMDIR + || (t->qid.path = addport(t->name)) < Qport + || (mode & ~(OTRUNC|OCEXEC)) != OREAD){ + /* port may have been created but only a reader gets a fid */ + fsysrespond(t, buf, Eperm); + return t; + } + t->qid.type = QTFILE; + t->qid.vers = 0; + t->iounit = 0; + qlock(&queue); + f->qid = t->qid; + f->mode = mode; + f->open = 1; + f->dir = dir + t->qid.path; + f->dir->nopen++; + f->nextopen = f->dir->fopen; + f->dir->fopen = f; + queueheld(f->dir); + qunlock(&queue); + fsysrespond(t, buf, nil); return t; } @@ -814,7 +838,7 @@ if(f->qid.path == Qrules) return fsysreadrules(t, buf); /* read from port */ - if(f->qid.path < NQID){ + if(f->qid.path < Qport){ fsysrespond(t, buf, "internal error: unknown read port"); return t; } --- a/sys/src/cmd/plumb/plumber.h +++ b/sys/src/cmd/plumb/plumber.h @@ -77,7 +77,7 @@ void freeexec(Exec*); char* startup(Ruleset*, Exec*); char* printrules(void); -void addport(char*); +uvlong addport(char*); char* writerules(char*, int); char* expand(Exec*, char*, char**); void makeports(Ruleset*[]);