DVD+RW/+R for Linux

by <appro@fy.chalmers.se>, November 2002


Q. What is it (not)?
A. Maybe to your disappointment it is not about video. The scope of this page is computer storage applications, things like backup, archiving, data exchange... The downloadable files are an optional kernel patch and a couple of user-land utilities dubbed as dvd+rw-tools.

Q. Kernel patch? What's wrong with cdrecord/cdrtools?
A. Nothing! Moreover, you actually need them (cdrtools). It's just that you can't use them to manage the DVD+RW nor DVD+R media itself. DVD+RW media has no notion of [multiple] sessions or packet writing, so cdrecord[-ProDVD] wouldn't really know what to do (nor would dvdrtools despite what RedHat 7.3 Release Notes say). But most important is that DVD+RW is a true random write access media and therefore is suitable for housing of arbitrary filesystem, e.g. udf, vfat, ext2, etc. This, and this alone, qualifies DVD+RW support for kernel implementation. However! Support for arbitrary filesystem doesn't seem to work with 1st generation drives, Ricoh MP5120A and derivatives (see Technical Ramblings below for further details).

It should be explicitly noted that dvd+rw-tools do not require kernel support and if they fulfill your expectations, then the patch is by all means optional.

Q. What are dvd+rw-tools for?
A. To format blank DVD+RW media to start with. Secondly, even though you [might] have an opportunity to put for example an ext2 filesystem on DVD+RW, it's not very practical because you most likely want to access the data on arbitrary computer. Or in other words you most likely want ISO9660. Trouble is that you very likely want to add data now and then. And what options do you have in the lack of multiple sessions? Complete remastering which takes more and more time as dataset grows? Well, yes, unless you employ growisofs! growisofs provides the way to lay down and grow an ISO9660 filesystem on, as well as to burn an arbitrary pre-mastered image to both DVD+RW and DVD+R media.

Q. [grow]isofs? Isn't UDF the one to use?
A. My initial experience [from late 2001] with UDF was rather poor. I couldn't even mount an UDF volume created under Windows [with Veritas DLA] in either Linux or Solaris. Now it doesn't appear to be an issue anymore... Your milage may of course vary... But one way or another I still have to recommend to deploy it with caution, see tutorial for further details.

Q. What do I need cdrtools for?
A. The DVD+RW drives available on the market can burn even CD-R[W] media and cdrecord is the tool for this job [and this job only]. Besides, growisofs is just a front-end [rather back-end] to mkisofs.


Foreword/Disclaimer

Provided the absolute lack of support from vendor(s) you should consider this page to be a result of guesswork. There still is a couple of fatal failures indicated by vendor-specific error codes (see Technical Ramblings) and I didn't yet figured out the way around 'em. So the status of this "project" is rather "gathering experience" than "ready for production environment."


Tutorial



Compatibility caveat lector


In order to optimize seek times [most?] DVD[-ROM] players calibrate their mechanics at the moment of media mount by sliding the optical head some place, picking up the signal and noting the physical block address underneath the lens. In order for this procedure to work with rewritable/recordable media, that particular spot has to be written to [or de-iced in DVD+RW case]. Some units slide the head to 30mm [radial] to calibrate. In order to keep such players "happy," make sure that at least 500MB is written.

Other units attempt to seek to lead-out [or vicinity of it] for calibration purposes. Now the catch is that it's perfectly possible to produce a DVD+RW disk without lead-out. Most notably media initially formatted with dvd+rw-format [apparently] doesn't have any lead-out, not to mention that practically whole surface remains virgin. If you fail to mount/play DVD+RW media, attempt to

dvd+rw-format -lead-out /dev/scdN

which relocates the lead-out next to outermost written sector as well as makes sure there is no virgin surface before it.

