On Tue, 1 Feb 2005, Olaf Hering wrote:

> I got an USB stick with write protection switch, writing to it did
> not work at all. I was told "if the blue LED goes on during plugin,
> no trouble. But if it remains off, writing gives io errors". 
> Even reading did not work, like md5sum /mnt/$file gave io errors.
> 
> The odd thing, after a few tries I plugged it into an just powered on G5
> and the light was on! After that, the stick worked ok on all my test boxes.
> Since there was no MacOS running at this point, I guess something happend
> inside the stick.
> Another guy told me, his stick also works only in 90% of the times.
> 
> Are there any magic bits in an usb-storage device that need tweaking to
> deal with the write protection? Maybe the working and non-working state
> can be compared somehow? I know there is a new config option
> CONFIG_USB_STORAGE_RW_DETECT since a while, we have it enabled.

I've never heard of any such magic bits, apart from the bit that contains
the actual write-protect setting.  Either that bit is set or it isn't.  
If it is then writes won't work; if it isn't then writes should work.
Reads should always work regardless.

In principle it might be possible for a user program to turn the 
write-protect bit on or off.  But that functionality doesn't belong in 
the usb-storage driver.

> I just checked, USB_STORAGE_RW_DETECT appears only once in the source.
> Cant this be made a module option for usb-storage?
> So it can be switched on or off at runtime via sysfs.

Below is a patch for 2.6.11-rc2 that makes write-protect detection into a 
module parameter.  Matt Dharm has considered doing this in the past; I 
don't remember if he came to a final decision.

Alan Stern



===== drivers/usb/storage/Kconfig 1.20 vs edited =====
--- 1.20/drivers/usb/storage/Kconfig    2005-01-24 19:07:19 -05:00
+++ edited/drivers/usb/storage/Kconfig  2005-02-02 11:51:56 -05:00
@@ -30,28 +30,6 @@
          Say Y here in order to have the USB Mass Storage code generate
          verbose debugging messages.
 
-config USB_STORAGE_RW_DETECT
-       bool "USB Mass Storage Write-Protected Media Detection (EXPERIMENTAL)"
-       depends on USB_STORAGE && EXPERIMENTAL
-       help
-         Say Y here in order to have the USB Mass Storage code indicate to
-         the SCSI layer that using MODE SENSE(6) and MODE SENSE(10) to
-         determine if the media is write-protected is a good thing to do.
-
-         Many devices have historically had trouble with these commands,
-         hence the default 2.6.x behavior has been to suppress their use.
-         2.4.x used these commands with (at best) mixed results, often
-         crashing the firmware of the device.  However, the SCSI layer now
-         issues these commands in a manner more consistent with other
-         "popular" OSes, in an attempt to improve compatibility.
-
-         Saying Y here allows these commands to be sent to a USB device.
-         If you find a device this doesn't work for, switch to N and let
-         us know at <[EMAIL PROTECTED]>
-
-         If you say N here, the kernel will assume that all disk-like USB
-         devices are write-enabled.
-
 config USB_STORAGE_DATAFAB
        bool "Datafab Compact Flash Reader support (EXPERIMENTAL)"
        depends on USB_STORAGE && EXPERIMENTAL
===== drivers/usb/storage/scsiglue.c 1.94 vs edited =====
--- 1.94/drivers/usb/storage/scsiglue.c 2005-01-30 20:02:07 -05:00
+++ edited/drivers/usb/storage/scsiglue.c       2005-02-02 11:46:53 -05:00
@@ -62,6 +62,14 @@
 #include "protocol.h"
 
 /***********************************************************************
+ * Module parameters
+ ***********************************************************************/
+
+static int wp_detect = 1;
+module_param(wp_detect, bool, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(wp_detect, "enable write-protect detection");
+
+/***********************************************************************
  * Host functions 
  ***********************************************************************/
 
@@ -141,13 +149,12 @@
                 * page x08, so we will skip it. */
                sdev->skip_ms_page_8 = 1;
 
-#ifndef CONFIG_USB_STORAGE_RW_DETECT
                /* Some devices may not like MODE SENSE with page=0x3f.
                 * Now that we're using 192-byte transfers this may no
                 * longer be a problem.  So this will be a configuration
                 * option. */
-               sdev->skip_ms_page_3f = 1;
-#endif
+               if (!wp_detect)
+                       sdev->skip_ms_page_3f = 1;
 
                /* Some disks return the total number blocks in response
                 * to READ CAPACITY rather than the highest block number.



-------------------------------------------------------
This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting
Tool for open source databases. Create drag-&-drop reports. Save time
by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc.
Download a FREE copy at http://www.intelliview.com/go/osdn_nl
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to