diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.17/drivers/block/Config.in linux/drivers/block/Config.in
--- /tmp/linux-2.3.17/drivers/block/Config.in	Wed Sep  8 21:03:28 1999
+++ linux/drivers/block/Config.in	Fri Sep 10 01:29:04 1999
@@ -28,9 +28,6 @@
     bool '     Use multi-mode by default' CONFIG_IDEDISK_MULTI_MODE
   fi
   dep_tristate '   Include IDE/ATAPI CDROM support' CONFIG_BLK_DEV_IDECD $CONFIG_BLK_DEV_IDE
-  if [ "$CONFIG_BLK_DEV_IDECD" = "y" ]; then
-    bool '     Include CD-Changer Reporting' CONFIG_IDECD_SLOTS
-  fi
   dep_tristate '   Include IDE/ATAPI TAPE support' CONFIG_BLK_DEV_IDETAPE $CONFIG_BLK_DEV_IDE
   dep_tristate '   Include IDE/ATAPI FLOPPY support' CONFIG_BLK_DEV_IDEFLOPPY $CONFIG_BLK_DEV_IDE
   dep_tristate '   SCSI emulation support' CONFIG_BLK_DEV_IDESCSI $CONFIG_BLK_DEV_IDE
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.17/drivers/block/ide-cd.c linux/drivers/block/ide-cd.c
--- /tmp/linux-2.3.17/drivers/block/ide-cd.c	Wed Sep  8 21:03:28 1999
+++ linux/drivers/block/ide-cd.c	Fri Sep 10 18:46:14 1999
@@ -12,11 +12,11 @@
  *
  * Suggestions are welcome. Patches that work are more welcome though. ;-)
  * For those wishing to work on this driver, please be sure you download
- * and comply with the latest Mt. Fuji (SFF8090 version 3) and ATAPI 
+ * and comply with the latest Mt. Fuji (SFF8090 version 4) and ATAPI 
  * (SFF-8020i rev 2.6) standards. These documents can be obtained by 
  * anonymous ftp from:
  * ftp://fission.dt.wdc.com/pub/standards/SFF/specs/INF-8020.PDF
- * ftp://fission.dt.wdc.com/pub/standards/SFF/specs/INF-8090.PDF
+ * ftp://ftp.avc-pioneer.com/Mtfuji4/Spec/Fuji4r01.pdf
  *
  * Drives that deviate from these standards will be accomodated as much
  * as possible via compile time or command-line options.  Since I only have
@@ -29,14 +29,8 @@
  *   This will allow us to get automagically notified when the media changes
  *   on ATAPI drives (something the stock ATAPI spec is lacking).  Looks
  *   very cool.  I discovered its existance the other day at work...
