root / libburn / trunk / doc / cookbook.txt

Revision 3036, 64.8 kB (checked in by scdbackup, 7 months ago)

Lifted ban to derive GPLv3, extended copyright range to 2010

Line 
1libburnia-project.org Optical Media Rotisserie Recipes as of January 2010
2
3Content:
4- TAO Multi-Session CD Cookbook (CD-R, CD-RW)
5- SAO CD Cookbook (CD-R, CD-RW, pure audio or pure data only)
6- Overwriteable DVD Cookbook (DVD-RAM, DVD+RW, DVD-RW, BD-RE)
7- Sequential DVD-R[W] Cookbook
8- DVD+R[/DL] Cookbook
9- BD-R Cookbook
10
11-------------------------------------------------------------------------------
12                         TAO Multi-Session CD Cookbook
13-------------------------------------------------------------------------------
14Guided by reading mmc-r10a.pdf , O.8 "Write a Track"
15                               from http://www.t10.org/ftp/t10/drafts/mmc/
16backed by reading mmc5r03c.pdf from http://www.t10.org/ftp/t10/drafts/mmc5/
17by reading        spc3r23.pdf  from http://www.t10.org/ftp/t10/drafts/spc3/
18by reading        libburn/*    from http://icculus.org/burn
19and by experiments with drives NEC ND-4570A, LG GSA-4082B, LITE-ON LTR48125S
20which used in part code from http://icculus.org/burn.
21
22For libburnia-project.org by Thomas Schmitt <scdbackup@gmx.net>
23
24-------------------------------------------------------------------------------
25
26Media type can be recognized by Current Profile from 46h GET CONFIGURATION.
27(mmc5r03c.pdf 6.6.2.1)
28
29CD-R                           0009h
30CD-RW                          000ah
31
32The following topics are covered in this text:
33- About blank, appendable and finalized CD media
34- Writing a session to CD in TAO mode
35- Obtaining CD multi-session info for extending ISO-9660 filesystems
36- Obtaining a Table Of Content from CD
37
38
39-------------------------------------------------------------------------------
40About blank, appendable and finalized CD media :
41
42CD media have to be blank or appendable in order to be writeable in TAO mode.
43The according status may be inquired by 51h READ DISC INFORMATION requesting
44Data Type 000b Standard Disc Information, where reply value Disc Status
45indicates:
46 00b   blank
47 01b   appendable
48 10b   finalized
49 11b   others (unsuitable for this recipe)
50(mmc5r03c.pdf 6.22.3.1.4)
51
52CD-RW which are finalized or appendable may be blanked by command A1h BLANK
53with blanking types 000b "Blank the disc" or 001b "Minimally blank the disc".
54The Start Address/Track Number will be ignored so it may well be 0.
55
56Because the operation is long running it is advised to set the Immed bit and to
57watch the progress by commands 00h TEST UNIT READY and 03h REQUEST SENSE
58with DESC bit set to 0 for fixed format reply.
59It is done when 00h succeeds and 03h reports 0 in PROGRESS INDICATION
60(byte 1+2 in Table 22 = byte 16+17 SENSE KEY SPECIFIC in table 26).
61(mmc5r03c.pdf 6.2 BLANK)
62(spc3r23.pdf 4.5.2.4.4 table 22, 4.5.3 table 26,
63             6.27 REQUEST SENSE, 6.33 TEST UNIT READY)
64
65
66-------------------------------------------------------------------------------
67Writing a session to CD in TAO mode :
68
69The writing method for blank or appendable media is the same. A new session
70will get created automatically by the first track when it is written. If the
71media is blank then the new session will be the first and only one in the
72table of content. If the media is appendable then a new session will be
73appended to the existing sessions. In any case the new track will be the
74first one in the new session.
75
76Speed may be set by BBh SET CD SPEED parameter Drive Write Speed. Note that
77kbytes/sec means 1000 bytes/sec and not 1024/sec. Rotational control should
78be set to 00b. 1x CD speed is 176.4 kbytes/sec. Speed is usually set to the
79next lower possible value by the drive. So it is helpful to add a few
80kbytes/sec just in case the drive has rounding problems.
81(mmc5r03c.pdf 6.37)
82
83Before writing can occur, a Write Parameters mode page 05h has to be composed
84and transmitted via 55h MODE SELECT. Mode page 05h describes several burn
85parameters:
86 BUFE             Buffer Underrun protection      0=off, 1=on
87 Test Write       -dummy mode for writing         0=off, 1=on
88 Write Type       Packet/TAO/SAO/RAW              01h = TAO
89 Multi-session    Whether to keep appendable      00b = finalize
90                                                  11b = keep appendable
91 Track Mode       Describes frame type            4 for data , 0 for audio
92 Data Block Type  Layout of payload blocks        8 for 2048 byte data blocks
93                                                  0 for 2352 byte audio blocks
94 Audio Pause Length                               150 = 2 seconds
95Any other parameters may be set to 0.
96Mode page data as of MMC-5 table 644 are preceded by a Mode Parameter Header
97as of SPC-3 table 240. This 8-byte header may be filled with zeros.
98(mmc5r03c.pdf 7.5.4 The Mode Page, 4.2.3.4 Table 17 CONTROL = Track Mode)
99(spc3r23.pdf 6.8 MODE SELECT, 7.4.3 Mode parameter header formats)
100
101
102Writing has to begin at the address returned by 52h READ TRACK INFORMATION
103with Address/Number Type set to 01b and Logical Block Address/Track/Session
104Number set to FFh. The Next Writeable Address as of table 500 is the number
105to start writing with.
106(mmc5r03c.pdf 6.27 )
107
108Writing is performed by one or more 2Ah WRITE transactions with the Logical
109Block Address counted up from the initial number in sync with the number of
110blocks written. I.e the Transfer Length of the previous 2Ah WRITE has to be
111added to the Logical Block Address for the next 2Ah WRITE. Only full blocks
112can be written.
113(mmc5r03c.pdf, 6.44)
114When writing is done, it is mandatory to force the drive's buffer to media by
11535h SYNCHRONIZE CACHE.
116(mmc5r03c.pdf, 6.41)
117
118A track must at least contain 300 payload blocks: 4 seconds of audio or
119600 KiB of data.
120(mmc5r03c.pdf 6.3.3.1.2)
121
122Up to december 2009 the track was closed by 5Bh CLOSE TRACK SESSION Close
123Function 001b. Older MMC specifies a valid Logical Track Number FFh to depict
124the open track.  MMC-5 is quite silent about this. FFh worked for my drives.
125(mmc5r03c.pdf 6.3.3.1.2)
126This is omitted since libburn-0.7.4, relying entirely on 35h SYNCHRONIZE CACHE.
127First appeared a drive where CLOSE TRACK fails in simulation mode, later
128another one produced error replies even with real burning.
129
130After that, a new track may be written beginning with sending the mode page 05h
131again. It is not tested whether 05h can be omitted if Track Mode and Data Block
132Type are the same as with the previous track.
133The new track will be added to the session which was opened by the first track.
134
135After the last track of a session, 5Bh CLOSE TRACK SESSION Close Function 010b
136with Logical Track Number 0 closes the session. It depends on the Multi-Session
137value in mode page 05h whether the disc is finalized or stays appendable.
138(mmc5r03c.pdf 6.3.3.1.3)
139
140
141-------------------------------------------------------------------------------
142Obtaining CD multi-session info for extending ISO-9660 filesystems :
143
144Program mkisofs expects two numbers with its option -C which describe the
145situation on an appendable CD which already contains a ISO-9660 filesystem
146in the first track of the last session.
147
148The first number is the Logical Block Address of that track containing the
149existing ISO-9660 filesystem image. This number is needed for mkisofs option
150-M to connect to the existing image. The new image will refer to files in
151the previously existing image. mkisofs option -M needs read access to the
152CD or a blockwise copy of it on hard disk.
153The number is gained by 43h READ TOC/PMA/ATIP.
154(mmc5r03c.pdf 6.26)
155Untested is Format 0001b which in table 478 promises quick access via
156Start Address Of First Track In Last Session.
157(mmc5r03c.pdf 6.26.2.5 table 478, 6.26.3.3.1)
158libburn gets the number from its Table Of Content model which is obtained
159by 43h READ TOC/PMA/ATIP, Format 0010b. See below.
160
161The second number is an exact prediction of the Logical Block Address of the
162new track which will contain the newly generated ISO-9660 image.
163Even without mkisofs option -M this second number is still needed to make the
164inner block address pointers of the image match the Logical Block Addresses
165on CD. For that one may inquire 52h READ TRACK INFORMATION with
166Address/Number Type set to 01b and Logical Block Address/Track/Session
167Number set to FFh. The Next Writeable Address as of table 500 is the number
168to use.
169(mmc5r03c.pdf 6.27 )
170
171
172-------------------------------------------------------------------------------
173Obtaining a Table Of Content from CD :
174
175The structure of a CD is comprised of sessions. Each session contains one or
176more tracks and is followed by a lead-out. A track has an address and a length.
177
178Table of content information is gained by 43h READ TOC/PMA/ATIP, Format 0010b.
179(mmc5r03c.pdf 6.26.2.5 table 478)
180
181The number of sessions is given by Last Complete Session Number.
182The number of TOC Track descriptors is: (TOC Data Length - 2)/11 .
183
184Each TOC Track Descriptor contains a Session Number.
185
186If POINT is >= 1 and <= 99 (63h) then the descriptor is about the track of
187which POINT tells the number.
188The start address of this track can be read from PMIN, PSEC, PFRAME where
189it is encoded in MSF format:
190blocks = frames - 150, 75 frames = 1 sec , 60 sec = 1 min.
191The length of the track is given by MIN,SEC,FRAME in the same format.
192
193If POINT = A0h then the descriptor tells in PMIN the first track number of its
194session.
195POINT = A1h tells in PMIN the last track number of its session.
196POINT = A2h describes in PMIN, PSEC, PFRAME the lead-out of a session, i.e the
197first address after the session's end. (Next writeable address typically is
198lead-out + 11400 after the first session, lead-out + 6900 after further
199sessions.)
200POINT = B0h tells in MIN,SEC,FRAME this next writeable address or FFh,FFh,FFh
201for finalized disc.
202(mmc5r03c.pdf 6.26.3.4 table 489, 4.2.3.7 Mode-1 Q, Mode-5 Q)
203
204
205In libburn the address of the first track in the last session is obtained from
206the last session's POINT = A0h and from the track descriptor with the POINT
207value matching the PMIN value of the A0h descriptor.
208Untested is whether POINT = B0h and 52h READ TRACK INFORMATION are always in
209sync. libburn uses the info provided by 52h READ TRACK INFORMATION.
210
211
212-------------------------------------------------------------------------------
213
214-------------------------------------------------------------------------------
215                                 SAO CD Cookbook
216-------------------------------------------------------------------------------
217Guided by reading libburn/*    from http://icculus.org/burn
218backed by reading mmc5r03c.pdf from http://www.t10.org/ftp/t10/drafts/mmc5/
219and by experiments with drives NEC ND-4570A, LG GSA-4082B, LITE-ON LTR48125S
220which used in part code from http://icculus.org/burn.
221
222For libburnia-project.org by Thomas Schmitt <scdbackup@gmx.net>
223
224-------------------------------------------------------------------------------
225
226Recognition of media type and state (blank, appendable, finalized) is as
227described in the TAO Multi-Session CD Cookbook. See there.
228
229The MMC specs do not give much hint about the combination of SAO and
230multi-session. My drives refused not only on a few experiments which i did
231in libburn but also failed with cdrecord -sao on an appendable CD.
232So for now only blank CD seem to be suitable for SAO writing. 
233
234Different from TAO mode, the whole session layout is announced to the drive by
235sending a Cue Sheet. This implies that the sizes of the tracks have to be known
236in advance, which is a heavy drawback when dealing with track data sources like
237stdin, named pipes or sockets.
238Nevertheless, SAO seems to be best writing mode for audio purposes, as our
239audio expert Lorenzo Taylor found out.
240
241A SAO session in libburn may either consist entirely of audio tracks or
242entirely of data tracks. For mixed sessions, only TAO is usable yet.
243
244- Composing a SAO CD Cue Sheet (either audio or data, but not mixed)
245- Writing the prepared SAO CD session
246- What is known about mixed mode sessions
247
248
249-------------------------------------------------------------------------------
250Composing a Cue Sheet (either audio or data, but not mixed) :
251
252The Cue Sheet will get submitted to the drive by 5Dh SEND CUE SHEET.
253Each entry of the sheet is of 8 bytes size. Its fields are named
254CTL|ADR, TNO, INDEX, DATA FORM, SCMS, MIN, SEC, FRAME .
255(mmc5r03c.pdf 6.33)
256
257CTL is 40h for data and 00h for audio.
258(mmc5r03c.pdf 6.33.3.4)
259ADR is always 01h.
260TNO is the track number (1 to 99).
261INDEX is a subaddress within tracks. This recipe uses only INDEX 01h within
262tracks.
263(mmc5r03c.pdf 4.2.3.5.2)
264DATA FORM is 00h for audio payload , 10h for data. (01h for audio pause is not
265used in libburn).
266(mmc5r03c.pdf 6.33.3.11 CD-DA Data Form, 6.33.3.12 CD-ROM mode 1 Form)
267SCMS is always 00h.
268MIN, SEC, FRAME give the MSF address where the described data entity starts.
269LBA = frames - 150, 75 frames = 1 sec , 60 sec = 1 min.
270This address must increase from entry to entry (or at least stay equal).
271
272
273The first entry describes the Lead-in. Its content is
274(CTL|ADR ,00h,00h,01h,00h,00h,00h,00h)
275With the CTL|ADR for the first track: 41h for data, 01h for audio.
276
277The LBA for the first write is negative: -150. This corresponds to MSF address
27800h:00h:00h. All addresses are to be given in MSF format.
279The first information track on disc is preceded by a pause encoding of 2 sec:
280(CTL|ADR,01h,00h, DATA FORM ,00h,00h,00h,00h)
281with DATA FORM = 00h for audio and 10h for data. By those 2 seconds the MSF
282address increases to 00h:02h:00h = LBA 0.
283
284Each track is represented by an entry
285(CTL|ADR, TNO ,01h,DATA FORM,00h, MIN , SEC , FRAME)
286TNO gives the track number. MIN, SEC, FRAME give the MSF address which becomes
287the start address of the track. The MSF address is then increased by the size
288of the track (to be used with next track or with lead-out).
289
290A track must at least contain 300 payload blocks: 4 seconds of audio or
291600 KiB of data.
292(mmc5r03c.pdf 6.33.3.6)
293
294At the end of the session there is a lead-out entry
295(CTL|ADR,AAh,01h,01h,00h,MIN,SEC,FRAME)
296marking the end of the last track. (With libburn CTL is as of the last track.)
297
298
299-------------------------------------------------------------------------------
300Writing the prepared session :
301
302Speed may be set by BBh SET CD SPEED parameter Drive Write Speed. Note that
303kbytes/sec means 1000 bytes/sec and not 1024/sec. Rotational control should
304be set to 00b. 1x CD speed is 176.4 kbytes/sec. Speed is usually set to the
305next lower possible value by the drive. So it is helpful to add a few
306kbytes/sec just in case the drive has rounding problems.
307(mmc5r03c.pdf 6.37)
308
309A Write Parameters mode page 05h has to be composed and transmitted via
31055h MODE SELECT. This page describes the following parameters:
311 BUFE             Buffer Underrun protection      0=off, 1=on
312 Test Write       -dummy mode for writing         0=off, 1=on
313 Write Type       Packet/TAO/SAO/RAW              02h = SAO
314 Multi-session    Whether to keep appendable      00b = finalize
315                                                  11b = keep appendable
316 Track Mode       Describes frame type            0 (is ignored)
317 Data Block Type  Layout of payload blocks        0 (is ignored)
318 Audio Pause Length                               150 = 2 seconds (ignored ?)
319Any other parameters may be set to 0.
320Mode page data as of MMC-5 table 644 are preceded by a Mode Parameter Header
321as of SPC-3 table 240. This 8-byte header may be filled with zeros.
322(mmc5r03c.pdf 7.5.4 The Mode Page, 4.2.3.4 Table 17 CONTROL = Track Mode)
323(spc3r23.pdf 6.8 MODE SELECT, 7.4.3 Mode parameter header formats)
324
325The Cue Sheet is submitted to the drive by 5Dh SEND CUE SHEET. Cue Sheet Size
326is 8 times the number of entries.
327(mmc5r03c.pdf 6.33)
328
329Writing is performed by multiple 2Ah WRITE transactions with the Logical
330Block Address counted up from the initial number in sync with the number of
331blocks written. I.e the Transfer Length of the previous 2Ah WRITE has to be
332added to the Logical Block Address for the next 2Ah WRITE. Only full blocks
333can be written.
334(mmc5r03c.pdf, 6.44)
335Writing begins at LBA -150 which is to be transmitted as 4-byte, Big-endian,
336two's-complement. E.g:  -150 = FFh FFh FFh 6Ah. This is the natural form found
337with about any 32-bit processor, so only the endianness has to be taken into
338respect when converting a 32-bit integer into a LBA for command 2Ah WRITE.
339
340
341At first the mandatory pause preceding the first track has to be written as
342150 blocks of the matching sector size: 2048 for data, 2352 for audio.
343By this, the LBA increases from -150 to 0.
344
345Next the tracks' payload is sent. For each track exactly the number of blocks
346has to be transmitted as is announced in the Cue Sheet by the difference
347of the track's own start address and the start address of the next entry in
348the Cue Sheet. After each write the LBA for the next write has to be increased
349by the number of blocks transmitted. Just like with TAO writing.
350
351There is no separator between the tracks of a pure mode SAO session.
352(If the session was mixed mode, there would be extended Pre-gaps and Post-gaps
353between data mode tracks and audio mode tracks.)
354(libburn sends its own buffer to the drive at the end of each track but does
355not sync the drive's chache. It is unclear whether this separation of tracks
356on the level of 2Ah WRITE is necessary with a pure mode session. It does not
357harm in any case and would probably be unavoidable if audio and data tracks
358were mixed.)
359
360When writing of all tracks is done, it is mandatory to force the drive's buffer
361to media by 35h SYNCHRONIZE CACHE.
362(mmc5r03c.pdf, 6.41)
363
364No further finalization is necessary. (I.e. no 5Bh CLOSE TRACK SESSION.)
365
366
367----------------------------------------------------------------------------
368What is known about mixed mode sessions :
369
370For now, SAO sessions with a mix of data and audio are not supported in
371libburn. Here are the reasons why.
372
373Obviously the code of http://icculus.org/burn is incomplete in this aspect.
374In mmc5r03c.pdf comparison of table 555 and 6.33.3.18 seems self-contradicting.
375(The second Pre-gap in table 555 does not match any of the criteria of
3766.33.3.18. Also, there is no Post-gap shown in table 555 although 6.33.3.19
377would prescribe some.)
378
379If a data track follows an audio track then the data track gets a preceding
380extended Pre-gap:
381(CTL|ADR, TNO ,01h,DATA FORM,00h, MIN , SEC , FRAME)
382with TNO already the number of the data track. The MSF address is to be
383increased by 3 seconds. The first second of the extended Pre-gap needs to be
384written in the audio track's mode and the other 2 seconds are to be written
385in the data track's mode.
386(libburn compares DATA FORM rather than burn_track.mode . Wrong ?)
387(libburn currently does only 2 seconds and the second part of Pre-gap. There is
388an issue with burn_track.pregap1 about this. Seems libburn mistakes the pause
389preceding track 1 for a part 2 of an extended Pre-gap.)
390
391If a data track is followed by an audio track then it gets a Post-gap of at
392least two seconds.
393No example of Post-gap is given for Cue Sheet. Maybe it is to be added to the
394track, or maybe it gets an own Cue Sheet entry ... who knows ?
395(libburn contains write code for pregap1, pregap2 and postgap. But only
396pregap2 ever gets activated. Once hackingly for the first 2 second pause, once
397incompletely for a change of DATA FORM.)
398
399Seems nobody ever tested this. Libburnia simply knows no use case where the
400correctness of Pre-gap and Post-gap would become evident.
401
402
403-------------------------------------------------------------------------------
404
405-------------------------------------------------------------------------------
406                           Overwriteable DVD Cookbook
407-------------------------------------------------------------------------------
408Inspired by Andy Polyakov's http://fy.chalmers.se/~appro/linux/DVD+RW/tools ,
409backed by reading mmc5r03c.pdf from http://www.t10.org/ftp/t10/drafts/mmc5/
410by own experiments with drives NEC ND-4570A, LG GSA-4082B, PHILIPS SPD3300L,
411LG GGW H20L, and by BD-RE experiments done by Giulio Orsero on LG BE06LU10.
412
413For libburnia-project.org by Thomas Schmitt <scdbackup@gmx.net>
414
415-------------------------------------------------------------------------------
416
417Media type can be recognized by Current Profile from 46h GET CONFIGURATION.
418(mmc5r03c.pdf 6.6.2.1)
419
420DVD-RAM                        0012h
421DVD-RW Restricted Overwrite    0013h
422DVD-RW Sequential Recording    0014h (i.e. unformatted)
423DVD+RW                         001Ah
424BD-RE                          0043h
425
426A short compilation of the write model:
427- Overwriting in general
428
429The recipes described here are depending on formatting state:
430- DVD-RAM, fully formatted DVD+RW, DVD-RW, BD-RE
431- Unformatted DVD+RW
432- Partly formatted DVD+RW
433- Unformatted DVD-RW
434- Partly formatted DVD-RW
435- Intermediate state DVD-RW
436- DVD-RAM and BD-RE formatting
437- DVD-RAM and BD-RE speed tuning
438
439Slightly off topic are
440- ISO 9660 multi-session emulation on overwriteable media
441- ISO 9660 based TOC emulation on overwriteable media
442
443-------------------------------------------------------------------------------
444Overwriting in general :
445
446Depending on media type, some kind of formatting has to have happened before
447data can be written. Formatting may happen separately from writing or
448simultaneously. See the particular recipes below.
449
450No Write Parameters mode page 05h is to be sent. Speed can be influenced by
451B6h SET STREAMING , speed capabilities can be inquired by ACh GET PERFORMANCE.
452It is advised to set only speeds and sizes which are returned by ACh.
453(mmc5r03c.pdf 6.39 SET STREAMING, 6.8 GET PERFORMANCE)
454Optimal performance is promised without any speed setting. But my experiments
455showed that SET STREAMING values persist after media change.
456
457In the formatted area of the media, coarse random access is possible.
458For DVD-RAM, DVD+RW, BD-RE write addresses and data size need to be aligned
459to 2 KiB. For DVD-RW alignment has to be 32 KiB. Within these limitations
460the write address is at the discretion of the sending program.
461Just use 2Ah WRITE to send data.
462(mmc5r03c.pdf, 6.44)
463When writing is done, it is mandatory to force the drive's buffer to media by
46435h SYNCHRONIZE CACHE.
465(mmc5r03c.pdf, 6.41)
466
467The size of the formatted area can be inquired by 23h READ FORMAT CAPACITIES.
468The Number Of Blocks value in the Current/Maximum Capacity Descriptor gives
469this size in 2 KiB blocks. But this is true only if Descriptor Type is 10b
470("Formatted Media").
471(mmc5r03c.pdf, 6.24.3.2.1, 6.24.3.2.3)
472
473Not yet formatted areas may be completely forbidden or they may be allowed for
474sequential writing (DVD-RW Intermediate state) or they may be allowed for
475random access only after the necessary waiting time for formatting to reach
476the desired address (DVD+RW with background formatting active).
477
478Already written areas can be overwritten without special precaution.
479Blanking a DVD-RW actually destroys its formatting.
480
481
482Most of the concepts usually expressed in Write Parameters mode page 05h do not
483apply to the recipes here: Test-Write, Buffer Underrun protection,
484Multi-session, Write Type, Block Type, Track Mode, ...
485There are hints for multi-session formats with DVD-RW but both of my drives
486do not offer "Add Session" Format Types 12h or 14h.
487(mmc5r03c.pdf 6.5.4.2.7 , 6.5.4.2.9)
488
489
490Caution: Drive and media compatibility seems still to be quite an adventure.
491If you experience problems, especially problems with readability, then try
492different drives and media brands. Failure does not necessarily mean that the
493software did anything wrong.
494
495
496-------------------------------------------------------------------------------
497DVD-RAM, fully formatted DVD+RW, DVD-RW, BD-RE :
498
499Full format is the natural state of DVD-RAM.
500
501BD-RE are sold unformatted and need to be fully formatted first.
502See paragraph about DVD-RAM and BD-RE formatting below.
503
504DVD+RW reaches this state if Background Formatting is allowed to finish without
505being stopped by 5Bh CLOSE TRACK SESSION.
506(mmc5r03c.pdf, 6.5 FORMAT UNIT, 6.5.4.2.14 Format Type = 26h)
507The formatting state of a DVD+RW may be inquired by 51h READ DISC INFORMATION
508requesting Data Type 000b "Standard Disc Information". In the reply,
509BG Format 3 indicates fully formatted media.
510(mmc5r03c.pdf 6.22.3.1.13)
511
512DVD-RW reaches this state either by Format Type 00h (or 10h) with maximum
513size given as Number Of Blocks, or by writing sequentially until the disc is
514completely full into an intermediate session opened by format 15h resp. 13h.
515(mmc5r03c.pdf, 6.5 FORMAT UNIT, 6.5.4.2.1, 6.5.4.2.10, 6.5.4.2.8)
516A fully formatted DVD-RW can be recognized by 23h READ FORMAT CAPACITIES. The
517Descriptor Type of the Current/Maximum Capacity Descriptor is 10b ("Formatted
518Media") and 0 blocks are offered with Format Types 13h or 11h.
519(mmc5r03c.pdf, 6.24.3.2.1, 6.24.3.3)
520See also discussion of unformatted or partially formatted DVD-RW below.
521
522
523In fully formatted state there is no need for any formatting before writing nor
524for any finalizing other than forcing the drive's buffer to media by
52535h SYNCHRONIZE CACHE (which is mandatory for writing, anyway).
526(mmc5r03c.pdf, 6.41)
527
528(It seems to do no harm to send to DVD+RW or DVD-RW a 5Bh CLOSE TRACK SESSION
529with Close Function 010b despite there is no session open in this scenario.)
530
531
532-------------------------------------------------------------------------------
533Unformatted DVD+RW :
534
535This is the state of previously unused DVD+RW media.
536
537The formatting state of a DVD+RW may be inquired by 51h READ DISC INFORMATION
538requiring Data Type 000b "Standard Disc Information".
539In the reply, BG Format 0 indicates unformatted media (or unsuitable media).
540(mmc5r03c.pdf 6.22.3.1.13)
541
542Formatting has to be started by command 04h FORMAT UNIT, Format Type 26h.
543Different from other format types, 26h allows to send a fantasy size of
5440xffffffff blocks and does not require the caller to know the exact maximum
545size offered with that format.
546(mmc5r03c.pdf, 6.5 FORMAT UNIT, 6.5.4.2.14 Format Type = 26h)
547
548As its name suggests, one has not to wait for background formatting to end
549but may very soon start writing as on formatted media. Random access to
550yet unformatted areas can last long, though.
551
552If backup formatting has been started at the beginning of the session, then
553it may get stopped after the final cache sync by 5Bh CLOSE TRACK SESSION
554with Close Function 010b.
555(mmc5r03c.pdf 6.3.3.6)
556
557Formatting of DVD+RW is called "de-icing" because unformatted areas offer
558no hold for random access addressing and are thus slippery like ice. One can
559also see a color change from shiny unformatted to more dull formatted media.
560
561
562-------------------------------------------------------------------------------
563Partly formatted DVD+RW :
564
565This state is achieved by stopping background formatting before the media
566was completely formmatted.
567
568The formatting state of a DVD+RW is obtained by 51h READ DISC INFORMATION
569requiring Data Type 000b "Standard Disc Information".
570In the reply, BG Format 1 indicates partly formatted media.
571(mmc5r03c.pdf 6.22.3.1.13)
572
573If the data of the session surely fit into the formatted area, then it would
574be unnecessary to restart background formatting.
575But in order to make the DVD+RW surely accept its maximum number of bytes,
576formatting may be restarted by command 04h FORMAT UNIT, Format Type 26h,
577with the Restart bit set and Number of Blocks set to 0xffffffff.
578(mmc5r03c.pdf, 6.5 FORMAT UNIT, 6.5.4.2.14 Format Type = 26h)
579
580From then on, the same rules apply as for previously unformatted DVD+RW.
581
582
583-------------------------------------------------------------------------------
584Unformatted DVD-RW (media profile is 0014h) :
585
586This state is present with previously unused media. It is also present with
587media blanked by programs cdrecord, wodim or dvd+rw-format and with media which
588were sequentially written from blank state.
589Profile transition from formatted 0013h to unformatted 0014h is done by
590A1h BLANK.
591(mmc5r03c.pdf, 6.2)
592Experiments on my drives indicate that only Blanking Type 000b "Blank the disc"
593achieves neat media. Media blanked via type 001b offer no feature 0021h and
594stall cdrecord or libburn already when those media get examined. growisofs can
595burn them - but only via DAO (feature 002Fh which prescribes Write Type 2).
596(mmc5r03c.pdf 5.3.11, 5.3.25)
597
598For becoming overwriteable such media need to be treated by command 04h FORMAT
599UNIT.
600(mmc5r03c.pdf, 6.5)
601The Format Type has to be chosen from the list replied by 23h READ FORMAT
602CAPACITIES. Suitable are Format Types 00h, 10h, 15h.
603(mmc5r03c.pdf 6.24)
604
605Format Types 00h and 10h provide a writeable area of a size given by Number of
606Blocks. Type 00h seems to be the most traditional and complete one. It needs
607no closing of a session at the end of writing.
608The Number Of Blocks may be at most the value reported by 23h READ FORMAT
609CAPACITIES in the entry for the desired format type. Full format is achieved
610by sending exactly the reported value.
611(mmc5r03c.pdf, 6.5.4.2.1 Format Type = 00h, 6.5.4.2.5 Format Type = 10h)
612
613Format Type 15h provides a writeable area of given size too, but this area can
614be expanded by sequential writing and afterwards marked as overwriteable by
615closing the session. It is even allowed to format with size 0 and to leave
616the size claim entirely to a sequential write process beginning at LBA 0.
617(mmc5r03c.pdf, 6.5.4.2.10 Format Type = 15h)
618When writing is done and cache is synced, one should send 5Bh CLOSE TRACK
619SESSION with Close Function 010b in order to bring the session out of
620Intermediate state.
621(mmc5r03c.pdf 6.3.3.2.3)
622If not written up to the last 32 KiB block, the DVD-RW is only partly formatted
623after that.
624
625
626-------------------------------------------------------------------------------
627Partly formatted DVD-RW (media profile is 0013h) :
628
629This state is achieved by formatting a DVD-RW with a number of blocks which
630is less than offered for the Format Type by the drive's reply to 23h READ
631FORMAT CAPACITIES. If the media was most recently formatted by Format Types
632015h or 013h then it must have got written some bytes and afterwards treated
633by 5Bh CLOSE TRACK SESSION, 010b in order to be partly formatted.
634(mmc5r03c.pdf 6.3.3.2.3 CLOSE TRACK SESSION 010b, 6.24 READ FORMAT CAPACITIES)
635Elsewise the media is in Intermediate state. See below.
636
637A partly formatted DVD-RW can be recognized by 23h READ FORMAT CAPACITIES. The
638Descriptor Type of the Current/Maximum Capacity Descriptor is 10b ("Formatted
639Media") and the Number Of Blocks with formats 00h, 10h or 15h is larger than the
640currently formatted size, resp. more than 0 blocks are offered with Format
641Types 13h or 11h.
642(mmc5r03c.pdf, 6.24.3.2.1, 6.24.3.3)
643
644If the data of the session surely fit into the formatted area, then it would
645be unnecessary to do any further formatting.
646But in order to make the DVD-RW surely accept its maximum number of bytes,
647partial formatting may be expanded by command 04h FORMAT UNIT, Format Type 13h,
648which is supposed to be offered by the drive in this state. This brings the
649session again into Intermediate state and thus allows expansion by sequential
650writing. As with Format Type 15h it is ok to set Number Of Blocks to 0, so that
651no fixed size formatting work is done and writing can begin soon after.
652(mmc5r03c.pdf, 6.5.4.2.8 Format Type = 13h)
653
654When writing is done and cache is synced, one should send 5Bh CLOSE TRACK
655SESSION with Close Function 010b in order to bring the session out of
656Intermediate state.
657(mmc5r03c.pdf 6.3.3.2.3)
658If not written up to the last 32 KiB block, the DVD-RW is only partly formatted
659after that.
660
661Format Type 13h has been tested only with expanding sessions formatted by 15h.
662Nevertheless it is offered with sessions from 00h and 10h, too.
663According to the specs, Format Type 11h would expand a session by a fixed
664size. This has not been tested yet because it is less appealing than 13h.
665(mmc5r03c.pdf, 6.5.4.2.6 Format Type = 11h)
666
667
668-------------------------------------------------------------------------------
669Intermediate state DVD-RW (media profile is 0013h) :
670
671This state is achieved by formatting a DVD-RW with Format Type 15h or 13h
672without subsequentially writing data and sending 5Bh CLOSE TRACK SESSION
673with Close Function 010b.
674Such media behave very unpleasing with my DVD-ROM drive under Linux 2.4 ide-cd.
675One should therefore better avoid to release media in this state.
676
677This state can be recognized by 23h READ FORMAT CAPACITIES. The Descriptor Type
678of the Current/Maximum Capacity Descriptor is 11b ("Unknown Capacity") and
679no formats 13h or 11h are offered.
680(mmc5r03c.pdf, 6.24.3.2.1, 6.24.3.3)
681
682One may treat such media as if Format Type 15h or 13h had been freshly applied.
683I.e. sequential writing from LBA 0. After cache sync bring the session out
684of Intermediate state by 5Bh CLOSE TRACK SESSION with Close Function 010b.
685(mmc5r03c.pdf 6.3.3.2.3)
686
687
688-------------------------------------------------------------------------------
689DVD-RAM and BD-RE formatting :
690
691Although DVD-RAM usually are sold formatted, there may still arise the wish
692to adjust formatting.
693BD-RE are sold unformatted and need to be formatted prior to usage.
694
695Two format types are relevant for DVD-RAM : 00h and 01h.
69600h offers the default size format and usually a maximum payload size format.
697Even with that maximum size payload there is hardware defect management.
698(mmc5r03c.pdf 6.5.4.2.1.2)
69901h allows to convert payload capacity into spare blocks for defect
700managment. There is no way to increase payload capacity by format 01h.
701(mmc5r03c.pdf 6.5.4.2.2.1)
702
703With BD-RE there are three format types : 00h, 30h and 31h.
70400h offers the default size format. This may be the only fast formatting
705mode that is offered by the drive.
706Feature 0023h tells whether format 31h and certain 30h subtypes are available.
707(mmc5r03c.pdf 5.3.13)
70830h offers several sizes with defect management. Usually there are three
709sizes given: #1: default size, #2: maximum spare area, #3: minimal spare.
710One may demand any spare size between maximum and minimum. There may be quick
711certification and full certification. See feature 0023h.
71231h offers a single size and disables defect management. This has the side
713effect to speed up writing to nominal speed.
714(mmc5r03c.pdf 6.5.4.2.15, 6.24.3.3, Table 472)
715
716Only format sizes from the list of format descriptors are permissible
717for DVD-RAM. The format list can be obtained by 23h READ FORMAT CAPACITIES.
718It also includes a description of the current formatting state.
719(mmc5r03c.pdf 6.24, 6.24.3.2, 6.24.3.3)
720
721Formatting is done by command 04h FORMAT UNIT. Its data payload consists
722of a Format List Header and a Format Descriptor. It is advisable to set
723the Immed bit and the FOV bit in header byte number 1. The descriptor should
724be a copy of a descriptor from 23h READ FORMAT CAPACITIES.
725(mmc5r03c.pdf 6.5, 6.5.3.2, 6.5.3.3)
726With nearly all formats Sub-type should be set to 0. But with BD-RE formats
72730h and 31h the Sub-type selects the certification mode.
728Usable with 30h seem 10b Full Certification and 11b Quick Certification.
729Usable with 31h seem also 00b Quick Reformat and 01b No Certification.
730(mmc5r03c.pdf 6.5.4.2.15.1)
731
732Other format types have their certification intensity controlled by
733a pair of bits: CmpList and DCRT.
734CmpList resides in CDB byte 1 as bit 3. DCRT resides in the payload byte 1
735as bit 5. Both together should request a quick size change without lengthy
736certification but maintaining the list of known defects.
737(mmc5r03c.pdf 6.5, table 249, 6.5.3.2)
738With DVD-RAM on my PHILIPS SPD3300L drive they prevent any format size
739change though. The TSSTcorp SH-S203B works properly.
740With BD-RE format 00h, the default is specified to be Quick Reformat,
741and with 00h in general certification can only be disabled not enabled.
742(mmc5r03c.pdf 6.5.4.2.1.7)
743
744
745-------------------------------------------------------------------------------
746DVD-RAM and BD-RE tuning :
747
748A special aspect of DVD-RAM and BD-RE is their low speed with write operations,
749which usually is only half than the nominal speed of media and drive.
750This is blamed to the automatic checkreading which happens for managing
751eventual defects.
752
753Defect management of BD-RE can be disabled by format type 31h. See above.
754There is no drive known yet which would apply command 2Ah WRITE10 to DVD-RAM
755with full speed.
756
757The only known way to get full speed from DVD-RAM or BD-RE with enabled defect
758management is the use of AAh WRITE12 with Streaming Bit set to 1.
759(mmc5r03c.pdf 6.45)
760With some DVD-RAM drives this fails if a write buffer is not full 32 kB.
761With the tested BD-RE one must write full 64 kB buffers, or else writing
762might not get into effect at all.
763
764Although it seems not optimal, this is specified not only to disable the
765cumbersome checkread but also to ignore known defects and to write data
766to these defective addresses.
767(mmc5r03c.pdf 4.8.5)
768So the speed-up is only advisable as long as the media are free of
769incorrectable errors.
770
771Caveat:
772MMC-5 does not guarantee AAh WRITE12 to work on DVD-RAM or BD-RE at all.
773None of the features of profiles 0012h and 0043h promises the existence of
774AAh WRITE12.
775(mmc5r03c.pdf 5.4.13, 6.45)
776Nevertheless it worked on all tested drives if proper alignment and block
777size was observed.
778
779
780-------------------------------------------------------------------------------
781ISO 9660 multi-session emulation on overwriteable media :
782
783Overwriteable media provide a single overwriteable track which may grow up to
784the full media capacity. There is no builtin table-of-content which records
785the history of write sessions.
786mount -t iso9660 will use sbsector=0 as default.
787The term "superblock" shall depict the first 64 KiB after the sbsector address.
788
789ISO 9660 multi-session depends on typical TOC information in two ways:
790It needs the superblock address MSC1 of the most recently recorded session and
791it needs the Next Writeable Address NWA for which to prepare the adress offset.
792
793The following is learned from growisofs and from ECMA-119:
794http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-119.pdf
795
796ISO 9660 filesystems provide information about the number of sectors which
797is also the lowest unused block address and thus a suitable NWA.
798This block address is stored in the Primary Volume Descriptor which is supposed
799to be stored in block 16 (eventually relative to MSC1).
800The bytes 0 to 5 of a PVD block are
801   0x01 'C' 'D' '0' '0' '1'
802The sector count can then be read from byte 80 to 83
803   sectors= pvd[80] | (pvd[81] << 8) | (pvd[82] << 16) | (pvd[83] << 24);
804(Ecma-119.pdf 8.4)
805To support CD, DVD and BD media alike, it is advisable to round the NWA
806to the next multiple of 32 (= 64 KiB).
807
808So one can use 0 as MSC1 and prepare a new ISO session for the computed NWA.
809After writing the session it is necessary to patch the PVD at LBA 16.
810The minimal change would be to update the number of image sectors.
811It is stored in both notations LSB and MSB:
812   for(i= 0; i < 4; i++)
813     pvd[87 - i]= pvd[80 + i]= (sectors >> (8 * i)) & 0xff;
814
815cdrskin --grow_overwriteable_iso not only patches the sector fields of the
816PVD block but also the blocks up to LBA 31 which begin with
817   0xff 'C' 'D' '0' '0' '1'
818libisoburn submits 64 KiB data buffer to libisofs before image generation and
819afterwards writes these 64 KiB as new superblock to LBA 0.
820
821
822-------------------------------------------------------------------------------
823ISO 9660 based TOC emulation on overwriteable media :
824
825Above method of multi-session emulation yields a single session image after
826each add-on session. No reliable session history can be read because the
827sector size of the existing session gets overwritten by the new one.
828A TOC with session history is nevertheless desirable with incremental backups
829in order to access older backup states by mounting older superblocks at the
830start addresses of older sessions.
831
832All usual ISO 9660 formatter programs write a complete superblock to the
833start of each session.
834With a uniform NWA rounding rule it is possible to compute the address of
835superblock N+1 as the NWA after session N. The only problem is N=1
836because it gets overwritten by later sessions.
837
838libisoburn preserves the information of session 1 by writing the first session
839to LBA 32 rather than LBA 0. Afterwards it writes the overall superblock to
840LBA 0 (up to 31).
841So with all further add-on sessions the superblock at LBA 0 will enclose the
842overall image, while the superblocks of the sessions form a chain beginning
843at LBA 32. Each session superblock points to the next one by its sector count
844rounded up to 32. The chain end is marked by the overall image size.
845This chain gives the start addresses of sessions. The sector count minus start
846address gives the size of a particular session. ECMA-119 explains how to
847retrieve more info from the PVD (e.g. the volume id).
848
849See also the multi-session example in libisofs/doc/checksums.txt.
850
851
852-------------------------------------------------------------------------------
853
854-------------------------------------------------------------------------------
855                        Sequential DVD-R[W] Cookbook
856-------------------------------------------------------------------------------
857Inspired by Andy Polyakov's http://fy.chalmers.se/~appro/linux/DVD+RW/tools ,
858backed by reading mmc5r03c.pdf from http://www.t10.org/ftp/t10/drafts/mmc5/
859and by experiments with drives NEC ND-4570A and LG GSA-4082B.
860
861For libburnia-project.org by Thomas Schmitt <scdbackup@gmx.net>
862
863-------------------------------------------------------------------------------
864
865Media type can be recognized by Current Profile from 46h GET CONFIGURATION.
866(mmc5r03c.pdf 6.6.2.1)
867DVD-R                          0011h
868DVD-RW Restricted Overwrite    0013h
869DVD-RW Sequential Recording    0014h
870(DVD-R/DL Sequential Recording 0015h untested, might be single-session only)
871
872There are two approaches for writing to sequential DVD-R[W]: DAO and
873Incremental. Not all media and drives offer Incremental which allows
874multi-session as with CD media and does not demand a predicted track size.
875DAO seems to be the older method. It allows only one single session and
876track and it demands an exactly predicted track size.
877
878- About overwriteable, blank, appendable and finalized DVD-R[W] media
879- Incremental writing
880- DAO writing
881- Obtaining DVD-R[W] multi-session info for extending ISO-9660 filesystems
882- Obtaining a Table Of Content from DVD-R[W]
883- Hearsay about DVD-R/DL (Dual Layer)
884
885
886-------------------------------------------------------------------------------
887About overwriteable, blank, appendable and finalized DVD-R[W] media :
888
889DVD-RW can be either in formatted state Restricted Overwrite or in unformatted
890state Sequential Recording. Sequential media can be either blank, appendable
891or finalized.
892
893Only blank and appendable media are sequentially writeable. For overwriteable
894DVD-RW see the Overwriteable DVD Cookbook.
895
896Overwriteable DVD-RW can be detected by their profile number 0013h in contrast
897to profile number 0014h for sequential DVD-RW.
898The status of sequential media can be inquired like with CD by 51h READ DISC
899INFORMATION requesting Data Type 000b Standard Disc Information, where reply
900value Disc Status indicates:
901 00b   blank
902 01b   appendable 
903 10b   finalized
904 11b   others (unsuitable for this recipe)
905(mmc5r03c.pdf 6.22.3.1.4)
906
907Finalized, appendable or overwriteable DVD-RW can be brought into blank
908sequential state by command A1h BLANK with blanking type 000b "Blank the disc".
909See TAO Multi-Session CD Cookbook for details about blanking.
910
911After minimal blanking (type 001b) DVD-RW my two drives do not offer the
912Incremental Streaming feature 0021h the media any more. Full blanking (000b)
913brings back this feature.
914(mmc5r03c.pdf 6.2)
915
916
917-------------------------------------------------------------------------------
918Incremental writing :
919
920Incremental writing allows to produce multi-session DVDs. It is indicated
921by feature 0021h being marked current in the reply of 46h GET CONFIGURATION.
922growisofs inquires 0021h by setting Starting Feature Number to 0x21 and
923Allocation Length to 16 in order to get only this one. The feature descriptor
924begins at byte 8 of the reply. Its availability is indicated by the Current
925Bit. libburn obtains the full feature list for this and other info.
926(mmc5r03c.pdf 5.2.2. Feature Descriptor format, 5.3.11 Feature 0021h,
927 6.2 46h GET CONFIGURATION, )
928In mode page 05h this method is selected by Write Type 00h.
929
930Speed can be influenced by B6h SET STREAMING , speed capabilities can be
931inquired by ACh GET PERFORMANCE. It is advised to set only speeds and sizes
932which are returned by ACh.
933(mmc5r03c.pdf 6.39 SET STREAMING, 6.8 GET PERFORMANCE) 
934
935growisofs fetches a mode page 05h template by MODE SENSE and inserts its own
936parameters.  It sets Multi-session to 11b, unless dvd_compat is nonzero.
937libburn composes its mode page 05h from zero and allows control of
938Multi-Session by the application.
939 BUFE             Buffer Underrun protection      0=off, 1=on
940 LS_V             Link size valid                 1=true
941 Test Write       -dummy mode for writing         0=off, 1=on
942 Write Type       Packet/TAO/SAO/RAW              00h = Incremental (Packet)
943 Multi-session    Whether to keep appendable      00b = finalize
944                                                  11b = keep appendable
945 Track Mode       Describes frame type            5  [*1]
946 Data Block Type  Layout of payload blocks        8  [*2]
947 Link Size        ???                             16 [*3]
948 FP               Fixed Packet Size Bit           1
949 Packet Size                                      16 [*4] 
950(mmc5r03c.pdf 7.5.4 The Mode Page, 4.2.3.4 Table 17 CONTROL = Track Mode)
951(spc3r23.pdf 6.8 MODE SELECT, 7.4.3 Mode parameter header formats)
952[*1:]
953growisofs takes the Track Mode from 52h READ TRACK INFORMATION, Address/Number
954Type 1, Track 1, Track Information Block byte 5 & 0xf.
955(mmc5r03.pdf 6.27)
956The specs predict that this will be Track Mode 4 (6.27.3.8) and also state that
957default is 5 (7.5.4.12). 4 means: uninterrupted, do not copy. 5 means
958increment, do not copy.
959[*2:]
9608 means: 2048 byte data blocks. growisofs sets this value if Data Mode from
961above 52h READ TRACK INFORMATION is 1 or Fh, which is predicted by the specs
962to be always true.
963(mmc5r03.pdf 6.27.3.10)
964[*3:]
965growisofs (transport.hxx) sets Link Size to 16 for profiles 0011h and 0014h.
966libburn now records the first link size from feature 0021h in its burn_drive
967structure. If another link size item is 16, then 16 is used.
968[*4:]
969growisofs takes Packet Size from 52h. Specs predict it will be 16 (= 32 kiB).
970(mmc5r03.pdf 7.5.4.16)
971
972The writing process is much like in "Writing a session to CD in TAO mode" :
973Next Writeable Address is fetched from the reply of 52h READ TRACK INFORMATION.
974libburn writes full 32 kiB buffers via 2Ah WRITE.
975(mmc5r03c.pdf, 6.27 READ TRACK INFORMATION, 6.44 WRITE)
976When writing is done, it is mandatory to force the drive's buffer to media by
97735h SYNCHRONIZE CACHE.
978(mmc5r03c.pdf, 6.41)
979
980The track has to be closed by 5Bh CLOSE TRACK SESSION Close Function 001b.
981growisofs uses the logical track number for that and not FFh like libburn
982does with TAO CD. So libburn obtains the Last Track Number in Last Session
983from the reply of  51h READ DISC INFORMATION requesting Data Type 000b
984"Standard Disc Information".
985(mmc5r03c.pdf 6.3.3.2.2 CLOSE TRACK, 6.22.3.1.)
986
987Multiple tracks are permissible in a single session. After all of them have
988been written, 5Bh CLOSE TRACK SESSION Close Function 010b with Logical Track
989Number 0 closes the session. It depends on the Multi-Session value in mode
990page 05h whether the disc is finalized or stays appendable.
991(mmc5r03c.pdf 6.3.3.2.3)
992
993
994-------------------------------------------------------------------------------
995DAO writing :
996
997DAO is the mode described by feature 002Fh. This feature also gives information
998about capabilities for Burnfree (BUF), Test Write and DVD-RW.
999(mmc5r03c.pdf 5.3.25)
1000Experiments with growisofs showed that the track size needs to be predicted
1001and may not be exceeded during the write process. (growisofs ran into SCSI
1002errors with piped non-ISO-9660 images and with piped ISO-9660 which have
1003trailing data.)
1004
1005Speed can be influenced by B6h SET STREAMING , speed capabilities can be
1006inquired by ACh GET PERFORMANCE. It is advised to set only speeds and sizes
1007which are returned by ACh.
1008(mmc5r03c.pdf 6.39 SET STREAMING, 6.8 GET PERFORMANCE) 
1009
1010The mode page 05h to be sent :
1011 BUFE             Buffer Underrun protection      0=off, 1=on
1012 LS_V             Link size valid                 0=false [*3]
1013 Test Write       -dummy mode for writing         0=off, 1=on
1014 Write Type       Packet/TAO/SAO/RAW              02h = DAO (same code as SAO)
1015 Multi-session    Whether to keep appendable      00b = finalize
1016 Track Mode       Describes frame type            5  [*1]
1017 Data Block Type  Layout of payload blocks        8  [*2]
1018 Link Size        ???                             0 [*3]
1019 FP               Fixed Packet Size Bit           0 [*3]
1020 Packet Size                                      0 [*3] 
1021(mmc5r03c.pdf 7.5.4 The Mode Page, 4.2.3.4 Table 17 CONTROL = Track Mode)
1022(spc3r23.pdf 6.8 MODE SELECT, 7.4.3 Mode parameter header formats)
1023[*1:]
1024growisofs takes the Track Mode from 52h READ TRACK INFORMATION, Address/Number
1025Type 1, Track 1, Track Information Block byte 5 & 0xf.
1026(mmc5r03.pdf 6.27)
1027[*2:]
10288 means: 2048 byte data blocks. growisofs sets this value if Data Mode from
1029above 52h READ TRACK INFORMATION is 1 or Fh, which is predicted by the specs
1030to be always true. (If not: growisofs aborts.)
1031(mmc5r03.pdf 6.27.3.10)
1032[*3:]
1033Link Size, Packet Size and their companions only apply to Write Type 00h.
1034
1035The session layout must be described by 53h RESERVE TRACK, RMZ=ARSV=0.
1036Reservation size should better already be aligned to 32 KiB. It has not been
1037tested yet, what happens if not enough data get written.
1038(mmc5r03c.pdf 6.31)
1039
1040Next Writeable Address is fetched from the reply of 52h READ TRACK INFORMATION.
1041The reply is supposed to be 0. libburn writes full 32 kiB buffers via
10422Ah WRITE.
1043(mmc5r03c.pdf, 6.27 READ TRACK INFORMATION, 6.44 WRITE)
1044If the track source delivers less than the announced size then libburn pads up
1045by zeros.
1046When writing is done, it is mandatory to force the drive's buffer to media by
104735h SYNCHRONIZE CACHE.
1048(mmc5r03c.pdf, 6.41)
1049
1050No further finalization is necessary. (I.e. no 5Bh CLOSE TRACK SESSION.)
1051
1052
1053-------------------------------------------------------------------------------
1054Obtaining DVD-R[W] multi-session info for extending ISO-9660 filesystems :
1055(valid for DVD+R too)
1056
1057Like with CD it is necessary to obtain the two numbers for mkisofs option -C
1058in order to prepare a ISO-9660 filesystem image which by its inner pointers
1059matches the block addresses of the future location on media.
1060These are the start address of the first track in the last complete session
1061and the predicted start address of the track which will host the new image.
1062See TAO Multi-Session CD Cookbook for some more info about mkisofs aspects.
1063
1064
1065The first number may be gained by 43h READ TOC/PMA/ATIP Format 0001b which in
1066table 478 promises quick access via Start Address Of First Track In Last
1067Session.
1068(mmc5r03c.pdf 6.26.2.5 table 478, 6.26.3.3.1)
1069Regrettably the MMC-5 specs still define a useless reply for non-CD media
1070which obviously stems from MMC-3 times when no multi-session was possible
1071with non-CD.
1072(mmc5r03c.pdf 6.26.3.3.3)
1073Both my drives do give a useful reply with the correct number for appendable
1074DVD-RW. But not being backed by the specs this method appears unappealing .
1075
1076Another approach would be a formatted Table of Content, obtained by 43h READ
1077TOC/PMA/ATIP Format 0000b. The specs do not totally outrule that this returns
1078useful data with non-CD but they define a crippled TOC for multi-session.
1079(mmc5r03c.pdf 6.26.3.2.4)
1080My LG drive returns a more detailed TOC, my NEC drive stays with the rather
1081suboptimal specs. So one would get different TOCs on different drives.
1082Nevertheless, the MMC-5 compliant TOC would return the desired number in
1083the Track Start address of the track with the highest number before AAh.
1084
1085Most stable seems the approach to obtain the desired number from the reply
1086of 52h READ TRACK INFORMATION, Address/Number Type 01b. The field Logical Block
1087Address/Track/Session has to bear the track number of the first track in the
1088last complete session. To determine this number one has to determine the
1089number of the last session and the number of the last track from 51h READ DISC
1090INFORMATION and to iterate over the tracknumber by 52h READ TRACK INFORMATION
1091until the first track with the desired session number appears and reveils
1092its start address.
1093(mmc5r03c.pdf 6.22 51h DISC, 6.27 52h TRACK)
1094This method is very near to fabricating an own TOC. So libburn does this
1095when inspecting the media. If the first number for -C is needed, libburn
1096inquires its TOC model for the address of the first track in the last
1097complete session. See below for a detailed description of TOC fabrication.
1098
1099
1100The second -C number is the exact prediction of future track start address. It
1101is gained like with CD by 52h READ TRACK INFORMATION Type 01b. Different from
1102CD one may not use track number FFh but has to use the Last Track in Last
1103Session from 51h READ DISC INFORMATION.
1104(mmc5r03c.pdf 6.22 51h DISC, 6.27 52h TRACK)
1105
1106
1107-------------------------------------------------------------------------------
1108Obtaining a Table Of Content from DVD-R[W]:
1109(valid for DVD+R too)
1110
1111The raw TOC entries from 43h READ TOC/PMA/ATIP Format 0010b as described with
1112CD media are not available with non-CD.
1113There is a Format 0000b "Formatted TOC" but this is with non-CD a fictional
1114information much at the discretion of the drive. Two drives with the same disc
1115may well return different Formatted TOC. They are supposed to be consistent
1116only about the last complete session and even there the MMC-5 specification
11176.26.3.2.5 seems to prescribe a structure which does not match the true
1118structure of incremental writing to sequential DVD-R[W].
1119(mmc5r03c.pdf 6.26.3.2)
1120So i prefer not to use this method of getting a TOC.
1121
1122
1123The alternative is to produce an own TOC from information gained by 51h READ
1124DISC INFORMATION and by 52h READ TRACK INFORMATION which reveil a CD-like
1125structure of sessions and 1:n related tracks.
1126
112751h READ DISC INFORMATION Data Type 000b, fields Number of Sessions (Least
1128Significant Byte) and Number of Sessions (Most Significant Byte) give the
1129number of sessions. The last complete session number of an appendable disc
1130is one less because there is an incomplete session at its end. libburn only
1131records complete sessions in its TOC model.
1132libburn uses Last Track in Last Session as a hint for the range of track
1133numbers.
1134(mmc5r03c.pdf 6.22)
1135
1136Next step is to iterate from 1 up to the last track number and to obtain
1137the according track info by 52h READ TRACK INFORMATION. Each track tells its
1138Session Number (LSB at byte 2, MSB at 33), its Logical Track Start Address,
1139its Logical Track Size, and much more which is not needed for a fake CD TOC.
1140One may analyze the track info more finely but for this special purpose
1141it is enough to discard the tracks which do not belong to complete sessions.
1142(mmc5r03c.pdf 6.27)
1143
1144At the end of each session libburn inserts fake leadout entries into its TOC
1145model. Their start address is computed from the start and size of the last
1146track of the session.
1147
1148
1149-------------------------------------------------------------------------------
1150Hearsay about DVD-R/DL (Dual Layer) :
1151
1152DVD-R/DL can assume profile 0015h DVD-R Dual Layer Sequential which is supposed
1153to behave like DVD-R or 0016h DVD-R Dual Layer Jump which has no counterpart
1154with DVD-R.
1155
1156A half-sentence in mmc5r03c.pdf 6.3.3.3.3 might indicate that closing a session
1157by 5Bh CLOSE TRACK SESSION Close Function 010b overrides the multi-session bits
1158in mode page 05h.
1159growisofs applies this function in case of not DAO, though. A comment in
1160growisofs_mmc.cpp states: "// DVD-R DL Seq has no notion of multi-session".
1161I am not reading this from the specs - but not explicitely the contrary either.
1162
1163For now libburn will close the session but there is a macro prepared in
1164libburn/write.c Libburn_dvd_r_dl_multi_no_close_sessioN which will suppress
1165close session if multi-session is demanded.
1166
1167
1168-------------------------------------------------------------------------------
1169
1170-------------------------------------------------------------------------------
1171                             DVD+R[/DL] Cookbook
1172-------------------------------------------------------------------------------
1173Inspired by reading mmc5r03c.pdf from http://www.t10.org/ftp/t10/drafts/mmc5/
1174backed by Andy Polyakov's http://fy.chalmers.se/~appro/linux/DVD+RW/tools ,
1175
1176For libburnia-project.org by Thomas Schmitt <scdbackup@gmx.net>
1177
1178-------------------------------------------------------------------------------
1179
1180Media type can be recognized by Current Profile from 46h GET CONFIGURATION.
1181(mmc5r03c.pdf 6.6.2.1)
1182DVD+R                          001bh
1183DVD+R/DL                       002bh
1184
1185- About empty, appendable and finalized DVD+R
1186- Writing a Pseudo Session to DVD+R
1187- DVD+R/DL (Dual Layer
1188
1189The following two chapters of the Sequential DVD-R[W] Cookbook are valid for
1190DVD+R media too:
1191- Obtaining DVD-R[W] multi-session info for extending ISO-9660 filesystems
1192- Obtaining a Table Of Content from DVD-R[W]
1193
1194-------------------------------------------------------------------------------
1195About blank, appendable and finalized DVD+R :
1196
1197In the beginning a DVD+R holds an empty session and the Incomplete Fragment.
1198From these one may spawn reserved fragments or one may write directly to
1199the incomplete fragment. As soon as this is done the empty session becomes the
1200open session which finally needs to get closed. By closing fragments and
1201session a new empty session with empty Incomplete Fragment gets spawned.
1202So the disc stays appendable.
1203
1204A DVD+R may hold 153 closed sessions with a single track each.
1205The open session may hold up to 15 open fragments. But on closure of the
1206session those fragments together form a single logical track.  So one will
1207usually only use a single fragment for sequential writing.
1208(mmc5r03c.pdf 4.3.6.2)
1209
1210The disc may get finalized by another close command so that no more data can
1211be written.
1212(mmc5r03c.pdf 6.3.3.4.4)
1213
1214
1215-------------------------------------------------------------------------------
1216Writing a Pseudo Session to DVD+R :
1217
1218Session writing has to be pseudo because only one logical track per session
1219can be distinguished. So actually there have to be written multiple sessions
1220to mark multiple tracks. The pseudo session cannot get marked on disc and thus
1221the tracks of a pseudo session cannot be grouped accordingly in a TOC.
1222
1223Speed can be influenced by B6h SET STREAMING , speed capabilities can be
1224inquired by ACh GET PERFORMANCE. It is advised to set only speeds and sizes
1225which are returned by ACh.
1226(mmc5r03c.pdf 6.39 SET STREAMING, 6.8 GET PERFORMANCE) 
1227
1228No mode page 05h is to be sent.
1229growisofs sends a page but the specs clearly state that one shall not do.
1230(mmc5r03c.pdf 7.5.3)
1231
1232It is optional whether a track size is reserved in advance or not. Eventually
1233this is done by 53h RESERVE TRACK, RMZ=ARSV=0. Reservation size should better
1234already be aligned to 32 KiB.
1235(mmc5r03c.pdf 6.31)
1236The specs promise to pad up the track if not enough data get written.
1237(mmc5r03c.pdf 6.3.3.4.2)
1238
1239Next Writeable Address is fetched from the reply of 52h READ TRACK INFORMATION
1240with track number FFh.
1241(mmc5r03c.pdf 6.27)
1242Since the fixely set write type is 16-block packet, full 32 kiB buffers have
1243to be transmitted via 2Ah WRITE.
1244(mmc5r03c.pdf 4.3.6.2.2)
1245
1246When writing is done, it is mandatory to force the drive's buffer to media by
124735h SYNCHRONIZE CACHE.
1248(mmc5r03c.pdf 6.41)
1249
1250The written fragment (i.e. track-to-be) has to be closed by 5Bh CLOSE TRACK
1251SESSION Close Function 001b.
1252(mmc5r03c.pdf 6.3.3.4.2)
1253libburn obtains the necessary logical track number from Last Track Number in
1254Last Session from the reply of 51h READ DISC INFORMATION requesting
1255Data Type 000b.
1256(mmc5r03c.pdf 6.22)
1257
1258After each track 5Bh CLOSE TRACK SESSION Close Function 010b with Logical Track
1259Number 0 closes the DVD+R session but keeps the media appendable.
1260(mmc5r03c.pdf 6.3.3.4.3)
1261If the media shall not stay appendable then the last DVD+R session is to be
1262closed by Close Function 101b rather than 010b. This finalizes the media
1263"with minimal radius".
1264(mmc5r03c.pdf 6.3.3.4.4)
1265
1266Note: growisofs has code for that gesture but explicitly avoids to use it, if
1267the media was appendable before writing began. Instead it recommends to fill
1268up the media with zeros. This gesture nevertheless caused error replies from
1269the drives in my own experiments.
1270The reason given by Andy Polyakov is that some DVD-ROM drives get mislead by
1271the lead-out information of (formerly) appendable media unless the media is
1272fully written.
1273(http://fy.chalmers.se/~appro/linux/DVD+RW/ , "Compatibility: caveat lector")
1274
1275Own experiments showed no such problems with PC attached PATA DVD-ROM drives.
1276For best DVD-ROM compatibility one should avoid appendable media at all
1277by closing them already after the first session.
1278
1279
1280-------------------------------------------------------------------------------
1281DVD+R/DL (Dual Layer) :
1282
1283libburn treats DL media just like their single layer equivalents.
1284This seems to work fine for DVD+R/DL, according to a report by nightmorph
1285in http://libburnia-project.org/ticket/13 .
1286
1287-------------------------------------------------------------------------------
1288
1289-------------------------------------------------------------------------------
1290                              BD-R Cookbook
1291-------------------------------------------------------------------------------
1292Inspired by reading mmc5r03c.pdf from http://www.t10.org/ftp/t10/drafts/mmc5/
1293backed by experiments iwith drive LG GGW H20L.
1294
1295For libburnia-project.org by Thomas Schmitt <scdbackup@gmx.net>
1296
1297-------------------------------------------------------------------------------
1298Media type can be recognized by Current Profile from 46h GET CONFIGURATION.
1299(mmc5r03c.pdf 6.6.2.1)
1300BD-R                           0042h
1301
1302There are two basic recording modes defined: Sequential Recording Mode SRM and
1303Random Recording Mode RRM. The latter is optional and for now not topic of this
1304text.
1305(mmc5r03c.pdf 4.5.3.5)
1306
1307
1308- SRM Formatting
1309- Writing a session in SRM-POW
1310(- Pseudo-OverWrite SRM+POW)
1311
1312
1313-------------------------------------------------------------------------------
1314SRM Formatting:
1315
1316Despite being write-once media BD-R can optionally carry some formatting.
1317
1318SRM has a disc structure model with tracks and sessions.
1319Several tracks may be open at the same time, each having its own NWA.
1320(mmc5r03c.pdf 4.5.3.5.2.2)
1321This structure is formatted onto blank media automatically as soon as the
1322first serious write attempt occurs.
1323(mmc5r03c.pdf 4.5.3.5)
1324Before such a write attempt, blank media may be explicitely formatted with
1325spares, which provide defect management.
1326(mmc5r03c.pdf 4.5.3.5.3)
1327Tracks get created from other tracks via RESERVE TRACK splitting.
1328(mmc5r03c.pdf 4.5.3.5.2.5)
1329
1330On top of defect management there may be Pseudo-OverWrite SRM+POW, a costly
1331way to write several times to the same LBA. See below.
1332Fully sequential states are called SRM-POW.
1333(mmc5r03c.pdf 4.5.3.5.4)
1334
1335Explicite formatting is done by 04h FORMAT UNIT. Its data payload consists
1336of a Format List Header and a Format Descriptor. It is advisable to set
1337the Immed bit and the FOV bit in header byte number 1. The descriptor should
1338be a copy of a descriptor from 23h READ FORMAT CAPACITIES but the size may be
1339adjusted within a certain range.
1340(mmc5r03c.pdf 6.5, 6.5.3.2, 6.5.3.3)
1341
1342Format type 00h creates SRM layouts with a default number of spares (or
1343eventually RRM) chosen by the format sub-type:
1344  00b = SRM with support for POW
1345  01b = SRM without POW (but with some spares for defect management)
1346  10b = (RRM)
1347(mmc5r03c.pdf 6.5.4.2.1.6)
1348
1349Format type 32h uses the same sub-types but allows to allocate non-default
1350amounts of spares. Similar to BD-RE format 31h, three format descriptors are
1351offered: #1: default size, #2: maximum spare area, #3: minimal spare.
1352The size may be chosen within that range.
1353
1354The sense behind the Type Dependent Parameters is obscure
1355to me. Best will be to set ISA_V and TDMA_V to 0.
1356(mmc5r03c.pdf 6.5.4.2.1.17)
1357
1358
1359-------------------------------------------------------------------------------
1360Writing a session in SRM:
1361
1362The procedure and constraints for writing BD-R SRM-POW are very similar to
1363DVD+R. libburn flatly re-uses its DVD+R code except the Close Function for
1364finalizing a disc.
1365
1366In short:
1367If all written sessions are closed, then there is exactly one NWA.
1368In the beginning there is an empty session and track. A new track can be
1369written either with pre-announced size (by RESERVE TRACK) or open-end by
1370simply starting to write to the NWA. When done the track gets closed by
1371close function 001b. Then either session or disc gets closed depending on
1372the Close Function used:
1373- Close Function 010b closes the session and keeps the media appendable
1374  (same as with DVD+R)
1375- Close Function 110b finalizes the media and makes it read-only.
1376  (differs from libburn DVD+R procedure which uses 101b)
1377
1378-------------------------------------------------------------------------------
1379Pseudo-OverWrite POW: (no used yet by libburn)
1380
1381This enhancement of SRM emulates overwriting of existing data blocks.
1382(mmc5r03c.pdf 4.5.3.5.4)
1383
1384POW establishes a virtual vLBA space on top of the real address space rLBA.
1385All read and write commands deal with vLBA. It seems that track NWAs are
1386assumed to be identical in vLBA space and in rLBA space.
1387It is not clear whether one may write to vLBA blocks which are neither written
1388yet nor at one of the track NWAs. Probably not, or else one could make NWAs run
1389into vLBAs which are associated with older rLBAs.
1390
1391Replacing invalidated blocks consumes addresses in rLBA space at the NWA of
1392some track. I.e. no spares are consumed by POW. Nevertheless it is costly by
1393a special map called Orphanage. It covers rLBA which have been consumed
1394by differing vLBAs. It never shrinks and can grow with each write to remapped
1395addresses.
1396To avoid heavy Orphanage growth it is advised to write mostly to vLBA which
1397still coincide with their rLBA. E.g. those addresses which have neither been
1398written as rLBA nor as vLBA yet. So one should begin the vLBA of new sessions
1399at the NWA of a sufficiently sized track.
1400(mmc5r03c.pdf 4.5.3.5.4.2 , 4.5.3.6.9)
1401
1402-------------------------------------------------------------------------------
1403
Note: See TracBrowser for help on using the browser.