floppy: fix endless loop when trying to change floppy type on media change

This commit is contained in:
cinap_lenrek 2012-08-07 07:08:33 +02:00
parent e15b523a6c
commit 7fbae174eb

View file

@ -134,6 +134,8 @@ static Cmdtab floppyctlmsg[] =
CMreset, "reset", 1, CMreset, "reset", 1,
}; };
static char Echange[] = "media or partition has changed";
static void static void
fldump(void) fldump(void)
{ {
@ -149,12 +151,14 @@ floppysetdef(FDrive *dp)
{ {
FType *t; FType *t;
dp->t = floppytype;
for(t = floppytype; t < &floppytype[nelem(floppytype)]; t++) for(t = floppytype; t < &floppytype[nelem(floppytype)]; t++)
if(dp->dt == t->dt){ if(dp->dt == t->dt){
dp->t = t; dp->t = t;
floppydir[1+NFDIR*dp->dev].length = dp->t->cap;
break; break;
} }
floppydir[1+NFDIR*dp->dev].length = dp->t->cap;
dp->dt = dp->t->dt;
} }
static void static void
@ -323,21 +327,21 @@ changed(Chan *c, FDrive *dp)
nexterror(); nexterror();
while(++dp->t){ while(++dp->t){
if(dp->t == &floppytype[nelem(floppytype)]) if(dp->t >= &floppytype[nelem(floppytype)])
dp->t = floppytype; dp->t = floppytype;
if(dp->dt == dp->t->dt) if(dp->t == start || dp->dt == dp->t->dt)
break; break;
} }
floppydir[1+NFDIR*dp->dev].length = dp->t->cap; floppydir[1+NFDIR*dp->dev].length = dp->t->cap;
/* floppyon will fail if there's a controller but no drive */ /* floppyon will fail if there's a controller but no drive */
if(floppyon(dp) < 0) if(floppyon(dp) < 0)
error(Eio); nexterror();
if(dp->t == start)
nexterror();
DPRINT("changed: trying %s\n", dp->t->name); DPRINT("changed: trying %s\n", dp->t->name);
fldump(); fldump();
if(dp->t == start)
nexterror();
} }
/* if the read succeeds, we've got the density right */ /* if the read succeeds, we've got the density right */
@ -349,7 +353,7 @@ changed(Chan *c, FDrive *dp)
old = c->qid.vers; old = c->qid.vers;
c->qid.vers = dp->vers; c->qid.vers = dp->vers;
if(old && old != dp->vers) if(old && old != dp->vers)
error(Eio); error(Echange);
} }
static int static int