diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.18ac9/drivers/block/icside.c linux/drivers/block/icside.c
--- /tmp/linux-2.3.18ac9/drivers/block/icside.c	Sun Sep 26 20:57:08 1999
+++ linux/drivers/block/icside.c	Sun Sep 26 19:36:46 1999
@@ -382,7 +382,8 @@
 		if (drive->media != ide_disk)
 			return 0;
 
-		ide_set_handler(drive, &ide_dma_intr, WAIT_CMD);
+		drive->timeout = WAIT_CMD;
+		ide_set_handler(drive, &ide_dma_intr);
 		OUT_BYTE(reading ? WIN_READDMA : WIN_WRITEDMA,
 			 IDE_COMMAND_REG);
 
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.18ac9/drivers/block/ide-cd.c linux/drivers/block/ide-cd.c
--- /tmp/linux-2.3.18ac9/drivers/block/ide-cd.c	Sun Sep 26 20:57:38 1999
+++ linux/drivers/block/ide-cd.c	Sun Sep 26 21:04:41 1999
@@ -699,7 +699,7 @@
 		(void) (HWIF(drive)->dmaproc(ide_dma_begin, drive));
 
 	if (CDROM_CONFIG_FLAGS (drive)->drq_interrupt) {
-		ide_set_handler (drive, handler, WAIT_CMD);
+		ide_set_handler (drive, handler);
 		OUT_BYTE (WIN_PACKETCMD, IDE_COMMAND_REG); /* packet command */
 	} else {
 		OUT_BYTE (WIN_PACKETCMD, IDE_COMMAND_REG); /* packet command */
@@ -716,9 +716,13 @@
    HANDLER is the interrupt handler to call when the command completes
    or there's data ready. */
 static int cdrom_transfer_packet_command (ide_drive_t *drive,
-                                          char *cmd_buf, int cmd_len,
+                                          unsigned char *cmd_buf, int cmd_len,
 					  ide_handler_t *handler)
 {
+	/* set timeout to an hour */
+	if (cmd_buf[0] == GPCMD_BLANK || cmd_buf[0] == GPCMD_FORMAT_UNIT)
+		drive->timeout = 3600*HZ;
+
 	if (CDROM_CONFIG_FLAGS (drive)->drq_interrupt) {
 		/* Here we should have been called after receiving an interrupt
 		   from the device.  DRQ should how be set. */
@@ -734,7 +738,7 @@
 	}
 
 	/* Arm the interrupt handler. */
-	ide_set_handler (drive, handler, WAIT_CMD);
+	ide_set_handler (drive, handler);
 
 	/* Send the command to the device. */
 	atapi_output_bytes (drive, cmd_buf, cmd_len);
@@ -827,6 +831,12 @@
 			atapi_output_bytes (drive, &dum, sizeof (dum));
 			len -= sizeof (dum);
 		}
+	} else  if (ireason == 1) {
+		/* Some drives (ASUS) seem to tell us that status
+		 * info is available. just get it and ignore.
+		 */
+		GET_STAT();
+		return 0;
 	} else {
 		/* Drive wants a command packet, or invalid ireason... */
 		printk ("%s: cdrom_read_intr: bad interrupt reason %d\n",
@@ -837,7 +847,6 @@
 	return -1;
 }
 
-
 /*
  * Interrupt routine.  Called when a read request has completed.
  */
@@ -966,7 +975,7 @@
 
 	/* Done moving data!
 	   Wait for another interrupt. */
-	ide_set_handler (drive, &cdrom_read_intr, WAIT_CMD);
+	ide_set_handler (drive, &cdrom_read_intr);
 }
 
 
@@ -1026,8 +1035,6 @@
 	return 0;
 }
 
-
-
 /*
  * Routine to send a read packet command to the drive.
  * This is usually called directly from cdrom_start_read.
@@ -1084,7 +1091,7 @@
 	pc.c[0] = GPCMD_READ_10;
 	pc.c[7] = (nframes >> 8);
 	pc.c[8] = (nframes & 0xff);
-	put_unaligned(htonl (frame), (unsigned int *) &pc.c[2]);
+	put_unaligned(cpu_to_be32(frame), (unsigned int *) &pc.c[2]);
 
 	/* Send the command to the drive and return. */
 	(void) cdrom_transfer_packet_command (drive, pc.c, sizeof (pc.c),
@@ -1127,7 +1134,7 @@
 
 	memset (&pc.c, 0, sizeof (pc.c));
 	pc.c[0] = GPCMD_SEEK;
-	put_unaligned(htonl (frame), (unsigned int *) &pc.c[2]);
+	put_unaligned(cpu_to_be32(frame), (unsigned int *) &pc.c[2]);
 	(void) cdrom_transfer_packet_command (drive, pc.c, sizeof (pc.c), &cdrom_seek_intr);
 }
 
@@ -1179,8 +1186,6 @@
 }
 
 
-
-
 /****************************************************************************
  * Execute all other packet commands.
  */
@@ -1197,6 +1202,9 @@
 	struct request *rq = HWGROUP(drive)->rq;
 	struct packet_command *pc = (struct packet_command *)rq->buffer;
 
+	/* restore timeout after blank or format command */
+	drive->timeout = WAIT_CMD;
+
 	/* Check for errors. */
 	if (cdrom_decode_status (drive, 0, &stat))
 		return;
@@ -1282,7 +1290,7 @@
 	}
 
 	/* Now we wait for another interrupt. */
-	ide_set_handler (drive, &cdrom_pc_intr, WAIT_CMD);
+	ide_set_handler (drive, &cdrom_pc_intr);
 }
 
 
@@ -1334,6 +1342,7 @@
 	if (pc->sense_data == NULL)
 		pc->sense_data = &my_reqbuf;
 	pc->sense_data->sense_key = 0;
+
 	/* Start of retry loop. */
 	do {
 		ide_init_drive_cmd (&req);
@@ -1368,7 +1377,6 @@
 		/* End of retry loop. */
 	} while (pc->stat != 0 && retries >= 0);
 
-
 	/* Return an error if the command failed. */
 	if (pc->stat != 0)
 		return -EIO;
