This message is copied the from usb-storage development list for wider 
exposure and testing.  I would appreciate getting bug reports from anyone 
who has a USB mass storage device and for whom this patch doesn't work.

Alan Stern

-------------------------------------------------------------------------

Matt:

Now that Patrick Mansfield's 192-byte MODE SENSE change has filtered down 
to Greg's development kernel, I want to submit this patch.  It does 
several things, all of which make usb-storage behave more like Windows:

        For disk-type devices, allow MODE SENSE with page=x3f for
        determining write-enable status.  (Note however that the
        sd driver only does this for devices with removable media.
        I don't understand why; surely fixed-media devices can also
        be write-protected.)  Page=x08 is still forbidden.

        For disk-type devices use MODE SENSE(6) if the protocol is
        Transparent SCSI.  For all other devices and other protocols
        use MODE SENSE(10).

        For disk-type devices make MODE SENSE use 192-byte transfer
        length.  Other device types can use arbitrary lengths.
        (Actually sd.c only interprets this flag for MODE SENSE with
        page=x3f; we may need to change that if we add support for
        page=x08.)

This works okay with my devices, but that's a very limited sample.  We 
should try to make sure that allowing page x3f won't cause problems with 
more than a handful of aberrant devices -- if necessary they can be added 
to a SCSI blacklist or unusual_devs.h.

It sure will be nice to be able to detect write-protected devices!

Alan Stern



===== drivers/usb/storage/scsiglue.c 1.73 vs edited =====
--- 1.73/drivers/usb/storage/scsiglue.c Wed Apr 14 13:12:47 2004
+++ edited/drivers/usb/storage/scsiglue.c       Mon Apr 26 11:50:21 2004
@@ -48,6 +48,7 @@
 #include "usb.h"
 #include "debug.h"
 #include "transport.h"
+#include "protocol.h"
 
 #include <linux/slab.h>
 #include <linux/module.h>
@@ -70,8 +71,17 @@
         * Set default bflags. These can be overridden for individual
         * models and vendors via the scsi devinfo mechanism.
         */
-       sdev->sdev_bflags = (BLIST_MS_SKIP_PAGE_08 | BLIST_MS_SKIP_PAGE_3F |
-                            BLIST_USE_10_BYTE_MS);
+
+       /* By default, USB mass storage devices use MODE SENSE(10).
+        * By default, use 192 byte transfers for MODE SENSE with page=x3f.
+        * We don't know how reliable MODE SENSE page x08 is, so for
+        * now skip it by default.
+       sdev->sdev_bflags = (BLIST_USE_10_BYTE_MS |
+                       BLIST_MS_192_BYTES_FOR_3F |
+                       BLIST_MS_SKIP_PAGE_08);
+       /* Maybe add an unusual_devs flag for BLIST_MS_SKIP_PAGE_3F if
+        * too many devices fail to support it. */
+
        return 0;
 }
 
@@ -99,7 +109,24 @@
                        us->pusb_dev->speed == USB_SPEED_HIGH)
                blk_queue_max_sectors(sdev->request_queue, 128);
 
-       /* this is to satisify the compiler, tho I don't think the 
+       /* We can't put these settings in slave_alloc() because that gets
+        * called before the device type is known.  Consequently these
+        * settings can't be overridden via the scsi devinfo mechanism. */
+       if (sdev->type == TYPE_DISK) {
+
+               /* Disk-type devices use MODE SENSE(6) if the protocol
+                * (SubClass) is Transparent SCSI */
+               if (us->subclass == US_SC_SCSI)
+                       sdev->use_10_for_ms = 0;
+       } else {
+
+               /* Non-disk-type devices don't need to blacklist page x08
+                * or to force 192 byte transfer lengths for MODE SENSE. */
+               sdev->skip_ms_page_8 = 0;
+               sdev->use_192_bytes_for_3f = 0;
+       }
+
+       /* this is to satisfy the compiler, tho I don't think the 
         * return code is ever checked anywhere. */
        return 0;
 }

_______________________________________________
Usb-storage mailing list
[EMAIL PROTECTED]
https://lists.one-eyed-alien.net/mailman/listinfo/usb-storage




-------------------------------------------------------
This SF.net email is sponsored by: The Robotic Monkeys at ThinkGeek
For a limited time only, get FREE Ground shipping on all orders of $35
or more. Hurry up and shop folks, this offer expires April 30th!
http://www.thinkgeek.com/freeshipping/?cpg=12297
_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to