Then non-finalized DVD+R disks don't have lead-out either(*). If you fail to mount/play DVD+R media and wish to sacrifice the remaining space for immediate compatibility, just fill the media up(**). Alternatively if you master DVD+R disc in a single take and don't plan to use it for multi-sessioning(***), you have the option to invoke growisofs with -dvd-compat option and cut the real lead-out already at the end of first session.

(*) Well, there are lead-outs at the session edges, but the problem is that "End Physical Sector Number of Data Area" field in "Control Data Zone" of the lead-in contains address of the largest media sector, which makes DVD[-ROM] players look for lead-out at the outermost edge instead of the first session. Actually I fail to understand why don't they burn the address of last sector of the first session in the lead-in even on multi-session disks? Something to correct in next firmware update?
(**) The easiest way is to create couple of holey files with 'touch hugeN.void' and 'perl -e 'truncate ("hugeN.void", 0x7ffffffe)'', and finally to 'growisofs ... huge*.void'. The command is bound to fail with "end of medium reached," but that's what you basically want.
(***) E.g. when mastering DVD-Video disk:-) Note that -dvd-video option [passed to mkisofs] engages -dvd-compat automatically.


Then we have logical format compatibility issue(s). The very ground for all the controversy around DVD+RW, rather around DVD+RW media not being playable in a whole range of players. DVD+RW Alliance was keen to blame on DVD-ROM vendors, even claiming that they deliberately block playback. But the fact is that format specifications don't explicitely say that unrecognized format [designated by "Book Type" field in "Control Data Zone" of the lead-in] should be treated as DVD-ROM and [in my opinion] it was rather naive of them to claim and expect that the media will be playable in "virtually all players." This deficiency was recognized by practically all DVD+RW vendors [apparently all except Sony] and a secret vendor-specific command manipulating this "Book Type" field was implemented. If you fail to mount/play DVD+RW media, attempt to

dvd+rw-booktype -dvd-rom -media /dev/scdN

It's naturally not possible to manipulate the "Book Type" field on DVD+R media, that is not after the lead-in is written [which takes place at the moment the first session gets closed]. But it's possible to control how it [lead-in] is going to be branded by programming the drive in advance:

dvd+rw-booktype -dvd-rom -unit+r /dev/scdN

Meaning that if you fail to play DVD+R media, you can attempt to burn another disc with different unit settings. For more background information about dvd+rw-booktype, see "Compatibility Bitsettings" article at dvdplusrw.org.

There [potentially] are other logical format incompatibilites, but the "Book Type" issue discussed above is the only one "officially" recognized. Well, it's actually understandable as it's the only one that can be recognized and addressed by a DVD+RW vendor alone. Recognition of other incompatibilities would require cooperation from DVD[-ROM] player vendors and that's something they apparently are not willing to show referring to the fact that DVD+RW format is not approved [and apprently never will be] by DVD Forum(*).

(*) To which I say "so what?" DVD Forum is an alliance of manufacturers just like DVD+RW Alliance is. It [or any other party for that matter] has no authority to deny a technology development initiative.


Finally there is a physical incompatibility issue. They claim that there're optical pick-ups out there not being capable to decode the track because of low reflectivity [of DVD+RW media surface]. I write "they claim," because in the lack of cooperation from DVD[-ROM] vendors it's not possible to distinguish physical from logical format incompatibility, which I find important to tell apart in order to make sure at least logical format incompatibility issues don't persist over time. But either way, there is very little you can do about this one, but to try another player...


Technical Ramblings


What does "DVD+RW support" really mean? Even though DVD+RW has no notion of [multiple] sessions, to ensure compatibility with DVD-ROM it's essential to issue "CLOSE TRACK/SESSION (5Bh)" MMC command to terminate/suspend background formatting (if any in progress) whenever you intend to eject the media or simply stop writing and want better read performance (e.g. remount filesystem read-only). This is what the patch is basically about: noting when/if media was written to and "finalizing" at unlock door.

