From 7fbae174eb6d4252a26f57485cd6eb7f3ef1ac84 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Tue, 7 Aug 2012 07:08:33 +0200 Subject: floppy: fix endless loop when trying to change floppy type on media change --- sys/src/9/pc/devfloppy.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/sys/src/9/pc/devfloppy.c b/sys/src/9/pc/devfloppy.c index 9ff866529..b9cabcf6a 100644 --- a/sys/src/9/pc/devfloppy.c +++ b/sys/src/9/pc/devfloppy.c @@ -134,6 +134,8 @@ static Cmdtab floppyctlmsg[] = CMreset, "reset", 1, }; +static char Echange[] = "media or partition has changed"; + static void fldump(void) { @@ -149,12 +151,14 @@ floppysetdef(FDrive *dp) { FType *t; + dp->t = floppytype; for(t = floppytype; t < &floppytype[nelem(floppytype)]; t++) if(dp->dt == t->dt){ dp->t = t; - floppydir[1+NFDIR*dp->dev].length = dp->t->cap; break; } + floppydir[1+NFDIR*dp->dev].length = dp->t->cap; + dp->dt = dp->t->dt; } static void @@ -323,21 +327,21 @@ changed(Chan *c, FDrive *dp) nexterror(); while(++dp->t){ - if(dp->t == &floppytype[nelem(floppytype)]) + if(dp->t >= &floppytype[nelem(floppytype)]) dp->t = floppytype; - if(dp->dt == dp->t->dt) + if(dp->t == start || dp->dt == dp->t->dt) break; } floppydir[1+NFDIR*dp->dev].length = dp->t->cap; /* floppyon will fail if there's a controller but no drive */ if(floppyon(dp) < 0) - error(Eio); + nexterror(); + if(dp->t == start) + nexterror(); DPRINT("changed: trying %s\n", dp->t->name); fldump(); - if(dp->t == start) - nexterror(); } /* if the read succeeds, we've got the density right */ @@ -349,7 +353,7 @@ changed(Chan *c, FDrive *dp) old = c->qid.vers; c->qid.vers = dp->vers; if(old && old != dp->vers) - error(Eio); + error(Echange); } static int -- cgit v1.2.3