An idea beyond this patch is to disallow r/w mounts for storage devices 
emulated with
g_file_storage with 'ro=1'. This is done by setting device type to TYPE_ROM 
instead
of TYPE_DISK.

Dmitry

--- linux.orig/drivers/usb/gadget/file_storage.c        2005-10-31 
14:26:41.000000000 +0300
+++ linux/drivers/usb/gadget/file_storage.c     2005-12-08 18:36:26.000000000 
+0300
@@ -517,6 +517,11 @@
 #define SS_WRITE_ERROR                         0x030c02
 #define SS_WRITE_PROTECTED                     0x072700

+/* Subset of SCSI device types we emulate */
+#define SD_TYPE_DISK                    0x00
+#define SD_TYPE_ROM                     0x05
+#define SD_TYPE_NO_LUN                  0x7f
+
 #define SK(x)          ((u8) ((x) >> 16))        // Sense Key byte, etc.
 #define ASC(x)         ((u8) ((x) >> 8))
 #define ASCQ(x)                ((u8) (x))
@@ -2028,17 +2033,25 @@
        if (!fsg->curlun) {          // Unsupported LUNs are okay
                fsg->bad_lun_okay = 1;
                memset(buf, 0, 36);
-               buf[0] = 0x7f;          // Unsupported, no device-type
+               buf[0] = SD_TYPE_NO_LUN; // Unsupported, no device-type
                return 36;
        }

-       memset(buf, 0, 8);      // Non-removable, direct-access device
-       if (mod_data.removable)
-               buf[1] = 0x80;
+       if (fsg->curlun->ro == 1) {
+               DBG(fsg, "LUN%d: will emulate SCSI CDROM\n", fsg->lun);
+               buf[0] = SD_TYPE_ROM;
+       }
+       else {
+               DBG(fsg, "LUN%d: will emulate SCSI disk\n", fsg->lun);
+               buf[0] = SD_TYPE_DISK;
+       }
+       buf[1] = mod_data.removable ? 0x80 : 0x0;
        buf[2] = 2;             // ANSI SCSI level 2
        buf[3] = 2;             // SCSI-2 INQUIRY data format
        buf[4] = 31;            // Additional length
                                // No special options
+       memset(buf + 5, 0, 3);
+
        sprintf(buf + 8, "%-8s%-16s%04x", vendor_id, product_id,
                        mod_data.release);
        return 36;


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
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