@@ -1397,16 +1405,8 @@
 static
 void ide_do_rw_cdrom (ide_drive_t *drive, struct request *rq, unsigned long block)
 {
-	if (rq -> cmd == PACKET_COMMAND || rq -> cmd == REQUEST_SENSE_COMMAND)
-		cdrom_do_packet_command (drive);
-	else if (rq -> cmd == RESET_DRIVE_COMMAND) {
-		cdrom_end_request (1, drive);
-		ide_do_reset (drive);
-		return;
-	} else if (rq -> cmd != READ) {
-		printk ("ide-cd: bad cmd %d\n", rq -> cmd);
-		cdrom_end_request (0, drive);
-	} else {
+	switch (rq->cmd) {
+	case READ: {
 		struct cdrom_info *info = drive->driver_data;
 
 		if (CDROM_CONFIG_FLAGS(drive)->seeking) {
@@ -1415,7 +1415,7 @@
 
 			if ((stat & SEEK_STAT) != SEEK_STAT) {
 				if (elpased < IDECD_SEEK_TIMEOUT) {
-					ide_stall_queue (drive, IDECD_SEEK_TIMER);
+					ide_stall_queue(drive, IDECD_SEEK_TIMER);
 					return;
 				}
 				printk ("%s: DSC timeout\n", drive->name);
@@ -1427,6 +1427,26 @@
 		else
 			cdrom_start_read (drive, block);
 		info->last_block = block;
+		break;
+	}
+
+	case PACKET_COMMAND:
+	case REQUEST_SENSE_COMMAND: {
+		cdrom_do_packet_command(drive);
+		break;
+	}
+
+	case RESET_DRIVE_COMMAND: {
+		cdrom_end_request(1, drive);
+		ide_do_reset(drive);
+		break;
+	}
+
+	default: {
+		printk("ide-cd: bad cmd %d\n", rq -> cmd);
+		cdrom_end_request(0, drive);
+		break;
+	}
 	}
 }
 
@@ -1600,7 +1620,7 @@
 
 	stat = cdrom_queue_packet_command (drive, &pc);
 	if (stat == 0)
-		*capacity = ntohl (capbuf.lba);
+		*capacity = be32_to_cpu(capbuf.lba);
 
 	return stat;
 }
@@ -1879,64 +1899,7 @@
 
 
 
-/* This gets the mechanism status per ATAPI draft spec 2.6 */
-static int
-cdrom_read_mech_status (ide_drive_t *drive, char *buf, int buflen,
-			struct atapi_request_sense *reqbuf)
-{
-	struct packet_command pc;
-
-	memset (&pc, 0, sizeof (pc));
-	pc.sense_data = reqbuf;
-
-	pc.buffer = buf;
-	pc.buflen = buflen;
-	pc.c[0] = GPCMD_MECHANISM_STATUS;
-	pc.c[8] = (buflen >> 8);
-	pc.c[9] = (buflen & 0xff);
-	return cdrom_queue_packet_command (drive, &pc);
-}
 
-/* Read the drive mechanism status and slot table into our internal buffer.
-   If the buffer does not yet exist, allocate it. */
-static int
-cdrom_read_changer_info (ide_drive_t *drive)
-{
-	int nslots;
-	struct cdrom_info *info = drive->driver_data;
-
-	if (info->changer_info)
-		nslots = info->changer_info->hdr.nslots;
-
-	else {
-		struct atapi_mechstat_header mechbuf;
-		int stat;
-
-		stat = cdrom_read_mech_status (drive,
-					       (char *)&mechbuf,
-					       sizeof (mechbuf),
-					       NULL);
-		if (stat)
-			return stat;
-
-		nslots = mechbuf.nslots;
-		info->changer_info =
-			(struct atapi_changer_info *)
-			kmalloc (sizeof (struct atapi_changer_info) +
-				 nslots * sizeof (struct atapi_slot),
-				 GFP_KERNEL);
-
-		if (info->changer_info == NULL)
-			return -ENOMEM;
-	}
-
-	return cdrom_read_mech_status
-		(drive,
-		 (char *)&info->changer_info->hdr,
-		 sizeof (struct atapi_mechstat_header) +
-		 nslots * sizeof (struct atapi_slot),
-		 NULL);
-}
 
 /* the generic packet interface to cdrom.c */
 static int ide_cdrom_packet(struct cdrom_device_info *cdi,
@@ -1952,8 +1915,7 @@
 	memcpy(pc.c, cgc->cmd, CDROM_PACKET_SIZE);
 	pc.buffer = cgc->buffer;
 	pc.buflen = cgc->buflen;
-	cgc->stat = cdrom_queue_packet_command(drive, &pc);
-	return cgc->stat;
+	return cgc->stat = cdrom_queue_packet_command(drive, &pc);
 }
 
 static
@@ -2130,7 +2092,6 @@
 int ide_cdrom_drive_status (struct cdrom_device_info *cdi, int slot_nr)
 {
 	ide_drive_t *drive = (ide_drive_t*) cdi->handle;
-	struct cdrom_info *info = drive->driver_data;
 
 	if (slot_nr == CDSL_CURRENT) {
 
@@ -2147,24 +2108,8 @@
 		}
 
 		return CDS_DRIVE_NOT_READY;
-	}
-
-#if ! STANDARD_ATAPI
-	else if (cdi->sanyo_slot > 0)
-		return CDS_NO_INFO;
-#endif /* not STANDARD_ATAPI */
-
-	else {
-		struct atapi_changer_info *ci;
-		int stat = cdrom_read_changer_info (drive);
-		if (stat < 0)
-			return stat;
-		ci = info->changer_info;
-
-		if (ci->slots[slot_nr].disc_present)
-			return CDS_DISC_OK;
-		else
-			return CDS_NO_DISC;
+	} else {
+		return -EINVAL;
 	}
 }
 
@@ -2215,47 +2160,14 @@
 				       int slot_nr)
 {
 	ide_drive_t *drive = (ide_drive_t*) cdi->handle;
-	struct cdrom_info *info = drive->driver_data;
-	struct atapi_request_sense reqbuf;
-	int retval;
 	
 	if (slot_nr == CDSL_CURRENT) {
 		(void) cdrom_check_status (drive, NULL);
-		retval = CDROM_STATE_FLAGS (drive)->media_changed;
 		CDROM_STATE_FLAGS (drive)->media_changed = 0;
+		return CDROM_STATE_FLAGS (drive)->media_changed;
+	} else {
+		return -EINVAL;
 	}
-
-#if ! STANDARD_ATAPI
-	else if (cdi->sanyo_slot > 0) {
-		retval = 0;
-	}
-#endif /* not STANDARD_ATAPI */
-
-	else {
-		struct atapi_changer_info *ci;
-		int stat = cdrom_read_changer_info (drive);
-		if (stat < 0)
-			return stat;
-		ci = info->changer_info;
-
-		/* This test may be redundant with cdrom.c. */
-		if (slot_nr < 0 || slot_nr >= ci->hdr.nslots)
-			return -EINVAL;
-
-		retval = ci->slots[slot_nr].change;
-	}
-	
-	/* if the media has changed, check if a disc is in the drive
-	   and read the toc info. */
-	if (retval || !CDROM_STATE_FLAGS (drive)->toc_valid) {
-		/* if cdrom_read_toc fails, return 1 to indicate
-		   that a disc change has occured. there might not
-		   be a disc in the drive. */
-		if ((retval = cdrom_read_toc (drive, &reqbuf)))
-			return 1;
-	}
-		
-	return retval;
 }
 
 
@@ -2361,11 +2273,12 @@
 	 * be queued with ide_cdrom_packet(), which extracts the
 	 * drive from cdi->handle. Since this device hasn't been
 	 * registered with the Uniform layer yet, it can't do this.
-	 * Same goes cdi->ops.
+	 * Same goes for cdi->ops.
 	 */
 	cdi->handle = (ide_drive_t *) drive;
 	cdi->ops = &ide_cdrom_dops;
-	do {	/* we seem to get stat=0x01,err=0x00 the first time (??) */
+	/* we seem to get stat=0x01,err=0x00 the first time (??) */
+	do {
 		if (attempts-- <= 0)
 			return 0;
 		stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CAPABILITIES_PAGE, 0);
@@ -2402,14 +2315,9 @@
 #endif /* not STANDARD_ATAPI */
 	if (buf.cap.mechtype == mechtype_individual_changer ||
 	    buf.cap.mechtype == mechtype_cartridge_changer) {
-		struct atapi_mechstat_header mechbuf;
-
-		stat = cdrom_read_mech_status (drive, (char*)&mechbuf,
-					       sizeof (mechbuf), NULL);
-		if (!stat) {
+		if ((nslots = cdrom_number_of_slots(cdi)) > 1) {
 			CDROM_CONFIG_FLAGS (drive)->is_changer = 1;
 			CDROM_CONFIG_FLAGS (drive)->supp_disc_present = 1;
-			nslots = mechbuf.nslots;
 		}
 	}
 
@@ -2445,7 +2353,7 @@
         else 	
         	printk (" drive");
 
-	printk (", %dkB Cache", ntohs(buf.cap.buffer_size));
+	printk (", %dkB Cache", be16_to_cpu(buf.cap.buffer_size));
 
 	if (drive->using_dma) {
 		if ((drive->id->field_valid & 4) &&
@@ -2482,13 +2390,12 @@
 	int minor = drive->select.b.unit << PARTN_BITS;
 	int nslots;
 
-	kdev_t dev = MKDEV(HWIF(drive)->major, minor);
-
-	set_device_ro (dev, 1);
+	set_device_ro(MKDEV(HWIF(drive)->major, minor), 1);
 	blksize_size[HWIF(drive)->major][minor] = CD_FRAMESIZE;
 
-	drive->special.all = 0;
-	drive->ready_stat = 0;
+	drive->special.all	= 0;
+	drive->ready_stat	= 0;
+	drive->timeout		= WAIT_CMD;
 
 	CDROM_STATE_FLAGS (drive)->media_changed = 1;
 	CDROM_STATE_FLAGS (drive)->toc_valid     = 0;
@@ -2594,6 +2501,8 @@
 	info->sector_buffered   = 0;
 	info->nsectors_buffered = 0;
 	info->changer_info      = NULL;
+	info->last_block	= 0;
+	info->start_seek	= 0;
 
 	nslots = ide_cdrom_probe_capabilities (drive);
 
@@ -2654,14 +2563,14 @@
 	if (ide_unregister_subdriver (drive))
 		return 1;
 	if (info->sector_buffer != NULL)
-		kfree (info->sector_buffer);
+		kfree(info->sector_buffer);
 	if (info->toc != NULL)
-		kfree (info->toc);
+		kfree(info->toc);
 	if (info->changer_info != NULL)
-		kfree (info->changer_info);
+		kfree(info->changer_info);
 	if (devinfo->handle == drive && unregister_cdrom (devinfo))
 		printk ("%s: ide_cdrom_cleanup failed to unregister device from the cdrom driver.\n", drive->name);
-	kfree (info);
+	kfree(info);
 	drive->driver_data = NULL;
 	return 0;
 }
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.18ac9/drivers/block/ide-cd.h linux/drivers/block/ide-cd.h
--- /tmp/linux-2.3.18ac9/drivers/block/ide-cd.h	Sun Sep 26 20:57:38 1999
+++ linux/drivers/block/ide-cd.h	Sat Sep 25 15:14:27 1999
@@ -96,7 +96,8 @@
 	__u8 media_changed : 1; /* Driver has noticed a media change. */
 	__u8 toc_valid     : 1; /* Saved TOC information is current. */
 	__u8 door_locked   : 1; /* We think that the drive door is locked. */
-	__u8 reserved      : 5;
+	__u8 writing       : 1; /* the drive is currently writing */
+	__u8 reserved      : 4;
 	byte current_speed;	/* Current speed of the drive */
 };
 #define CDROM_STATE_FLAGS(drive) (&(((struct cdrom_info *)(drive->driver_data))->state_flags))
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.18ac9/drivers/block/ide-disk.c linux/drivers/block/ide-disk.c
--- /tmp/linux-2.3.18ac9/drivers/block/ide-disk.c	Sun Sep 26 20:57:38 1999
+++ linux/drivers/block/ide-disk.c	Sun Sep 26 20:53:58 1999
@@ -175,7 +175,7 @@
 	if (i > 0) {
 		if (msect)
 			goto read_next;
-		ide_set_handler (drive, &read_intr, WAIT_CMD);
+		ide_set_handler (drive, &read_intr);
 	}
 }
 
@@ -206,7 +206,7 @@
 				ide_end_request(1, hwgroup);
 			if (i > 0) {
 				idedisk_output_data (drive, rq->buffer, SECTOR_WORDS);
-				ide_set_handler (drive, &write_intr, WAIT_CMD);
+				ide_set_handler (drive, &write_intr);
 			}
 			goto out;
 		}
