devshr, devaudio: openmode()/devopen() error handling
This commit is contained in:
parent
52a84514ac
commit
84109a3159
|
@ -177,18 +177,28 @@ audioopen(Chan *c, int omode)
|
||||||
adev = ac->adev;
|
adev = ac->adev;
|
||||||
if(c->qid.path == Qaudio){
|
if(c->qid.path == Qaudio){
|
||||||
mode = openmode(omode);
|
mode = openmode(omode);
|
||||||
if(mode == OWRITE || mode == ORDWR)
|
if(waserror()){
|
||||||
if(incref(&adev->audioopenw) != 1){
|
if(mode == OREAD || mode == ORDWR)
|
||||||
decref(&adev->audioopenw);
|
|
||||||
error(Ebusy);
|
|
||||||
}
|
|
||||||
if(mode == OREAD || mode == ORDWR)
|
|
||||||
if(incref(&adev->audioopenr) != 1){
|
|
||||||
decref(&adev->audioopenr);
|
decref(&adev->audioopenr);
|
||||||
if(mode == ORDWR)
|
nexterror();
|
||||||
decref(&adev->audioopenw);
|
}
|
||||||
|
if(mode == OREAD || mode == ORDWR)
|
||||||
|
if(incref(&adev->audioopenr) != 1)
|
||||||
error(Ebusy);
|
error(Ebusy);
|
||||||
}
|
|
||||||
|
if(waserror()){
|
||||||
|
if(mode == OWRITE || mode == ORDWR)
|
||||||
|
decref(&adev->audioopenw);
|
||||||
|
nexterror();
|
||||||
|
}
|
||||||
|
if(mode == OWRITE || mode == ORDWR)
|
||||||
|
if(incref(&adev->audioopenw) != 1)
|
||||||
|
error(Ebusy);
|
||||||
|
|
||||||
|
c = devopen(c, omode, audiodir, nelem(audiodir), devgen);
|
||||||
|
poperror();
|
||||||
|
poperror();
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
return devopen(c, omode, audiodir, nelem(audiodir), devgen);
|
return devopen(c, omode, audiodir, nelem(audiodir), devgen);
|
||||||
}
|
}
|
||||||
|
|
|
@ -375,10 +375,12 @@ shropen(Chan *c, int omode)
|
||||||
Sch *sch;
|
Sch *sch;
|
||||||
Shr *shr;
|
Shr *shr;
|
||||||
Mpt *mpt;
|
Mpt *mpt;
|
||||||
|
int mode;
|
||||||
|
|
||||||
if(c->qid.type == QTDIR && omode != OREAD)
|
if(c->qid.type == QTDIR && omode != OREAD)
|
||||||
error(Eisdir);
|
error(Eisdir);
|
||||||
|
|
||||||
|
mode = openmode(omode);
|
||||||
sch = tosch(c);
|
sch = tosch(c);
|
||||||
switch(sch->level){
|
switch(sch->level){
|
||||||
default:
|
default:
|
||||||
|
@ -389,14 +391,14 @@ shropen(Chan *c, int omode)
|
||||||
case Qshr:
|
case Qshr:
|
||||||
case Qcshr:
|
case Qcshr:
|
||||||
shr = sch->shr;
|
shr = sch->shr;
|
||||||
devpermcheck(shr->owner, shr->perm, openmode(omode));
|
devpermcheck(shr->owner, shr->perm, mode);
|
||||||
break;
|
break;
|
||||||
case Qcmpt:
|
case Qcmpt:
|
||||||
if(omode&OTRUNC)
|
if(omode&OTRUNC)
|
||||||
error(Eexist);
|
error(Eexist);
|
||||||
shr = sch->shr;
|
shr = sch->shr;
|
||||||
mpt = sch->mpt;
|
mpt = sch->mpt;
|
||||||
devpermcheck(mpt->owner, mpt->perm, openmode(omode));
|
devpermcheck(mpt->owner, mpt->perm, mode);
|
||||||
rlock(&shr->umh.lock);
|
rlock(&shr->umh.lock);
|
||||||
if(mpt->m.to == nil || mpt->m.to->mchan == nil){
|
if(mpt->m.to == nil || mpt->m.to->mchan == nil){
|
||||||
runlock(&shr->umh.lock);
|
runlock(&shr->umh.lock);
|
||||||
|
@ -405,14 +407,14 @@ shropen(Chan *c, int omode)
|
||||||
nc = mpt->m.to->mchan;
|
nc = mpt->m.to->mchan;
|
||||||
incref(nc);
|
incref(nc);
|
||||||
runlock(&shr->umh.lock);
|
runlock(&shr->umh.lock);
|
||||||
if(openmode(omode) != nc->mode){
|
if(mode != nc->mode){
|
||||||
cclose(nc);
|
cclose(nc);
|
||||||
error(Eperm);
|
error(Eperm);
|
||||||
}
|
}
|
||||||
cclose(c);
|
cclose(c);
|
||||||
return nc;
|
return nc;
|
||||||
}
|
}
|
||||||
c->mode = openmode(omode);
|
c->mode = mode;
|
||||||
c->flag |= COPEN;
|
c->flag |= COPEN;
|
||||||
c->offset = 0;
|
c->offset = 0;
|
||||||
return c;
|
return c;
|
||||||
|
@ -430,7 +432,9 @@ shrcreate(Chan *c, char *name, int omode, ulong perm)
|
||||||
Mhead *h;
|
Mhead *h;
|
||||||
Mount *m;
|
Mount *m;
|
||||||
Chan *nc;
|
Chan *nc;
|
||||||
|
int mode;
|
||||||
|
|
||||||
|
mode = openmode(omode);
|
||||||
sch = tosch(c);
|
sch = tosch(c);
|
||||||
switch(sch->level){
|
switch(sch->level){
|
||||||
case Qcroot:
|
case Qcroot:
|
||||||
|
@ -460,7 +464,7 @@ shrcreate(Chan *c, char *name, int omode, ulong perm)
|
||||||
case Qcroot:
|
case Qcroot:
|
||||||
if(up->pgrp->noattach)
|
if(up->pgrp->noattach)
|
||||||
error(Enoattach);
|
error(Enoattach);
|
||||||
if((perm & DMDIR) == 0 || openmode(omode) != OREAD)
|
if((perm & DMDIR) == 0 || mode != OREAD)
|
||||||
error(Eperm);
|
error(Eperm);
|
||||||
if(strlen(name) >= sizeof(up->genbuf))
|
if(strlen(name) >= sizeof(up->genbuf))
|
||||||
error(Etoolong);
|
error(Etoolong);
|
||||||
|
@ -494,7 +498,7 @@ shrcreate(Chan *c, char *name, int omode, ulong perm)
|
||||||
case Qcshr:
|
case Qcshr:
|
||||||
if(up->pgrp->noattach)
|
if(up->pgrp->noattach)
|
||||||
error(Enoattach);
|
error(Enoattach);
|
||||||
if((perm & DMDIR) != 0 || openmode(omode) != OWRITE)
|
if((perm & DMDIR) != 0 || mode != OWRITE)
|
||||||
error(Eperm);
|
error(Eperm);
|
||||||
|
|
||||||
shr = sch->shr;
|
shr = sch->shr;
|
||||||
|
@ -539,7 +543,7 @@ shrcreate(Chan *c, char *name, int omode, ulong perm)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
c->flag |= COPEN;
|
c->flag |= COPEN;
|
||||||
c->mode = openmode(omode);
|
c->mode = mode;
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue