patch-2.2.18 linux/drivers/scsi/sd.c

Next file: linux/drivers/scsi/seagate.c
Previous file: linux/drivers/scsi/scsi_obsolete.c
Back to the patch index
Back to the overall index

diff -u --new-file --recursive --exclude-from /usr/src/exclude v2.2.17/drivers/scsi/sd.c linux/drivers/scsi/sd.c
@@ -150,36 +150,43 @@
      * This is also used to lock out further access when the partition table
      * is being re-read.
      */
-
     while (rscsi_disks[target].device->busy)
         barrier();
-    if(rscsi_disks[target].device->removable) {
+
+    /*
+     * When opening removable disks, we check media...
+     * ... unless media don't matter, due to O_NONBLOCK.
+     */
+    if ( rscsi_disks[target].device->removable
+         && !(filp->f_flags & O_NONBLOCK) )
+    {
+        /*
+         * Note disk change and/or removal.
+         * Also try to read new partition table (if any).
+         */
 	check_disk_change(inode->i_rdev);
 
-	/*
-	 * If the drive is empty, just let the open fail.
-	 */
+        /*
+         * If the drive is empty, let the open fail.
+         */
 	if ( !rscsi_disks[target].ready )
-	    return -ENXIO;
+            return -ENXIO;
 
-	/*
-	 * Similarly, if the device has the write protect tab set,
-	 * have the open fail if the user expects to be able to write
-	 * to the thing.
-	 */
-	if ( (rscsi_disks[target].write_prot) && (filp->f_mode & 2) )
-	    return -EROFS;
+        /*
+         * If the device has the write protect tab set,
+         * let the open fail if the user expects to be able to write.
+         */
+        if ( (rscsi_disks[target].write_prot) && (filp->f_mode & 2) )
+            return -EROFS;
     }
 
     /*
-     * It is possible that the disk changing stuff resulted in the device being taken
-     * offline.  If this is the case, report this to the user, and don't pretend that
-     * the open actually succeeded.
+     * It is possible that the disk changing stuff (or something
+     * else?) resulted in the device being taken offline.
+     * If so, let the open fail.
      */
-    if( !rscsi_disks[target].device->online )
-    {
+    if ( !rscsi_disks[target].device->online )
         return -ENXIO;
-    }
 
     /*
      * See if we are requesting a non-existent partition.  Do this
@@ -1068,7 +1075,6 @@
     int retval;
     int target;
     struct inode inode;
-    int flag = 0;
 
     target =  DEVICE_NR(full_dev);
 
@@ -1120,11 +1126,11 @@
      * presence of disk in the drive. This is kept in the Scsi_Disk
      * struct and tested at open !  Daniel Roche ( dan@lectra.fr )
      */
-
     rscsi_disks[target].ready = 1;	/* FLOPTICAL */
 
     retval = rscsi_disks[target].device->changed;
-    if(!flag) rscsi_disks[target].device->changed = 0;
+    rscsi_disks[target].device->changed = 0;
+
     return retval;
 }
 
@@ -1769,6 +1775,8 @@
 	    dpnt->device = NULL;
 	    dpnt->capacity = 0;
 	    SDp->attached--;
+            if (SDp->scsi_request_fn == do_sd_request)
+         	SDp->scsi_request_fn = NULL;
 	    sd_template.dev_noticed--;
 	    sd_template.nr_dev--;
 	    SD_GENDISK(i).nr_real--;

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)