@@ -271,7 +271,7 @@
 		if (stat & DRQ_STAT) {
 			if (rq->nr_sectors) {
 				ide_multwrite(drive, drive->mult_count);
-				ide_set_handler (drive, &multwrite_intr, WAIT_CMD);
+				ide_set_handler (drive, &multwrite_intr);
 				goto out;
 			}
 		} else {
@@ -385,7 +385,7 @@
 		if (drive->using_dma && !(HWIF(drive)->dmaproc(ide_dma_read, drive)))
 			return;
 #endif /* CONFIG_BLK_DEV_IDEDMA */
-		ide_set_handler(drive, &read_intr, WAIT_CMD);
+		ide_set_handler(drive, &read_intr);
 		OUT_BYTE(drive->mult_count ? WIN_MULTREAD : WIN_READ, IDE_COMMAND_REG);
 		return;
 	}
@@ -404,10 +404,10 @@
 			__cli();	/* local CPU only */
 		if (drive->mult_count) {
 			HWGROUP(drive)->wrq = *rq; /* scratchpad */
-			ide_set_handler (drive, &multwrite_intr, WAIT_CMD);
+			ide_set_handler (drive, &multwrite_intr);
 			ide_multwrite(drive, drive->mult_count);
 		} else {
-			ide_set_handler (drive, &write_intr, WAIT_CMD);
+			ide_set_handler (drive, &write_intr);
 			idedisk_output_data(drive, rq->buffer, SECTOR_WORDS);
 		}
 		return;
@@ -506,6 +506,7 @@
 	drive->special.all = 0;
 	drive->special.b.set_geometry = 1;
 	drive->special.b.recalibrate  = 1;
+	drive->timeout = WAIT_CMD;
 	if (OK_TO_RESET_CONTROLLER)
 		drive->mult_count = 0;
 	if (!drive->keep_settings)
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.18ac9/drivers/block/ide-dma.c linux/drivers/block/ide-dma.c
--- /tmp/linux-2.3.18ac9/drivers/block/ide-dma.c	Sun Sep 26 20:57:08 1999
+++ linux/drivers/block/ide-dma.c	Sun Sep 26 19:38:05 1999
@@ -420,7 +420,8 @@
 			drive->waiting_for_dma = 1;
 			if (drive->media != ide_disk)
 				return 0;
-			ide_set_handler(drive, &ide_dma_intr, WAIT_CMD);/* issue cmd to drive */
+			drive->timeout = WAIT_CMD;
+			ide_set_handler(drive, &ide_dma_intr);/* issue cmd to drive */
 			OUT_BYTE(reading ? WIN_READDMA : WIN_WRITEDMA, IDE_COMMAND_REG);
 		case ide_dma_begin:
 			/* Note that this is done *after* the cmd has
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.18ac9/drivers/block/ide-floppy.c linux/drivers/block/ide-floppy.c
--- /tmp/linux-2.3.18ac9/drivers/block/ide-floppy.c	Sun Sep 26 20:57:38 1999
+++ linux/drivers/block/ide-floppy.c	Sun Sep 26 20:53:58 1999
@@ -916,7 +916,7 @@
 			if (temp > pc->buffer_size) {
 				printk (KERN_ERR "ide-floppy: The floppy wants to send us more data than expected - discarding data\n");
 				idefloppy_discard_data (drive,bcount.all);
-				ide_set_handler (drive,&idefloppy_pc_intr,IDEFLOPPY_WAIT_CMD);
+				ide_set_handler (drive,&idefloppy_pc_intr);
 				return;
 			}
 #if IDEFLOPPY_DEBUG_LOG
@@ -938,7 +938,7 @@
 	pc->actually_transferred+=bcount.all;				/* Update the current position */
 	pc->current_position+=bcount.all;
 
-	ide_set_handler (drive,&idefloppy_pc_intr,IDEFLOPPY_WAIT_CMD);		/* And set the interrupt handler again */
+	ide_set_handler (drive,&idefloppy_pc_intr);		/* And set the interrupt handler again */
 }
 
 static void idefloppy_transfer_pc (ide_drive_t *drive)
@@ -956,7 +956,7 @@
 		ide_do_reset (drive);
 		return;
 	}
-	ide_set_handler (drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD);	/* Set the interrupt routine */
+	ide_set_handler (drive, &idefloppy_pc_intr);	/* Set the interrupt routine */
 	atapi_output_bytes (drive, floppy->pc->c, 12);		/* Send the actual packet */
 }
 
@@ -1025,7 +1025,7 @@
 #endif /* CONFIG_BLK_DEV_IDEDMA */
 
 	if (test_bit (IDEFLOPPY_DRQ_INTERRUPT, &floppy->flags)) {
-		ide_set_handler (drive, &idefloppy_transfer_pc, IDEFLOPPY_WAIT_CMD);
+		ide_set_handler (drive, &idefloppy_transfer_pc);
 		OUT_BYTE (WIN_PACKETCMD, IDE_COMMAND_REG);		/* Issue the packet command */
 	} else {
 		OUT_BYTE (WIN_PACKETCMD, IDE_COMMAND_REG);
@@ -1519,6 +1519,7 @@
 	*((unsigned short *) &gcw) = drive->id->config;
 	drive->driver_data = floppy;
 	drive->ready_stat = 0;
+	drive->timeout = IDEFLOPPY_WAIT_CMD;
 	memset (floppy, 0, sizeof (idefloppy_floppy_t));
 	floppy->drive = drive;
 	floppy->pc = floppy->pc_stack;
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.18ac9/drivers/block/ide-tape.c linux/drivers/block/ide-tape.c
--- /tmp/linux-2.3.18ac9/drivers/block/ide-tape.c	Sun Sep 26 20:57:38 1999
+++ linux/drivers/block/ide-tape.c	Sun Sep 26 20:53:58 1999
@@ -1833,7 +1833,7 @@
 			if (temp > pc->buffer_size) {
 				printk (KERN_ERR "ide-tape: The tape wants to send us more data than expected - discarding data\n");
 				idetape_discard_data (drive,bcount.all);
-				ide_set_handler (drive,&idetape_pc_intr,IDETAPE_WAIT_CMD);
+				ide_set_handler (drive,&idetape_pc_intr);
 				return;
 			}
 #if IDETAPE_DEBUG_LOG
@@ -1855,7 +1855,7 @@
 	pc->actually_transferred+=bcount.all;					/* Update the current position */
 	pc->current_position+=bcount.all;
 
-	ide_set_handler (drive,&idetape_pc_intr,IDETAPE_WAIT_CMD);		/* And set the interrupt handler again */
+	ide_set_handler (drive,&idetape_pc_intr);		/* And set the interrupt handler again */
 }
 
 /*
@@ -1928,7 +1928,7 @@
 		ide_do_reset (drive);
 		return;
 	}
-	ide_set_handler(drive, &idetape_pc_intr, IDETAPE_WAIT_CMD);	/* Set the interrupt routine */
+	ide_set_handler(drive, &idetape_pc_intr);	/* Set the interrupt routine */
 	atapi_output_bytes (drive,pc->c,12);			/* Send the actual packet */
 }
 
@@ -1995,7 +1995,7 @@
 	}
 #endif /* CONFIG_BLK_DEV_IDEDMA */
 	if (test_bit(IDETAPE_DRQ_INTERRUPT, &tape->flags)) {
-		ide_set_handler(drive, &idetape_transfer_pc, IDETAPE_WAIT_CMD);
+		ide_set_handler(drive, &idetape_transfer_pc);
 		OUT_BYTE(WIN_PACKETCMD, IDE_COMMAND_REG);
 	} else {
 		OUT_BYTE(WIN_PACKETCMD, IDE_COMMAND_REG);
@@ -3579,6 +3579,7 @@
 	spin_lock_init(&tape->spinlock);
 	drive->driver_data = tape;
 	drive->ready_stat = 0;			/* An ATAPI device ignores DRDY */
+	drive->timeout = IDETAPE_WAIT_CMD;
 #ifdef CONFIG_BLK_DEV_IDEPCI
 	/*
 	 *  These two ide-pci host adapters appear to need this disabled.
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.18ac9/drivers/block/ide.c linux/drivers/block/ide.c
--- /tmp/linux-2.3.18ac9/drivers/block/ide.c	Sun Sep 26 20:57:38 1999
+++ linux/drivers/block/ide.c	Sun Sep 26 20:53:58 1999
@@ -504,7 +504,7 @@
  * timer is started to prevent us from waiting forever in case
  * something goes wrong (see the ide_timer_expiry() handler later on).
  */
-void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler, unsigned int timeout)
+void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler)
 {
 	unsigned long flags;
 	ide_hwgroup_t *hwgroup = HWGROUP(drive);
@@ -517,7 +517,7 @@
 	}
 #endif
 	hwgroup->handler       = handler;
-	hwgroup->timer.expires = jiffies + timeout;
+	hwgroup->timer.expires = jiffies + drive->timeout;
 	add_timer(&(hwgroup->timer));
 	spin_unlock_irqrestore(&hwgroup->spinlock, flags);
 }
