Bdale Garbee writes:
> Sure, I can apply your patch in the Debian cpmtools package, since
> it has been accepted upstream.  I try to avoid forks, but gaining
> quicker access to something that is coming in upstream's next
> release seems good.

OK, here it is.
It's expected to be released in cpmtools 2.24.
Subject: libdsk: reset geometry if autoprobe isn't sane

So that weirdness from any misfiring auto-geometry heuristic in LibDsk
doesn't cause trouble later. (We were overwriting the most common
parameters, but not all of them.)
(Triggered by Debian bug #1079619, where a spurious dg_sidedness caused
trouble after LibDsk's Opus Discovery heuristic misfired -- that
heuristic has been improved in libdsk 1.5.20, but this change provides
defence in depth.)
---
 device_libdsk.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/device_libdsk.c b/device_libdsk.c
index 7baaed4..82b79d1 100644
--- a/device_libdsk.c
+++ b/device_libdsk.c
@@ -72,6 +72,7 @@ const char *Device_open(struct Device *this, const char *filename, int mode, con
 const char *Device_setGeometry(struct Device *this, int secLength, int sectrk, int tracks, off_t offset, const char *libdskGeometry)
 {
   char *boo;
+  int probeOk;
 
   this->secLength=secLength;
   this->sectrk=sectrk;
@@ -85,11 +86,22 @@ const char *Device_setGeometry(struct Device *this, int secLength, int sectrk, i
     return lookupFormat(&this->geom, libdskGeometry);
   }
   
+  /* Did the autoprobe guess right about the number of sectors & cylinders? */
+  if (this->geom.dg_cylinders * this->geom.dg_heads == tracks)
+  {
+    probeOk = 1;
+  }
+  else
+  {
+    /* If not, reset to a minimal geometry (to undo any randomness from
+     * a failed autoprobe), and guess some parameters */
+    probeOk = 0;
+    dg_stdformat(&this->geom, FMT_180K, NULL, NULL);
+  }
   this->geom.dg_secsize   = secLength;
   this->geom.dg_sectors   = sectrk;
-  /* Did the autoprobe guess right about the number of sectors & cylinders? */
-  if (this->geom.dg_cylinders * this->geom.dg_heads == tracks) return NULL;
-  /* Otherwise we guess: <= 43 tracks: single-sided. Else double. This
+  if (probeOk) return NULL;
+  /* We guess: <= 43 tracks: single-sided. Else double. This
    * fails for 80-track single-sided if there are any such beasts */
   if (tracks <= 43) 
   {
-- 
2.30.2

Reply via email to