[comp.sys.cbm] SAVE-WITH-REPLACE bug found and fixed

mac@harris.cis.ksu.edu (Myron A. Calhoun) (04/10/89)

The definitive description/cure of the save-with-replace bug was given
in the October and November, 1985, issues of COMPUTE!  In those issues
the bug is proven to exist, a good description of what causes the bug
is given, and the way to avoid it is described.  The problem began when
Commodore decided to address multiple drives by changing the DEVICE #
instead of the DRIVE number as earlier C= equipment did.  Summarizing
five pages and quoting from page 79 of the October COMPUTE! issue:

  "Therefore, the key to avoiding the SAVE@ bug is to always
   specify drive 0 when performing any disk drive function,
   or to always reset the drive before any SAVE@ operation."

Notice the words "ALWAYS"!  you must ALWAYS use the drive number for
EVERY disk operation, or you must ALWAYS reset the drive (i.e., turn
it off and then on, or sending a reset command OPEN15,8,15,"UJ")
before doing any SAVE@ operation.  Quoting further:

  "SAVE@ always works properly in our tests if the drive number is
   specified on all operations and no direct access buffers are
   allocated.  We are not aware of anyone who has documented a failure
   under these conditions (assuming a closed file was specified,
   sufficient room was present on the disk, and no read or write
   errors occurred).  Thus, Commodore experts who claim there is no
   bug are partially correct.  We have also found that if the drive
   number is not always specified during loads and directory listings,
   as is common practice, the SAVE@ bug can occur even though the
   drive number is specified in the SAVE@ command.

  "Files stored in just one or two tracks--such as short files on a
   fresh disk--are not prone to the SAVE@ bug.  Files stored over
   many tracks on disks on which many files have been saved and
   scratched are the most susceptible, as are files saved with some
   utilities intended to speed up the 1541 disk drive."

(Any typing errors above are probably mine.)  For the gory details,
I heartily recommend reading the COMPUTE! two-month article.
--Myron
--
Myron A. Calhoun, PhD EE, W0PBV, (913) 532-6350 (work), 539-4448 (home).
INTERNET: mac@ksuvax1.cis.ksu.edu
BITNET:   mac@ksuvax1.bitnet
UUCP:  ...{rutgers, texbell}!ksuvax1!harry!mac