@@ -565,6 +565,7 @@
 static void atapi_reset_pollfunc (ide_drive_t *drive)
 {
 	ide_hwgroup_t *hwgroup = HWGROUP(drive);
+	unsigned long old_timeout;
 	byte stat;
 
 	SELECT_DRIVE(HWIF(drive),drive);
@@ -574,7 +575,10 @@
 		printk("%s: ATAPI reset complete\n", drive->name);
 	} else {
 		if (0 < (signed long)(hwgroup->poll_timeout - jiffies)) {
-			ide_set_handler (drive, &atapi_reset_pollfunc, HZ/20);
+			old_timeout = drive->timeout;
+			drive->timeout = HZ / 20;
+			ide_set_handler (drive, &atapi_reset_pollfunc);
+			drive->timeout = old_timeout;
 			return;	/* continue polling */
 		}
 		hwgroup->poll_timeout = 0;	/* end of polling */
@@ -595,11 +599,15 @@
 {
 	ide_hwgroup_t *hwgroup = HWGROUP(drive);
 	ide_hwif_t *hwif = HWIF(drive);
+	unsigned long old_timeout;
 	byte tmp;
 
 	if (!OK_STAT(tmp=GET_STAT(), 0, BUSY_STAT)) {
 		if (0 < (signed long)(hwgroup->poll_timeout - jiffies)) {
-			ide_set_handler (drive, &reset_pollfunc, HZ/20);
+			old_timeout = drive->timeout;
+			drive->timeout = HZ / 20;
+			ide_set_handler (drive, &reset_pollfunc);
+			drive->timeout = old_timeout;
 			return;	/* continue polling */
 		}
 		printk("%s: reset timed-out, status=0x%02x\n", hwif->name, tmp);
@@ -667,6 +675,7 @@
 	unsigned long flags;
 	ide_hwif_t *hwif = HWIF(drive);
 	ide_hwgroup_t *hwgroup = HWGROUP(drive);
+	unsigned long old_timeout;
 
 	__save_flags(flags);	/* local CPU only */
 	__cli();		/* local CPU only */
@@ -678,7 +687,10 @@
 		udelay (20);
 		OUT_BYTE (WIN_SRST, IDE_COMMAND_REG);
 		hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE;
-		ide_set_handler (drive, &atapi_reset_pollfunc, HZ/20);
+		old_timeout = drive->timeout;
+		drive->timeout = HZ / 20;
+		ide_set_handler (drive, &atapi_reset_pollfunc);
+		drive->timeout = old_timeout;
 		__restore_flags (flags);	/* local CPU only */
 		return;
 	}
@@ -708,7 +720,10 @@
 	OUT_BYTE(drive->ctl|2,IDE_CONTROL_REG);	/* clear SRST, leave nIEN */
 	udelay(10);			/* more than enough time */
 	hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE;
-	ide_set_handler (drive, &reset_pollfunc, HZ/20);
+	old_timeout = drive->timeout;
+	drive->timeout = HZ / 20;
+	ide_set_handler (drive, &reset_pollfunc);
+	drive->timeout = old_timeout;
 #endif	/* OK_TO_RESET_CONTROLLER */
 
 	__restore_flags (flags);	/* local CPU only */
@@ -899,7 +914,7 @@
  */
 void ide_cmd(ide_drive_t *drive, byte cmd, byte nsect, ide_handler_t *handler)
 {
-	ide_set_handler (drive, handler, WAIT_CMD);
+	ide_set_handler (drive, handler);
 	if (IDE_CONTROL_REG)
 		OUT_BYTE(drive->ctl,IDE_CONTROL_REG);	/* clear nIEN */
 	OUT_BYTE(nsect,IDE_NSECTOR_REG);
@@ -1373,8 +1388,8 @@
 	}
 	hwgroup->busy = 1;	/* should already be "1" */
 	hwgroup->handler = NULL;
-	del_timer(&hwgroup->timer);	/* Is this needed?? */
-	if (hwgroup->poll_timeout != 0) {	/* polling in progress? */
+	/* polling in progress or just don't timeout */
+	if (hwgroup->poll_timeout != 0) {
 		spin_unlock_irqrestore(&hwgroup->spinlock, flags);
 		handler(drive);
 	} else if (drive_is_ready(drive)) {
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.18ac9/drivers/block/paride/pcd.c linux/drivers/block/paride/pcd.c
--- /tmp/linux-2.3.18ac9/drivers/block/paride/pcd.c	Sun Sep 26 20:57:38 1999
+++ linux/drivers/block/paride/pcd.c	Sun Sep 26 20:53:58 1999
@@ -214,8 +214,11 @@
 static int pcd_get_mcn (struct cdrom_device_info *cdi, struct cdrom_mcn *mcn);
 static int pcd_audio_ioctl(struct cdrom_device_info *cdi,
 				unsigned int cmd, void *arg);
+static int pcd_packet(struct cdrom_device_info *cdi,
+				struct cdrom_generic_command *cgc);
 
 static int 	pcd_detect(void);
+static void 	pcd_probe_capabilities(void);
 static void     do_pcd_read_drq(void);
 static void 	do_pcd_request(void);
 static void 	do_pcd_read(void);
@@ -276,14 +279,18 @@
 	pcd_drive_reset,
 	pcd_audio_ioctl,
 	0,			/* dev_ioctl */
-	CDC_CLOSE_TRAY    |
-	CDC_OPEN_TRAY     |
-	CDC_LOCK          |
-	CDC_MCN		  |
-	CDC_MEDIA_CHANGED |
-	CDC_RESET	  |
-	CDC_PLAY_AUDIO,
-	0
+	CDC_CLOSE_TRAY	   |
+	CDC_OPEN_TRAY	   |
+	CDC_LOCK	   |
+	CDC_MCN		   |
+	CDC_MEDIA_CHANGED  |
+	CDC_RESET	   |
+	CDC_PLAY_AUDIO	   |
+	CDC_GENERIC_PACKET |
+	CDC_CD_R	   |
+	CDC_CD_RW,
+	0,
+	pcd_packet,
 };
 
 static void pcd_init_units( void )
@@ -325,6 +332,9 @@
 
 	if (pcd_detect()) return -1;
 
+	/* get the atapi capabilities page */
+	pcd_probe_capabilities();
+
 	if (register_blkdev(MAJOR_NR,name,&cdrom_fops)) {
 		printk("pcd: unable to get major number %d\n",MAJOR_NR);
 		return -1;
@@ -525,6 +535,16 @@
 	return r;
 }
 
+static int pcd_packet(struct cdrom_device_info *cdi,
+				struct cdrom_generic_command *cgc)
+{
+	char	*un_cmd;
+	int	unit = DEVICE_NR(cdi->dev);
+
+	un_cmd = cgc->cmd;
+	return pcd_atapi(unit,un_cmd,cgc->buflen,cgc->buffer, "generic packet");
+}
+
 #define DBMSG(msg)	((verbose>1)?(msg):NULL)
 
 static int pcd_media_changed(struct cdrom_device_info *cdi, int slot_nr)
@@ -667,6 +687,32 @@
 	return -1;
 }
 
+static void pcd_probe_capabilities( void )
+
+{	int	unit, r;
+	char	buffer[32];
+	char 	cmd[12]={0x5a,1<<3,0x2a,0,0,0,0,18,0,0,0,0};
+
+	for (unit=0;unit<PCD_UNITS;unit++) {
+		if (!PCD.present) continue;
+		r = pcd_atapi(unit,cmd,18, buffer,"mode sense capabilities");
+		if (r) continue;
+		/* we should now have the cap page */
+		if ((buffer[11] & 1) == 0)
+			PCD.info.mask |= CDC_CD_R;
+		if ((buffer[11] & 2) == 0)
+			PCD.info.mask |= CDC_CD_RW;
+		if ((buffer[12] & 1) == 0)
+			PCD.info.mask |= CDC_PLAY_AUDIO;
+		if ((buffer[14] & 1) == 0)
+			PCD.info.mask |= CDC_LOCK;
+		if ((buffer[14] & 8) == 0)
+			PCD.info.mask |= CDC_OPEN_TRAY;
+		if ((buffer[14] >> 6) == 0)
+			PCD.info.mask |= CDC_CLOSE_TRAY;
+	}
+}
+
 static int pcd_detect( void )
 
 {	char    id[18];
@@ -836,63 +882,6 @@
  
     	switch (cmd) { 
     
-	case CDROMPAUSE: 
-
-	{       char cmd[12]={GPCMD_PAUSE_RESUME,0,0,0,0,0,0,0,0,0,0,0};
-
-		return (pcd_atapi(unit,cmd,0,NULL,"pause")) * EIO;
-	}
-
-	case CDROMRESUME:
-	
-	{       char cmd[12]={GPCMD_PAUSE_RESUME,0,0,0,0,0,0,0,1,0,0,0};
-
-		return (pcd_atapi(unit,cmd,0,NULL,"resume")) * EIO;
-	}
-	
-	case CDROMPLAYMSF:
-
-	{	char cmd[12]={GPCMD_PLAY_AUDIO_MSF,0,0,0,0,0,0,0,0,0,0,0};
-		struct cdrom_msf* msf = (struct cdrom_msf*)arg;
-
-		cmd[3] = msf->cdmsf_min0;
-		cmd[4] = msf->cdmsf_sec0;
-		cmd[5] = msf->cdmsf_frame0;
-		cmd[6] = msf->cdmsf_min1;
-		cmd[7] = msf->cdmsf_sec1;
-		cmd[8] = msf->cdmsf_frame1;
-	
-		return (pcd_atapi(unit,cmd,0,NULL,"play msf")) * EIO;
-    	}
-
-    	case CDROMPLAYBLK:
-
-    	{	char cmd[12]={GPCMD_PLAY_AUDIO_10,0,0,0,0,0,0,0,0,0,0,0};
-		struct cdrom_blk* blk = (struct cdrom_blk*)arg;
-
-		cmd[2] = blk->from >> 24;
-		cmd[3] = blk->from >> 16;
-		cmd[4] = blk->from >> 8;
-		cmd[5] = blk->from;
-		cmd[7] = blk->len >> 8;
-		cmd[8] = blk->len;
-	
-		return (pcd_atapi(unit,cmd,0,NULL,"play block")) * EIO;
-    	}
-		
-    	case CDROMPLAYTRKIND:
-
-    	{	char cmd[12]={GPCMD_PLAYAUDIO_TI,0,0,0,0,0,0,0,0,0,0,0};
-		struct cdrom_ti* ti = (struct cdrom_ti*)arg;
-
-		cmd[4] = ti->cdti_trk0;
-		cmd[5] = ti->cdti_ind0;
-		cmd[7] = ti->cdti_trk1;
-		cmd[8] = ti->cdti_ind1;
-
-		return (pcd_atapi(unit,cmd,0,NULL,"play track")) * EIO;
-    	}
-	
     	case CDROMREADTOCHDR:
     
 	{	char cmd[12]={GPCMD_READ_TOC_PMA_ATIP,0,0,0,0,0,0,0,12,0,0,0};
@@ -935,97 +924,6 @@
 	
                 return r * EIO;
         }
-
-    	case CDROMSTOP:
-
-	{	char cmd[12]={GPCMD_START_STOP_UNIT,1,0,0,0,0,0,0,0,0,0,0};
-
-                return (pcd_atapi(unit,cmd,0,NULL,"stop")) * EIO;
-        }                                                         
-	
-    	case CDROMSTART:
-
-        {       char cmd[12]={GPCMD_START_STOP_UNIT,1,0,0,1,0,0,0,0,0,0,0};
-
-                return (pcd_atapi(unit,cmd,0,NULL,"start")) * EIO;
-        } 
-	
-    	case CDROMVOLCTRL:
-
-	{	char cmd[12]={GPCMD_MODE_SENSE_10,0,0,0,0,0,0,0,0,0,0,0};
-		char buffer[32];
-		char mask[32];
-		struct cdrom_volctrl* volctrl = (struct cdrom_volctrl*)arg;
-
-		cmd[2] = 0xe;
-		cmd[4] = 28;
-
-                if (pcd_atapi(unit,cmd,28,buffer,"mode sense vol")) 
-			return -EIO;
-
-		cmd[2] = 0x4e;
-	
-		if (pcd_atapi(unit,cmd,28,buffer,"mode sense vol mask"))
-			return -EIO;
-	
-		buffer[0] = 0;
-	
-		buffer[21] = volctrl->channel0 & mask[21];
-		buffer[23] = volctrl->channel1 & mask[23];
-		buffer[25] = volctrl->channel2 & mask[25];
-		buffer[27] = volctrl->channel3 & mask[27];
-	
-		cmd[0] = 0x55;
-		cmd[1] = 0x10;
-
-		return pcd_atapi(unit,cmd,28,buffer,"mode select vol") * EIO;
-    	}
-
-    	case CDROMVOLREAD:
-
-        {       char cmd[12]={GPCMD_MODE_SENSE_10,0,0,0,0,0,0,0,0,0,0,0};
-                char buffer[32];
-                struct cdrom_volctrl* volctrl = (struct cdrom_volctrl*)arg;
-                int     r;
-
-                cmd[2] = 0xe;
-                cmd[4] = 28;
-
-                r = pcd_atapi(unit,cmd,28,buffer,"mode sense vol read");
-
-		volctrl->channel0 = buffer[21];
-		volctrl->channel1 = buffer[23];
-		volctrl->channel2 = buffer[25];
-		volctrl->channel3 = buffer[27];
-
-                return r * EIO;
-        }
-  
-	
-    	case CDROMSUBCHNL:
-
-	{	char cmd[12]={GPCMD_READ_SUBCHANNEL,2,0x40,1,0,0,0,0,16,0,0,0};
-		struct cdrom_subchnl* subchnl = (struct cdrom_subchnl*)arg;
-		char buffer[32];
-	
-                if (pcd_atapi(unit,cmd,16,buffer,"read subchannel"))
-                        return -EIO;
-   	
-		subchnl->cdsc_audiostatus = buffer[1];
-		subchnl->cdsc_format = CDROM_MSF;
-		subchnl->cdsc_ctrl = buffer[5] & 0xf;
-		subchnl->cdsc_trk = buffer[6];
-		subchnl->cdsc_ind = buffer[7];
-	
-		subchnl->cdsc_reladdr.msf.minute = buffer[13];
-		subchnl->cdsc_reladdr.msf.second = buffer[14];
-		subchnl->cdsc_reladdr.msf.frame = buffer[15];
-		subchnl->cdsc_absaddr.msf.minute = buffer[9];
-		subchnl->cdsc_absaddr.msf.second = buffer[10];
-		subchnl->cdsc_absaddr.msf.frame = buffer[11];
-
-		return 0;	
-    	}
 
     	default:
 
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.18ac9/drivers/block/pdc4030.c linux/drivers/block/pdc4030.c
--- /tmp/linux-2.3.18ac9/drivers/block/pdc4030.c	Sat Jun 26 17:34:20 1999
+++ linux/drivers/block/pdc4030.c	Sun Sep 26 19:45:40 1999
@@ -162,6 +162,7 @@
 	if (!hwif) return 0;
 
 	drive = &hwif->drives[0];
+	drive->timeout = HZ/100;
 	hwif2 = &ide_hwifs[hwif->index+1];
 	if (hwif->chipset == ide_pdc4030) /* we've already been found ! */
 		return 1;
@@ -307,6 +308,9 @@
 	unsigned int sectors_left, sectors_avail, nsect;
 	struct request *rq;
 
+	/* reset timeout */
+	drive->timeout = HZ/100;
+	
 	if (!OK_STAT(stat=GET_STAT(),DATA_READY,BAD_R_STAT)) {
 		ide_error(drive, "promise_read_intr", stat);
 		return;
@@ -361,7 +365,8 @@
 		if (stat & DRQ_STAT)
 			goto read_again;
 		if (stat & BUSY_STAT) {
-			ide_set_handler (drive, &promise_read_intr, WAIT_CMD);
+			drive->timeout = WAIT_CMD;
+			ide_set_handler (drive, &promise_read_intr);
 #ifdef DEBUG_READ
 			printk(KERN_DEBUG "%s: promise_read: waiting for"
 			       "interrupt\n", drive->name);
@@ -390,7 +395,7 @@
 
 	if (GET_STAT() & BUSY_STAT) {
 		if (time_before(jiffies, hwgroup->poll_timeout)) {
-			ide_set_handler(drive, &promise_complete_pollfunc, 1);
+			ide_set_handler(drive, &promise_complete_pollfunc);
 			return; /* continue polling... */
 		}
 		hwgroup->poll_timeout = 0;
@@ -419,7 +424,7 @@
 
 	if (IN_BYTE(IDE_NSECTOR_REG) != 0) {
 		if (time_before(jiffies, hwgroup->poll_timeout)) {
-			ide_set_handler (drive, &promise_write_pollfunc, 1);
+			ide_set_handler (drive, &promise_write_pollfunc);
 			return; /* continue polling... */
 		}
 		hwgroup->poll_timeout = 0;
@@ -433,7 +438,7 @@
 	 */
 	ide_multwrite(drive, 4);
 	hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE;
-	ide_set_handler(drive, &promise_complete_pollfunc, 1);
+	ide_set_handler(drive, &promise_complete_pollfunc);
 #ifdef DEBUG_WRITE
 	printk(KERN_DEBUG "%s: Done last 4 sectors - status = %02x\n",
 		drive->name, GET_STAT());
@@ -466,7 +471,7 @@
 	if (rq->nr_sectors > 4) {
 		ide_multwrite(drive, rq->nr_sectors - 4);
 		hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE;
-		ide_set_handler (drive, &promise_write_pollfunc, 1);
+		ide_set_handler (drive, &promise_write_pollfunc);
 	} else {
 	/*
 	 * There are 4 or fewer sectors to transfer, do them all in one go
@@ -474,7 +479,7 @@
 	 */
 		ide_multwrite(drive, rq->nr_sectors);
 		hwgroup->poll_timeout = jiffies + WAIT_WORSTCASE;
-		ide_set_handler(drive, &promise_complete_pollfunc, 1);
+		ide_set_handler(drive, &promise_complete_pollfunc);
 #ifdef DEBUG_WRITE
 		printk(KERN_DEBUG "%s: promise_write: <= 4 sectors, "
 			"status = %02x\n", drive->name, GET_STAT());
@@ -517,7 +522,8 @@
 				printk(KERN_DEBUG "%s: read: waiting for "
 				                  "interrupt\n", drive->name);
 #endif
-				ide_set_handler(drive, &promise_read_intr, WAIT_CMD);
+				drive->timeout = WAIT_CMD;
+				ide_set_handler(drive, &promise_read_intr);
 				return;
 			}
 			udelay(1);
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.18ac9/drivers/cdrom/cdrom.c linux/drivers/cdrom/cdrom.c
--- /tmp/linux-2.3.18ac9/drivers/cdrom/cdrom.c	Sun Sep 26 20:57:38 1999
+++ linux/drivers/cdrom/cdrom.c	Sun Sep 26 19:16:46 1999
@@ -177,10 +177,15 @@
   for ide-cd to handle multisession discs.
   -- Export cdrom_mode_sense and cdrom_mode_select.
   -- init_cdrom_command() for setting up a cgc command.
+  
+  3.05 Sep 23, 1999 - Jens Axboe <axboe@image.dk>
+  -- Changed the interface for CDROM_SEND_PACKET. Before it was virtually
+  impossible to send the drive data in a sensible way.
+  
 -------------------------------------------------------------------------*/
 
-#define REVISION "Revision: 3.04"
-#define VERSION "Id: cdrom.c 3.04 1999/09/14"
+#define REVISION "Revision: 3.05"
+#define VERSION "Id: cdrom.c 3.05 1999/09/23"
 
 /* I use an error-log mask to give fine grain control over the type of
    messages dumped to the system logs.  The available masks include: */
@@ -213,6 +218,7 @@
 #include <linux/cdrom.h>
 #include <linux/sysctl.h>
 #include <linux/proc_fs.h>
+#include <linux/init.h>
 #include <asm/fcntl.h>
 #include <asm/segment.h>
 #include <asm/uaccess.h>
@@ -302,6 +308,8 @@
  */
 #define ENSURE(call, bits) if (cdo->call == NULL) *change_capability &= ~(bits)
 
+static int cdrom_setup_writemode(struct cdrom_device_info *cdi);
+
 int register_cdrom(struct cdrom_device_info *cdi)
 {
 	static char banner_printed = 0;
@@ -316,7 +324,7 @@
 	if (cdo->open == NULL || cdo->release == NULL)
 		return -2;
 	if ( !banner_printed ) {
-		printk(KERN_INFO "Uniform CDROM driver " REVISION "\n");
+		printk(KERN_INFO "Uniform CD-ROM driver " REVISION "\n");
 		banner_printed = 1;
 #ifdef CONFIG_SYSCTL
 		cdrom_sysctl_register();
@@ -349,6 +357,9 @@
 	cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
 	cdi->next = topCdromPtr; 	
 	topCdromPtr = cdi;
+	if (CDROM_CAN(CDC_CD_R) || CDROM_CAN(CDC_CD_RW) || CDROM_CAN(CDC_DVD_R))
+		(void)cdrom_setup_writemode(cdi);
+				
 	return 0;
 }
 #undef ENSURE
@@ -1701,8 +1712,8 @@
 		     unsigned long arg)
 {		
 	struct cdrom_device_ops *cdo = cdi->ops;
-	kdev_t dev = cdi->dev;
 	struct cdrom_generic_command cgc;
+	kdev_t dev = cdi->dev;
 	char buffer[32];
 	int ret = 0;
 
@@ -1919,7 +1930,7 @@
 
 	case CDROMSTART:
 	case CDROMSTOP: {
-		cdinfo(CD_DO_IOCTL, "entering audio ioctl (start/stop)\n"); 
+		cdinfo(CD_DO_IOCTL, "entering CDROMSTART/CDROMSTOP\n"); 
 		cgc.cmd[0] = GPCMD_START_STOP_UNIT;
 		cgc.cmd[1] = 1;
 		cgc.cmd[4] = (cmd == CDROMSTART) ? 1 : 0;
@@ -1928,7 +1939,7 @@
 
 	case CDROMPAUSE:
 	case CDROMRESUME: {
-		cdinfo(CD_DO_IOCTL, "entering audio ioctl (pause/resume)\n"); 
+		cdinfo(CD_DO_IOCTL, "entering CDROMPAUSE/CDROMRESUME\n"); 
 		cgc.cmd[0] = GPCMD_PAUSE_RESUME;
 		cgc.cmd[8] = (cmd == CDROMRESUME) ? 1 : 0;
 		return cdo->generic_packet(cdi, &cgc);
@@ -1938,7 +1949,7 @@
 		dvd_struct s;
 		if (!CDROM_CAN(CDC_DVD))
 			return -ENOSYS;
-		cdinfo(CD_DO_IOCTL, "entering dvd_read_struct\n"); 
+		cdinfo(CD_DO_IOCTL, "entering DVD_READ_STRUCT\n"); 
 		IOCTL_IN(arg, dvd_struct, s);
 		if ((ret = dvd_read_struct(cdi, &s)))
 			return ret;
@@ -1950,7 +1961,7 @@
 		dvd_authinfo ai;
 		if (!CDROM_CAN(CDC_DVD))
 			return -ENOSYS;
-		cdinfo(CD_DO_IOCTL, "entering dvd_auth\n"); 
+		cdinfo(CD_DO_IOCTL, "entering DVD_AUTH\n"); 
 		IOCTL_IN(arg, dvd_authinfo, ai);
 		if ((ret = dvd_do_auth (cdi, &ai)))
 			return ret;
@@ -1959,26 +1970,58 @@
 		}
 
 	case CDROM_SEND_PACKET: {
+		__u8 *userbuf, copy = 0;
 		if (!CDROM_CAN(CDC_GENERIC_PACKET))
 			return -ENOSYS;
-		cdinfo(CD_DO_IOCTL, "entering send_packet\n"); 
+		cdinfo(CD_DO_IOCTL, "entering CDROM_SEND_PACKET\n"); 
 		IOCTL_IN(arg, struct cdrom_generic_command, cgc);
-		cgc.buffer = kmalloc(cgc.buflen, GFP_KERNEL);
+		copy = !!cgc.buflen;
+		userbuf = cgc.buffer;
+		cgc.buffer = NULL;
+		if (userbuf != NULL && copy) {
+			/* usually commands just copy data one way, i.e.
+			 * we send a buffer to the drive and the command
+			 * specifies whether the drive will read or
+			 * write to that buffer. usually the buffers
+			 * are very small, so we don't loose that much
+			 * by doing a redundant copy each time. */
+			if (!access_ok(VERIFY_WRITE, userbuf, cgc.buflen)) {
+				printk("can't get write perms\n");
+				return -EFAULT;
+			}
+			if (!access_ok(VERIFY_READ, userbuf, cgc.buflen)) {
+				printk("can't get read perms\n");
+				return -EFAULT;
+			}
+		}
+		/* reasonable limits */
+		if (cgc.buflen < 0 || cgc.buflen > 131072) {
+			printk("invalid size given\n");
+			return -EINVAL;
+		}
+		if (copy) {
+			cgc.buffer = kmalloc(cgc.buflen, GFP_KERNEL);
+			if (cgc.buffer == NULL)
+				return -ENOMEM;
+			__copy_from_user(cgc.buffer, userbuf, cgc.buflen);
+		}
 		ret = cdo->generic_packet(cdi, &cgc);
-		if (copy_to_user((void*)arg, cgc.buffer, cgc.buflen))
-			ret = -EFAULT;
+		if (copy && !ret)
+			__copy_to_user(userbuf, cgc.buffer, cgc.buflen);
 		kfree(cgc.buffer);
 		return ret;
 		}
 	case CDROM_NEXT_WRITABLE: {
-		long next;
+		long next = 0;
+		cdinfo(CD_DO_IOCTL, "entering CDROM_NEXT_WRITABLE\n"); 
 		if ((ret = cdrom_get_next_writable(dev, &next)))
 			return ret;
 		IOCTL_OUT(arg, long, next);
 		return 0;
 		}
 	case CDROM_LAST_WRITTEN: {
-		long last;
+		long last = 0;
+		cdinfo(CD_DO_IOCTL, "entering CDROM_LAST_WRITTEN\n"); 
 		if ((ret = cdrom_get_last_written(dev, &last)))
 			return ret;
 		IOCTL_OUT(arg, long, last);
@@ -2038,10 +2081,10 @@
 	track_information ti;
 	__u32 last_track;
 	int ret = -1;
-	
+
 	if (!CDROM_CAN(CDC_GENERIC_PACKET))
 		goto use_toc;
-	
+
 	if ((ret = cdrom_get_disc_info(dev, &di)))
 		goto use_toc;
 
@@ -2089,7 +2132,7 @@
 	track_information ti;
 	__u16 last_track;
 	int ret = -1;
-	
+
 	if (!CDROM_CAN(CDC_GENERIC_PACKET))
 		goto use_last_written;
 
@@ -2125,6 +2168,58 @@
 	}
 }
 
+/* return 0 if succesful and the disc can be considered writeable. */
+static int cdrom_setup_writemode(struct cdrom_device_info *cdi)
+{
+	struct cdrom_generic_command cgc;
+	write_param_page wp;
+	disc_information di;
+	track_information ti;
+	int ret, last_track;
+
+	memset(&di, 0, sizeof(disc_information));
+	memset(&ti, 0, sizeof(track_information));
+	memset(&wp, 0, sizeof(write_param_page));
+
+	if ((ret = cdrom_get_disc_info(cdi->dev, &di)))
+		return ret;
+
+	last_track = (di.last_track_msb << 8) | di.last_track_lsb;
+	if ((ret = cdrom_get_track_info(cdi->dev, last_track, 1, &ti)))
+		return ret;
+
+	init_cdrom_command(&cgc, &wp, 0x3c);
+	if ((ret = cdrom_mode_sense(cdi, &cgc, GPMODE_WRITE_PARMS_PAGE, 0)))
+		return ret;
+
+	/* sanity checks */
+	if ((ti.damage && !ti.nwa_v) || ti.blank)
+		return 1;
+
+	cdi->packet_size = wp.packet_size = be32_to_cpu(ti.fixed_packet_size);
+	cdi->nwa = ti.nwa_v ? be32_to_cpu(ti.next_writable) : 0;
+	wp.track_mode = ti.track_mode;
+	/* write_type 0 == packet/incremental writing */
+	wp.write_type = 0;
+
+	/* MODE1 or MODE2 writing */
+	switch (ti.data_mode) {
+	case 1: wp.data_block_type =  8; break;
+	case 2: wp.data_block_type = 13; break;
+	default: return 1;
+	}
+
+	if ((ret = cdrom_mode_select(cdi, &cgc)))
+		return ret;
+
+	printk("%s: writeable with %s packets of %lu in length", cdi->name,
+						wp.fp ? "fixed" : "variable",
+						(unsigned long)cdi->packet_size);
+	printk(", nwa = %lu\n", (unsigned long)cdi->nwa);
+
+	return 0;
+}
+
 EXPORT_SYMBOL(cdrom_get_next_writable);
 EXPORT_SYMBOL(cdrom_get_last_written);
 EXPORT_SYMBOL(cdrom_count_tracks);
@@ -2390,16 +2485,13 @@
 {
 	unregister_sysctl_table(cdrom_sysctl_header);
 }
-#endif /* endif MODULE */
 #endif /* endif CONFIG_SYSCTL */
 
-#ifdef MODULE
-
 int init_module(void)
 {
 #ifdef CONFIG_SYSCTL
 	cdrom_sysctl_register();
-#endif /* CONFIG_SYSCTL */ 
+#endif
 	return 0;
 }
 
@@ -2410,5 +2502,5 @@
 	cdrom_sysctl_unregister();
 #endif /* CONFIG_SYSCTL */ 
 }
-
 #endif /* endif MODULE */
+
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.18ac9/drivers/scsi/ide-scsi.c linux/drivers/scsi/ide-scsi.c
--- /tmp/linux-2.3.18ac9/drivers/scsi/ide-scsi.c	Sun Sep 26 20:57:43 1999
+++ linux/drivers/scsi/ide-scsi.c	Sun Sep 26 20:54:00 1999
@@ -299,11 +299,6 @@
 	scsi->pc = NULL;
 }
 
-static inline unsigned long get_timeout(idescsi_pc_t *pc)
-{
-	return IDE_MAX(WAIT_CMD, pc->timeout - jiffies);
-}
-
 /*
  *	Our interrupt handler.
  */
@@ -364,7 +359,8 @@
 				pc->actually_transferred += temp;
 				pc->current_position += temp;
 				idescsi_discard_data (drive,bcount - temp);
-				ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc));
+				drive->timeout = IDE_MAX(WAIT_CMD, pc->timeout - jiffies);
+				ide_set_handler(drive, &idescsi_pc_intr);
 				return;
 			}
 #if IDESCSI_DEBUG_LOG
@@ -388,7 +384,8 @@
 	pc->actually_transferred+=bcount;				/* Update the current position */
 	pc->current_position+=bcount;
 
-	ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc));	/* And set the interrupt handler again */
+	drive->timeout = IDE_MAX(WAIT_CMD, pc->timeout - jiffies);
+	ide_set_handler(drive, &idescsi_pc_intr);	/* And set the interrupt handler again */
 }
 
 static void idescsi_transfer_pc (ide_drive_t *drive)
@@ -407,7 +404,8 @@
 		ide_do_reset (drive);
 		return;
 	}
