ref: 4bd9ed80c379d0f531a8fc8e8307dea36df0c8c0
parent: 311a99e23b2f1adcf01a91db3e551dc1dda9f61a
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Jul 28 05:52:21 EDT 2015
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).
--- a/sys/src/9/port/chan.c
+++ b/sys/src/9/port/chan.c
@@ -1399,8 +1399,6 @@
*/
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);
--- a/sys/src/9/port/devmnt.c
+++ b/sys/src/9/port/devmnt.c
@@ -302,22 +302,12 @@
}
-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){
mntversion(c, nil, 0, 0);
@@ -342,12 +332,12 @@
}
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,12 +350,19 @@
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)
{
Chan *c;
@@ -1422,7 +1419,7 @@
mntreset,
devinit,
devshutdown,
- mntattach,
+ noattach,
mntwalk,
mntstat,
mntopen,
--- a/sys/src/9/port/devshr.c
+++ b/sys/src/9/port/devshr.c
@@ -724,12 +724,6 @@
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 @@
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();
--- a/sys/src/9/port/portfns.h
+++ b/sys/src/9/port/portfns.h
@@ -173,6 +173,7 @@
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);
--- a/sys/src/9/port/sysfile.c
+++ b/sys/src/9/port/sysfile.c
@@ -1006,12 +1006,6 @@
{
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 @@
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);