[patch] scsi-removeable devices

Michael Vogt (mvogt@acm.org)
Mon, 19 Jul 1999 10:15:04 +0200


Hi

This is a small patch I made for 2.3.7 (it apply fine to 2.3.10). It adds a
generic IOCTL to the scsi layer that supports ejecting removable media like
mo or scsi-zip.
"eject /dev/sdd" works fine for me and my Fujitsu mo drive.
It also cleans up sd_init_onedisk() when it try to scan a drive without medium
in it.

cu
Michael

------------------------------8<-------------------------------------
diff -r -u /usr/src/linux-2.3.7/drivers/scsi/scsi_ioctl.c /usr/src/linux/drivers/scsi/scsi_ioctl.c
--- /usr/src/linux-2.3.7/drivers/scsi/scsi_ioctl.c Sat Jun 12 19:03:02 1999
+++ /usr/src/linux/drivers/scsi/scsi_ioctl.c Mon Jun 21 17:32:04 1999
@@ -448,6 +448,19 @@
return ioctl_internal_command((Scsi_Device *) dev, scsi_cmd,
START_STOP_TIMEOUT, NORMAL_RETRIES);
break;
+ case SCSI_IOCTL_EJECT:
+ if (!dev->removable ) return 0;
+ /* allow 1 for access count for auto-eject feature */
+ if( dev->access_count > 1 )
+ return -EBUSY;
+ scsi_ioctl((Scsi_Device *)dev, SCSI_IOCTL_DOORUNLOCK, 0);
+ scsi_cmd[0] = START_STOP;
+ scsi_cmd[1] = dev->lun << 5;
+ scsi_cmd[2] = scsi_cmd[3] = scsi_cmd[5] = 0;
+ scsi_cmd[4] = 0x02 /* eject */;
+ return ioctl_internal_command((Scsi_Device *) dev, scsi_cmd,
+ START_STOP_TIMEOUT, NORMAL_RETRIES);
+ break;
default :
if (dev->host->hostt->ioctl)
return dev->host->hostt->ioctl(dev, cmd, arg);
diff -r -u /usr/src/linux-2.3.7/drivers/scsi/sd.c /usr/src/linux/drivers/scsi/sd.c
--- /usr/src/linux-2.3.7/drivers/scsi/sd.c Sat Jun 12 19:04:26 1999
+++ /usr/src/linux/drivers/scsi/sd.c Mon Jun 21 17:41:47 1999
@@ -157,10 +157,11 @@
check_disk_change(inode->i_rdev);

/*
- * If the drive is empty, just let the open fail.
+ * If the drive is empty, just let the open fail
+ * and return the same error as returned by "sr.c".
*/
if ( !rscsi_disks[target].ready )
- return -ENXIO;
+ return -ENOMEDIUM;

/*
* Similarly, if the device has the write protect tab set,
@@ -1253,6 +1254,19 @@
}

retries = 3;
+ /* if there is no medium present in a removable drive
+ * do not do a READ_CAPACITY (becaus this will fail)
+ */
+ if(the_result && rscsi_disks[i].device->removable &&
+ SCpnt->sense_buffer[2] == NOT_READY) {
+
+ /* magic, to show we have no partition */
+ sd[i << 4].start_sect = -1;
+ rscsi_disks[i].device->changed = 1;
+ rscsi_disks[i].has_part_table = 0;
+ goto no_medium_present;
+ }
+
do {
cmd[0] = READ_CAPACITY;
cmd[1] = (rscsi_disks[i].device->lun << 5) & 0xe0;
@@ -1470,6 +1484,7 @@

} /* check for write protect */

+ no_medium_present:
/* Wake up a process waiting for device */
wake_up(&SCpnt->device->device_wait);
scsi_release_command(SCpnt);
diff -r -u /usr/src/linux-2.3.7/include/scsi/scsi_ioctl.h /usr/src/linux/include/scsi/scsi_ioctl.h
--- /usr/src/linux-2.3.7/include/scsi/scsi_ioctl.h Fri May 1 18:19:58 1998
+++ /usr/src/linux/include/scsi/scsi_ioctl.h Mon Jun 21 17:39:04 1999
@@ -11,6 +11,10 @@
the cdrom */
#define SCSI_IOCTL_DOORLOCK 0x5380 /* lock the eject mechanism */
#define SCSI_IOCTL_DOORUNLOCK 0x5381 /* unlock the mechanism */
+/* eject (same as in /usr/src/linux/include/linux/cdrom.h),
+ * so "eject(1)" will work.
+*/
+#define SCSI_IOCTL_EJECT 0x5309

#define SCSI_REMOVAL_PREVENT 1
#define SCSI_REMOVAL_ALLOW 0
------------------------------8<-------------------------------------

--
"Hi! I'm a .signature virus! 
 copy me into your ~/.signature file to help me spread!"

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/