-	ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc));	/* Set the interrupt routine */
+	drive->timeout = IDE_MAX(WAIT_CMD, pc->timeout - jiffies);
+	ide_set_handler(drive, &idescsi_pc_intr);	/* Set the interrupt routine */
 	atapi_output_bytes (drive, scsi->pc->c, 12);			/* Send the actual packet */
 }
 
@@ -441,7 +439,8 @@
 		(void) (HWIF(drive)->dmaproc(ide_dma_begin, drive));
 	}
 	if (test_bit (IDESCSI_DRQ_INTERRUPT, &scsi->flags)) {
-		ide_set_handler (drive, &idescsi_transfer_pc, get_timeout(pc));
+		drive->timeout = IDE_MAX(WAIT_CMD, pc->timeout - jiffies);
+		ide_set_handler (drive, &idescsi_transfer_pc);
 		OUT_BYTE (WIN_PACKETCMD, IDE_COMMAND_REG);		/* Issue the packet command */
 	} else {
 		OUT_BYTE (WIN_PACKETCMD, IDE_COMMAND_REG);
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.18ac9/drivers/scsi/sr.c linux/drivers/scsi/sr.c
--- /tmp/linux-2.3.18ac9/drivers/scsi/sr.c	Sun Sep 26 20:57:43 1999
+++ linux/drivers/scsi/sr.c	Sun Sep 26 16:46:50 1999
@@ -861,7 +861,6 @@
 	unsigned char *buffer;
 	int the_result, retries;
 	Scsi_Cmnd *SCpnt;
-	unsigned long flags;
 
 	buffer = (unsigned char *) scsi_malloc(512);
 	SCpnt = scsi_allocate_device(NULL, scsi_CDs[i].device, 1);
@@ -1031,7 +1030,6 @@
 {
 	Scsi_Cmnd *SCpnt;
 	Scsi_Device *device = scsi_CDs[MINOR(cdi->dev)].device;
-	unsigned long flags;
 	int stat;
 
 	/* get the device */
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.18ac9/include/linux/cdrom.h linux/include/linux/cdrom.h
--- /tmp/linux-2.3.18ac9/include/linux/cdrom.h	Sun Sep 26 20:57:45 1999
+++ linux/include/linux/cdrom.h	Sun Sep 26 19:11:13 1999
@@ -673,6 +673,8 @@
 /* per-device flags */
         __u8 sanyo_slot		: 2;	/* Sanyo 3 CD changer support */
         __u8 reserved		: 6;	/* not used yet */
+	__u32 packet_size;		/* write out this number of packets */
+	__u32 nwa;			/* next writeable address */
 };
 
 struct cdrom_device_ops {
@@ -760,8 +762,6 @@
         __u8 uru			: 1;
         __u8 dbc_v			: 1;
 	__u8 did_v			: 1;
-#else
-#error "Please fix <asm/byteorder.h>"
 #endif
 	__u8 disc_type;
 	__u8 n_sessions_msb;
@@ -806,8 +806,6 @@
 	__u8 nwa_v			: 1;
 	__u8 lra_v			: 1;
 	__u8 reserved3			: 6;
-#else
-#error "Please fix <asm/byteorder.h>"
 #endif
 	__u32 track_start;
 	__u32 next_writable;
@@ -835,15 +833,12 @@
 	__u8 reserved1     : 4;
 	__u8 door_open     : 1;
 	__u8 mech_state    : 3;
-#else
-#error "Please fix <asm/byteorder.h>"
 #endif
 	__u8     curlba[3];
 	__u8     nslots;
 	__u8 short slot_tablelen;
 };
 
-
 struct cdrom_slot {
 #if defined(__BIG_ENDIAN_BITFIELD)
 	__u8 disc_present : 1;
@@ -853,8 +848,6 @@
 	__u8 change       : 1;
 	__u8 reserved1    : 6;
 	__u8 disc_present : 1;
-#else
-#error "Please fix <asm/byteorder.h>"
 #endif
 	__u8 reserved2[3];
 };
@@ -871,6 +864,71 @@
 	mechtype_individual_changer = 4,
 	mechtype_cartridge_changer  = 5
 } mechtype_t;
