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).
This commit is contained in:
parent
311a99e23b
commit
4bd9ed80c3
5 changed files with 17 additions and 42 deletions
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue