\documentclass{article}
\def\version{$Id: cdrom-standard.tex,v 1.9 1997/12/28 15:42:49 david Exp $}
\newcommand{\newsection}[1]{\newpage\section{#1}}
\evensidemargin=0pt
\oddsidemargin=0pt
\topmargin=-\headheight \advance\topmargin by -\headsep
\textwidth=15.99cm \textheight=24.62cm % normal A4, 1'' margin
\def\linux{{\sc Linux}}
\def\cdrom{{\sc cd-rom}}
\def\UCD{{\sc Uniform cd-rom Driver}}
\def\cdromc{{\tt {cdrom.c}}}
\def\cdromh{{\tt {cdrom.h}}}
\def\fo{\sl} % foreign words
\def\ie{{\fo i.e.}}
\def\eg{{\fo e.g.}}
\everymath{\it} \everydisplay{\it}
\catcode `\_=\active \def_{\_\penalty100 }
\catcode`\<=\active \def<#1>{{\langle\hbox{\rm#1}\rangle}}
\begin{document}
\title{A \linux\ \cdrom\ standard}
\author{David van Leeuwen\\{\normalsize\tt david@ElseWare.cistron.nl}
\\{\footnotesize updated by Erik Andersen {\tt(andersee@debian.org)}}
\\{\footnotesize updated by Jens Axboe {\tt(axboe@image.dk)}}}
\date{12 March 1999}
\maketitle
\newsection{Introduction}
\linux\ is probably the Unix-like operating system that supports
the widest variety of hardware devices. The reasons for this are
presumably
\begin{itemize}
\item
The large list of hardware devices available for the many platforms
that \linux\ now supports (\ie, i386-PCs, Sparc Suns, etc.)
\item
The open design of the operating system, such that anybody can write a
driver for \linux.
\item
There is plenty of source code around as examples of how to write a driver.
\end{itemize}
The openness of \linux, and the many different types of available
hardware has allowed \linux\ to support many different hardware devices.
Unfortunately, the very openness that has allowed \linux\ to support
all these different devices has also allowed the behavior of each
device driver to differ significantly from one device to another.
This divergence of behavior has been very significant for \cdrom\
devices; the way a particular drive reacts to a `standard' $ioctl()$
call varies greatly from one device driver to another. To avoid making
their drivers totally inconsistent, the writers of \linux\ \cdrom\
drivers generally created new device drivers by understanding, copying,
and then changing an existing one. Unfortunately, this practice did not
maintain uniform behavior across all the \linux\ \cdrom\ drivers.
This document describes an effort to establish Uniform behavior across
all the different \cdrom\ device drivers for \linux. This document also
defines the various $ioctl$s, and how the low-level \cdrom\ device
drivers should implement them. Currently (as of the \linux\ 2.1.$x$
development kernels) several low-level \cdrom\ device drivers, including
both IDE/ATAPI and SCSI, now use this Uniform interface.
When the \cdrom\ was developed, the interface between the \cdrom\ drive
and the computer was not specified in the standards. As a result, many
different \cdrom\ interfaces were developed. Some of them had their
own proprietary design (Sony, Mitsumi, Panasonic, Philips), other
manufacturers adopted an existing electrical interface and changed
the functionality (CreativeLabs/SoundBlaster, Teac, Funai) or simply
adapted their drives to one or more of the already existing electrical
interfaces (Aztech, Sanyo, Funai, Vertos, Longshine, Optics Storage and
most of the `NoName' manufacturers). In cases where a new drive really
brought its own interface or used its own command set and flow control
scheme, either a separate driver had to be written, or an existing
driver had to be enhanced. History has delivered us \cdrom\ support for
many of these different interfaces. Nowadays, almost all new \cdrom\
drives are either IDE/ATAPI or SCSI, and it is very unlikely that any
manufacturer will create a new interface. Even finding drives for the
old proprietary interfaces is getting difficult.
When (in the 1.3.70's) I looked at the existing software interface,
which was expressed through \cdromh, it appeared to be a rather wild
set of commands and data formats.\footnote{I cannot recollect what
kernel version I looked at, then, presumably 1.2.13 and 1.3.34---the
latest kernel that I was indirectly involved in.} It seemed that many
features of the software interface had been added to accommodate the
capabilities of a particular drive, in an {\fo ad hoc\/} manner. More
importantly, it appeared that the behavior of the `standard' commands
was different for most of the different drivers: \eg, some drivers
close the tray if an $open()$ call occurs when the tray is open, while
others do not. Some drivers lock the door upon opening the device, to
prevent an incoherent file system, but others don't, to allow software
ejection. Undoubtedly, the capabilities of the different drives vary,
but even when two drives have the same capability their drivers'
behavior was usually different.
I decided to start a discussion on how to make all the \linux\ \cdrom\
drivers behave more uniformly. I began by contacting the developers of
the many \cdrom\ drivers found in the \linux\ kernel. Their reactions
encouraged me to write the \UCD\ which this document is intended to
describe. The implementation of the \UCD\ is in the file \cdromc. This
driver is intended to be an additional software layer that sits on top
of the low-level device drivers for each \cdrom\ drive. By adding this
additional layer, it is possible to have all the different \cdrom\
devices behave {\em exactly\/} the same (insofar as the underlying
hardware will allow).
The goal of the \UCD\ is {\em not\/} to alienate driver developers who
have not yet taken steps to support this effort. The goal of \UCD\ is
simply to give people writing application programs for \cdrom\ drives
{\em one\/} \linux\ \cdrom\ interface with consistent behavior for all