[comp.sys.amiga] AmigaDOS File Error Problem

mrr@amanpt1.UUCP (Mark Rinfret) (02/03/88)

I'm having a problem with AmigaDOS file error handling.  I have a known bad
^^^^^^^^^^^^^^^^^^^^---> I might make this my middle name.
floppy diskette which I use for testing.  The symptoms of my problem are a
"retry forever" loop which is definitely not being performed by my application.
Following this message is a short, dirty little program which I have found
to exhibit the same behavior that I have been experiencing elsewhere.  When
the bad spot is hit, I get a disk error requester with RETRY and CANCEL
options.  I would expect CANCEL to abort the operation and return to my
application's Write call with an error status (via IoErr).  What I'm seeing
is a never-ending retry (the Write call never returns).  Is this a known
problem?  Is there a way to circumvent it?  

Before someone asks, I'm formatting the test disk with the FormatDisk
routine recently posted with my program, MRBackup.  This routine does a
format-without-verify which allows the bad sector to slip by undetected until
accessed by subsequent read/write attempts.  I don't want to argue the
relative merits (demerits?) of this and whether it's the cause of my problem.
I maintain that it is not.  Though a verify-read would catch media defects
present at the time the disk was formatted, defects can also occur after the
disk has been placed in storage.  

I'm running an Amiga 1000, PAL Jr., 1.5 megs RAM, dual floppies and KickStart
1.2.  I had PopCLI II, ConMan 1.0 and Nag running at the time of the tests
(included for the outside chance that these details are relevant).  To
duplicate my results, you'll need a formatted disk with a bad spot.  Get
creative - use a magnet or a pin!  Everyone needs at least one bad diskette
in their collection.  As always, thanks for your help.

P.S. Special note to Marco - thanks for your help with my previous problems.
your examples hit the nail on the head.  I tried for several days to get
back to you but the mail kept on a-bouncin'.  Just wanted to let you know
that you're appreciated.

============================================================================

/* This crummy little program reveals a problem with AmigaDOS file
 * error handling.  It requires a known bad floppy diskette which is
 * freshly formatted.  When the media defect is encountered, a requester
 * appears:
 *
 * Volume
 * <volume name>
 * has a read error
 * RETRY            CANCEL
 *
 * Clicking on CANCEL does NOT allow Write to terminate with an I/O error.
 * It appears that the file handler loops forever, ignoring the CANCEL
 * request and retrying (whatever it's doing...). 
 *
 * Compiled/Linked with Manx Aztec C, 3.4b.
 * Please - no nits or flames on program style.  This isn't exactly something
 * I intend to save forever :-) .
 * 
 * Usage:	WriteTest <drive>
 *			where <drive> is 0 or 1
 */

#define BUFSIZE       20 * 1024
#define MODE_NEWFILE  1006L

static char *buffer;

main(argc, argv)
	int argc; char **argv;
{
	char *malloc();
	long Open(), Write(), IoErr();

	char drive;
	char fileName[20];
	long fileHandle;	/* let's pretend it's a long, OK? */ 
	long fileSize = 0;
	long status = 0;

	buffer = malloc(BUFSIZE);
	if (! buffer ) {
		puts("No memory, no testy!");
		exit(1);
	}
	if (argc != 2) {
badargs:
		puts("Usage: WriteTest <drive>");
	}
	else {
		drive = **(++argv);
		if (drive < '0' || drive > '1') goto badargs;
		sprintf(fileName,"DF%c:TestFile", drive);

		if (! (fileHandle = Open(fileName, MODE_NEWFILE) ) ) {
			printf("Couldn't create file '%s'\n", fileName);
			exit(1);
		}

		for (fileSize = 0; 
			Write(fileHandle, buffer, (long) BUFSIZE) == BUFSIZE; )
			fileSize += BUFSIZE;

		/* With a bad disk, the program never gets here. */
		status = IoErr();
		Close(fileHandle);
		printf("%ld bytes written; end status == %ld\n", 
			fileSize, status);
	}
}
-- 
< Mark R. Rinfret,  mrr@amanpt1.ZONE1.COM | ...rayssd!galaxia!amanpt1!mrr    >
< Aquidneck Management Associates       Home: 401-846-7639                   >
< 6 John Clarke Road                    Work: 401-849-8900 x56               >
< Middletown, RI 02840          	"If I just had a little more time...">