- * -Query the drive to find what features are available before trying to
- *   use them (like trying to close the tray in drives that can't).
  * -Make it so that Pioneer CD DR-A24X and friends don't get screwed up on
  *   boot
- * -Integrate DVD-ROM support in driver. Thanks to Merete Gotsæd-Petersen
- *   of Pioneer Denmark for providing me with a drive for testing.
- * -Implement Features and Profiles.
- *
  *
  * ----------------------------------
  * 1.00  Oct 31, 1994 -- Initial version.
@@ -548,6 +542,7 @@
 {
 	struct request *rq = HWGROUP(drive)->rq;
 	int stat, cmd, err, sense_key;
+	struct packet_command *pc = (struct packet_command *) rq->buffer;
 	
 	/* Check for errors. */
 	stat = GET_STAT();
@@ -571,8 +566,6 @@
 			   from the drive (probably while trying
 			   to recover from a former error).  Just give up. */
 
-			struct packet_command *pc = (struct packet_command *)
-				                      rq->buffer;
 			pc->stat = 1;
 			cdrom_end_request (1, drive);
 			ide_error (drive, "request sense failure", stat);
@@ -581,23 +574,11 @@
 		} else if (cmd == PACKET_COMMAND) {
 			/* All other functions, except for READ. */
 
-			struct packet_command *pc = (struct packet_command *)
-				                      rq->buffer;
 			struct semaphore *sem = NULL;
 
 			/* Check for tray open. */
 			if (sense_key == NOT_READY) {
 				cdrom_saw_media_change (drive);
-#if 0	/* let the upper layers do the complaining */
-				/* Print an error message to the syslog.
-				   Exception: don't print anything if this
-				   is a read subchannel command.  This is
-				   because workman constantly polls the drive
-				   with this command, and we don't want
-				   to uselessly fill up the syslog. */
-				if (pc->c[0] != GPCMD_READ_SUBCHANNEL)
-					printk ("%s: tray open or drive not ready\n", drive->name);
-#endif
 			} else if (sense_key == UNIT_ATTENTION) {
 				/* Check for media change. */
 				cdrom_saw_media_change (drive);
@@ -1344,13 +1325,12 @@
 	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);
 		req.cmd = PACKET_COMMAND;
 		req.buffer = (char *)pc;
-		if (ide_do_drive_cmd (drive, &req, ide_wait)) {
+		if (ide_do_drive_cmd_wait(drive, &req)) {
 			printk("%s: do_drive_cmd returned stat=%02x,err=%02x\n",
 				drive->name, req.buffer[0], req.buffer[1]);
 			/* FIXME: we should probably abort/retry or something */
@@ -1386,8 +1366,8 @@
 	else {
 		/* The command succeeded.  If it was anything other than
 		   a request sense, eject, or door lock command,
-		   and we think that the door is presently, lock it again.
-		   (The door was probably unlocked via an explicit
+		   and we think that the door is presently unlocked, lock it
+		   again. (The door was probably unlocked via an explicit
 		   CDROMEJECT ioctl.) */
 		if (CDROM_STATE_FLAGS (drive)->door_locked == 0 &&
 		    (pc->c[0] != GPCMD_TEST_UNIT_READY &&
@@ -1502,6 +1482,8 @@
 		    struct atapi_request_sense *reqbuf)
 {
 	struct packet_command pc;
+	struct cdrom_info *info = drive->driver_data;
+	struct cdrom_device_info *cdi = &info->devinfo;
 
 	memset (&pc, 0, sizeof (pc));
 
@@ -1512,7 +1494,7 @@
         /* the Sanyo 3 CD changer uses byte 7 of TEST_UNIT_READY to 
            switch CDs instead of supporting the LOAD_UNLOAD opcode   */
 
-        pc.c[7] = CDROM_STATE_FLAGS (drive)->sanyo_slot % 3;
+        pc.c[7] = cdi->sanyo_slot % 3;
 #endif /* not STANDARD_ATAPI */
 
 	return cdrom_queue_packet_command (drive, &pc);
@@ -1639,8 +1621,7 @@
 
 /* Try to read the entire TOC for the disk into our internal buffer. */
 static int
-cdrom_read_toc (ide_drive_t *drive,
-		struct atapi_request_sense *reqbuf)
+cdrom_read_toc (ide_drive_t *drive, struct atapi_request_sense *reqbuf)
 {
 	int stat, ntracks, i;
 	struct cdrom_info *info = drive->driver_data;
@@ -1685,10 +1666,9 @@
 	if (ntracks > MAX_TRACKS) ntracks = MAX_TRACKS;
 
 	/* Now read the whole schmeer. */
-	stat = cdrom_read_tocentry (drive, toc->hdr.first_track-1, 1, 0,
-				   (char *)&toc->hdr,
+	stat = cdrom_read_tocentry (drive, 0, 1, 0, (char *)&toc->hdr,
 				    sizeof (struct atapi_toc_header) +
-				    (ntracks+1) *
+				    (ntracks + 1) *
 				    sizeof (struct atapi_toc_entry), reqbuf);
 
 	if (stat && toc->hdr.first_track > 1) {
@@ -1724,6 +1704,7 @@
 	} else if (stat) {
 		return stat;
 	}
+	if (stat) return stat;
 
 	toc->hdr.toc_length = ntohs (toc->hdr.toc_length);
 
@@ -1910,48 +1891,6 @@
 }
 
 
-/* If SLOT<0, unload the current slot.  Otherwise, try to load SLOT. */
-static int
-cdrom_load_unload (ide_drive_t *drive, int slot,
-		   struct atapi_request_sense *reqbuf)
-{
-#if ! STANDARD_ATAPI
-	/* if the drive is a Sanyo 3 CD changer then TEST_UNIT_READY
-           (used in the cdrom_check_status function) is used to 
-           switch CDs instead of LOAD_UNLOAD */
-
-	if (CDROM_STATE_FLAGS (drive)->sanyo_slot > 0) {
-
-        	if ((slot == 1) || (slot == 2))
-			CDROM_STATE_FLAGS (drive)->sanyo_slot = slot;
-		else if (slot >= 0)
-			CDROM_STATE_FLAGS (drive)->sanyo_slot = 3;
-		else
-			return 0;
-
-		return cdrom_check_status (drive, reqbuf);
-
-	}
-	else
-#endif /*not STANDARD_ATAPI */
-	{
-
-		/* ATAPI Rev. 2.2+ standard for requesting switching of
-                   CDs in a multiplatter device */
-
-		struct packet_command pc;
-
-		memset (&pc, 0, sizeof (pc));
-		pc.sense_data = reqbuf;
-
-		pc.c[0] = GPCMD_LOAD_UNLOAD;
-		pc.c[4] = 2 + (slot >= 0);
-		pc.c[8] = slot;
-		return cdrom_queue_packet_command (drive, &pc);
-
-	}
-}
-
 
 /* This gets the mechanism status per ATAPI draft spec 2.6 */
 static int
@@ -2139,7 +2078,7 @@
 
 	ide_init_drive_cmd (&req);
 	req.cmd = RESET_DRIVE_COMMAND;
-	return ide_do_drive_cmd (drive, &req, ide_wait);
+	return ide_do_drive_cmd_wait(drive, &req);
 }
 
 
@@ -2202,87 +2141,6 @@
         return 0;
 }
 
-
-static
-int ide_cdrom_select_disc (struct cdrom_device_info *cdi, int slot)
-{
-	ide_drive_t *drive = (ide_drive_t*) cdi->handle;
-	struct cdrom_info *info = drive->driver_data;
-
-	struct atapi_request_sense my_reqbuf;
-	int stat;
-	int nslots, curslot;
-
-	if ( ! CDROM_CONFIG_FLAGS (drive)->is_changer) 
-		return -EDRIVE_CANT_DO_THIS;
-
-#if ! STANDARD_ATAPI
-	if (CDROM_STATE_FLAGS (drive)->sanyo_slot > 0) {
-		nslots = 3;
-		curslot = CDROM_STATE_FLAGS (drive)->sanyo_slot;
-		if (curslot == 3)
-			curslot = 0;
-	} else
-#endif /* not STANDARD_ATAPI */
-	{
-		stat = cdrom_read_changer_info (drive);
-		if (stat)
-			return stat;
-
-		nslots = info->changer_info->hdr.nslots;
-		curslot = info->changer_info->hdr.curslot;
-	}
-
-	if (slot == curslot)
-		return curslot;
-
-	if (slot == CDSL_CURRENT)
-		return curslot;
-
-	if (slot != CDSL_NONE && (slot < 0 || slot >= nslots))
-		return -EINVAL;
-
-	if (drive->usage > 1)
-		return -EBUSY;
-
-	if (slot == CDSL_NONE) {
-		(void) cdrom_load_unload (drive, -1, NULL);
-		cdrom_saw_media_change (drive);
-		(void) cdrom_lockdoor (drive, 0, NULL);
-		return 0;
-	}
-	else {
-		int was_locked;
-
-		if (
-#if ! STANDARD_ATAPI
-		    CDROM_STATE_FLAGS (drive)->sanyo_slot == 0 &&
-#endif
-		    info->changer_info->slots[slot].disc_present == 0) {
-			return -ENOMEDIUM;
-		}
-
-		was_locked = CDROM_STATE_FLAGS (drive)->door_locked;
-		if (was_locked)
-			(void) cdrom_lockdoor (drive, 0, NULL);
-
-		stat = cdrom_load_unload (drive, slot, NULL);
-		cdrom_saw_media_change (drive);
-		if (stat)
-			return stat;
-			
-		stat = cdrom_check_status (drive, &my_reqbuf);
-		if (stat && my_reqbuf.sense_key == NOT_READY)
-			return -ENOENT;
-
-		if (was_locked)
-			(void) cdrom_lockdoor (drive, 1, NULL);
-
-		return slot;
-	}
-}
-
-
 static
 int ide_cdrom_drive_status (struct cdrom_device_info *cdi, int slot_nr)
 {
@@ -2307,7 +2165,7 @@
 	}
 
 #if ! STANDARD_ATAPI
-	else if (CDROM_STATE_FLAGS (drive)->sanyo_slot > 0)
+	else if (cdi->sanyo_slot > 0)
 		return CDS_NO_INFO;
 #endif /* not STANDARD_ATAPI */
 
@@ -2383,7 +2241,7 @@
 	}
 
 #if ! STANDARD_ATAPI
-	else if (CDROM_STATE_FLAGS (drive)->sanyo_slot > 0) {
+	else if (cdi->sanyo_slot > 0) {
 		retval = 0;
 	}
 #endif /* not STANDARD_ATAPI */
@@ -2447,7 +2305,7 @@
 	ide_cdrom_tray_move,    /* tray_move */
 	ide_cdrom_lock_door,    /* lock_door */
 	ide_cdrom_select_speed, /* select_speed */
-	ide_cdrom_select_disc, /* select_disc */
+	NULL,			/* select_disc */
 	ide_cdrom_get_last_session, /* get_last_session */
 	ide_cdrom_get_mcn, /* get_mcn */
 	ide_cdrom_reset, /* reset */
@@ -2501,6 +2359,8 @@
 static
 int ide_cdrom_probe_capabilities (ide_drive_t *drive)
 {
+	struct cdrom_info *info = drive->driver_data;
+	struct cdrom_device_info *cdi = &info->devinfo;
 	int stat, nslots = 1, attempts = 3;
  	struct {
 		char pad[8];
@@ -2539,7 +2399,7 @@
 		CDROM_CONFIG_FLAGS (drive)->close_tray = 0;
 
 #if ! STANDARD_ATAPI
-	if (CDROM_STATE_FLAGS (drive)->sanyo_slot > 0) {
+	if (cdi->sanyo_slot > 0) {
 		CDROM_CONFIG_FLAGS (drive)->is_changer = 1;
 		nslots = 3;
 	}
@@ -2619,58 +2479,12 @@
 	ide_add_setting(drive,	"dsc_overlap",		SETTING_RW, -1, -1, TYPE_BYTE, 0, 1, 1,	1, &drive->dsc_overlap, NULL);
 }
 
-#ifdef CONFIG_IDECD_SLOTS
-static void ide_cdrom_slot_check (ide_drive_t *drive, int nslots)
-{
-	tracktype tracks;
-	struct cdrom_info *info = drive->driver_data;
-	struct cdrom_device_info *devinfo = &info->devinfo;
-	int slot_count = 0, drive_stat = 0, tmp;
-
-	for (slot_count=0;slot_count<nslots;slot_count++) {
-		(void) ide_cdrom_select_disc(devinfo, slot_count);
-		printk("     CD Slot %d ", slot_count+1);
-
-		drive_stat = ide_cdrom_drive_status(devinfo, slot_count);
-		if (drive_stat<0) {
-			continue;
-		} else switch(drive_stat) {
-			case CDS_DISC_OK:
-				/* use routine in Uniform CD-ROM driver */
-				cdrom_count_tracks(devinfo, &tracks);
-				tmp = tracks.audio + tracks.data +
-					tracks.cdi + tracks.xa;
-				printk(": Disc has %d track%s: ", tmp,
-					(tmp == 1)? "" : "s");
-				printk("%d=data %d=audio %d=Cd-I %d=XA\n",
-					tracks.data, tracks.audio,
-					tracks.cdi, tracks.xa);
-				break;
-			case CDS_NO_DISC:
-				printk("Empty slot.\n");
-				break;
-			case CDS_TRAY_OPEN:
-				printk("CD-ROM tray open.\n");
-				break;
-			case CDS_DRIVE_NOT_READY:
-				printk("CD-ROM drive not ready.\n");
-				break;
-			case CDS_NO_INFO:
-				printk("No Information available.\n");
-				break;
-			default:
-				printk("This Should not happen!\n");
-				break;
-		}
-	}
-	(void) ide_cdrom_select_disc(devinfo, 0);
-}
-#endif /* CONFIG_IDECD_SLOTS */
 
 static
 int ide_cdrom_setup (ide_drive_t *drive)
 {
 	struct cdrom_info *info = drive->driver_data;
+	struct cdrom_device_info *cdi = &info->devinfo;
 	int nslots;
 
 	kdev_t dev = MKDEV (HWIF (drive)->major,
@@ -2723,7 +2537,7 @@
 #if ! STANDARD_ATAPI
 	/* by default Sanyo 3 CD changer support is turned off and
            ATAPI Rev 2.2+ standard support for CD changers is used */
-	CDROM_STATE_FLAGS (drive)->sanyo_slot = 0;
+	cdi->sanyo_slot = 0;
 
 	CDROM_CONFIG_FLAGS (drive)->nec260 = 0;
 	CDROM_CONFIG_FLAGS (drive)->toctracks_as_bcd = 0;
@@ -2775,7 +2589,7 @@
                          (strcmp(drive->id->model, "CD-ROM CDR-C3G") == 0) ||
                          (strcmp(drive->id->model, "CD-ROM CDR_C36") == 0)) {
                         /* uses CD in slot 0 when value is set to 3 */
-                        CDROM_STATE_FLAGS (drive)->sanyo_slot = 3;
+                        cdi->sanyo_slot = 3;
                 }
 
 
@@ -2796,11 +2610,6 @@
 		return 1;
 	}
 	ide_cdrom_add_settings(drive);
-#ifdef CONFIG_IDECD_SLOTS
-	if (CDROM_CONFIG_FLAGS (drive)->is_changer) {
-		ide_cdrom_slot_check(drive, nslots);
-	}
-#endif /* CONFIG_IDECD_SLOTS */
 	return 0;
 }
 
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.17/drivers/block/ide-cd.h linux/drivers/block/ide-cd.h
--- /tmp/linux-2.3.17/drivers/block/ide-cd.h	Wed Sep  1 11:29:53 1999
+++ linux/drivers/block/ide-cd.h	Wed Sep  8 20:18:06 1999
@@ -96,8 +96,7 @@
 	__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 sanyo_slot    : 2; /* Sanyo 3 CD changer support */
-	__u8 reserved      : 3;
+	__u8 reserved      : 5;
 	byte current_speed;	/* Current speed of the drive */
 };
 #define CDROM_STATE_FLAGS(drive) (&(((struct cdrom_info *)(drive->driver_data))->state_flags))
@@ -218,14 +217,6 @@
 	} acdsc_reladdr;
 };
 
-
-typedef enum {
-	mechtype_caddy = 0,
-	mechtype_tray  = 1,
-	mechtype_popup = 2,
-	mechtype_individual_changer = 4,
-	mechtype_cartridge_changer  = 5
-} mechtype_t;
 
 
 /* This should probably go into cdrom.h along with the other
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.17/drivers/block/ide.c linux/drivers/block/ide.c
--- /tmp/linux-2.3.17/drivers/block/ide.c	Wed Sep  1 11:29:53 1999
+++ linux/drivers/block/ide.c	Fri Sep 10 18:37:02 1999
@@ -1618,6 +1618,48 @@
 }
 
 /*
+ * Like ide_do_drive_cmd()m but with ide_wait as ide_action. Only
+ * disables interrupts locally.
+ */
+int ide_do_drive_cmd_wait (ide_drive_t *drive, struct request *rq)
+{
+	unsigned long flags;
+	ide_hwgroup_t *hwgroup = HWGROUP(drive);
+	unsigned int major = HWIF(drive)->major;
+	struct request *cur_rq = drive->queue;
+	DECLARE_MUTEX_LOCKED(sem);
+
+#ifdef CONFIG_BLK_DEV_PDC4030
+	if (HWIF(drive)->chipset == ide_pdc4030 && rq->buffer != NULL)
+		return -ENOSYS;  /* special drive cmds not supported */
+#endif
+
+	rq->errors = 0;
+	rq->rq_status = RQ_ACTIVE;
+	rq->rq_dev = MKDEV(major,(drive->select.b.unit)<<PARTN_BITS);
+	rq->sem = &sem;
+
+	spin_lock_irqsave(&io_request_lock, flags);
+	if (cur_rq == NULL) {
+		rq->next = cur_rq;
+		drive->queue = rq;
+	} else {
+		while (cur_rq->next != NULL)	/* find end of list */
+			cur_rq = cur_rq->next;
+		rq->next = cur_rq->next;
+		cur_rq->next = rq;
+	}
+	spin_unlock_irqrestore(&io_request_lock, flags);
+	do_hwgroup_request(hwgroup);
+	__save_flags(flags);
+	__cli();
+	if (rq->rq_status != RQ_INACTIVE)
+		down(&sem);
+	__restore_flags(flags);
+	return rq->errors ? -EIO : 0;
+}
+
+/*
  * This routine is called to flush all partitions and partition tables
  * for a changed disk, and then re-read the new partition table.
  * If we are revalidating a disk because of a media change, then we
@@ -3502,6 +3544,7 @@
 EXPORT_SYMBOL(ide_do_reset);
 EXPORT_SYMBOL(ide_init_drive_cmd);
 EXPORT_SYMBOL(ide_do_drive_cmd);
+EXPORT_SYMBOL(ide_do_drive_cmd_wait);
 EXPORT_SYMBOL(ide_end_drive_cmd);
 EXPORT_SYMBOL(ide_end_request);
 EXPORT_SYMBOL(ide_revalidate_disk);
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.17/drivers/block/paride/pcd.c linux/drivers/block/paride/pcd.c
--- /tmp/linux-2.3.17/drivers/block/paride/pcd.c	Fri Sep 10 18:37:42 1999
+++ linux/drivers/block/paride/pcd.c	Fri Sep 10 11:05:28 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.17/drivers/cdrom/cdrom.c linux/drivers/cdrom/cdrom.c
--- /tmp/linux-2.3.17/drivers/cdrom/cdrom.c	Wed Sep  8 21:03:28 1999
+++ linux/drivers/cdrom/cdrom.c	Thu Sep  9 17:38:07 1999
@@ -164,6 +164,10 @@
   drivers are updated as well.
   -- Various other cleanups.
 
+  3.04 Sep 6, 1999 - Jens Axboe <axboe@image.dk>
+  -- Fixed a couple of possible memory leaks (if an operation failed and
+  we didn't free the buffer before returning the error).
+
 -------------------------------------------------------------------------*/
 
 #define REVISION "Revision: 3.03"
@@ -210,7 +214,8 @@
 static int autoclose=1;
 static int autoeject=0;
 static int lockdoor = 1;
-static int check_media_type = 1;
+/* will we ever get to use this... sigh. */
+static int check_media_type = 0;
 MODULE_PARM(debug, "i");
 MODULE_PARM(autoclose, "i");
 MODULE_PARM(autoeject, "i");
@@ -311,7 +316,6 @@
 	ENSURE(tray_move, CDC_CLOSE_TRAY | CDC_OPEN_TRAY);
 	ENSURE(lock_door, CDC_LOCK);
 	ENSURE(select_speed, CDC_SELECT_SPEED);
-	ENSURE(select_disc, CDC_SELECT_DISC);
 	ENSURE(get_last_session, CDC_MULTI_SESSION);
 	ENSURE(get_mcn, CDC_MCN);
 	ENSURE(reset, CDC_RESET);
@@ -610,6 +614,134 @@
 	return 0;
 }
 
+static int cdrom_read_mech_status(struct cdrom_device_info *cdi, 
+				  struct cdrom_changer_info *buf)
+{
+	struct cdrom_generic_command cgc;
+	struct cdrom_device_ops *cdo = cdi->ops;
+	int length;
+
+	length = sizeof(struct cdrom_mechstat_header) +
+		 cdi->capacity * sizeof(struct cdrom_slot);
+
+	cgc.cmd[0] = GPCMD_MECHANISM_STATUS;
+	cgc.cmd[8] = (length >> 8) & 0xff;
+	cgc.cmd[9] = length & 0xff;
+	cgc.buffer = (unsigned char *) buf;
+	cgc.buflen = length;
+
+	return cdo->generic_packet(cdi, &cgc);
+}
+
+static int cdrom_slot_status(struct cdrom_device_info *cdi, int slot)
+{
+	struct cdrom_changer_info info;
+	int nslots, status, curslot;
+	int stat;
+
+	if (cdi->sanyo_slot)
+		return CDS_NO_INFO;
+	
+	if ((stat = cdrom_read_mech_status(cdi, &info)) == 0) {
+		nslots = info.hdr.nslots;
+		status = info.slots[slot].disc_present;
+		curslot = info.hdr.curslot;
+		if (status)
+			return CDS_DISC_OK;
+		else
+			return CDS_NO_DISC;
+	}
+
+	return stat;
+}
+
+/* Return the number of slots for an ATAPI/SCSI cdrom, 
+ * return 0 if not a changer. 
+ */
+int cdrom_number_of_slots(struct cdrom_device_info *cdi) 
+{
+	int status;
+	int nslots = 0;
+	struct cdrom_changer_info info;
+
+	/* cdrom_read_mech_status requires a valid value for capacity: */
+	cdi->capacity = 0; 
+
+	if ((status = cdrom_read_mech_status(cdi, &info)) == 0)
+		nslots = info.hdr.nslots;
+
+	return nslots;
+}
+
+
+/* If SLOT < 0, unload the current slot.  Otherwise, try to load SLOT. */
+static int cdrom_load_unload(struct cdrom_device_info *cdi, int slot) 
+{
+	struct cdrom_generic_command cgc;
+
+	memset(&cgc, 0, sizeof(cgc));
+	cgc.cmd[0] = GPCMD_LOAD_UNLOAD;
+	cgc.cmd[4] = 2 + (slot >= 0);
+	cgc.cmd[8] = slot;
+	cgc.buffer = NULL;
+
+	/* The Sanyo 3 CD changer uses byte 7 of the 
+	GPCMD_TEST_UNIT_READY to command to switch CDs instead of
+	using the GPCMD_LOAD_UNLOAD opcode. */
+	if (cdi->sanyo_slot && slot)
+		return 0;
+
+	cgc.cmd[0] = GPCMD_TEST_UNIT_READY;
+	cgc.cmd[7] = slot;
+	cdi->sanyo_slot = slot ? slot : 3;
+
+	return cdi->ops->generic_packet(cdi, &cgc);
+}
+
+int cdrom_select_disc (struct cdrom_device_info *cdi, int slot)
+{
+	struct cdrom_changer_info info;
+	int curslot;
+	int ret;
+
+	if (!CDROM_CAN(CDC_SELECT_DISC))
+		return -EDRIVE_CANT_DO_THIS;
+
+	if (slot == CDSL_NONE) {
+		/* set media changed bits, on both queues */
+		cdi->mc_flags = 0x3;
+		return cdrom_load_unload(cdi, -1);
+	}
+
+	if ((ret = cdrom_read_mech_status(cdi, &info)))
+		return ret;
+
+	curslot = info.hdr.curslot;
+
+	if (cdi->use_count > 1 || keeplocked) {
+		if (slot == CDSL_CURRENT) {
+	    		return curslot;
+		} else {
+			return -EBUSY;
+		}
+	}
+
+	/* Specifying CDSL_CURRENT will attempt to load the currnet slot,
+	which is useful if it had been previously unloaded.
+	Whether it can or not, it returns the current slot. 
+	Similarly,  if slot happens to be the current one, we still
+	try and load it. */
+	if (slot == CDSL_CURRENT)
+		slot = curslot;
+
+	/* set media changed bits on both queues */
+	cdi->mc_flags = 0x3;
+	if ((ret = cdrom_load_unload(cdi, slot)))
+		return ret;
+
+	return slot;
+}
+
 /* We want to make media_changed accessible to the user through an
  * ioctl. The main problem now is that we must double-buffer the
  * low-level implementation, to assure that the VFS and the user both
@@ -1138,12 +1270,16 @@
 	cgc->cmd[4] = (lba >>  8) & 0xff;
 	cgc->cmd[5] = lba & 0xff;
 	/* number of blocks */
-	cgc->cmd[8] = nblocks;
+	cgc->cmd[6] = (nblocks >> 16) & 0xff;
+	cgc->cmd[7] = (nblocks >>  8) & 0xff;
+	cgc->cmd[8] = nblocks & 0xff;
 	cgc->buflen = blksize * nblocks;
+	
+	/* set the header info returned */
 	switch (blksize) {
-	case CD_FRAMESIZE_RAW0	: cgc->cmd[9] = 0x58;
-	case CD_FRAMESIZE_RAW1	: cgc->cmd[9] = 0x78;
-	case CD_FRAMESIZE_RAW	: cgc->cmd[9] = 0xf8;
+	case CD_FRAMESIZE_RAW0	: cgc->cmd[9] = 0x58; break;
+	case CD_FRAMESIZE_RAW1	: cgc->cmd[9] = 0x78; break;
+	case CD_FRAMESIZE_RAW	: cgc->cmd[9] = 0xf8; break;
 	default			: cgc->cmd[9] = 0x10;
 	}
 	
@@ -1235,15 +1371,25 @@
 		}
 
 	case CDROM_MEDIA_CHANGED: {
+		struct cdrom_changer_info info;
+
 		cdinfo(CD_DO_IOCTL, "entering CDROM_MEDIA_CHANGED\n"); 
 		if (!CDROM_CAN(CDC_MEDIA_CHANGED))
 			return -ENOSYS;
 		if (!CDROM_CAN(CDC_SELECT_DISC) || arg == CDSL_CURRENT)
 			/* cannot select disc or select current disc */
 			return media_changed(cdi, 1);
-		if ((unsigned int)arg >= cdi->capacity)
+		if ((unsigned int)arg >= cdi->capacity) {
 			return -EINVAL;
-		return cdo->media_changed (cdi, arg);
+		}
+
+		if ((ret = cdrom_read_mech_status(cdi, &info)))
+			return ret;
+
+		cdinfo(CD_DO_IOCTL, 
+		       "CDROM_MEDIA_CHANGED returning %d for slot %d\n",
+		       info.slots[arg].change, (int)arg);
+		return info.slots[arg].change;
 		}
 
 	case CDROM_SET_OPTIONS: {
@@ -1286,11 +1432,21 @@
 		cdinfo(CD_DO_IOCTL, "entering CDROM_SELECT_DISC\n"); 
 		if (!CDROM_CAN(CDC_SELECT_DISC))
 			return -ENOSYS;
-                if ((arg == CDSL_CURRENT) || (arg == CDSL_NONE)) 
-			return cdo->select_disc(cdi, arg);
-		if ((int)arg >= cdi->capacity)
+
+                if ((arg != CDSL_CURRENT) && (arg != CDSL_NONE)) {
+		    if ((int)arg >= cdi->capacity)
 			return -EINVAL;
-		return cdo->select_disc(cdi, arg);
+		}
+		/* cdo->select_disc is a hook to allow a driver-specific
+		 * way of seleting disc.  However, since there is no
+		 * equiv hook for cdrom_slot_status this may not 
+		 * actually be useful...
+		 */
+		if (cdo->select_disc != NULL)
+			return cdo->select_disc(cdi, arg);
+
+		/* no driver specific select_disc(), call our own */
+		return cdrom_select_disc(cdi, arg);
 		}
 
 	case CDROMRESET: {
@@ -1352,7 +1508,7 @@
 			return cdo->drive_status(cdi, CDSL_CURRENT);
 		if (((int)arg >= cdi->capacity))
 			return -EINVAL;
-		return cdo->drive_status(cdi, arg);
+		return cdrom_slot_status(cdi, arg);
 		}
 
 	/* Ok, this is where problems start.  The current interface for the
@@ -1552,15 +1708,13 @@
 		switch (cmd) {
 		case CDROMREADRAW:
 			blocksize = CD_FRAMESIZE_RAW;
-			format = 0;
 			break;
 		case CDROMREADMODE1:
-			blocksize = CD_FRAMESIZE; break;
+			blocksize = CD_FRAMESIZE;
 			format = 2;
 			break;
 		case CDROMREADMODE2:
-			blocksize = CD_FRAMESIZE_RAW0; break;
-			format = 0;
+			blocksize = CD_FRAMESIZE_RAW0;
 			break;
 		}
 		IOCTL_IN(arg, struct cdrom_msf, msf);
@@ -1574,7 +1728,7 @@
 		ret = cdrom_read_block(cdi, &cgc, lba, 1, format, blocksize);
 		if (!ret)
 			if (copy_to_user((char *)arg, cgc.buffer, blocksize))
-				return -EFAULT;
+				ret = -EFAULT;
 		kfree(cgc.buffer);
 		return ret;
 		}
@@ -1606,8 +1760,10 @@
 						   GFP_KERNEL)) == NULL)
 			return -ENOMEM;
 
-		if (!access_ok(VERIFY_WRITE, ra.buf, ra.nframes*CD_FRAMESIZE_RAW))
+		if (!access_ok(VERIFY_WRITE, ra.buf, ra.nframes*CD_FRAMESIZE_RAW)) {
+			kfree(cgc.buffer);
 			return -EFAULT;
+		}
 
 		while (ra.nframes > 0) {
 			ret = cdrom_read_block(cdi, &cgc, lba, ra.nframes, 1,
@@ -1642,13 +1798,29 @@
 		}
 	case CDROMPLAYTRKIND: {
 		struct cdrom_ti ti;
+		struct cdrom_tocentry entry;
+
 		cdinfo(CD_DO_IOCTL, "entering CDROMPLAYTRKIND\n");
 		IOCTL_IN(arg, struct cdrom_ti, ti);
-		cgc.cmd[0] = GPCMD_PLAYAUDIO_TI;
-		cgc.cmd[4] = ti.cdti_trk0;
-		cgc.cmd[5] = ti.cdti_ind0;
-		cgc.cmd[7] = ti.cdti_trk1;
-		cgc.cmd[8] = ti.cdti_ind1;
+		entry.cdte_format = CDROM_MSF;
+
+		/* get toc entry for start and end track */
+		entry.cdte_track = ti.cdti_trk0;
+		if (cdi->ops->audio_ioctl(cdi, CDROMREADTOCENTRY, &entry))
+			return -EINVAL;
+
+		cgc.cmd[3] = entry.cdte_addr.msf.minute;
+		cgc.cmd[4] = entry.cdte_addr.msf.second;
+		cgc.cmd[5] = entry.cdte_addr.msf.frame;
+
+		entry.cdte_track = ti.cdti_trk1;
+		if (cdi->ops->audio_ioctl(cdi, CDROMREADTOCENTRY, &entry))
+			return -EINVAL;
+
+		cgc.cmd[6] = entry.cdte_addr.msf.minute;
+		cgc.cmd[7] = entry.cdte_addr.msf.second;
+		cgc.cmd[8] = entry.cdte_addr.msf.frame;
+		cgc.cmd[0] = GPCMD_PLAY_AUDIO_MSF;
 		return cdo->generic_packet(cdi, &cgc);
 		}
 	case CDROMPLAYMSF: {
@@ -1783,10 +1955,8 @@
 		IOCTL_IN(arg, struct cdrom_generic_command, cgc);
 		cgc.buffer = kmalloc(cgc.buflen, GFP_KERNEL);
 		ret = cdo->generic_packet(cdi, &cgc);
-		if (copy_to_user((void*)arg, cgc.buffer, cgc.buflen)) {
-			kfree(cgc.buffer);
-			return -EFAULT;
-		}
+		if (copy_to_user((void*)arg, cgc.buffer, cgc.buflen))
+			ret = -EFAULT;
 		kfree(cgc.buffer);
 		return ret;
 		}
@@ -1953,6 +2123,8 @@
 EXPORT_SYMBOL(register_cdrom);
 EXPORT_SYMBOL(unregister_cdrom);
 EXPORT_SYMBOL(cdrom_fops);
+EXPORT_SYMBOL(cdrom_number_of_slots);
+EXPORT_SYMBOL(cdrom_select_disc);
 
 #ifdef CONFIG_SYSCTL
 
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.17/drivers/scsi/sr.c linux/drivers/scsi/sr.c
--- /tmp/linux-2.3.17/drivers/scsi/sr.c	Wed Sep  8 21:03:29 1999
+++ linux/drivers/scsi/sr.c	Wed Sep  8 21:51:41 1999
@@ -106,9 +106,10 @@
 	sr_audio_ioctl,		/* audio ioctl */
 	sr_dev_ioctl,		/* device-specific ioctl */
 	CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK | CDC_SELECT_SPEED |
-	CDC_MULTI_SESSION | CDC_MCN | CDC_MEDIA_CHANGED | CDC_PLAY_AUDIO |
-	CDC_RESET | CDC_IOCTLS | CDC_DRIVE_STATUS | CDC_CD_R | CDC_CD_RW |
-	CDC_DVD | CDC_DVD_R | CDC_DVD_RAM | CDC_GENERIC_PACKET,
+	CDC_SELECT_DISC | CDC_MULTI_SESSION | CDC_MCN | CDC_MEDIA_CHANGED |
+	CDC_PLAY_AUDIO | CDC_RESET | CDC_IOCTLS | CDC_DRIVE_STATUS |
+	CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R | CDC_DVD_RAM |
+	CDC_GENERIC_PACKET,
 	0,
 	sr_packet
 };
