9.2. CDROM driver (sr or scd)

CDROM and DVD drives (and WORM devices) are accessible via the sr upper level device driver. While is "sr" is the device driver name, "sr_mod" is its module name. The device file name is either /dev/sr<n> or /dev/scd<n>.

Following is a diagram illustrating the CDROM subsystem of which sr is a part:

The architecture of the CD-ROM subsystem.

This diagram glosses over some of the differences between the protocol stacks. CDROM device names are not maintained by the uniform CDROM layer but rather by each individual protocol stack. In the case of the SCSI subsystem, device names are maintained by the sr driver while the IDE subsystem maintains device names with its central "ide" driver (i.e. not by the ide-cd driver). USB and IEEE1394 cd devices names are maintained by their respective stacks. This may partially explain why the /dev/cdrom is often a symbolic link to the appropriate subsystem's device name.

Two types of SCSI devices are accessible via the sr driver:

The sr driver is capable of recognizing 256 CDROM/DVD drives when it is loaded at kernel boot time or later as a module. However, once it is loaded, it will only recognize a fixed number of additional drives. The number of additional drives that can be accommodated is set by the kernel configuration parameter CONFIG_SR_EXTRA_DEVS whose default value is 2.

9.2.1. sr boot parameters

None.

9.2.2. sr module parameters

Doing a test to find out if a cdrom drive supports XA mode (mode 2) triggers firmware bugs on some drives. Consequently the check for XA mode support is turned off by default. The following module parameter is provided:
    xa_test=<0|1>
to override the default. [Currently there seems to be no way to turn on XA mode testing when the sr driver is built into the kernel.]

9.2.3. sr proc interface

All the following files are readable by all and produce ASCII output when read:
 /proc/sys/dev/cdrom/autoclose
 /proc/sys/dev/cdrom/autoeject
 /proc/sys/dev/cdrom/check_media
 /proc/sys/dev/cdrom/debug
 /proc/sys/dev/cdrom/info
 /proc/sys/dev/cdrom/lock
They reflect the current state of the CDROM subsystem. This location is part of the procfs's window through to the sysctl configuration mechanism (see man sysctl). All but info are writable by the superuser. There is a column for each CDROM and DVD player in the system in info (not just SCSI devices).

As an example, the auto eject feature can be turned on by the superuser with the command echo "1" > /proc/sys/dev/cdrom/autoeject. This will cause cdroms to be ejected from the drive when unmounted.

9.2.4. ATAPI cdroms

Many Linux users have no SCSI devices (or adapters) in their systems. They become a little perplexed as to why cd writer software (e.g. cdrecord and cdrdao) and cd music reading programs (e.g. cdparanoia) use the Linux SCSI subsystem. The answer is that these programs need lower level access to these devices. ATAPI (ATA Packet Interface) is essentially a SCSI command set sent over an ATA [1] transport.

Currently both cdrecord and cdparanoia interface to the SCSI generic driver (sg) and, in the case of ATAPI cd devices, use the ide-scsi pseudo device driver to access the hardware. This may change in the future as in the 2.4 series kernels a packet interface ioctl has been added to the uniform cdrom layer (see the diagram in the CDROM section above). [2]

The default action of the IDE subsystem in Linux is to claim all ATA devices for its drivers. In the case of an ATAPI cd writer, it will be claimed by the ide-cd driver. Once this has happened, the SCSI subsystem is unable to get control over an ATAPI device. The ide-scsi (pseudo lower level SCSI) driver can only register ATAPI devices in the SCSI subsystem that have not already been claimed by IDE subsystem.

To change this default action, parameters need to be passed to the IDE subsystem that instruct it not to register a given device. Let us assume that a cd writer is connected to the second IDE controller in the slave position (i.e. /dev/hdd). One of the following two techniques may [3] be used:

The first technique can only be done at boot time (and can be automated using lilo with an "append" in the /etc/lilo.conf file). It assumes that the main IDE subsystem driver is built in, which is almost always the case. The second technique assumes that the ide-cd driver is a module which is not normally the case (i.e. most distributions build it in). After one of these techniques has been applied, loading the ide-scsi driver should register the cd writer at /dev/hdd as /dev/sr<n> where the "n" is the next available number.

To find out if the above worked, the output of cat /proc/scsi/scsi can be checked. Perhaps a simpler method is to observe the "drive name:" line of cat /proc/sys/dev/cdrom/info for "sr" entries. The following output is from my system:
$ cat /proc/sys/dev/cdrom/info 
CD-ROM information, Id: cdrom.c 3.12 2000/10/18

drive name:             sr1     sr0
drive speed:            16      0
drive # of slots:       1       1
Can close tray:         1       1
Can open tray:          1       1
Can lock tray:          1       1
Can change speed:       1       1
Can select disk:        0       0
Can read multisession:  1       1
Can read MCN:           1       1
Reports media changed:  1       1
Can play audio:         1       1
Can write CD-R:         1       0
Can write CD-RW:        1       0
Can read DVD:           0       1
Can write DVD-R:        0       0
Can write DVD-RAM:      0       0

Once an ATAPI cd writer at /dev/hdd has been registered by the SCSI subsystem, then cdroms should be mounted via the "sr" device name and cd players should also use the "sr" device. Strangely the hdparm command should still use the /dev/hdd device file.

Notes

[1]

ATA is the modern name for what was previously known as IDE and/or EIDE. Note that the subsystem that controls ATA devices in Linux is called the "IDE" subsystem for historical reasons.

[2]

Other ATA devices such as tapes and floppies often use the ATAPI interface. However, the vast majority of ATA disks do not use the ATAPI interface.

[3]

Another less targeted approach is available when both the ide-cd and ide-scsi drivers are modules. That is to rmmod ide-scsi; rmmod ide-cd; modprobe ide-scsi.