Subject: L68K: next new amiflop patch
To: linux-m68k@lists.linux-m68k.org (linux-list),
        Jes.Sorensen@cern.ch (Jes Sorensen)
Date: Fri, 9 Jan 1998 10:33:45 +0100 (MET)
From: "J." Dorchain <dorchain@gate.moebelwalther.de>
Sender: owner-linux-m68k@phil.uni-sb.de
Reply-To: jdorchain@i-con.de

Hi,

this fixes a rather serious bug. Due to an unthought side effect of dump
search and replace, a cast had the wrong related expression, causing
innocent memory beeing overwritten, with all it's ill and silly effects.
This occured when trying to write to amigados formatted disks. msdos format
is not affected.

We learn three things:

1. beta driver are alpha in real
2. Ever think when you doing anything
3. don't use casts if you don't absolutly need them

Disgarding will take alimony for your whole life ;-)

Sorry,

Joerg


P.s.: Hopefully this was the last thing of that kind.

--- amiflop.c.07011998	Wed Jan  7 23:27:31 1998
+++ amiflop.c	Thu Jan  8 00:47:56 1998
@@ -856,7 +856,7 @@
   }
 }
 
-static unsigned long *putsec(int disk, unsigned long *raw, int track, int cnt)
+static unsigned long *putsec(int disk, unsigned long *raw, int cnt)
 {
 	struct header hdr;
 	int i;
@@ -867,14 +867,14 @@
 	*raw++ = 0x44894489;
 
 	hdr.magic = 0xFF;
-	hdr.track = track;
+	hdr.track = unit[disk].track;
 	hdr.sect = cnt;
 	hdr.ord = unit[disk].dtype->sects * unit[disk].type->sect_mult - cnt;
 	for (i = 0; i < 16; i++)
 		hdr.labels[i] = 0;
 	hdr.hdrchk = checksum((ulong *)&hdr,
 			      (char *)&hdr.hdrchk-(char *)&hdr);
-	hdr.datachk = checksum((ulong *)unit[disk].trackbuf+cnt*512, 512);
+	hdr.datachk = checksum((ulong *)(unit[disk].trackbuf+cnt*512), 512);
 
 	encode_block(raw, (ulong *)&hdr.magic, 4);
 	raw += 2;
@@ -884,7 +884,7 @@
 	raw += 2;
 	encode_block(raw, (ulong *)&hdr.datachk, 4);
 	raw += 2;
-	encode_block(raw, (ulong *)unit[disk].trackbuf+cnt*512, 512);
+	encode_block(raw, (ulong *)(unit[disk].trackbuf+cnt*512), 512);
 	raw += 256;
 
 	return raw;
@@ -902,7 +902,7 @@
 
 	/* sectors */
 	for (cnt = 0; cnt < unit[disk].dtype->sects * unit[disk].type->sect_mult; cnt++)
-		ptr = putsec (disk, ptr, unit[disk].track, cnt);
+		ptr = putsec (disk, ptr, cnt);
 	*(ushort *)ptr = (ptr[-1]&1) ? 0x2AA8 : 0xAAA8;
 }
 
@@ -1188,7 +1188,7 @@
 }
 }
 
-static unsigned long *ms_putsec(int drive, unsigned long *raw, int track, int cnt)
+static unsigned long *ms_putsec(int drive, unsigned long *raw, int cnt)
 {
 static struct dos_header hdr={0,0,0,2,0,
   {78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78,78}};
@@ -1205,8 +1205,8 @@
 *raw++=0x44895554;
 
 /* fill in the variable parts of the header */
-hdr.track=track/unit[drive].type->heads;
-hdr.side=track%unit[drive].type->heads;
+hdr.track=unit[drive].track/unit[drive].type->heads;
+hdr.side=unit[drive].track%unit[drive].type->heads;
 hdr.sec=cnt+1;
 hdr.crc=dos_hdr_crc(&hdr);
 
@@ -1266,7 +1266,7 @@
 
 /* sectors */
 for(cnt = 0; cnt < unit[disk].dtype->sects * unit[disk].type->sect_mult; cnt++)
-  ptr=ms_putsec(disk,ptr,unit[disk].track,cnt);
+  ptr=ms_putsec(disk,ptr,cnt);
 
 *(ushort *)ptr = 0xaaa8; /* MFM word before is always 0x9254 */
 }
