CDC_MMC_WR
Subsystems (2)
PATCH 1/1 CDC_MMC_WR
Jens A:
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Please add ...
tocdrom.cinstead ...GPCMD_GET_CONFIGURATIONHappily will do. I'll continue to reply
as I progress or not.Great, thanks.
Please tell me what we think of this new patch?
You can see I've guessed I now should launch a new thread. The linux-scsi thread "writable mmc profiles actually are writable" walked us thru every painful step of me learning to write this patch.
So far I see Three design goals:
a) Add CDC_MMC_WR, masked by default, to: include/cdrom.h, to drivers/ide/ide-cd.c, and to drivers/scsi/sr.c.
b) Correct device->writeable in sr.c sometime after drivers/cdrom/cdrom.c discovers it was wrong.
c) Teach cdrom.c to discover CDC_MMC_WR.
That last goal I see divide into Eight changes to cdrom.c:
c1) Refuse to pass thru writes only if CDC_MMC_WR, no matter CDC_DVD_RAM.
c2) Define cdrom_get_cdc and call cdrom_get_cdc only if register_cdrom succeeds, just before register_cdrom does succeed.
c3) In cdrom_get_cdc, say &= ~CDC_MMC_WR if ide-cd or sr said &= ~CDC_DVD_RAM.
c4) In cdrom_get_cdc, also say &= ~CDC_MMC_WR if cdrom_get_capabilities ok and cdrom_get_configuration ok and the profile fetched is any one of the seven standard "random writable" profiles of mmc except not the x001A dvd+rw profile that maybe can't be overwritten more than 1000 times in place, per Andy Polyakov's:
http://fy.chalmers.se/~appro/linux/DVD+RW/#udf
c5) Define cdrom_get_capabilities in terms of cdrom_mode_sense by block-copy-edit of other cdrom.c source.
c6) Define cdrom_get_configuration in terms of cdo->generic_packet by block-copy-edit of other cdrom.c source
c7) Add a line of text to /proc/sys/dev/cdrom/info to reveal CDC_MMC_WR.
c8) Update change history, REVISION, VERSION.
Please tell me what we think of this new patch?
Pat LaVarre
drivers/cdrom/cdrom.c +79 -3
@@ -228,10 +228,13 @@3.12 Oct 18, 2000 - Jens Axboe <[email protected]> -- Use quiet bit on packet commands not known to work +3.13 Oct 10, 2003 - Jens Axboe <[email protected]> +-- Pass writes thru to all CDC_MMC_WR profiles, not just CDC_DVD_RAM. +-------------------------------------------------------------------------*/ -#define REVISION "Revision: 3.12" -#define VERSION "Id: cdrom.c 3.12 2000/10/18" +#define REVISION "Revision: 3.13" +#define VERSION "Id: cdrom.c 3.13 2003/10/10"/* I use an error-log mask to give fine grain control over the type of messages dumped to the system logs. The available masks include: */
@@ -313,6 +316,7 @@#define CHECKAUDIO if ((ret=check_for_audio_disc(cdi, cdo))) return ret/* Not-exported routines. */ +static void cdrom_get_cdc (struct cdrom_device_info *cdi);static int open_for_data (struct cdrom_device_info * cdi);static int check_for_audio_disc (struct cdrom_device_info * cdi,struct cdrom_device_ops * cdo);
@@ -381,6 +385,8 @@cdinfo (CD_REG_UNREG ,"drive \"/dev/%s\" registered\n" , cdi->name); cdi->next = topCdromPtr; topCdromPtr = cdi; + +cdrom_get_cdc (cdi);return 0 ; }#undef ENSURE
@@ -408,6 +414,71 @@return 0 ; } +static int cdrom_get_capabilities (struct cdrom_device_info *cdi) +{ +struct cdrom_generic_command cgc0; +struct cdrom_generic_command * cgc = &cgc0; +u_char buf[0x18 ];/* ide-cd length = x18, sr length = x80 */ +int ret; +memset (cgc,0 ,sizeof *cgc); +memset (&buf[0 ],0 ,sizeof (buf)); + cgc->buffer = buf; + cgc->buflen =sizeof buf; + ret =cdrom_mode_sense (cdi, cgc,GPMODE_CAPABILITIES_PAGE ,0 ); +return ret; +} + +static int cdrom_get_configuration (struct cdrom_device_info *cdi) +{ +struct cdrom_generic_command cgc0; +struct cdrom_generic_command * cgc = &cgc0; +struct cdrom_device_ops *cdo = cdi->ops; +u_char buf[8 ]; +int ret; +int profile; +memset (cgc,0 ,sizeof *cgc); +memset (&buf[0 ],0 ,sizeof (buf)); + cgc->buffer = buf; + cgc->buflen =sizeof buf; + cgc->cmd[0 ] =GPCMD_GET_CONFIGURATION ; + cgc->cmd[7 ] = cgc->buflen >>8 ; + cgc->cmd[8 ] = cgc->buflen &0xff ; + cgc->data_direction =CGC_DATA_READ ; + ret = cdo->generic_packet (cdi, cgc); +if (ret)return ret; + profile = buf[6 ] <<8 | buf[7 ]; +cdinfo (CD_REG_UNREG ,"profile x%04X\n" , profile); +switch (profile) { +case 0x0001 :/* Non-Removable Disk */ +case 0x0002 :/* Removable Disk */ +case 0x0003 :/* Magneto-Optical Erasable */ +case 0x0005 :/* AS-MO */ +case 0x0012 :/* DVD-RAM */ +case 0x0022 :/* DDCD-RW */ + cdi->mask &= ~CDC_MMC_WR ; +break ; +case 0x001A :/* DVD+RW = not very rewritable in place */ +break ; +default : +break ; + } +return ret; +} + +static void cdrom_get_cdc (struct cdrom_device_info *cdi) +{ +cdinfo (CD_REG_UNREG ,"cdrom_get_cdc\n" ); +if (CDROM_CAN (CDC_DVD_RAM )) { + cdi->mask &= ~CDC_MMC_WR ; + }else if (cdrom_get_capabilities (cdi)) { +cdinfo (CD_WARNING ,"GET_CAPABILITIES not\n" ); + }else { +if (cdrom_get_configuration (cdi)) { +cdinfo (CD_WARNING ,"GET_CONFIGURATION not\n" ); + } + } +} +/* We use the open-option O_NONBLOCK to indicate that the * purpose of opening is only for subsequent ioctl() calls; no device * integrity checks are performed.
@@ -426,8 +497,9 @@if ((fp->f_flags &O_NONBLOCK ) && (cdi->options &CDO_USE_FFLAGS )) ret = cdi->ops->open (cdi,1 );else { -if ((fp->f_mode &FMODE_WRITE ) && !CDROM_CAN (CDC_DVD_RAM )) +if ((fp->f_mode &FMODE_WRITE ) && !CDROM_CAN (CDC_MMC_WR )) {return -EROFS ; + } ret =open_for_data (cdi); }
@@ -2406,6 +2478,10 @@for (cdi=topCdromPtr;cdi!=NULL ;cdi=cdi->next) pos +=sprintf (info+pos,"\t%d" ,CDROM_CAN (CDC_DVD_RAM ) !=0 ); + pos +=sprintf (info+pos,"\nTolerates random write:" ); +for (cdi=topCdromPtr;cdi!=NULL ;cdi=cdi->next) + pos +=sprintf (info+pos,"\t%d" ,CDROM_CAN (CDC_MMC_WR ) !=0 ); +strcpy (info+pos,"\n\n" );return proc_dostring (ctl, write, filp, buffer, lenp);
include/linux/cdrom.h +1 -0
@@ -388,6 +388,7 @@#define CDC_DVD_R 0x10000/* drive can write DVD-R */ #define CDC_DVD_RAM 0x20000/* drive can write DVD-RAM */ #define CDC_MO_DRIVE 0x40000/* drive is an MO device */ +#define CDC_MMC_WR 0x80000/* profile includes random write */ /* drive status possibilities returned by CDROM_DRIVE_STATUS ioctl */ #define CDS_NO_INFO 0/* if not implemented */
drivers/ide/ide-cd.c +2 -2
@@ -2822,7 +2822,7 @@CDC_MEDIA_CHANGED |CDC_PLAY_AUDIO |CDC_RESET |CDC_IOCTLS |CDC_DRIVE_STATUS |CDC_CD_R |CDC_CD_RW |CDC_DVD |CDC_DVD_R |CDC_DVD_RAM | - CDC_GENERIC_PACKET | CDC_MO_DRIVE, + CDC_GENERIC_PACKET | CDC_MO_DRIVE | CDC_MMC_WR, .generic_packet = ide_cdrom_packet, };
@@ -2832,7 +2832,7 @@struct cdrom_device_info *devinfo = &info->devinfo; devinfo->ops = &ide_cdrom_dops; - devinfo->mask =0 ; + devinfo->mask =CDC_MMC_WR ; devinfo->speed =CDROM_STATE_FLAGS (drive)->current_speed; devinfo->capacity = nslots; devinfo->handle = (void *) drive;
drivers/scsi/sr.c +9 -4
@@ -67,7 +67,8 @@ (CDC_CLOSE_TRAY |CDC_OPEN_TRAY |CDC_LOCK |CDC_SELECT_SPEED | \CDC_SELECT_DISC |CDC_MULTI_SESSION |CDC_MCN |CDC_MEDIA_CHANGED | \CDC_PLAY_AUDIO |CDC_RESET |CDC_IOCTLS |CDC_DRIVE_STATUS | \ - CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET) +CDC_CD_R |CDC_CD_RW |CDC_DVD |CDC_DVD_R |CDC_DVD_RAM |CDC_GENERIC_PACKET | \ + CDC_MMC_WR)static int sr_probe (struct device *);static int sr_remove (struct device *);
@@ -327,8 +328,12 @@ }if (rq_data_dir (SCpnt->request) ==WRITE ) { -if (!cd->device->writeable) -return 0 ; +if (!cd->device->writeable) { +if ((cd->cdi.mask &CDC_MMC_WR ) !=0 ) { +return 0 ; + } + cd->device->writeable =1 ; + } SCpnt->cmnd[0 ] =WRITE_10 ; SCpnt->sc_data_direction =SCSI_DATA_WRITE ; }else if (rq_data_dir (SCpnt->request) ==READ ) {
@@ -550,7 +555,7 @@ cd->cdi.ops = &sr_dops; cd->cdi.handle = cd; - cd->cdi.mask =0 ; + cd->cdi.mask =CDC_MMC_WR ; cd->cdi.capacity =1 ;sprintf (cd->cdi.name,"sr%d" , minor);
Quoted 47 lines · Pat LaVarre
Jens A:
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Please add ...
tocdrom.cinstead ...GPCMD_GET_CONFIGURATIONHappily will do. I'll continue to reply
as I progress or not.Great, thanks.
Please tell me what we think of this new patch?
You can see I've guessed I now should launch a new thread. The linux-scsi thread "writable mmc profiles actually are writable" walked us thru every painful step of me learning to write this patch.
So far I see Three design goals:
a) Add
CDC_MMC_WR, masked by default, to:include/cdrom.h, todrivers/ide/ide-cd.c, and todrivers/scsi/sr.c.b) Correct
device->writeableinsr.csometime afterdrivers/cdrom/cdrom.cdiscovers it was wrong.c) Teach
cdrom.cto discoverCDC_MMC_WR.That last goal I see divide into Eight changes to
cdrom.c:c1) Refuse to pass thru writes only if
CDC_MMC_WR, no matterCDC_DVD_RAM.c2) Define
cdrom_get_cdcand callcdrom_get_cdconly ifregister_cdromsucceeds, just beforeregister_cdromdoes succeed.c3) In
cdrom_get_cdc, say &= ~CDC_MMC_WR if ide-cd or sr said &= ~CDC_DVD_RAM.c4) In
cdrom_get_cdc, also say &= ~CDC_MMC_WR ifcdrom_get_capabilitiesok andcdrom_get_configurationok and the profile fetched is any one of the seven standard "random writable" profiles of mmc except not the x001A dvd+rw profile that maybe can't be overwritten more than 1000 times in place, per Andy Polyakov's:
http://fy.chalmers.se/~appro/linux/DVD+RW/#udfc5) Define
cdrom_get_capabilitiesin terms ofcdrom_mode_senseby block-copy-edit of othercdrom.csource.
Quoted 8 lines
c6) Define
cdrom_get_configurationin terms ofcdo->generic_packetby block-copy-edit of othercdrom.csourcec7) Add a line of text to
/proc/sys/dev/cdrom/infoto revealCDC_MMC_WR.c8) Update change history, REVISION, VERSION.
Please tell me what we think of this new patch?
Lots of small nits, but in general I like it.
drivers/cdrom/cdrom.c line 232
Quoted 2 lines
drivers/cdrom/cdrom.c +2
-0+ 3.13 Oct 10, 2003 - Jens Axboe <[email protected]> + -- Pass writes thru to all CDC_MMC_WR profiles, not just CDC_DVD_RAM.
That should be you :)
drivers/cdrom/cdrom.c line 420
Quoted 4 lines
drivers/cdrom/cdrom.c +4
-0+static int cdrom_get_capabilities (struct cdrom_device_info *cdi) +{ +struct cdrom_generic_command cgc0; +struct cdrom_generic_command * cgc = &cgc0;
I see this repeated, what is the point? you are wasting 4/8 bytes on the stack each time.
drivers/cdrom/cdrom.c line 423
Quoted 3 lines
drivers/cdrom/cdrom.c +3
-0+u_char buf[0x18 ];/* ide-cd length = x18, sr length = x80 */ +int ret; +memset (cgc,0 ,sizeof *cgc);
sizeof(*cgc);
drivers/cdrom/cdrom.c line 426
Quoted 3 lines
drivers/cdrom/cdrom.c +3
-0+memset (&buf[0 ],0 ,sizeof (buf)); + cgc->buffer = buf; + cgc->buflen =sizeof buf;
sizeof(buf). There's a init_cdrom_command() for these types of situations, please use it.
Review
Quoted 2 lines
(quoted diff) +2
-0+ ret = cdrom_mode_sense(cdi, cgc, GPMODE_CAPABILITIES_PAGE, 0); + return ret;
No need for ret, either.
drivers/cdrom/cdrom.c line 434
Quoted 6 lines
drivers/cdrom/cdrom.c +6
-0+} + +static int cdrom_get_configuration (struct cdrom_device_info *cdi) +{ +struct cdrom_generic_command cgc0; +struct cdrom_generic_command * cgc = &cgc0;
Ditto
drivers/cdrom/cdrom.c line 439
Quoted 5 lines
drivers/cdrom/cdrom.c +5
-0+struct cdrom_device_ops *cdo = cdi->ops; +u_char buf[8 ]; +int ret; +int profile; +memset (cgc,0 ,sizeof *cgc);
Ditto
Quoted 16 lines
drivers/cdrom/cdrom.c +16
-0+memset (&buf[0 ],0 ,sizeof (buf)); + cgc->buffer = buf; + cgc->buflen =sizeof buf; + cgc->cmd[0 ] =GPCMD_GET_CONFIGURATION ; + cgc->cmd[7 ] = cgc->buflen >>8 ; + cgc->cmd[8 ] = cgc->buflen &0xff ; + cgc->data_direction =CGC_DATA_READ ; + ret = cdo->generic_packet (cdi, cgc); +if (ret)return ret; + profile = buf[6 ] <<8 | buf[7 ]; +cdinfo (CD_REG_UNREG ,"profile x%04X\n" , profile); +switch (profile) { +case 0x0001 :/* Non-Removable Disk */ +case 0x0002 :/* Removable Disk */ +case 0x0003 :/* Magneto-Optical Erasable */ +case 0x0005 :/* AS-MO */
drivers/cdrom/cdrom.c line 465
Quoted 10 lines
drivers/cdrom/cdrom.c +10
-0+case 0x0012 :/* DVD-RAM */ +case 0x0022 :/* DDCD-RW */ + cdi->mask &= ~CDC_MMC_WR ; +break ; +case 0x001A :/* DVD+RW = not very rewritable in place */ +break ; +default : +break ; + } +return ret;
ret must be 0 here, so return 0 to make that clear.
drivers/cdrom/cdrom.c line 480
Quoted 13 lines
drivers/cdrom/cdrom.c +13
-0+static void cdrom_get_cdc (struct cdrom_device_info *cdi) +{ +cdinfo (CD_REG_UNREG ,"cdrom_get_cdc\n" ); +if (CDROM_CAN (CDC_DVD_RAM )) { + cdi->mask &= ~CDC_MMC_WR ; + }else if (cdrom_get_capabilities (cdi)) { +cdinfo (CD_WARNING ,"GET_CAPABILITIES not\n" ); + }else { +if (cdrom_get_configuration (cdi)) { +cdinfo (CD_WARNING ,"GET_CONFIGURATION not\n" ); + } + } +}
Ugly flow here. And what is the point of the cdrom_get_capabilities() call? If you just want to see if it's supported, the probe sequence in ide-cd/sr should already have done that. I'd greatly prefer something ala:
static void cdrom_get_cdc(struct cdrom_device_info *cdi)
{
cdrom_get_configuration(cdi);
if (CDROM_CAN(CDC_DVD_RAM))
cdi->mask &= ~CDC_MMC_WR
}Quoted 46 lines
drivers/cdrom/cdrom.c +6
-1@@ -426,8 +497,9 @@if ((fp->f_flags &O_NONBLOCK ) && (cdi->options &CDO_USE_FFLAGS )) ret = cdi->ops->open (cdi,1 );else { -if ((fp->f_mode &FMODE_WRITE ) && !CDROM_CAN (CDC_DVD_RAM )) +if ((fp->f_mode &FMODE_WRITE ) && !CDROM_CAN (CDC_MMC_WR )) {return -EROFS ; + } ret =open_for_data (cdi); }@@ -2406,6 +2478,10 @@for (cdi=topCdromPtr;cdi!=NULL ;cdi=cdi->next) pos +=sprintf (info+pos,"\t%d" ,CDROM_CAN (CDC_DVD_RAM ) !=0 ); + pos +=sprintf (info+pos,"\nTolerates random write:" ); +for (cdi=topCdromPtr;cdi!=NULL ;cdi=cdi->next) + pos +=sprintf (info+pos,"\t%d" ,CDROM_CAN (CDC_MMC_WR ) !=0 ); +strcpy (info+pos,"\n\n" );return proc_dostring (ctl, write, filp, buffer, lenp);diff -Nur
linux-2.6.0-test7/include/linux/cdrom.hlinux/include/linux/cdrom.hinclude/linux/cdrom.h +1
-0@@ -388,6 +388,7 @@#define CDC_DVD_R 0x10000/* drive can write DVD-R */ #define CDC_DVD_RAM 0x20000/* drive can write DVD-RAM */ #define CDC_MO_DRIVE 0x40000/* drive is an MO device */ +#define CDC_MMC_WR 0x80000/* profile includes random write */ /* drive status possibilities returned by CDROM_DRIVE_STATUS ioctl */ #define CDS_NO_INFO 0/* if not implemented */ diff -Nur
linux-2.6.0-test7/drivers/ide/ide-cd.clinux/drivers/ide/ide-cd.cdrivers/ide/ide-cd.c +1
-1@@ -2822,7 +2822,7 @@CDC_MEDIA_CHANGED |CDC_PLAY_AUDIO |CDC_RESET |CDC_IOCTLS |CDC_DRIVE_STATUS |CDC_CD_R |CDC_CD_RW |CDC_DVD |CDC_DVD_R |CDC_DVD_RAM | - CDC_GENERIC_PACKET | CDC_MO_DRIVE, + CDC_GENERIC_PACKET | CDC_MO_DRIVE | CDC_MMC_WR, .generic_packet = ide_cdrom_packet, };
drivers/ide/ide-cd.c line 2835
Quoted 5 lines
drivers/ide/ide-cd.c +1
-1@@ -2832,7 +2832,7 @@struct cdrom_device_info *devinfo = &info->devinfo; devinfo->ops = &ide_cdrom_dops; - devinfo->mask =0 ; + devinfo->mask =CDC_MMC_WR ;
Must be left-over junk, should still be 0 here.
Quoted 18 lines
drivers/ide/ide-cd.c +0
-0devinfo->speed =CDROM_STATE_FLAGS (drive)->current_speed; devinfo->capacity = nslots; devinfo->handle = (void *) drive;diff -Nur
linux-2.6.0-test7/drivers/scsi/sr.clinux/drivers/scsi/sr.cdrivers/scsi/sr.c +2
-1@@ -67,7 +67,8 @@ (CDC_CLOSE_TRAY |CDC_OPEN_TRAY |CDC_LOCK |CDC_SELECT_SPEED | \CDC_SELECT_DISC |CDC_MULTI_SESSION |CDC_MCN |CDC_MEDIA_CHANGED | \CDC_PLAY_AUDIO |CDC_RESET |CDC_IOCTLS |CDC_DRIVE_STATUS | \ - CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET) +CDC_CD_R |CDC_CD_RW |CDC_DVD |CDC_DVD_R |CDC_DVD_RAM |CDC_GENERIC_PACKET | \ + CDC_MMC_WR)static int sr_probe (struct device *);static int sr_remove (struct device *);@@ -327,8 +328,12 @@ }
drivers/scsi/sr.c line 336
Quoted 10 lines
drivers/scsi/sr.c +6
-2if (rq_data_dir (SCpnt->request) ==WRITE ) { -if (!cd->device->writeable) -return 0 ; +if (!cd->device->writeable) { +if ((cd->cdi.mask &CDC_MMC_WR ) !=0 ) { +return 0 ; + } + cd->device->writeable =1 ; + }
This is ugly, don't hack around it like that. If CDC_MMC_WR set, sr should have set device->writeable as well. Needs to go.
drivers/scsi/sr.c line 560
Quoted 11 lines
drivers/scsi/sr.c +1
-1SCpnt->cmnd[0 ] =WRITE_10 ; SCpnt->sc_data_direction =SCSI_DATA_WRITE ; }else if (rq_data_dir (SCpnt->request) ==READ ) {@@ -550,7 +555,7 @@ cd->cdi.ops = &sr_dops; cd->cdi.handle = cd; - cd->cdi.mask =0 ; + cd->cdi.mask =CDC_MMC_WR ; cd->cdi.capacity =1 ;sprintf (cd->cdi.name,"sr%d" , minor);
Ditto, why are you changing this?! Why do you think CDC_MMC_WR is special compared to the other mask flags?
Signature · 1 line
Jens Axboe
Jens A:
Much better now?
Pat LaVarre
drivers/cdrom/cdrom.c +57 -4
@@ -1,7 +1,7 @@/* linux/drivers/cdrom/cdrom.c. Copyright (c) 1996, 1997 David A. van Leeuwen. Copyright (c) 1997, 1998 Erik Andersen <[email protected]> -Copyright (c) 1998, 1999 Jens Axboe <[email protected]> +Copyright (c) 1998, 1999, 2003 Jens Axboe <[email protected]> May be copied or modified under the terms of the GNU General Public License. See linux/COPYING for more information.
@@ -228,10 +228,13 @@3.12 Oct 18, 2000 - Jens Axboe <[email protected]> -- Use quiet bit on packet commands not known to work +3.13 Oct 13, 2003 - Jens Axboe <[email protected]> +-- Now mask CDC_MMC_WR only if not std. rewritable, was mask if not DVD_RAM. +-------------------------------------------------------------------------*/ -#define REVISION "Revision: 3.12" -#define VERSION "Id: cdrom.c 3.12 2000/10/18" +#define REVISION "Revision: 3.13" +#define VERSION "Id: cdrom.c 3.13 2003/10/13"/* I use an error-log mask to give fine grain control over the type of messages dumped to the system logs. The available masks include: */
@@ -313,6 +316,7 @@#define CHECKAUDIO if ((ret=check_for_audio_disc(cdi, cdo))) return ret/* Not-exported routines. */ +static void cdrom_get_cdc (struct cdrom_device_info *cdi);static int open_for_data (struct cdrom_device_info * cdi);static int check_for_audio_disc (struct cdrom_device_info * cdi,struct cdrom_device_ops * cdo);
@@ -381,6 +385,8 @@cdinfo (CD_REG_UNREG ,"drive \"/dev/%s\" registered\n" , cdi->name); cdi->next = topCdromPtr; topCdromPtr = cdi; + +cdrom_get_cdc (cdi);return 0 ; }#undef ENSURE
@@ -408,6 +414,48 @@return 0 ; } +static int cdrom_get_configuration (struct cdrom_device_info *cdi) +{ +struct cdrom_generic_command cgc; +struct cdrom_device_ops *cdo = cdi->ops; +u_char buf[8 ]; +int ret; +init_cdrom_command (&cgc, buf,sizeof (buf),CGC_DATA_READ ); + cgc.cmd[0 ] =GPCMD_GET_CONFIGURATION ; + cgc.cmd[7 ] = cgc.buflen >>8 ; + cgc.cmd[8 ] = cgc.buflen &0xff ; + cgc.data_direction =CGC_DATA_READ ; + ret = cdo->generic_packet (cdi, &cgc); +if (!ret) { +int profile = buf[6 ] <<8 | buf[7 ]; +cdinfo (CD_REG_UNREG ,"profile x%04X\n" , profile); +switch (profile) { +case 0x0001 :/* Non-Removable Disk */ +case 0x0002 :/* Removable Disk */ +case 0x0003 :/* Magneto-Optical Erasable */ +case 0x0005 :/* AS-MO */ +case 0x0012 :/* DVD-RAM */ +case 0x0022 :/* DDCD-RW */ +return 0 ; +case 0x001A :/* DVD+RW = not much rewrite in place */ +default : +break ; + } + } + cdi->mask |=CDC_MMC_WR ; +return ret; +} + +static void cdrom_get_cdc (struct cdrom_device_info *cdi) +{ +if (CDROM_CAN (CDC_MMC_WR ) && !CDROM_CAN (CDC_DVD_RAM )) { +cdinfo (CD_REG_UNREG ,"cdrom_get_configuration\n" ); +if (cdrom_get_configuration (cdi)) { +cdinfo (CD_REG_UNREG ,"cdrom_get_configuration not\n" ); + } + } +} +/* We use the open-option O_NONBLOCK to indicate that the * purpose of opening is only for subsequent ioctl() calls; no device * integrity checks are performed.
@@ -426,8 +474,9 @@if ((fp->f_flags &O_NONBLOCK ) && (cdi->options &CDO_USE_FFLAGS )) ret = cdi->ops->open (cdi,1 );else { -if ((fp->f_mode &FMODE_WRITE ) && !CDROM_CAN (CDC_DVD_RAM )) +if ((fp->f_mode &FMODE_WRITE ) && !CDROM_CAN (CDC_MMC_WR )) {return -EROFS ; + } ret =open_for_data (cdi); }
@@ -2406,6 +2455,10 @@for (cdi=topCdromPtr;cdi!=NULL ;cdi=cdi->next) pos +=sprintf (info+pos,"\t%d" ,CDROM_CAN (CDC_DVD_RAM ) !=0 ); + pos +=sprintf (info+pos,"\nTolerates random write:" ); +for (cdi=topCdromPtr;cdi!=NULL ;cdi=cdi->next) + pos +=sprintf (info+pos,"\t%d" ,CDROM_CAN (CDC_MMC_WR ) !=0 ); +strcpy (info+pos,"\n\n" );return proc_dostring (ctl, write, filp, buffer, lenp);
include/linux/cdrom.h +1 -0
@@ -388,6 +388,7 @@#define CDC_DVD_R 0x10000/* drive can write DVD-R */ #define CDC_DVD_RAM 0x20000/* drive can write DVD-RAM */ #define CDC_MO_DRIVE 0x40000/* drive is an MO device */ +#define CDC_MMC_WR 0x80000/* profile includes random write */ /* drive status possibilities returned by CDROM_DRIVE_STATUS ioctl */ #define CDS_NO_INFO 0/* if not implemented */
drivers/ide/ide-cd.c +1 -1
@@ -2822,7 +2822,7 @@CDC_MEDIA_CHANGED |CDC_PLAY_AUDIO |CDC_RESET |CDC_IOCTLS |CDC_DRIVE_STATUS |CDC_CD_R |CDC_CD_RW |CDC_DVD |CDC_DVD_R |CDC_DVD_RAM | - CDC_GENERIC_PACKET | CDC_MO_DRIVE, + CDC_GENERIC_PACKET | CDC_MO_DRIVE | CDC_MMC_WR, .generic_packet = ide_cdrom_packet, };
drivers/scsi/sr.c +4 -4
@@ -67,7 +67,8 @@ (CDC_CLOSE_TRAY |CDC_OPEN_TRAY |CDC_LOCK |CDC_SELECT_SPEED | \CDC_SELECT_DISC |CDC_MULTI_SESSION |CDC_MCN |CDC_MEDIA_CHANGED | \CDC_PLAY_AUDIO |CDC_RESET |CDC_IOCTLS |CDC_DRIVE_STATUS | \ - CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_DVD_RAM|CDC_GENERIC_PACKET) +CDC_CD_R |CDC_CD_RW |CDC_DVD |CDC_DVD_R |CDC_DVD_RAM |CDC_GENERIC_PACKET | \ + CDC_MMC_WR)static int sr_probe (struct device *);static int sr_remove (struct device *);
@@ -327,8 +328,9 @@ }if (rq_data_dir (SCpnt->request) ==WRITE ) { -if (!cd->device->writeable) +if ((cd->cdi.mask &CDC_MMC_WR ) !=0 ) {return 0 ; + } SCpnt->cmnd[0 ] =WRITE_10 ; SCpnt->sc_data_direction =SCSI_DATA_WRITE ; }else if (rq_data_dir (SCpnt->request) ==READ ) {
@@ -788,8 +790,6 @@if ((buffer[n +3 ] &0x20 ) ==0 ) {/* can't write DVD-RAM media */ cd->cdi.mask |=CDC_DVD_RAM ; - }else { - cd->device->writeable =1 ; }if ((buffer[n +3 ] &0x10 ) ==0 )/* can't write DVD-R media */
I double-checked.
My same -test7 patch applies without complaint to -test8:
patching file drivers/cdrom/cdrom.c
patching file include/linux/cdrom.h
patching file drivers/ide/ide-cd.c
patching file drivers/scsi/sr.c
diff thereafter confirms that precisely the same lines have changed as in -test7.
I'm guessing this patch changes no behaviour except that pdt x05 dvd/cd devices that support mode page x5A Capabilities thereafter get a chance via op x46 Get Configuration to end with CDC_MMC_WR unmasked ...
I'm curious to know how wrong I am.
Pat LaVarre
My 2003-10-13 -test7 patch, with the q=raw suffix included to help ask for hard tabs etc. intact, appears archived as:
http://marc.theaimsgroup.com/?l=linux-scsi&m=106669072008705&q=raw
Just now I triple-checked at my desk. To -test9, that same patch applies without complaint, produces precisely the same diff, and works.
I think that patch teaches Linux that standard mmc writable profile devices are writable, in the least disruptive way possible. I'm delighted to see that patch shrunk and shrunk again as we tutored me here.
Pat LaVarre