DVD+RW support for 2.6.7-bk13
Subsystems (4)
PATCH 1/1 DVD+RW support for 2.6.7-bk13
This patch adds support for using DVD+RW drives as writable block devices under the 2.6.7-bk13 kernel.
The patch is based on work from:
Andy Polyakov <[email protected]> - Wrote the 2.4 patch Nigel Kukard <[email protected]> - Initial porting to 2.6.x
It works for me using an Iomega Super DVD 8x USB drive.
---
linux-petero/drivers/cdrom/cdrom.c | 80 +++++++++++++++++++++++++++++++++++++ linux-petero/drivers/ide/ide-cd.c | 2 linux-petero/drivers/scsi/sr.c | 1 linux-petero/include/linux/cdrom.h | 2 4 files changed, 85 insertions(+)
drivers/cdrom/cdrom.c renamed from drivers/cdrom/cdrom.c~dvd+rw +80 -0
@@ -821,6 +821,41 @@ static int cdrom_ram_open_write(struct creturn ret; } +static void cdrom_mmc3_profile (struct cdrom_device_info *cdi) +{ +struct packet_command cgc; +char buffer[32 ]; +int ret, mmc3_profile; + +init_cdrom_command (&cgc, buffer,sizeof (buffer),CGC_DATA_READ ); + + cgc.cmd[0 ] =GPCMD_GET_CONFIGURATION ; + cgc.cmd[1 ] =0 ; + cgc.cmd[2 ] = cgc.cmd[3 ] =0 ;/* Starting Feature Number */ + cgc.cmd[7 ] =0 ; cgc.cmd [8 ] =8 ;/* Allocation Length */ + cgc.quiet =1 ; + +if ((ret = cdi->ops->generic_packet (cdi, &cgc))) { + mmc3_profile =0xffff ; + }else { + mmc3_profile = (buffer[6 ] <<8 ) | buffer[7 ]; +printk (KERN_INFO "cdrom: %s: mmc-3 profile capable, current profile: %Xh\n" , + cdi->name, mmc3_profile); + } + cdi->mmc3_profile = mmc3_profile; +} + +static int cdrom_is_dvd_rw (struct cdrom_device_info *cdi) +{ +switch (cdi->mmc3_profile) { +case 0x12 :/* DVD-RAM */ +case 0x1A :/* DVD+RW */ +return 0 ; +default : +return 1 ; + } +} +/* * returns 0 for ok to open write, non-0 to disallow */
@@ -859,10 +894,50 @@ static int cdrom_open_write(struct cdrom ret =cdrom_ram_open_write (cdi); else if (CDROM_CAN(CDC_MO_DRIVE)) ret =mo_open_write (cdi); + else if (!cdrom_is_dvd_rw(cdi)) + ret =0 ;return ret; } +static void cdrom_dvd_rw_close_write (struct cdrom_device_info *cdi) +{ +struct packet_command cgc; + +if (cdi->mmc3_profile !=0x1a ) { +cdinfo (CD_CLOSE ,"%s: No DVD+RW\n" , cdi->name); +return ; + } + +if (!cdi->media_written) { +cdinfo (CD_CLOSE ,"%s: DVD+RW media clean\n" , cdi->name); +return ; + } + +printk (KERN_INFO "cdrom: %s: dirty DVD+RW media, \"finalizing\"\n" , + cdi->name); + +init_cdrom_command (&cgc,NULL ,0 ,CGC_DATA_NONE ); + cgc.cmd[0 ] =GPCMD_FLUSH_CACHE ; + cgc.timeout =30 *HZ ; + cdi->ops->generic_packet (cdi, &cgc); + +init_cdrom_command (&cgc,NULL ,0 ,CGC_DATA_NONE ); + cgc.cmd[0 ] =GPCMD_CLOSE_TRACK ; + cgc.timeout =3000 *HZ ; + cgc.quiet =1 ; + cdi->ops->generic_packet (cdi, &cgc); + +init_cdrom_command (&cgc,NULL ,0 ,CGC_DATA_NONE ); + cgc.cmd[0 ] =GPCMD_CLOSE_TRACK ; + cgc.cmd[2 ] =2 ;/* Close session */ + cgc.quiet =1 ; + cgc.timeout =3000 *HZ ; + cdi->ops->generic_packet (cdi, &cgc); + + cdi->media_written =0 ; +} +static int cdrom_close_write (struct cdrom_device_info *cdi) {#if 0
@@ -895,6 +970,7 @@ int cdrom_open(struct cdrom_device_info ret =open_for_data (cdi);if (ret) goto err; +cdrom_mmc3_profile (cdi);if (fp->f_mode &FMODE_WRITE ) { ret = -EROFS ;if (!CDROM_CAN (CDC_RAM ))
@@ -902,6 +978,7 @@ int cdrom_open(struct cdrom_device_infoif (cdrom_open_write (cdi)) goto err; ret =0 ; + cdi->media_written =0 ; } }
@@ -1093,6 +1170,8 @@ int cdrom_release(struct cdrom_device_in cdi->use_count--;if (cdi->use_count ==0 )cdinfo (CD_CLOSE ,"Use count for \"/dev/%s\" now zero\n" , cdi->name); +if (cdi->use_count ==0 ) +cdrom_dvd_rw_close_write (cdi);if (cdi->use_count ==0 && (cdo->capability &CDC_LOCK ) && !keeplocked) {cdinfo (CD_CLOSE ,"Unlocking door!\n" );
@@ -1299,6 +1378,7 @@ int media_changed(struct cdrom_device_inif (cdi->ops->media_changed (cdi,CDSL_CURRENT )) { cdi->mc_flags =0x3 ;/* set bit on both queues */ ret |=1 ; + cdi->media_written =0 ; } cdi->mc_flags &= ~mask;/* clear bit */ return ret;
drivers/scsi/sr.c renamed from drivers/scsi/sr.c~dvd+rw +1 -0
@@ -379,6 +379,7 @@ static int sr_init_command(struct scsi_creturn 0 ; SCpnt->cmnd[0 ] =WRITE_10 ; SCpnt->sc_data_direction =DMA_TO_DEVICE ; + cd->cdi.media_written =1 ; }else if (rq_data_dir (SCpnt->request) ==READ ) { SCpnt->cmnd[0 ] =READ_10 ; SCpnt->sc_data_direction =DMA_FROM_DEVICE ;
drivers/ide/ide-cd.c renamed from drivers/ide/ide-cd.c~dvd+rw +2 -0
@@ -1940,6 +1940,8 @@ static ide_startstop_t cdrom_start_write info->dma = drive->using_dma ?1 :0 ; info->cmd =WRITE ; + info->devinfo.media_written =1 ; +/* Start sending the write request to the drive. */ return cdrom_start_packet_command (drive,32768 , cdrom_start_write_cont); }
include/linux/cdrom.h renamed from include/linux/cdrom.h~dvd+rw +2 -0
@@ -947,6 +947,8 @@ struct cdrom_device_info { __u8 reserved : 6; /* not used yet */int cdda_method;/* see flags */ __u8 last_sense; +__u8 media_written;/* dirty flag, DVD+RW bookkeeping */ +unsigned short mmc3_profile;/* current MMC3 profile */ int for_data;int (*exit)(struct cdrom_device_info *);int mrw_mode_page;
_
Signature · 2 lines
Peter Osterlund - [email protected] http://w1.894.telia.com/~u89404340
Quoted 9 lines
This patch adds support for using DVD+RW drives as writable block devices under the 2.6.7-bk13 kernel.
The patch is based on work from:
Andy Polyakov <[email protected]> - Wrote the 2.4 patch Nigel Kukard <[email protected]> - Initial porting to 2.6.x
It works for me using an Iomega Super DVD 8x USB drive.
Any chance of this working with dvd�r? (Same question for cd-r on the other patch).
Signature · 1 line
Lab tests show that use of micro$oft causes cancer in lab animals
Quoted 5 lines · Wakko Warner
Quoted 5 lines
This patch adds support for using DVD+RW drives as writable block devices under the 2.6.7-bk13 kernel.
The patch is based on work from:
Quoted 7 lines
Quoted 4 lines
Andy Polyakov <[email protected]> - Wrote the 2.4 patch Nigel Kukard <[email protected]> - Initial porting to 2.6.x
It works for me using an Iomega Super DVD 8x USB drive.
Any chance of this working with dvd±r? (Same question for cd-r on the other patch).
No, not for now. I think support for non-rewritable media requires changes both in the udf filesystem and in the pktcdvd driver.
Signature · 2 lines
Peter Osterlund - [email protected] http://w1.894.telia.com/~u89404340
Quoted 5 lines
Quoted 2 lines
Any chance of this working with dvd?r? (Same question for cd-r on the other patch).
No, not for now. I think support for non-rewritable media requires changes both in the udf filesystem and in the pktcdvd driver.
I can understand that. If I wish to write to dvd�rw, do i need both patches?
The one use for dvd�r would be for backup archival when the disc isn't going to be filled.
Signature · 1 line
Lab tests show that use of micro$oft causes cancer in lab animals
Quoted 8 lines · Wakko Warner
Quoted 5 lines
Quoted 2 lines
Any chance of this working with dvd?r? (Same question for cd-r on the other patch).
No, not for now. I think support for non-rewritable media requires changes both in the udf filesystem and in the pktcdvd driver.
I can understand that. If I wish to write to dvd±rw, do i need both patches?
For DVD+RW, you don't need any additional patches. For DVD-RW, you need the packet writing patch and the patch below.
You can also use the packet writing patch for DVD+RW to improve performance in case the drive firmware is not good at handling small writes. (This seems to be the case with my drive.)
---
linux-petero/drivers/block/Kconfig | 3 +- linux-petero/drivers/block/pktcdvd.c | 37 ++++++++++++++++++++++++++++++++--- linux-petero/include/linux/pktcdvd.h | 1 3 files changed, 37 insertions(+), 4 deletions(-)
drivers/block/Kconfig renamed from drivers/block/Kconfig~dvd-rw-packet +2 -1
@@ -348,7 +348,8 @@ config CDROM_PKTCDVD compliant ATAPI or SCSI drive, which is just about any newer CD writer. - Currently only writing to CD-RW discs is possible. + Currently only writing to CD-RW, DVD-RW and DVD+RW discs is possible. + DVD-RW disks must be in restricted overwrite mode. To compile this driver as a module, choose M here: the module will be called pktcdvd.
drivers/block/pktcdvd.c renamed from drivers/block/pktcdvd.c~dvd-rw-packet +34 -3
@@ -1410,6 +1410,10 @@ static int pkt_set_write_settings(structchar buffer[128 ];int ret, size; +/* doesn't apply to DVD+RW */ +if (pd->mmc3_profile ==0x1a ) +return 0 ; +memset (buffer,0 ,sizeof (buffer));init_cdrom_command (&cgc, buffer,sizeof (*wp),CGC_DATA_READ ); cgc.sense = &sense;
@@ -1515,6 +1519,18 @@ static int pkt_good_track(track_informat*/ static int pkt_good_disc (struct pktcdvd_device *pd,disc_information *di) { +switch (pd->mmc3_profile) { +case 0x0a :/* CD-RW */ +case 0xffff :/* MMC3 not supported */ +break ; +case 0x1a :/* DVD+RW */ +case 0x13 :/* DVD-RW */ +return 0 ; +default : +printk ("pktcdvd: Wrong disc profile (%x)\n" , pd->mmc3_profile); +return 1 ; + } +/* * for disc type 0xff we should probably reserve a new track. * but i'm not sure, should we leave this to user apps? probably.
@@ -1544,10 +1560,18 @@ static int pkt_good_disc(struct pktcdvd_static int pkt_probe_settings (struct pktcdvd_device *pd) { +struct packet_command cgc; +unsigned char buf[12 ];disc_information di;track_information ti;int ret, track; +init_cdrom_command (&cgc, buf,sizeof (buf),CGC_DATA_READ ); + cgc.cmd[0 ] =GPCMD_GET_CONFIGURATION ; + cgc.cmd[8 ] =8 ; + ret =pkt_generic_packet (pd, &cgc); + pd->mmc3_profile = ret ?0xffff : buf[6 ] <<8 | buf[7 ]; +memset (&di,0 ,sizeof (disc_information));memset (&ti,0 ,sizeof (track_information));
@@ -1845,9 +1869,16 @@ static int pkt_open_write(struct pktcdvdif ((ret =pkt_get_max_speed (pd, &write_speed))) write_speed =16 ; -if ((ret =pkt_media_speed (pd, &media_write_speed))) - media_write_speed =16 ; - write_speed =min (write_speed, media_write_speed); +switch (pd->mmc3_profile) { +case 0x13 :/* DVD-RW */ +case 0x1a :/* DVD+RW */ +break ; +default : +if ((ret =pkt_media_speed (pd, &media_write_speed))) + media_write_speed =16 ; + write_speed =min (write_speed, media_write_speed); +break ; + } read_speed = write_speed;if ((ret =pkt_set_speed (pd, write_speed, read_speed))) {
include/linux/pktcdvd.h renamed from include/linux/pktcdvd.h~dvd-rw-packet +1 -0
@@ -243,6 +243,7 @@ struct pktcdvd_device__u8 mode_offset;/* 0 / 8 */ __u8 type;unsigned long flags; +__u16 mmc3_profile;__u32 nwa;/* next writable address */ __u32 lra;/* last recorded address */ struct packet_cdrw cdrw;
_
Signature · 2 lines
Peter Osterlund - [email protected] http://w1.894.telia.com/~u89404340
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 2 lines · Andrew Morton
It wasn't obvious whether or not I was supposed to apply this, but I did.
Yes, I wanted you to apply it, thanks.
Quoted 1 line
What's it do?
It implements packet writing for DVD+RW and DVD-RW discs. Hopefully this patch makes it more clear:
Added information about packet writing for DVD+RW and DVD-RW media.
---
linux-petero/Documentation/cdrom/packet-writing.txt | 66 ++++++++++++++++++++ 1 files changed, 66 insertions(+)
Documentation/cdrom/packet-writing.txt renamed from Documentation/cdrom/packet-writing.txt~packet-doc-update +66 -0
@@ -20,3 +20,69 @@ Getting started quick - Now you can mount /dev/pktcdvd0 and copy files to it. Enjoy! # mount /dev/pktcdvd0 /cdrom -t udf -o rw,noatime + + +Packet writing for DVD-RW media +------------------------------- + +DVD-RW discs can be written to much like CD-RW discs if they are in +the so called "restricted overwrite" mode. To put a disc in restricted +overwrite mode, run: + + # dvd+rw-format /dev/hdc + +You can then use the disc the same way you would use a CD-RW disc: + + # pktsetup /dev/pktcdvd0 /dev/hdc + # mount /dev/pktcdvd0 /cdrom -t udf -o rw,noatime + + +Packet writing for DVD+RW media +------------------------------- + +According to the DVD+RW specification, a drive supporting DVD+RW discs +shall implement "true random writes with 2KB granularity", which means +that it should be possible to put any filesystem with a block size >= +2KB on such a disc. For example, it should be possible to do: + + # mkudffs /dev/hdc + # mount /dev/hdc /cdrom -t udf -o rw,noatime + +However, some drives don't follow the specification and expect the +host to perform aligned writes at 32KB boundaries. Other drives does +follow the specification, but suffer bad performance problems if the +writes are not 32KB aligned. + +Both problems can be solved by using the pktcdvd driver, which always +generates aligned writes. + + # pktsetup /dev/pktcdvd0 /dev/hdc + # mkudffs /dev/pktcdvd0 + # mount /dev/pktcdvd0 /cdrom -t udf -o rw,noatime + + +Notes +----- + +- CD-RW media can usually not be overwritten more than about 1000 + times, so to avoid unnecessary wear on the media, you should always + use the noatime mount option. + +- Defect management (ie automatic remapping of bad sectors) has not + been implemented yet, so you are likely to get at least some + filesystem corruption if the disc wears out. + +- Since the pktcdvd driver makes the disc appear as a regular block + device, you can put any filesystem you like on the disc. For + example, run: + + # /sbin/mke2fs /dev/pktcdvd0 + + to create an ext2 filesystem on the disc. + + +Links +----- + +See http://fy.chalmers.se/~appro/linux/DVD+RW/ for more information +about DVD writing.
_
Signature · 2 lines
Peter Osterlund - [email protected] http://w1.894.telia.com/~u89404340
Quoted 7 lines · Peter Osterlund
This patch adds support for using DVD+RW drives as writable block devices under the 2.6.7-bk13 kernel.
The patch is based on work from:
Andy Polyakov <[email protected]> - Wrote the 2.4 patch Nigel Kukard <[email protected]> - Initial porting to 2.6.x
...
Quoted 4 lines
linux-petero/drivers/cdrom/cdrom.c | 80 +++++++++++++++++++++++++++++++++++++ linux-petero/drivers/ide/ide-cd.c | 2 linux-petero/drivers/scsi/sr.c | 1 linux-petero/include/linux/cdrom.h | 2
Nigel pointed out that the earlier patches contained attributions that are not present in this patch. The 2.4 patch contains:
Nov 5 2001, Aug 8 2002. Modified by Andy Polyakov <[email protected]> to support MMC-3 complaint DVD+RW units.
and Nigel changed it to this in his 2.6 patch:
Modified by Nigel Kukard <[email protected]> - support DVD+RW 2.4.x patch by Andy Polyakov <[email protected]>
The patch I sent you deleted most of the earlier work and moved the rest to cdrom.c, but the comments were not moved over, since the earlier authors didn't modify cdrom.c.
Nigel wants to get credit for his work though, so were should we put those messages? Is this patch acceptable?
linux-petero/drivers/cdrom/cdrom.c | 6 ++++++ 1 files changed, 6 insertions(+)
drivers/cdrom/cdrom.c renamed from drivers/cdrom/cdrom.c~packet-copyright +6 -0
@@ -234,6 +234,12 @@-- Mt Rainier support -- DVD-RAM write open fixes +Nov 5 2001, Aug 8 2002. Modified by Andy Polyakov +<[email protected]> to support MMC-3 compliant DVD+RW units. + +Modified by Nigel Kukard <[email protected]> - support DVD+RW +2.4.x patch by Andy Polyakov <[email protected]> +-------------------------------------------------------------------------*/ #define REVISION "Revision: 3.20"
_
Signature · 2 lines
Peter Osterlund - [email protected] http://w1.894.telia.com/~u89404340
Quoted 11 lines
Nigel pointed out that the earlier patches contained attributions that are not present in this patch. The 2.4 patch contains:
Nov 5 2001, Aug 8 2002. Modified by Andy Polyakov <[email protected]> to support MMC-3 complaint DVD+RW units.
and Nigel changed it to this in his 2.6 patch:
Modified by Nigel Kukard <[email protected]> - support DVD+RW 2.4.x patch by Andy Polyakov <[email protected]>
Quoted 7 lines
The patch I sent you deleted most of the earlier work and moved the rest to
cdrom.c, but the comments were not moved over, since the earlier authors didn't modifycdrom.c.Nigel wants to get credit for his work though, so were should we put those messages? Is this patch acceptable?
Thanks Peter ;-)
Andy wrote the support for 2.4, I basically ported it to 2.6. Make sure you included aswell though, your help is greatly appreciated!
Everyone, enjoy your day!
-Nigel
Quoted 21 lines
linux-petero/drivers/cdrom/cdrom.c | 6 ++++++ 1 files changed, 6 insertions(+)diff -puN
drivers/cdrom/cdrom.c~packet-copyrightdrivers/cdrom/cdrom.cdrivers/cdrom/cdrom.c renamed from drivers/cdrom/cdrom.c~packet-copyright +6
-0@@ -234,6 +234,12 @@-- Mt Rainier support -- DVD-RAM write open fixes +Nov 5 2001, Aug 8 2002. Modified by Andy Polyakov +<[email protected]> to support MMC-3 compliant DVD+RW units. + +Modified by Nigel Kukard <[email protected]> - support DVD+RW +2.4.x patch by Andy Polyakov <[email protected]> +-------------------------------------------------------------------------*/ #define REVISION "Revision: 3.20"_