Secondly, whenever you employ fully fledged file system, I/O requests get inevitably fragmented. "Fragmented" means following. Even though you can address the data with 2KB granilarity, it [data] is physically laid out in 32KB chunks. This in turn means that for example writing of 2KB block involves reading of 32KB chunk, replacing corresponding 2KB and writing down of modified 32KB chunk. "Fragmented requests" are those that are smaller than 32KB or/and cross the modulus 32KB boundaries. In order to optimize the process certain caching algorithm is implemented in unit's firmware. Obviously it can't adequately meet all possible situations. And so in such unfortunate situations the drive apparently stops processing I/O requests returning "COMMAND SEQUENSE ERROR (2Ch)" ASC. This is the second essential of "DVD+RW support," namely injecting of "SYNCHRONIZE CACHE (35h)" MMC command in reply to the error condition in question. The command flushes the cached buffers which makes it possible to resume the data flow.

Unfortunately the above paragraph doesn't seem to apply to the 1st generation drives, Ricoh MP5120A and derivatives:-( "SYNCHRONIZE CACHE (35h)" doesn't seem to be sufficient and the unit keeps replying with "COMMAND SEQUENSE ERROR (2Ch)" going into end-less loop. This makes it impossible to deploy arbitrary file system. I'm open for suggestions... Meanwhile the I've chosen to simply suspend I/O till the media is unmounted.

Even 2nd gen unit were reported to exhibit similar [but not the same] behaviour under apparently extremely rare circumstanses. At least I failed to reproduce the problem... But it's being looked into...

This one really beats me. Sometimes the unit simply stops writing signalling a vendor specific positioning error, 03h/15h/82h to be specific. Especially if the media is newly formatted. Couple of work theories. One is that block buffer cache reorders requests so that they are not sequential anymore, "FLUSH CACHE" might do the trick. Another one is that under "underrun" condition background formatting kicks off and has to be explicitely stopped. "Underrun" is in quotes because the unit is supposed to handle temporary data stream outages gracefully. If you run into this (you most likely will), try to complement growisofs command line with [undocumented] -poor-man option (which has to be first in the command line). This option eliminates request reorders and minimizes possibility for "underrun" condition (by releasing the pressure off VM subsystem).

The original idea was to implement DVD+RW support in drivers/cdrom/cdrom.c. Unfortunately SCSI layer maintains private "writeable" flag controlling the ability to issue WRITE commands. The flag is impossible to reach for from the Unified CD-ROM driver. But why am I talking about SCSI when there are only IDE units out there (at least for the time being)? Well, as you most likely want to occasionally burn even CD-R[W] with cdrecord you want it to go through ide-scsi emulation layer anyway. So I figured that SCSI CD-ROM driver is the one to aim for even for DVD+RW.

Unfortunately it was not possible to implement it completely in sr_mod.o:-( Minor drivers/cdrom/cdrom.c modification was required to sense the media before decision about whether or not to permit write open. That's because DVD+RW drives are morphing their behaviour after currently mounted media and it's essential to identify newly inserted media.

Special comment about "what a dirty hack!!!" To my great surprise it turned out that timeout value you pass in cdrom_generic_command is simply ignored and timeout is set to precompiled value of 30 seconds. Unfortunately it's way too low for formatting purposes and I had to do something about it. Alternative to "the dirty hack" was to add another argument to sr_do_ioct and modify all the calls to it... I've chosen to take over those 31 unused bits from the "quiet" argument instead of modifying all the calls (too boring).

There is another kernel "deficiency" I ran into while working on the (original version of) dvd+rw-format utility. The drive provides background formatting progress status, but unfortunately it's impossible to access it. That's because progress counter is returned [in reply to "TEST UNIT READY"] as "NO SENSE/LOGICAL UNIT NOT READY/FORMAT IN PROGRESS" sense bytes but with "GOOD" status. Apparently any sense data with "GOOD" status is discarded by the common SCSI layer.

It was pointed out to me that DVD+RW units work with Acard SCSI to IDE bridges.