From 4bd9ed80c379d0f531a8fc8e8307dea36df0c8c0 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Tue, 28 Jul 2015 09:52:21 +0200 Subject: [PATCH] kernel: export mntattach() from devmnt.c avoiding bogus struct passing and special case in namec() we already export mntauth() and mntversion(), so why not stop being sneaky and just export mntattach() so bindmount() and devshr can just call it directly with proper arguments being checked. we can also avoid handling #M attach specially in namec() by having the devmnt's attach function do error(Enoattach). --- sys/src/9/port/chan.c | 2 -- sys/src/9/port/devmnt.c | 31 ++++++++++++++----------------- sys/src/9/port/devshr.c | 12 +----------- sys/src/9/port/portfns.h | 1 + sys/src/9/port/sysfile.c | 13 +------------ 5 files changed, 17 insertions(+), 42 deletions(-) diff --git a/sys/src/9/port/chan.c b/sys/src/9/port/chan.c index 82529ff3e..373c3b4cb 100644 --- a/sys/src/9/port/chan.c +++ b/sys/src/9/port/chan.c @@ -1399,8 +1399,6 @@ namec(char *aname, int amode, int omode, ulong perm) */ n = chartorune(&r, up->genbuf+1)+1; /* actually / is caught by parsing earlier */ - if(utfrune("M", r) != nil) - error(Enoattach); if(up->pgrp->noattach && utfrune("|decp", r)==nil) error(Enoattach); t = devno(r, 1); diff --git a/sys/src/9/port/devmnt.c b/sys/src/9/port/devmnt.c index 9f6728a4b..65bdf5453 100644 --- a/sys/src/9/port/devmnt.c +++ b/sys/src/9/port/devmnt.c @@ -302,21 +302,11 @@ mntauth(Chan *c, char *spec) } -static Chan* -mntattach(char *muxattach) +Chan* +mntattach(Chan *c, Chan *ac, char *spec, int flags) { Mnt *m; - Chan *c; Mntrpc *r; - struct bogus{ - Chan *chan; - Chan *authchan; - char *spec; - int flags; - }bogus; - - bogus = *((struct bogus *)muxattach); - c = bogus.chan; m = c->mux; if(m == nil){ @@ -342,12 +332,12 @@ mntattach(char *muxattach) } r->request.type = Tattach; r->request.fid = c->fid; - if(bogus.authchan == nil) + if(ac == nil) r->request.afid = NOFID; else - r->request.afid = bogus.authchan->fid; + r->request.afid = ac->fid; r->request.uname = up->user; - r->request.aname = bogus.spec; + r->request.aname = spec; mountrpc(m, r); c->qid = r->reply.qid; @@ -360,11 +350,18 @@ mntattach(char *muxattach) poperror(); /* c */ - if(bogus.flags&MCACHE) + if(flags&MCACHE) c->flag |= CCACHE; return c; } +static Chan* +noattach(char *) +{ + error(Enoattach); + return nil; +} + static Chan* mntchan(void) { @@ -1422,7 +1419,7 @@ Dev mntdevtab = { mntreset, devinit, devshutdown, - mntattach, + noattach, mntwalk, mntstat, mntopen, diff --git a/sys/src/9/port/devshr.c b/sys/src/9/port/devshr.c index e959261cb..03a79bc8a 100644 --- a/sys/src/9/port/devshr.c +++ b/sys/src/9/port/devshr.c @@ -724,12 +724,6 @@ shrwrite(Chan *c, void *va, long n, vlong) Chan *bc, *c0; Mhead *h; Mount *m; - struct{ - Chan *chan; - Chan *authchan; - char *spec; - int flags; - }bogus; if(up->pgrp->noattach) error(Enoattach); @@ -758,11 +752,7 @@ shrwrite(Chan *c, void *va, long n, vlong) cclose(bc); nexterror(); } - bogus.flags = 0; - bogus.chan = bc; - bogus.authchan = nil; - bogus.spec = aname; - c0 = devtab[devno('M', 0)]->attach((char*)&bogus); + c0 = mntattach(bc, nil, aname, 0); poperror(); cclose(bc); poperror(); diff --git a/sys/src/9/port/portfns.h b/sys/src/9/port/portfns.h index db547d1a1..15ca191a3 100644 --- a/sys/src/9/port/portfns.h +++ b/sys/src/9/port/portfns.h @@ -173,6 +173,7 @@ uvlong mk64fract(uvlong, uvlong); void mkqid(Qid*, vlong, ulong, int); void mmurelease(Proc*); void mmuswitch(Proc*); +Chan* mntattach(Chan*, Chan*, char*, int); Chan* mntauth(Chan*, char*); long mntversion(Chan*, char*, int, int); void mouseresize(void); diff --git a/sys/src/9/port/sysfile.c b/sys/src/9/port/sysfile.c index 43d384c2e..0b0e2e94c 100644 --- a/sys/src/9/port/sysfile.c +++ b/sys/src/9/port/sysfile.c @@ -1006,12 +1006,6 @@ bindmount(int ismount, int fd, int afd, char* arg0, char* arg1, ulong flag, char { int ret; Chan *c0, *c1, *ac, *bc; - struct{ - Chan *chan; - Chan *authchan; - char *spec; - int flags; - }bogus; if((flag&~MMASK) || (flag&MORDER)==(MBEFORE|MAFTER)) error(Ebadarg); @@ -1039,12 +1033,7 @@ bindmount(int ismount, int fd, int afd, char* arg0, char* arg1, ulong flag, char if(afd >= 0) ac = fdtochan(afd, ORDWR, 0, 1); - bogus.flags = flag & MCACHE; - bogus.chan = bc; - bogus.authchan = ac; - bogus.spec = spec; - ret = devno('M', 0); - c0 = devtab[ret]->attach((char*)&bogus); + c0 = mntattach(bc, ac, spec, flag&MCACHE); poperror(); /* ac bc */ if(ac != nil) cclose(ac);