lkml.org 
[lkml]   [2004]   [Jan]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: MO: opening for write in cdrom.c
On Mon, 26 Jan 2004, Pascal Schmidt wrote:

[short summary for l-k: this is about finding out whether an MO is
write-protected or not, code that is yet missing from cdrom.c]

> I'll try to implement the fallback that sd.c uses next. That code
> tries several mode senses with different page and length.

Okay, I got it working with the exact method that sd.c uses. I've put
a few printk's in to see where it fails a mode sense. It's actually
inconsistent:

a) insert a writable disc first after boot, method 1 works
b) then insert a non-writable disc once - suddenly method 1
stops working, even on writable discs, instead method 2
works
c) insert a non-writable disc first after boot, method 1
never works, but method 2 does

There's a third method in sd.c. I've also left that in since I suspect
it might be necessary under some circumstances, too.

From my testing, I get the impression that this Fujitsu drive only
has mode page 0, meaning that only 0x00 and 0x3F make sense, and that
mode page 0x00 also only contains very few bytes of information -
because asking for 16 bytes from 0x3F didn't work, but 4 bytes does.
What's weird is that asking for all pages can also stop suddenly, after
which only page 0x00 is accessible. And when that happens, we only get
a meaningless request sense of 00/00/00 back.

Oh well, strange hardware indeed.

Here's the patch that works for me, please consider applying and
pushing to Linus/Andrew:


--- linux-2.6.2-rc1/include/linux/cdrom.h.orig Sun Jan 25 23:21:19 2004
+++ linux-2.6.2-rc1/include/linux/cdrom.h Mon Jan 26 18:46:54 2004
@@ -496,6 +496,7 @@ struct cdrom_generic_command
#define GPCMD_GET_MEDIA_STATUS 0xda

/* Mode page codes for mode sense/set */
+#define GPMODE_VENDOR_PAGE 0x00
#define GPMODE_R_W_ERROR_PAGE 0x01
#define GPMODE_WRITE_PARMS_PAGE 0x05
#define GPMODE_AUDIO_CTL_PAGE 0x0e
--- linux-2.6.2-rc1/drivers/cdrom/cdrom.c.orig Sat Jan 24 01:23:30 2004
+++ linux-2.6.2-rc1/drivers/cdrom/cdrom.c Mon Jan 26 18:52:00 2004
@@ -696,6 +696,34 @@ static int cdrom_mrw_open_write(struct c
return ret;
}

+static int mo_open_write(struct cdrom_device_info *cdi)
+{
+ struct cdrom_generic_command cgc;
+ char buffer[255];
+ int ret;
+
+ init_cdrom_command(&cgc, &buffer, 4, CGC_DATA_READ);
+ cgc.quiet = 1;
+
+ /*
+ * obtain write protect information as per
+ * drivers/scsi/sd.c:sd_read_write_protect_flag
+ */
+
+ ret = cdrom_mode_sense(cdi, &cgc, GPMODE_ALL_PAGES, 0);
+ if (ret)
+ ret = cdrom_mode_sense(cdi, &cgc, GPMODE_VENDOR_PAGE, 0);
+ if (ret) {
+ cgc.buflen = 255;
+ ret = cdrom_mode_sense(cdi, &cgc, GPMODE_ALL_PAGES, 0);
+ }
+
+ if (ret)
+ return 1;
+
+ return (buffer[3] & 0x80) != 0;
+}
+
/*
* returns 0 for ok to open write, non-0 to disallow
*/
@@ -707,11 +735,8 @@ static int cdrom_open_write(struct cdrom
ret = cdrom_mrw_open_write(cdi);
else if (CDROM_CAN(CDC_DVD_RAM))
ret = cdrom_dvdram_open_write(cdi);
- /*
- * needs to really check whether media is writeable
- */
else if (CDROM_CAN(CDC_MO_DRIVE))
- ret = 0;
+ ret = mo_open_write(cdi);

return ret;
}

--
Ciao,
Pascal

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

\
 
 \ /
  Last update: 2005-03-22 14:00    [from the cache]
©2003-2011 Jasper Spaans