]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/9/port/devshr.c
devmnt: deal with partial response for Tversion request in mntversion()
[plan9front.git] / sys / src / 9 / port / devshr.c
index 03739a31de39bd846757561c69ab7b122411ff26..bc76772104171511729bd65108493754def9fb72 100644 (file)
@@ -375,10 +375,12 @@ shropen(Chan *c, int omode)
        Sch *sch;
        Shr *shr;
        Mpt *mpt;
+       int mode;
 
        if(c->qid.type == QTDIR && omode != OREAD)
                error(Eisdir);
 
+       mode = openmode(omode);
        sch = tosch(c);
        switch(sch->level){
        default:
@@ -389,14 +391,14 @@ shropen(Chan *c, int omode)
        case Qshr:
        case Qcshr:
                shr = sch->shr;
-               devpermcheck(shr->owner, shr->perm, openmode(omode));
+               devpermcheck(shr->owner, shr->perm, mode);
                break;
        case Qcmpt:
                if(omode&OTRUNC)
                        error(Eexist);
                shr = sch->shr;
                mpt = sch->mpt;
-               devpermcheck(mpt->owner, mpt->perm, openmode(omode));
+               devpermcheck(mpt->owner, mpt->perm, mode);
                rlock(&shr->umh.lock);
                if(mpt->m.to == nil || mpt->m.to->mchan == nil){
                        runlock(&shr->umh.lock);
@@ -405,14 +407,14 @@ shropen(Chan *c, int omode)
                nc = mpt->m.to->mchan;
                incref(nc);
                runlock(&shr->umh.lock);
-               if(openmode(omode) != nc->mode){
+               if(mode != nc->mode){
                        cclose(nc);
                        error(Eperm);
                }
                cclose(c);
                return nc;
        }
-       c->mode = openmode(omode);
+       c->mode = mode;
        c->flag |= COPEN;
        c->offset = 0;
        return c;
@@ -430,7 +432,9 @@ shrcreate(Chan *c, char *name, int omode, ulong perm)
        Mhead *h;
        Mount *m;
        Chan *nc;
+       int mode;
 
+       mode = openmode(omode);
        sch = tosch(c);
        switch(sch->level){
        case Qcroot:
@@ -460,7 +464,7 @@ shrcreate(Chan *c, char *name, int omode, ulong perm)
        case Qcroot:
                if(up->pgrp->noattach)
                        error(Enoattach);
-               if((perm & DMDIR) == 0 || openmode(omode) != OREAD)
+               if((perm & DMDIR) == 0 || mode != OREAD)
                        error(Eperm);
                if(strlen(name) >= sizeof(up->genbuf))
                        error(Etoolong);
@@ -494,7 +498,7 @@ shrcreate(Chan *c, char *name, int omode, ulong perm)
        case Qcshr:
                if(up->pgrp->noattach)
                        error(Enoattach);
-               if((perm & DMDIR) != 0 || openmode(omode) != OWRITE)
+               if((perm & DMDIR) != 0 || mode != OWRITE)
                        error(Eperm);
 
                shr = sch->shr;
@@ -527,7 +531,6 @@ shrcreate(Chan *c, char *name, int omode, ulong perm)
 
                incref(mpt);
                mpt->m.mflag = (h->mount == nil) ? MCREATE : 0;
-               mpt->m.head = h;
                mpt->m.next = h->mount;
                h->mount = &mpt->m;
 
@@ -539,7 +542,7 @@ shrcreate(Chan *c, char *name, int omode, ulong perm)
                break;
        }
        c->flag |= COPEN;
-       c->mode = openmode(omode);
+       c->mode = mode;
        return c;
 }
 
@@ -598,7 +601,6 @@ shrremove(Chan *c)
                        if(*ml == m){
                                *ml = m->next;
                                m->next = nil;
-                               m->head = nil;
                                putmpt(mpt);
                                break;
                        }
@@ -654,8 +656,6 @@ shrwstat(Chan *c, uchar *dp, int n)
        if(strcmp(ent->owner, up->user) && !iseve())
                error(Eperm);
 
-       if(d.mode != ~0UL)
-               ent->perm = d.mode & 0777;
        if(d.name != nil && *d.name && strcmp(ent->name, d.name) != 0) {
                if(strchr(d.name, '/') != nil)
                        error(Ebadchar);
@@ -665,6 +665,8 @@ shrwstat(Chan *c, uchar *dp, int n)
        }
        if(d.uid != nil && *d.uid)
                kstrdup(&ent->owner, d.uid);
+       if(d.mode != ~0UL)
+               ent->perm = d.mode & 0777;
 
        switch(sch->level){
        case Qcshr:
@@ -720,12 +722,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);
@@ -754,11 +750,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();