+
+struct mode_page_header {
+	__u16 mode_data_length;
+	__u8 medium_type;
+	__u8 reserved1;
+	__u8 reserved2;
+	__u8 reserved3;
+	__u16 desc_length;
+};
+
+typedef struct {
+	struct mode_page_header header;
+#if defined(__BIG_ENDIAN_BITFIELD)
+	__u8 ps			: 1;
+	__u8 reserved1		: 1;
+	__u8 page_code		: 6;
+        __u8 page_length;
+	__u8 reserved2		: 1;
+	__u8 bufe		: 1;
+	__u8 ls_v		: 1;
+	__u8 test_write		: 1;
+        __u8 write_type		: 4;
+	__u8 multi_session	: 2; /* or border, DVD */
+	__u8 fp			: 1;
+	__u8 copy		: 1;
+	__u8 track_mode		: 4;
+	__u8 reserved3		: 4;
+	__u8 data_block_type	: 4;
+#elif defined(__LITTLE_ENDIAN_BITFIELD)
+	__u8 page_code		: 6;
+	__u8 reserved1		: 1;
+	__u8 ps			: 1;
+        __u8 page_length;
+        __u8 write_type		: 4;
+	__u8 test_write		: 1;
+	__u8 ls_v		: 1;
+	__u8 bufe		: 1;
+	__u8 reserved2		: 1;
+	__u8 track_mode		: 4;
+	__u8 copy		: 1;
+	__u8 fp			: 1;
+	__u8 multi_session	: 2; /* or border, DVD */
+	__u8 data_block_type	: 4;
+	__u8 reserved3		: 4;
+#endif
+	__u8 link_size;
+	__u8 reserved4;
+#if defined(__BIG_ENDIAN_BITFIELD)
+	__u8 reserved5		: 2;
+	__u8 app_code		: 6;
+#elif defined(__LITTLE_ENDIAN_BITFIELD)
+	__u8 app_code		: 6;
+	__u8 reserved5		: 2;
+#endif
+	__u8 session_format;
+	__u8 reserved6;
+	__u32 packet_size;
+	__u16 audio_pause;
+	__u8 mcn[16];
+	__u8 isrc[16];
+	__u8 subhdr0;
+	__u8 subhdr1;
+	__u8 subhdr2;
+	__u8 subhdr3;
+} write_param_page __attribute__((packed));
 
 #endif  /* End of kernel only stuff */ 
 
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.18ac9/include/linux/ide.h linux/include/linux/ide.h
--- /tmp/linux-2.3.18ac9/include/linux/ide.h	Sun Sep 26 20:57:45 1999
+++ linux/include/linux/ide.h	Sun Sep 26 20:54:01 1999
@@ -236,6 +236,7 @@
 	unsigned long sleep;		/* sleep until this time */
 	unsigned long service_start;	/* time we started last request */
 	unsigned long service_time;	/* service time of last request */
+	unsigned long timeout;		/* max time to wait for irq */
 	special_t	special;	/* special action flags */
 	byte     keep_settings;		/* restore settings after drive reset */
 	byte     using_dma;		/* disk is using dma for read/write */
@@ -581,7 +582,7 @@
  * This is used on exit from the driver, to designate the next irq handler
  * and also to start the safety timer.
  */
-void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler, unsigned int timeout);
+void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler);
 
 /*
  * Error reporting, in human readable form (luxurious, but a memory hog).
Only in linux/net/irda: irlpt
Only in linux/: smp-2.3.18-B1