@@ -949,7 +950,7 @@
 {
 	unsigned char cmd[6];
 	unsigned char *buffer;
-	int rc, n;
+	int rc, n, nslots;
 
 	static char *loadmech[] =
 	{
@@ -958,7 +959,7 @@
 		"pop-up",
 		"",
 		"changer",
-		"changer",
+		"cartridge changer",
 		"",
 		""
 	};
@@ -1010,6 +1011,23 @@
 	if ((buffer[n + 3] & 0x1) == 0)
 		/* can't write CD-R media */
 		scsi_CDs[i].cdi.mask |= CDC_CD_R;
+	if ((buffer[n+6] & 0x8) == 0)
+		/* can't eject */
+		scsi_CDs[i].cdi.mask |= CDC_OPEN_TRAY;
+
+	if (!((buffer[n+6] >> 5) == mechtype_individual_changer ||
+	    (buffer[n+6] >> 5) == mechtype_cartridge_changer)) {
+		scsi_CDs[i].cdi.mask |= CDC_SELECT_DISC;
+	} else {
+		if ((nslots = cdrom_number_of_slots(&(scsi_CDs[i].cdi))) > 0) {
+			/* a changer can't close tray? */
+			/* scsi_CDs[i].cdi.mask |= CDC_CLOSE_TRAY; */
+			scsi_CDs[i].cdi.capacity = nslots;
+		} else {
+			/* it is not a changer */
+			scsi_CDs[i].cdi.mask |= CDC_SELECT_DISC;
+		}
+	}
 
 	scsi_free(buffer, 512);
 }
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.17/drivers/scsi/sr_ioctl.c linux/drivers/scsi/sr_ioctl.c
--- /tmp/linux-2.3.17/drivers/scsi/sr_ioctl.c	Wed Sep  1 11:29:55 1999
+++ linux/drivers/scsi/sr_ioctl.c	Tue Sep  7 21:20:50 1999
@@ -293,16 +293,14 @@
 int sr_audio_ioctl(struct cdrom_device_info *cdi, unsigned int cmd, void* arg)
 {
     u_char  sr_cmd[10];    
-    int result, target;
-    
-    target = MINOR(cdi->dev);
+    int result, target  = MINOR(cdi->dev);
+    unsigned char buffer[32];
     
     switch (cmd) 
     {
     case CDROMREADTOCHDR:
     {
 	struct cdrom_tochdr* tochdr = (struct cdrom_tochdr*)arg;
-	char buffer[32];
 	
 	sr_cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
 	sr_cmd[1] = ((scsi_CDs[target].device->lun) << 5);
@@ -323,7 +321,6 @@
     case CDROMREADTOCENTRY:
     {
 	struct cdrom_tocentry* tocentry = (struct cdrom_tocentry*)arg;
-	unsigned char buffer[32];
 	
 	sr_cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
 	sr_cmd[1] = ((scsi_CDs[target].device->lun) << 5) |
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.17/include/linux/cdrom.h linux/include/linux/cdrom.h
--- /tmp/linux-2.3.17/include/linux/cdrom.h	Wed Sep  1 11:29:58 1999
+++ linux/include/linux/cdrom.h	Wed Sep  8 20:22:06 1999
@@ -147,9 +147,9 @@
 /* Address in MSF format */
 struct cdrom_msf0		
 {
-	u_char	minute;
-	u_char	second;
-	u_char	frame;
+	__u8	minute;
+	__u8	second;
+	__u8	frame;
 };
 
 /* Address in either MSF or logical format */
@@ -162,48 +162,48 @@
 /* This struct is used by the CDROMPLAYMSF ioctl */ 
 struct cdrom_msf 
 {
-	u_char	cdmsf_min0;	/* start minute */
-	u_char	cdmsf_sec0;	/* start second */
-	u_char	cdmsf_frame0;	/* start frame */
-	u_char	cdmsf_min1;	/* end minute */
-	u_char	cdmsf_sec1;	/* end second */
-	u_char	cdmsf_frame1;	/* end frame */
+	__u8	cdmsf_min0;	/* start minute */
+	__u8	cdmsf_sec0;	/* start second */
+	__u8	cdmsf_frame0;	/* start frame */
+	__u8	cdmsf_min1;	/* end minute */
+	__u8	cdmsf_sec1;	/* end second */
+	__u8	cdmsf_frame1;	/* end frame */
 };
 
 /* This struct is used by the CDROMPLAYTRKIND ioctl */
 struct cdrom_ti 
 {
-	u_char	cdti_trk0;	/* start track */
-	u_char	cdti_ind0;	/* start index */
-	u_char	cdti_trk1;	/* end track */
-	u_char	cdti_ind1;	/* end index */
+	__u8	cdti_trk0;	/* start track */
+	__u8	cdti_ind0;	/* start index */
+	__u8	cdti_trk1;	/* end track */
+	__u8	cdti_ind1;	/* end index */
 };
 
 /* This struct is used by the CDROMREADTOCHDR ioctl */
 struct cdrom_tochdr 	
 {
-	u_char	cdth_trk0;	/* start track */
-	u_char	cdth_trk1;	/* end track */
+	__u8	cdth_trk0;	/* start track */
+	__u8	cdth_trk1;	/* end track */
 };
 
 /* This struct is used by the CDROMVOLCTRL and CDROMVOLREAD ioctls */
 struct cdrom_volctrl
 {
-	u_char	channel0;
-	u_char	channel1;
-	u_char	channel2;
-	u_char	channel3;
+	__u8	channel0;
+	__u8	channel1;
+	__u8	channel2;
+	__u8	channel3;
 };
 
 /* This struct is used by the CDROMSUBCHNL ioctl */
 struct cdrom_subchnl 
 {
-	u_char	cdsc_format;
-	u_char	cdsc_audiostatus;
-	u_char	cdsc_adr:	4;
-	u_char	cdsc_ctrl:	4;
-	u_char	cdsc_trk;
-	u_char	cdsc_ind;
+	__u8	cdsc_format;
+	__u8	cdsc_audiostatus;
+	__u8	cdsc_adr:	4;
+	__u8	cdsc_ctrl:	4;
+	__u8	cdsc_trk;
+	__u8	cdsc_ind;
 	union cdrom_addr cdsc_absaddr;
 	union cdrom_addr cdsc_reladdr;
 };
@@ -212,12 +212,12 @@
 /* This struct is used by the CDROMREADTOCENTRY ioctl */
 struct cdrom_tocentry 
 {
-	u_char	cdte_track;
-	u_char	cdte_adr	:4;
-	u_char	cdte_ctrl	:4;
-	u_char	cdte_format;
+	__u8	cdte_track;
+	__u8	cdte_adr	:4;
+	__u8	cdte_ctrl	:4;
+	__u8	cdte_format;
 	union cdrom_addr cdte_addr;
-	u_char	cdte_datamode;
+	__u8	cdte_datamode;
 };
 
 /* This struct is used by the CDROMREADMODE1, and CDROMREADMODE2 ioctls */
@@ -232,9 +232,9 @@
 struct cdrom_read_audio
 {
 	union cdrom_addr addr; /* frame address */
-	u_char addr_format;    /* CDROM_LBA or CDROM_MSF */
+	__u8 addr_format;    /* CDROM_LBA or CDROM_MSF */
 	int nframes;           /* number of 2352-byte-frames to read at once */
-	u_char *buf;           /* frame buffer (size: nframes*2352 bytes) */
+	__u8 *buf;           /* frame buffer (size: nframes*2352 bytes) */
 };
 
 /* This struct is used with the CDROMMULTISESSION ioctl */
@@ -243,8 +243,8 @@
 	union cdrom_addr addr; /* frame address: start-of-last-session 
 	                           (not the new "frame 16"!).  Only valid
 	                           if the "xa_flag" is true. */
-	u_char xa_flag;        /* 1: "is XA disk" */
-	u_char addr_format;    /* CDROM_LBA or CDROM_MSF */
+	__u8 xa_flag;        /* 1: "is XA disk" */
+	__u8 addr_format;    /* CDROM_LBA or CDROM_MSF */
 };
 
 /* This struct is used with the CDROM_GET_MCN ioctl.  
@@ -254,7 +254,7 @@
  */  
 struct cdrom_mcn 
 {
-  u_char medium_catalog_number[14]; /* 13 ASCII digits, null-terminated */
+  __u8 medium_catalog_number[14]; /* 13 ASCII digits, null-terminated */
 };
 
 /* This is used by the CDROMPLAYBLK ioctl */
@@ -495,59 +495,59 @@
 #define DVD_STRUCT_MANUFACT	0x04
 
 struct dvd_layer {
-	u_char book_version	: 4;
-	u_char book_type	: 4;
-	u_char min_rate		: 4;
-	u_char disc_size	: 4;
-	u_char layer_type	: 4;
-	u_char track_path	: 1;
-	u_char nlayers		: 2;
-	u_char track_density	: 4;
-	u_char linear_density	: 4;
-	u_char bca		: 1;
-	u_char start_sector;
-	u_char end_sector;
-	u_char end_sector_l0;
+	__u8 book_version	: 4;
+	__u8 book_type	: 4;
+	__u8 min_rate		: 4;
+	__u8 disc_size	: 4;
+	__u8 layer_type	: 4;
+	__u8 track_path	: 1;
+	__u8 nlayers		: 2;
+	__u8 track_density	: 4;
+	__u8 linear_density	: 4;
+	__u8 bca		: 1;
+	__u8 start_sector;
+	__u8 end_sector;
+	__u8 end_sector_l0;
 };
 
 struct dvd_physical {
-	u_char type;
-	u_char layer_num;
+	__u8 type;
+	__u8 layer_num;
 	struct dvd_layer layer[4];
 };
 
 struct dvd_copyright {
-	u_char type;
+	__u8 type;
 
-	u_char layer_num;
-	u_char cpst;
-	u_char rmi;
+	__u8 layer_num;
+	__u8 cpst;
+	__u8 rmi;
 };
 
 struct dvd_disckey {
-	u_char type;
+	__u8 type;
 
 	unsigned agid			: 2;
-	u_char value[2048];
+	__u8 value[2048];
 };
 
 struct dvd_bca {
-	u_char type;
+	__u8 type;
 
 	int len;
-	u_char value[188];
+	__u8 value[188];
 };
 
 struct dvd_manufact {
-	u_char type;
+	__u8 type;
 
-	u_char layer_num;
+	__u8 layer_num;
 	int len;
-	u_char value[2048];
+	__u8 value[2048];
 };
 
 typedef union {
-	u_char type;
+	__u8 type;
 
 	struct dvd_physical	physical;
 	struct dvd_copyright	copyright;
@@ -577,30 +577,30 @@
 #define DVD_INVALIDATE_AGID	9
 
 /* State data */
-typedef u_char dvd_key[5];		/* 40-bit value, MSB is first elem. */
-typedef u_char dvd_challenge[10];	/* 80-bit value, MSB is first elem. */
+typedef __u8 dvd_key[5];		/* 40-bit value, MSB is first elem. */
+typedef __u8 dvd_challenge[10];	/* 80-bit value, MSB is first elem. */
 
 struct dvd_lu_send_agid {
-	u_char type;
+	__u8 type;
 	unsigned agid		: 2;
 };
 
 struct dvd_host_send_challenge {
-	u_char type;
+	__u8 type;
 	unsigned agid		: 2;
 
 	dvd_challenge chal;
 };
 
 struct dvd_send_key {
-	u_char type;
+	__u8 type;
 	unsigned agid		: 2;
 
 	dvd_key key;
 };
 
 struct dvd_lu_send_challenge {
-	u_char type;
+	__u8 type;
 	unsigned agid		: 2;
 
 	dvd_challenge chal;
@@ -617,7 +617,7 @@
 #define DVD_CGMS_RESTRICTED	3
 
 struct dvd_lu_send_title_key {
-	u_char type;
+	__u8 type;
 	unsigned agid		: 2;
 
 	dvd_key title_key;
@@ -628,14 +628,14 @@
 };
 
 struct dvd_lu_send_asf {
-	u_char type;
+	__u8 type;
 	unsigned agid		: 2;
 
 	unsigned asf		: 1;
 };
 
 typedef union {
-	u_char type;
+	__u8 type;
 
 	struct dvd_lu_send_agid		lsa;
 	struct dvd_host_send_challenge	hsc;
@@ -658,11 +658,13 @@
 	int speed;			/* maximum speed for reading data */
 	int capacity;			/* number of discs in jukebox */
 /* device-related storage */
-	int options : 30;               /* options flags */
-	unsigned mc_flags : 2;          /* media change buffer flags */
+	int options		: 30;	/* options flags */
+	unsigned mc_flags	: 2;	/* media change buffer flags */
     	int use_count;                  /* number of times device opened */
     	char name[20];                  /* name of the device type */
-
+/* per-device flags */
+        __u8 sanyo_slot		: 2;	/* Sanyo 3 CD changer support */
+        __u8 reserved		: 6;	/* not used yet */
 };
 
 struct cdrom_device_ops {
@@ -709,6 +711,8 @@
 extern void cdrom_count_tracks(struct cdrom_device_info *cdi,tracktype* tracks);
 extern int cdrom_get_next_writable(kdev_t dev, long *next_writable);
 extern int cdrom_get_last_written(kdev_t dev, long *last_written);
+extern int cdrom_number_of_slots(struct cdrom_device_info *cdi);
+extern int cdrom_select_disc (struct cdrom_device_info *cdi, int slot);
 
 typedef struct {
 	__u16 disc_information_length;
@@ -795,6 +799,61 @@
 	__u32 track_size;
 	__u32 last_rec_address;
 } track_information;
+
+/* The SCSI spec says there could be 256 slots. */
+#define CDROM_MAX_SLOTS	256
+
+struct cdrom_mechstat_header {
+#if defined(__BIG_ENDIAN_BITFIELD)
+	__u8 fault         : 1;
+	__u8 changer_state : 2;
+	__u8 curslot       : 5;
+	__u8 mech_state    : 3;
+	__u8 door_open     : 1;
+	__u8 reserved1     : 4;
+#elif defined(__LITTLE_ENDIAN_BITFIELD)
+	__u8 curslot       : 5;
+	__u8 changer_state : 2;
+	__u8 fault         : 1;
+	__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;
+	__u8 reserved1    : 6;
+	__u8 change       : 1;
+#elif defined(__LITTLE_ENDIAN_BITFIELD)
+	__u8 change       : 1;
+	__u8 reserved1    : 6;
+	__u8 disc_present : 1;
+#else
+#error "Please fix <asm/byteorder.h>"
+#endif
+	__u8 reserved2[3];
+};
+
+struct cdrom_changer_info {
+	struct cdrom_mechstat_header hdr;
+	struct cdrom_slot slots[CDROM_MAX_SLOTS];
+};
+
+typedef enum {
+	mechtype_caddy = 0,
+	mechtype_tray  = 1,
+	mechtype_popup = 2,
+	mechtype_individual_changer = 4,
+	mechtype_cartridge_changer  = 5
+} mechtype_t;
 
 #endif  /* End of kernel only stuff */ 
 
diff -ur --exclude-from /home/axboe/cdrom/exclude-from /tmp/linux-2.3.17/include/linux/ide.h linux/include/linux/ide.h
--- /tmp/linux-2.3.17/include/linux/ide.h	Wed Sep  1 11:29:27 1999
+++ linux/include/linux/ide.h	Fri Sep 10 17:33:53 1999
@@ -688,6 +688,12 @@
 int ide_do_drive_cmd (ide_drive_t *drive, struct request *rq, ide_action_t action);
 
 /*
+ * Like ide_do_drive_cmd() but with ide_wait as ide_action. Only
+ * disables interrupts locally.
+ */
+int ide_do_drive_cmd_wait (ide_drive_t *drive, struct request *rq);
+
+/*
  * Clean up after success/failure of an explicit drive cmd.
  * stat/err are used only when (HWGROUP(drive)->rq->cmd == IDE_DRIVE_CMD).
  */
Only in linux/net/irda: irlpt
