Optical Drive

From OSDev Wiki
Jump to: navigation, search

This article is about the SCSI commands for optical drives. They are governed mainly by SCSI part MMC, but also by SPC, and by the 0x1B START/STOP UNIT command out of SBC.

Regrettably these specs are not officially available for free. One has to pay 30 USD per part as PDF. Many old links, which originally pointed to free-of-charge drafts of the specs, now lead to the new info PDFs of T10, which just tell where to buy the specs.



The communication between computer and optical drive can be done by various types of controllers and cabling. Like ATAPI, SATA, or USB. This task of transport is not in the scope of this article.

Many operating systems offer some kind of generic SCSI driver interface which abtracts the various transports to a single transaction API. These APIs are also available in userspace. Linux has ioctl(SG_IO), FreeBSD has CAM, Solaris has uscsi, ...

Your operating system should have such a thing too. If not for internal purposes, then for enabling the porting of burn programs, which usually run in userspace.

SCSI Transactions

A driver of optical drives will have to compose SCSI commands (Control Data Block, CDB) and provide payload data buffers. It will then hand them over to the transport drivers which bring them to the optical drive.

The drive will return a status indication and payload data, if appropriate. The transport driver will interpret the status and return it to the caller together with the payload data. It is nice of the transport driver if it also fetches diagnostic Sense Data if the status indicates their availability. This is to be done by command 0x03 REQUEST SENSE.

Readable Disc Content

Optical media and drives are structured in sessions and tracks. The readable entities are called Logical Track. They are contiguous strings of blocks. Some media types can bear several sessions with several tracks each, others bear only one session with one track.

The MMC specs mention with DVD and BD only block size 2048. These media can be read by the same SCSI commands as hard disks, e.g. by 0x28 READ(10).

The block sizes and formats on CD can be quite strange. Data CDs (CD-ROM) bear block size 2048 and can be read by the same SCSI commands as hard disks. Audio CDs (CD-DA) bear block size 2352 and can only be read by special SCSI commands like 0xBE READ CD. Further there are other CD block formats defined in MMC.

The track content of data CD, DVD, or BD is not restricted to particular filesystem formats. It may well be raw data blocks or tape archives.

Nevertheless, most data CD bear an ISO 9660 filesystem, often with Rock Ridge and Joliet extensions. DVD and BD for home entertainment video players bear UDF filesystems. For data exchange they often bear ISO 9660.

DVD, BD, and data CD may be prepared as boot medium by ISO 9660 with additional El-Torito data.

Getting an Overview of the Medium

The type of optical media can be deduced from the Current Profile as reported by command 0x46 GET CONFIGURATION. Actually this tells not the media type but the feature set of the medium. In a read-only drive everything might be reported as -ROM media profile. Writer drives are more accurate with their reports.

The medium can be either Blank, Appendable, Closed, or Overwritable. This can be inquired by command 0x51 READ DISC INFORMATION as "Empty Disc", "Incomplete Disc", "Finalized Disc", "Others".

Blank means that the medium contains no readable data and may be written. Some media types need to be formatted first.

Appendable means that the medium contains readable data, but may also be written in yet unreadable blocks.

Closed means that there are readable data and no more can be written.

Overwritable is the state of formatted re-usable media. Data can be read and written like with a hard disk. Formatted DVD-RW demand write transactions to be aligned to multiples of 16 blocks.

The first three states are assumed by sequential media: CD-R, CD-RW, DVD-R, unformatted DVD-RW, DVD+R, BD-R. Written CD-RW and DVD-RW can be brought back to state Blank.

CD-ROM, DVD-ROM, BD-ROM are always in state Closed.

The family of overwritable media may be in state Blank when sold: DVD+RW, DVD-RW, DVD-RAM, BD-RE. In this case it is necessary to format them to Overwritable, before write and read transactions be performed. DVD+RW must be entirely written for once to guarantee that formatting has reached all block addresses.

Sequential media in states Appendable and Closed can bear more than one session with more than one track each. The number of sessions and tracks can be inquired by 0x51 READ DISC INFORMATION, Data Type 000b. On appendable media, the free area is counted as last track of the last session. So in this case the number of readable sessions and tracks is one less. Track numbering usually starts at 1, but at least on CD the burn program can choose a higher start number.

Knowing the number range of readable tracks, their start address and size can be inquired by command 52h READ TRACK INFORMATION. This also tells the session number to which the track belongs.

There is another command 0x43 READ TOC/PMA/ATIP which gives complete information only about CD media. DVD and BD are at best represented by coarse fabricated information. So this command is mainly of interest if one wants to examine CD-specific features like block formats or CD-TEXT.

Command 0x25 READ CAPACITY tells the number of the last readable data block. Between block 0 and this block there may be unwritten blocks though, which are located outside any track.

Random Access Operation of DVD-RAM, DVD+RW, DVD-RW, BD-RE

Writing to sequential media types can demand quite tricky preparations. Therefore this is usually done by burn programs which live in userspace and use the SCSI transaction API to operate the drive.

But overwritable thoroughly formatted media are similar enough to hard disks so that they can easily be presented as block devices. Just use commands like 0xAA WRITE(12) or 0x28 READ(10).

Formatting is done by command 0x04 FORMAT UNIT. But it is not trivial with DVD+RW and DVD-RW. So it seems wise to format those media by help of a burn program like xorriso or a formatter program like dvd+rw-format out of dvd+rw-tools. After formatting it is wise to let the burn program write the medium up to the last block and to check whether they all are readable afterwards. In case of dvd+rw-format the burn program would be growisofs.

See Also


  • ATAPI - Transport protocol for SCSI over ATA
  • ISO 9660 - Technical properties of ISO 9660 filesystems
  • UDF - The filesystem used for video DVD and BD

External Links

  • T10 home page - Where the SCSI specs are made
  • INCITS Online Standards Store - Where to buy SCSI specs MMC-6, SPC-3, and SBC-2
  • libburn cookbook - Detailed description how libburn operates the various media types. You need SCSI specs for understanding this. The links to free drafts are semi-dead. If link is dead: see libburn-*/doc/cookbook.txt in any libburn tarball.
Personal tools