xref: /OK3568_Linux_fs/kernel/Documentation/cdrom/cdrom-standard.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun=======================
2*4882a593SmuzhiyunA Linux CD-ROM standard
3*4882a593Smuzhiyun=======================
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun:Author: David van Leeuwen <david@ElseWare.cistron.nl>
6*4882a593Smuzhiyun:Date: 12 March 1999
7*4882a593Smuzhiyun:Updated by: Erik Andersen (andersee@debian.org)
8*4882a593Smuzhiyun:Updated by: Jens Axboe (axboe@image.dk)
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunIntroduction
12*4882a593Smuzhiyun============
13*4882a593Smuzhiyun
14*4882a593SmuzhiyunLinux is probably the Unix-like operating system that supports
15*4882a593Smuzhiyunthe widest variety of hardware devices. The reasons for this are
16*4882a593Smuzhiyunpresumably
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun- The large list of hardware devices available for the many platforms
19*4882a593Smuzhiyun  that Linux now supports (i.e., i386-PCs, Sparc Suns, etc.)
20*4882a593Smuzhiyun- The open design of the operating system, such that anybody can write a
21*4882a593Smuzhiyun  driver for Linux.
22*4882a593Smuzhiyun- There is plenty of source code around as examples of how to write a driver.
23*4882a593Smuzhiyun
24*4882a593SmuzhiyunThe openness of Linux, and the many different types of available
25*4882a593Smuzhiyunhardware has allowed Linux to support many different hardware devices.
26*4882a593SmuzhiyunUnfortunately, the very openness that has allowed Linux to support
27*4882a593Smuzhiyunall these different devices has also allowed the behavior of each
28*4882a593Smuzhiyundevice driver to differ significantly from one device to another.
29*4882a593SmuzhiyunThis divergence of behavior has been very significant for CD-ROM
30*4882a593Smuzhiyundevices; the way a particular drive reacts to a `standard` *ioctl()*
31*4882a593Smuzhiyuncall varies greatly from one device driver to another. To avoid making
32*4882a593Smuzhiyuntheir drivers totally inconsistent, the writers of Linux CD-ROM
33*4882a593Smuzhiyundrivers generally created new device drivers by understanding, copying,
34*4882a593Smuzhiyunand then changing an existing one. Unfortunately, this practice did not
35*4882a593Smuzhiyunmaintain uniform behavior across all the Linux CD-ROM drivers.
36*4882a593Smuzhiyun
37*4882a593SmuzhiyunThis document describes an effort to establish Uniform behavior across
38*4882a593Smuzhiyunall the different CD-ROM device drivers for Linux. This document also
39*4882a593Smuzhiyundefines the various *ioctl()'s*, and how the low-level CD-ROM device
40*4882a593Smuzhiyundrivers should implement them. Currently (as of the Linux 2.1.\ *x*
41*4882a593Smuzhiyundevelopment kernels) several low-level CD-ROM device drivers, including
42*4882a593Smuzhiyunboth IDE/ATAPI and SCSI, now use this Uniform interface.
43*4882a593Smuzhiyun
44*4882a593SmuzhiyunWhen the CD-ROM was developed, the interface between the CD-ROM drive
45*4882a593Smuzhiyunand the computer was not specified in the standards. As a result, many
46*4882a593Smuzhiyundifferent CD-ROM interfaces were developed. Some of them had their
47*4882a593Smuzhiyunown proprietary design (Sony, Mitsumi, Panasonic, Philips), other
48*4882a593Smuzhiyunmanufacturers adopted an existing electrical interface and changed
49*4882a593Smuzhiyunthe functionality (CreativeLabs/SoundBlaster, Teac, Funai) or simply
50*4882a593Smuzhiyunadapted their drives to one or more of the already existing electrical
51*4882a593Smuzhiyuninterfaces (Aztech, Sanyo, Funai, Vertos, Longshine, Optics Storage and
52*4882a593Smuzhiyunmost of the `NoName` manufacturers). In cases where a new drive really
53*4882a593Smuzhiyunbrought its own interface or used its own command set and flow control
54*4882a593Smuzhiyunscheme, either a separate driver had to be written, or an existing
55*4882a593Smuzhiyundriver had to be enhanced. History has delivered us CD-ROM support for
56*4882a593Smuzhiyunmany of these different interfaces. Nowadays, almost all new CD-ROM
57*4882a593Smuzhiyundrives are either IDE/ATAPI or SCSI, and it is very unlikely that any
58*4882a593Smuzhiyunmanufacturer will create a new interface. Even finding drives for the
59*4882a593Smuzhiyunold proprietary interfaces is getting difficult.
60*4882a593Smuzhiyun
61*4882a593SmuzhiyunWhen (in the 1.3.70's) I looked at the existing software interface,
62*4882a593Smuzhiyunwhich was expressed through `cdrom.h`, it appeared to be a rather wild
63*4882a593Smuzhiyunset of commands and data formats [#f1]_. It seemed that many
64*4882a593Smuzhiyunfeatures of the software interface had been added to accommodate the
65*4882a593Smuzhiyuncapabilities of a particular drive, in an *ad hoc* manner. More
66*4882a593Smuzhiyunimportantly, it appeared that the behavior of the `standard` commands
67*4882a593Smuzhiyunwas different for most of the different drivers: e. g., some drivers
68*4882a593Smuzhiyunclose the tray if an *open()* call occurs when the tray is open, while
69*4882a593Smuzhiyunothers do not. Some drivers lock the door upon opening the device, to
70*4882a593Smuzhiyunprevent an incoherent file system, but others don't, to allow software
71*4882a593Smuzhiyunejection. Undoubtedly, the capabilities of the different drives vary,
72*4882a593Smuzhiyunbut even when two drives have the same capability their drivers'
73*4882a593Smuzhiyunbehavior was usually different.
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun.. [#f1]
76*4882a593Smuzhiyun   I cannot recollect what kernel version I looked at, then,
77*4882a593Smuzhiyun   presumably 1.2.13 and 1.3.34 --- the latest kernel that I was
78*4882a593Smuzhiyun   indirectly involved in.
79*4882a593Smuzhiyun
80*4882a593SmuzhiyunI decided to start a discussion on how to make all the Linux CD-ROM
81*4882a593Smuzhiyundrivers behave more uniformly. I began by contacting the developers of
82*4882a593Smuzhiyunthe many CD-ROM drivers found in the Linux kernel. Their reactions
83*4882a593Smuzhiyunencouraged me to write the Uniform CD-ROM Driver which this document is
84*4882a593Smuzhiyunintended to describe. The implementation of the Uniform CD-ROM Driver is
85*4882a593Smuzhiyunin the file `cdrom.c`. This driver is intended to be an additional software
86*4882a593Smuzhiyunlayer that sits on top of the low-level device drivers for each CD-ROM drive.
87*4882a593SmuzhiyunBy adding this additional layer, it is possible to have all the different
88*4882a593SmuzhiyunCD-ROM devices behave **exactly** the same (insofar as the underlying
89*4882a593Smuzhiyunhardware will allow).
90*4882a593Smuzhiyun
91*4882a593SmuzhiyunThe goal of the Uniform CD-ROM Driver is **not** to alienate driver developers
92*4882a593Smuzhiyunwhohave not yet taken steps to support this effort. The goal of Uniform CD-ROM
93*4882a593SmuzhiyunDriver is simply to give people writing application programs for CD-ROM drives
94*4882a593Smuzhiyun**one** Linux CD-ROM interface with consistent behavior for all
95*4882a593SmuzhiyunCD-ROM devices. In addition, this also provides a consistent interface
96*4882a593Smuzhiyunbetween the low-level device driver code and the Linux kernel. Care
97*4882a593Smuzhiyunis taken that 100% compatibility exists with the data structures and
98*4882a593Smuzhiyunprogrammer's interface defined in `cdrom.h`. This guide was written to
99*4882a593Smuzhiyunhelp CD-ROM driver developers adapt their code to use the Uniform CD-ROM
100*4882a593SmuzhiyunDriver code defined in `cdrom.c`.
101*4882a593Smuzhiyun
102*4882a593SmuzhiyunPersonally, I think that the most important hardware interfaces are
103*4882a593Smuzhiyunthe IDE/ATAPI drives and, of course, the SCSI drives, but as prices
104*4882a593Smuzhiyunof hardware drop continuously, it is also likely that people may have
105*4882a593Smuzhiyunmore than one CD-ROM drive, possibly of mixed types. It is important
106*4882a593Smuzhiyunthat these drives behave in the same way. In December 1994, one of the
107*4882a593Smuzhiyuncheapest CD-ROM drives was a Philips cm206, a double-speed proprietary
108*4882a593Smuzhiyundrive. In the months that I was busy writing a Linux driver for it,
109*4882a593Smuzhiyunproprietary drives became obsolete and IDE/ATAPI drives became the
110*4882a593Smuzhiyunstandard. At the time of the last update to this document (November
111*4882a593Smuzhiyun1997) it is becoming difficult to even **find** anything less than a
112*4882a593Smuzhiyun16 speed CD-ROM drive, and 24 speed drives are common.
113*4882a593Smuzhiyun
114*4882a593Smuzhiyun.. _cdrom_api:
115*4882a593Smuzhiyun
116*4882a593SmuzhiyunStandardizing through another software level
117*4882a593Smuzhiyun============================================
118*4882a593Smuzhiyun
119*4882a593SmuzhiyunAt the time this document was conceived, all drivers directly
120*4882a593Smuzhiyunimplemented the CD-ROM *ioctl()* calls through their own routines. This
121*4882a593Smuzhiyunled to the danger of different drivers forgetting to do important things
122*4882a593Smuzhiyunlike checking that the user was giving the driver valid data. More
123*4882a593Smuzhiyunimportantly, this led to the divergence of behavior, which has already
124*4882a593Smuzhiyunbeen discussed.
125*4882a593Smuzhiyun
126*4882a593SmuzhiyunFor this reason, the Uniform CD-ROM Driver was created to enforce consistent
127*4882a593SmuzhiyunCD-ROM drive behavior, and to provide a common set of services to the various
128*4882a593Smuzhiyunlow-level CD-ROM device drivers. The Uniform CD-ROM Driver now provides another
129*4882a593Smuzhiyunsoftware-level, that separates the *ioctl()* and *open()* implementation
130*4882a593Smuzhiyunfrom the actual hardware implementation. Note that this effort has
131*4882a593Smuzhiyunmade few changes which will affect a user's application programs. The
132*4882a593Smuzhiyungreatest change involved moving the contents of the various low-level
133*4882a593SmuzhiyunCD-ROM drivers\' header files to the kernel's cdrom directory. This was
134*4882a593Smuzhiyundone to help ensure that the user is only presented with only one cdrom
135*4882a593Smuzhiyuninterface, the interface defined in `cdrom.h`.
136*4882a593Smuzhiyun
137*4882a593SmuzhiyunCD-ROM drives are specific enough (i. e., different from other
138*4882a593Smuzhiyunblock-devices such as floppy or hard disc drives), to define a set
139*4882a593Smuzhiyunof common **CD-ROM device operations**, *<cdrom-device>_dops*.
140*4882a593SmuzhiyunThese operations are different from the classical block-device file
141*4882a593Smuzhiyunoperations, *<block-device>_fops*.
142*4882a593Smuzhiyun
143*4882a593SmuzhiyunThe routines for the Uniform CD-ROM Driver interface level are implemented
144*4882a593Smuzhiyunin the file `cdrom.c`. In this file, the Uniform CD-ROM Driver interfaces
145*4882a593Smuzhiyunwith the kernel as a block device by registering the following general
146*4882a593Smuzhiyun*struct file_operations*::
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun	struct file_operations cdrom_fops = {
149*4882a593Smuzhiyun		NULL,			/∗ lseek ∗/
150*4882a593Smuzhiyun		block _read ,		/∗ read—general block-dev read ∗/
151*4882a593Smuzhiyun		block _write,		/∗ write—general block-dev write ∗/
152*4882a593Smuzhiyun		NULL,			/∗ readdir ∗/
153*4882a593Smuzhiyun		NULL,			/∗ select ∗/
154*4882a593Smuzhiyun		cdrom_ioctl,		/∗ ioctl ∗/
155*4882a593Smuzhiyun		NULL,			/∗ mmap ∗/
156*4882a593Smuzhiyun		cdrom_open,		/∗ open ∗/
157*4882a593Smuzhiyun		cdrom_release,		/∗ release ∗/
158*4882a593Smuzhiyun		NULL,			/∗ fsync ∗/
159*4882a593Smuzhiyun		NULL,			/∗ fasync ∗/
160*4882a593Smuzhiyun		NULL			/∗ revalidate ∗/
161*4882a593Smuzhiyun	};
162*4882a593Smuzhiyun
163*4882a593SmuzhiyunEvery active CD-ROM device shares this *struct*. The routines
164*4882a593Smuzhiyundeclared above are all implemented in `cdrom.c`, since this file is the
165*4882a593Smuzhiyunplace where the behavior of all CD-ROM-devices is defined and
166*4882a593Smuzhiyunstandardized. The actual interface to the various types of CD-ROM
167*4882a593Smuzhiyunhardware is still performed by various low-level CD-ROM-device
168*4882a593Smuzhiyundrivers. These routines simply implement certain **capabilities**
169*4882a593Smuzhiyunthat are common to all CD-ROM (and really, all removable-media
170*4882a593Smuzhiyundevices).
171*4882a593Smuzhiyun
172*4882a593SmuzhiyunRegistration of a low-level CD-ROM device driver is now done through
173*4882a593Smuzhiyunthe general routines in `cdrom.c`, not through the Virtual File System
174*4882a593Smuzhiyun(VFS) any more. The interface implemented in `cdrom.c` is carried out
175*4882a593Smuzhiyunthrough two general structures that contain information about the
176*4882a593Smuzhiyuncapabilities of the driver, and the specific drives on which the
177*4882a593Smuzhiyundriver operates. The structures are:
178*4882a593Smuzhiyun
179*4882a593Smuzhiyuncdrom_device_ops
180*4882a593Smuzhiyun  This structure contains information about the low-level driver for a
181*4882a593Smuzhiyun  CD-ROM device. This structure is conceptually connected to the major
182*4882a593Smuzhiyun  number of the device (although some drivers may have different
183*4882a593Smuzhiyun  major numbers, as is the case for the IDE driver).
184*4882a593Smuzhiyun
185*4882a593Smuzhiyuncdrom_device_info
186*4882a593Smuzhiyun  This structure contains information about a particular CD-ROM drive,
187*4882a593Smuzhiyun  such as its device name, speed, etc. This structure is conceptually
188*4882a593Smuzhiyun  connected to the minor number of the device.
189*4882a593Smuzhiyun
190*4882a593SmuzhiyunRegistering a particular CD-ROM drive with the Uniform CD-ROM Driver
191*4882a593Smuzhiyunis done by the low-level device driver though a call to::
192*4882a593Smuzhiyun
193*4882a593Smuzhiyun	register_cdrom(struct cdrom_device_info * <device>_info)
194*4882a593Smuzhiyun
195*4882a593SmuzhiyunThe device information structure, *<device>_info*, contains all the
196*4882a593Smuzhiyuninformation needed for the kernel to interface with the low-level
197*4882a593SmuzhiyunCD-ROM device driver. One of the most important entries in this
198*4882a593Smuzhiyunstructure is a pointer to the *cdrom_device_ops* structure of the
199*4882a593Smuzhiyunlow-level driver.
200*4882a593Smuzhiyun
201*4882a593SmuzhiyunThe device operations structure, *cdrom_device_ops*, contains a list
202*4882a593Smuzhiyunof pointers to the functions which are implemented in the low-level
203*4882a593Smuzhiyundevice driver. When `cdrom.c` accesses a CD-ROM device, it does it
204*4882a593Smuzhiyunthrough the functions in this structure. It is impossible to know all
205*4882a593Smuzhiyunthe capabilities of future CD-ROM drives, so it is expected that this
206*4882a593Smuzhiyunlist may need to be expanded from time to time as new technologies are
207*4882a593Smuzhiyundeveloped. For example, CD-R and CD-R/W drives are beginning to become
208*4882a593Smuzhiyunpopular, and support will soon need to be added for them. For now, the
209*4882a593Smuzhiyuncurrent *struct* is::
210*4882a593Smuzhiyun
211*4882a593Smuzhiyun	struct cdrom_device_ops {
212*4882a593Smuzhiyun		int (*open)(struct cdrom_device_info *, int)
213*4882a593Smuzhiyun		void (*release)(struct cdrom_device_info *);
214*4882a593Smuzhiyun		int (*drive_status)(struct cdrom_device_info *, int);
215*4882a593Smuzhiyun		unsigned int (*check_events)(struct cdrom_device_info *,
216*4882a593Smuzhiyun					     unsigned int, int);
217*4882a593Smuzhiyun		int (*media_changed)(struct cdrom_device_info *, int);
218*4882a593Smuzhiyun		int (*tray_move)(struct cdrom_device_info *, int);
219*4882a593Smuzhiyun		int (*lock_door)(struct cdrom_device_info *, int);
220*4882a593Smuzhiyun		int (*select_speed)(struct cdrom_device_info *, int);
221*4882a593Smuzhiyun		int (*select_disc)(struct cdrom_device_info *, int);
222*4882a593Smuzhiyun		int (*get_last_session) (struct cdrom_device_info *,
223*4882a593Smuzhiyun					 struct cdrom_multisession *);
224*4882a593Smuzhiyun		int (*get_mcn)(struct cdrom_device_info *, struct cdrom_mcn *);
225*4882a593Smuzhiyun		int (*reset)(struct cdrom_device_info *);
226*4882a593Smuzhiyun		int (*audio_ioctl)(struct cdrom_device_info *,
227*4882a593Smuzhiyun				   unsigned int, void *);
228*4882a593Smuzhiyun		const int capability;		/* capability flags */
229*4882a593Smuzhiyun		int (*generic_packet)(struct cdrom_device_info *,
230*4882a593Smuzhiyun				      struct packet_command *);
231*4882a593Smuzhiyun	};
232*4882a593Smuzhiyun
233*4882a593SmuzhiyunWhen a low-level device driver implements one of these capabilities,
234*4882a593Smuzhiyunit should add a function pointer to this *struct*. When a particular
235*4882a593Smuzhiyunfunction is not implemented, however, this *struct* should contain a
236*4882a593SmuzhiyunNULL instead. The *capability* flags specify the capabilities of the
237*4882a593SmuzhiyunCD-ROM hardware and/or low-level CD-ROM driver when a CD-ROM drive
238*4882a593Smuzhiyunis registered with the Uniform CD-ROM Driver.
239*4882a593Smuzhiyun
240*4882a593SmuzhiyunNote that most functions have fewer parameters than their
241*4882a593Smuzhiyun*blkdev_fops* counterparts. This is because very little of the
242*4882a593Smuzhiyuninformation in the structures *inode* and *file* is used. For most
243*4882a593Smuzhiyundrivers, the main parameter is the *struct* *cdrom_device_info*, from
244*4882a593Smuzhiyunwhich the major and minor number can be extracted. (Most low-level
245*4882a593SmuzhiyunCD-ROM drivers don't even look at the major and minor number though,
246*4882a593Smuzhiyunsince many of them only support one device.) This will be available
247*4882a593Smuzhiyunthrough *dev* in *cdrom_device_info* described below.
248*4882a593Smuzhiyun
249*4882a593SmuzhiyunThe drive-specific, minor-like information that is registered with
250*4882a593Smuzhiyun`cdrom.c`, currently contains the following fields::
251*4882a593Smuzhiyun
252*4882a593Smuzhiyun  struct cdrom_device_info {
253*4882a593Smuzhiyun	const struct cdrom_device_ops * ops; 	/* device operations for this major */
254*4882a593Smuzhiyun	struct list_head list;			/* linked list of all device_info */
255*4882a593Smuzhiyun	struct gendisk * disk;			/* matching block layer disk */
256*4882a593Smuzhiyun	void *  handle;				/* driver-dependent data */
257*4882a593Smuzhiyun
258*4882a593Smuzhiyun	int mask; 				/* mask of capability: disables them */
259*4882a593Smuzhiyun	int speed;				/* maximum speed for reading data */
260*4882a593Smuzhiyun	int capacity;				/* number of discs in a jukebox */
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun	unsigned int options:30;		/* options flags */
263*4882a593Smuzhiyun	unsigned mc_flags:2;			/*  media-change buffer flags */
264*4882a593Smuzhiyun	unsigned int vfs_events;		/*  cached events for vfs path */
265*4882a593Smuzhiyun	unsigned int ioctl_events;		/*  cached events for ioctl path */
266*4882a593Smuzhiyun	int use_count;				/*  number of times device is opened */
267*4882a593Smuzhiyun	char name[20];				/*  name of the device type */
268*4882a593Smuzhiyun
269*4882a593Smuzhiyun	__u8 sanyo_slot : 2;			/*  Sanyo 3-CD changer support */
270*4882a593Smuzhiyun	__u8 keeplocked : 1;			/*  CDROM_LOCKDOOR status */
271*4882a593Smuzhiyun	__u8 reserved : 5;			/*  not used yet */
272*4882a593Smuzhiyun	int cdda_method;			/*  see CDDA_* flags */
273*4882a593Smuzhiyun	__u8 last_sense;			/*  saves last sense key */
274*4882a593Smuzhiyun	__u8 media_written;			/*  dirty flag, DVD+RW bookkeeping */
275*4882a593Smuzhiyun	unsigned short mmc3_profile;		/*  current MMC3 profile */
276*4882a593Smuzhiyun	int for_data;				/*  unknown:TBD */
277*4882a593Smuzhiyun	int (*exit)(struct cdrom_device_info *);/*  unknown:TBD */
278*4882a593Smuzhiyun	int mrw_mode_page;			/*  which MRW mode page is in use */
279*4882a593Smuzhiyun  };
280*4882a593Smuzhiyun
281*4882a593SmuzhiyunUsing this *struct*, a linked list of the registered minor devices is
282*4882a593Smuzhiyunbuilt, using the *next* field. The device number, the device operations
283*4882a593Smuzhiyunstruct and specifications of properties of the drive are stored in this
284*4882a593Smuzhiyunstructure.
285*4882a593Smuzhiyun
286*4882a593SmuzhiyunThe *mask* flags can be used to mask out some of the capabilities listed
287*4882a593Smuzhiyunin *ops->capability*, if a specific drive doesn't support a feature
288*4882a593Smuzhiyunof the driver. The value *speed* specifies the maximum head-rate of the
289*4882a593Smuzhiyundrive, measured in units of normal audio speed (176kB/sec raw data or
290*4882a593Smuzhiyun150kB/sec file system data). The parameters are declared *const*
291*4882a593Smuzhiyunbecause they describe properties of the drive, which don't change after
292*4882a593Smuzhiyunregistration.
293*4882a593Smuzhiyun
294*4882a593SmuzhiyunA few registers contain variables local to the CD-ROM drive. The
295*4882a593Smuzhiyunflags *options* are used to specify how the general CD-ROM routines
296*4882a593Smuzhiyunshould behave. These various flags registers should provide enough
297*4882a593Smuzhiyunflexibility to adapt to the different users' wishes (and **not** the
298*4882a593Smuzhiyun`arbitrary` wishes of the author of the low-level device driver, as is
299*4882a593Smuzhiyunthe case in the old scheme). The register *mc_flags* is used to buffer
300*4882a593Smuzhiyunthe information from *media_changed()* to two separate queues. Other
301*4882a593Smuzhiyundata that is specific to a minor drive, can be accessed through *handle*,
302*4882a593Smuzhiyunwhich can point to a data structure specific to the low-level driver.
303*4882a593SmuzhiyunThe fields *use_count*, *next*, *options* and *mc_flags* need not be
304*4882a593Smuzhiyuninitialized.
305*4882a593Smuzhiyun
306*4882a593SmuzhiyunThe intermediate software layer that `cdrom.c` forms will perform some
307*4882a593Smuzhiyunadditional bookkeeping. The use count of the device (the number of
308*4882a593Smuzhiyunprocesses that have the device opened) is registered in *use_count*. The
309*4882a593Smuzhiyunfunction *cdrom_ioctl()* will verify the appropriate user-memory regions
310*4882a593Smuzhiyunfor read and write, and in case a location on the CD is transferred,
311*4882a593Smuzhiyunit will `sanitize` the format by making requests to the low-level
312*4882a593Smuzhiyundrivers in a standard format, and translating all formats between the
313*4882a593Smuzhiyunuser-software and low level drivers. This relieves much of the drivers'
314*4882a593Smuzhiyunmemory checking and format checking and translation. Also, the necessary
315*4882a593Smuzhiyunstructures will be declared on the program stack.
316*4882a593Smuzhiyun
317*4882a593SmuzhiyunThe implementation of the functions should be as defined in the
318*4882a593Smuzhiyunfollowing sections. Two functions **must** be implemented, namely
319*4882a593Smuzhiyun*open()* and *release()*. Other functions may be omitted, their
320*4882a593Smuzhiyuncorresponding capability flags will be cleared upon registration.
321*4882a593SmuzhiyunGenerally, a function returns zero on success and negative on error. A
322*4882a593Smuzhiyunfunction call should return only after the command has completed, but of
323*4882a593Smuzhiyuncourse waiting for the device should not use processor time.
324*4882a593Smuzhiyun
325*4882a593Smuzhiyun::
326*4882a593Smuzhiyun
327*4882a593Smuzhiyun	int open(struct cdrom_device_info *cdi, int purpose)
328*4882a593Smuzhiyun
329*4882a593Smuzhiyun*Open()* should try to open the device for a specific *purpose*, which
330*4882a593Smuzhiyuncan be either:
331*4882a593Smuzhiyun
332*4882a593Smuzhiyun- Open for reading data, as done by `mount()` (2), or the
333*4882a593Smuzhiyun  user commands `dd` or `cat`.
334*4882a593Smuzhiyun- Open for *ioctl* commands, as done by audio-CD playing programs.
335*4882a593Smuzhiyun
336*4882a593SmuzhiyunNotice that any strategic code (closing tray upon *open()*, etc.) is
337*4882a593Smuzhiyundone by the calling routine in `cdrom.c`, so the low-level routine
338*4882a593Smuzhiyunshould only be concerned with proper initialization, such as spinning
339*4882a593Smuzhiyunup the disc, etc.
340*4882a593Smuzhiyun
341*4882a593Smuzhiyun::
342*4882a593Smuzhiyun
343*4882a593Smuzhiyun	void release(struct cdrom_device_info *cdi)
344*4882a593Smuzhiyun
345*4882a593SmuzhiyunDevice-specific actions should be taken such as spinning down the device.
346*4882a593SmuzhiyunHowever, strategic actions such as ejection of the tray, or unlocking
347*4882a593Smuzhiyunthe door, should be left over to the general routine *cdrom_release()*.
348*4882a593SmuzhiyunThis is the only function returning type *void*.
349*4882a593Smuzhiyun
350*4882a593Smuzhiyun.. _cdrom_drive_status:
351*4882a593Smuzhiyun
352*4882a593Smuzhiyun::
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun	int drive_status(struct cdrom_device_info *cdi, int slot_nr)
355*4882a593Smuzhiyun
356*4882a593SmuzhiyunThe function *drive_status*, if implemented, should provide
357*4882a593Smuzhiyuninformation on the status of the drive (not the status of the disc,
358*4882a593Smuzhiyunwhich may or may not be in the drive). If the drive is not a changer,
359*4882a593Smuzhiyun*slot_nr* should be ignored. In `cdrom.h` the possibilities are listed::
360*4882a593Smuzhiyun
361*4882a593Smuzhiyun
362*4882a593Smuzhiyun	CDS_NO_INFO		/* no information available */
363*4882a593Smuzhiyun	CDS_NO_DISC		/* no disc is inserted, tray is closed */
364*4882a593Smuzhiyun	CDS_TRAY_OPEN		/* tray is opened */
365*4882a593Smuzhiyun	CDS_DRIVE_NOT_READY	/* something is wrong, tray is moving? */
366*4882a593Smuzhiyun	CDS_DISC_OK		/* a disc is loaded and everything is fine */
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun::
369*4882a593Smuzhiyun
370*4882a593Smuzhiyun	int tray_move(struct cdrom_device_info *cdi, int position)
371*4882a593Smuzhiyun
372*4882a593SmuzhiyunThis function, if implemented, should control the tray movement. (No
373*4882a593Smuzhiyunother function should control this.) The parameter *position* controls
374*4882a593Smuzhiyunthe desired direction of movement:
375*4882a593Smuzhiyun
376*4882a593Smuzhiyun- 0 Close tray
377*4882a593Smuzhiyun- 1 Open tray
378*4882a593Smuzhiyun
379*4882a593SmuzhiyunThis function returns 0 upon success, and a non-zero value upon
380*4882a593Smuzhiyunerror. Note that if the tray is already in the desired position, no
381*4882a593Smuzhiyunaction need be taken, and the return value should be 0.
382*4882a593Smuzhiyun
383*4882a593Smuzhiyun::
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun	int lock_door(struct cdrom_device_info *cdi, int lock)
386*4882a593Smuzhiyun
387*4882a593SmuzhiyunThis function (and no other code) controls locking of the door, if the
388*4882a593Smuzhiyundrive allows this. The value of *lock* controls the desired locking
389*4882a593Smuzhiyunstate:
390*4882a593Smuzhiyun
391*4882a593Smuzhiyun- 0 Unlock door, manual opening is allowed
392*4882a593Smuzhiyun- 1 Lock door, tray cannot be ejected manually
393*4882a593Smuzhiyun
394*4882a593SmuzhiyunThis function returns 0 upon success, and a non-zero value upon
395*4882a593Smuzhiyunerror. Note that if the door is already in the requested state, no
396*4882a593Smuzhiyunaction need be taken, and the return value should be 0.
397*4882a593Smuzhiyun
398*4882a593Smuzhiyun::
399*4882a593Smuzhiyun
400*4882a593Smuzhiyun	int select_speed(struct cdrom_device_info *cdi, int speed)
401*4882a593Smuzhiyun
402*4882a593SmuzhiyunSome CD-ROM drives are capable of changing their head-speed. There
403*4882a593Smuzhiyunare several reasons for changing the speed of a CD-ROM drive. Badly
404*4882a593Smuzhiyunpressed CD-ROM s may benefit from less-than-maximum head rate. Modern
405*4882a593SmuzhiyunCD-ROM drives can obtain very high head rates (up to *24x* is
406*4882a593Smuzhiyuncommon). It has been reported that these drives can make reading
407*4882a593Smuzhiyunerrors at these high speeds, reducing the speed can prevent data loss
408*4882a593Smuzhiyunin these circumstances. Finally, some of these drives can
409*4882a593Smuzhiyunmake an annoyingly loud noise, which a lower speed may reduce.
410*4882a593Smuzhiyun
411*4882a593SmuzhiyunThis function specifies the speed at which data is read or audio is
412*4882a593Smuzhiyunplayed back. The value of *speed* specifies the head-speed of the
413*4882a593Smuzhiyundrive, measured in units of standard cdrom speed (176kB/sec raw data
414*4882a593Smuzhiyunor 150kB/sec file system data). So to request that a CD-ROM drive
415*4882a593Smuzhiyunoperate at 300kB/sec you would call the CDROM_SELECT_SPEED *ioctl*
416*4882a593Smuzhiyunwith *speed=2*. The special value `0` means `auto-selection`, i. e.,
417*4882a593Smuzhiyunmaximum data-rate or real-time audio rate. If the drive doesn't have
418*4882a593Smuzhiyunthis `auto-selection` capability, the decision should be made on the
419*4882a593Smuzhiyuncurrent disc loaded and the return value should be positive. A negative
420*4882a593Smuzhiyunreturn value indicates an error.
421*4882a593Smuzhiyun
422*4882a593Smuzhiyun::
423*4882a593Smuzhiyun
424*4882a593Smuzhiyun	int select_disc(struct cdrom_device_info *cdi, int number)
425*4882a593Smuzhiyun
426*4882a593SmuzhiyunIf the drive can store multiple discs (a juke-box) this function
427*4882a593Smuzhiyunwill perform disc selection. It should return the number of the
428*4882a593Smuzhiyunselected disc on success, a negative value on error. Currently, only
429*4882a593Smuzhiyunthe ide-cd driver supports this functionality.
430*4882a593Smuzhiyun
431*4882a593Smuzhiyun::
432*4882a593Smuzhiyun
433*4882a593Smuzhiyun	int get_last_session(struct cdrom_device_info *cdi,
434*4882a593Smuzhiyun			     struct cdrom_multisession *ms_info)
435*4882a593Smuzhiyun
436*4882a593SmuzhiyunThis function should implement the old corresponding *ioctl()*. For
437*4882a593Smuzhiyundevice *cdi->dev*, the start of the last session of the current disc
438*4882a593Smuzhiyunshould be returned in the pointer argument *ms_info*. Note that
439*4882a593Smuzhiyunroutines in `cdrom.c` have sanitized this argument: its requested
440*4882a593Smuzhiyunformat will **always** be of the type *CDROM_LBA* (linear block
441*4882a593Smuzhiyunaddressing mode), whatever the calling software requested. But
442*4882a593Smuzhiyunsanitization goes even further: the low-level implementation may
443*4882a593Smuzhiyunreturn the requested information in *CDROM_MSF* format if it wishes so
444*4882a593Smuzhiyun(setting the *ms_info->addr_format* field appropriately, of
445*4882a593Smuzhiyuncourse) and the routines in `cdrom.c` will make the transformation if
446*4882a593Smuzhiyunnecessary. The return value is 0 upon success.
447*4882a593Smuzhiyun
448*4882a593Smuzhiyun::
449*4882a593Smuzhiyun
450*4882a593Smuzhiyun	int get_mcn(struct cdrom_device_info *cdi,
451*4882a593Smuzhiyun		    struct cdrom_mcn *mcn)
452*4882a593Smuzhiyun
453*4882a593SmuzhiyunSome discs carry a `Media Catalog Number` (MCN), also called
454*4882a593Smuzhiyun`Universal Product Code` (UPC). This number should reflect the number
455*4882a593Smuzhiyunthat is generally found in the bar-code on the product. Unfortunately,
456*4882a593Smuzhiyunthe few discs that carry such a number on the disc don't even use the
457*4882a593Smuzhiyunsame format. The return argument to this function is a pointer to a
458*4882a593Smuzhiyunpre-declared memory region of type *struct cdrom_mcn*. The MCN is
459*4882a593Smuzhiyunexpected as a 13-character string, terminated by a null-character.
460*4882a593Smuzhiyun
461*4882a593Smuzhiyun::
462*4882a593Smuzhiyun
463*4882a593Smuzhiyun	int reset(struct cdrom_device_info *cdi)
464*4882a593Smuzhiyun
465*4882a593SmuzhiyunThis call should perform a hard-reset on the drive (although in
466*4882a593Smuzhiyuncircumstances that a hard-reset is necessary, a drive may very well not
467*4882a593Smuzhiyunlisten to commands anymore). Preferably, control is returned to the
468*4882a593Smuzhiyuncaller only after the drive has finished resetting. If the drive is no
469*4882a593Smuzhiyunlonger listening, it may be wise for the underlying low-level cdrom
470*4882a593Smuzhiyundriver to time out.
471*4882a593Smuzhiyun
472*4882a593Smuzhiyun::
473*4882a593Smuzhiyun
474*4882a593Smuzhiyun	int audio_ioctl(struct cdrom_device_info *cdi,
475*4882a593Smuzhiyun			unsigned int cmd, void *arg)
476*4882a593Smuzhiyun
477*4882a593SmuzhiyunSome of the CD-ROM-\ *ioctl()*\ 's defined in `cdrom.h` can be
478*4882a593Smuzhiyunimplemented by the routines described above, and hence the function
479*4882a593Smuzhiyun*cdrom_ioctl* will use those. However, most *ioctl()*\ 's deal with
480*4882a593Smuzhiyunaudio-control. We have decided to leave these to be accessed through a
481*4882a593Smuzhiyunsingle function, repeating the arguments *cmd* and *arg*. Note that
482*4882a593Smuzhiyunthe latter is of type *void*, rather than *unsigned long int*.
483*4882a593SmuzhiyunThe routine *cdrom_ioctl()* does do some useful things,
484*4882a593Smuzhiyunthough. It sanitizes the address format type to *CDROM_MSF* (Minutes,
485*4882a593SmuzhiyunSeconds, Frames) for all audio calls. It also verifies the memory
486*4882a593Smuzhiyunlocation of *arg*, and reserves stack-memory for the argument. This
487*4882a593Smuzhiyunmakes implementation of the *audio_ioctl()* much simpler than in the
488*4882a593Smuzhiyunold driver scheme. For example, you may look up the function
489*4882a593Smuzhiyun*cm206_audio_ioctl()* `cm206.c` that should be updated with
490*4882a593Smuzhiyunthis documentation.
491*4882a593Smuzhiyun
492*4882a593SmuzhiyunAn unimplemented ioctl should return *-ENOSYS*, but a harmless request
493*4882a593Smuzhiyun(e. g., *CDROMSTART*) may be ignored by returning 0 (success). Other
494*4882a593Smuzhiyunerrors should be according to the standards, whatever they are. When
495*4882a593Smuzhiyunan error is returned by the low-level driver, the Uniform CD-ROM Driver
496*4882a593Smuzhiyuntries whenever possible to return the error code to the calling program.
497*4882a593Smuzhiyun(We may decide to sanitize the return value in *cdrom_ioctl()* though, in
498*4882a593Smuzhiyunorder to guarantee a uniform interface to the audio-player software.)
499*4882a593Smuzhiyun
500*4882a593Smuzhiyun::
501*4882a593Smuzhiyun
502*4882a593Smuzhiyun	int dev_ioctl(struct cdrom_device_info *cdi,
503*4882a593Smuzhiyun		      unsigned int cmd, unsigned long arg)
504*4882a593Smuzhiyun
505*4882a593SmuzhiyunSome *ioctl()'s* seem to be specific to certain CD-ROM drives. That is,
506*4882a593Smuzhiyunthey are introduced to service some capabilities of certain drives. In
507*4882a593Smuzhiyunfact, there are 6 different *ioctl()'s* for reading data, either in some
508*4882a593Smuzhiyunparticular kind of format, or audio data. Not many drives support
509*4882a593Smuzhiyunreading audio tracks as data, I believe this is because of protection
510*4882a593Smuzhiyunof copyrights of artists. Moreover, I think that if audio-tracks are
511*4882a593Smuzhiyunsupported, it should be done through the VFS and not via *ioctl()'s*. A
512*4882a593Smuzhiyunproblem here could be the fact that audio-frames are 2352 bytes long,
513*4882a593Smuzhiyunso either the audio-file-system should ask for 75264 bytes at once
514*4882a593Smuzhiyun(the least common multiple of 512 and 2352), or the drivers should
515*4882a593Smuzhiyunbend their backs to cope with this incoherence (to which I would be
516*4882a593Smuzhiyunopposed). Furthermore, it is very difficult for the hardware to find
517*4882a593Smuzhiyunthe exact frame boundaries, since there are no synchronization headers
518*4882a593Smuzhiyunin audio frames. Once these issues are resolved, this code should be
519*4882a593Smuzhiyunstandardized in `cdrom.c`.
520*4882a593Smuzhiyun
521*4882a593SmuzhiyunBecause there are so many *ioctl()'s* that seem to be introduced to
522*4882a593Smuzhiyunsatisfy certain drivers [#f2]_, any non-standard *ioctl()*\ s
523*4882a593Smuzhiyunare routed through the call *dev_ioctl()*. In principle, `private`
524*4882a593Smuzhiyun*ioctl()*\ 's should be numbered after the device's major number, and not
525*4882a593Smuzhiyunthe general CD-ROM *ioctl* number, `0x53`. Currently the
526*4882a593Smuzhiyunnon-supported *ioctl()'s* are:
527*4882a593Smuzhiyun
528*4882a593Smuzhiyun	CDROMREADMODE1, CDROMREADMODE2, CDROMREADAUDIO, CDROMREADRAW,
529*4882a593Smuzhiyun	CDROMREADCOOKED, CDROMSEEK, CDROMPLAY-BLK and CDROM-READALL
530*4882a593Smuzhiyun
531*4882a593Smuzhiyun.. [#f2]
532*4882a593Smuzhiyun
533*4882a593Smuzhiyun   Is there software around that actually uses these? I'd be interested!
534*4882a593Smuzhiyun
535*4882a593Smuzhiyun.. _cdrom_capabilities:
536*4882a593Smuzhiyun
537*4882a593SmuzhiyunCD-ROM capabilities
538*4882a593Smuzhiyun-------------------
539*4882a593Smuzhiyun
540*4882a593SmuzhiyunInstead of just implementing some *ioctl* calls, the interface in
541*4882a593Smuzhiyun`cdrom.c` supplies the possibility to indicate the **capabilities**
542*4882a593Smuzhiyunof a CD-ROM drive. This can be done by ORing any number of
543*4882a593Smuzhiyuncapability-constants that are defined in `cdrom.h` at the registration
544*4882a593Smuzhiyunphase. Currently, the capabilities are any of::
545*4882a593Smuzhiyun
546*4882a593Smuzhiyun	CDC_CLOSE_TRAY		/* can close tray by software control */
547*4882a593Smuzhiyun	CDC_OPEN_TRAY		/* can open tray */
548*4882a593Smuzhiyun	CDC_LOCK		/* can lock and unlock the door */
549*4882a593Smuzhiyun	CDC_SELECT_SPEED	/* can select speed, in units of * sim*150 ,kB/s */
550*4882a593Smuzhiyun	CDC_SELECT_DISC		/* drive is juke-box */
551*4882a593Smuzhiyun	CDC_MULTI_SESSION	/* can read sessions *> rm1* */
552*4882a593Smuzhiyun	CDC_MCN			/* can read Media Catalog Number */
553*4882a593Smuzhiyun	CDC_MEDIA_CHANGED	/* can report if disc has changed */
554*4882a593Smuzhiyun	CDC_PLAY_AUDIO		/* can perform audio-functions (play, pause, etc) */
555*4882a593Smuzhiyun	CDC_RESET		/* hard reset device */
556*4882a593Smuzhiyun	CDC_IOCTLS		/* driver has non-standard ioctls */
557*4882a593Smuzhiyun	CDC_DRIVE_STATUS	/* driver implements drive status */
558*4882a593Smuzhiyun
559*4882a593SmuzhiyunThe capability flag is declared *const*, to prevent drivers from
560*4882a593Smuzhiyunaccidentally tampering with the contents. The capability flags actually
561*4882a593Smuzhiyuninform `cdrom.c` of what the driver can do. If the drive found
562*4882a593Smuzhiyunby the driver does not have the capability, is can be masked out by
563*4882a593Smuzhiyunthe *cdrom_device_info* variable *mask*. For instance, the SCSI CD-ROM
564*4882a593Smuzhiyundriver has implemented the code for loading and ejecting CD-ROM's, and
565*4882a593Smuzhiyunhence its corresponding flags in *capability* will be set. But a SCSI
566*4882a593SmuzhiyunCD-ROM drive might be a caddy system, which can't load the tray, and
567*4882a593Smuzhiyunhence for this drive the *cdrom_device_info* struct will have set
568*4882a593Smuzhiyunthe *CDC_CLOSE_TRAY* bit in *mask*.
569*4882a593Smuzhiyun
570*4882a593SmuzhiyunIn the file `cdrom.c` you will encounter many constructions of the type::
571*4882a593Smuzhiyun
572*4882a593Smuzhiyun	if (cdo->capability & ∼cdi->mask & CDC _⟨capability⟩) ...
573*4882a593Smuzhiyun
574*4882a593SmuzhiyunThere is no *ioctl* to set the mask... The reason is that
575*4882a593SmuzhiyunI think it is better to control the **behavior** rather than the
576*4882a593Smuzhiyun**capabilities**.
577*4882a593Smuzhiyun
578*4882a593SmuzhiyunOptions
579*4882a593Smuzhiyun-------
580*4882a593Smuzhiyun
581*4882a593SmuzhiyunA final flag register controls the **behavior** of the CD-ROM
582*4882a593Smuzhiyundrives, in order to satisfy different users' wishes, hopefully
583*4882a593Smuzhiyunindependently of the ideas of the respective author who happened to
584*4882a593Smuzhiyunhave made the drive's support available to the Linux community. The
585*4882a593Smuzhiyuncurrent behavior options are::
586*4882a593Smuzhiyun
587*4882a593Smuzhiyun	CDO_AUTO_CLOSE	/* try to close tray upon device open() */
588*4882a593Smuzhiyun	CDO_AUTO_EJECT	/* try to open tray on last device close() */
589*4882a593Smuzhiyun	CDO_USE_FFLAGS	/* use file_pointer->f_flags to indicate purpose for open() */
590*4882a593Smuzhiyun	CDO_LOCK	/* try to lock door if device is opened */
591*4882a593Smuzhiyun	CDO_CHECK_TYPE	/* ensure disc type is data if opened for data */
592*4882a593Smuzhiyun
593*4882a593SmuzhiyunThe initial value of this register is
594*4882a593Smuzhiyun`CDO_AUTO_CLOSE | CDO_USE_FFLAGS | CDO_LOCK`, reflecting my own view on user
595*4882a593Smuzhiyuninterface and software standards. Before you protest, there are two
596*4882a593Smuzhiyunnew *ioctl()'s* implemented in `cdrom.c`, that allow you to control the
597*4882a593Smuzhiyunbehavior by software. These are::
598*4882a593Smuzhiyun
599*4882a593Smuzhiyun	CDROM_SET_OPTIONS	/* set options specified in (int)arg */
600*4882a593Smuzhiyun	CDROM_CLEAR_OPTIONS	/* clear options specified in (int)arg */
601*4882a593Smuzhiyun
602*4882a593SmuzhiyunOne option needs some more explanation: *CDO_USE_FFLAGS*. In the next
603*4882a593Smuzhiyunnewsection we explain what the need for this option is.
604*4882a593Smuzhiyun
605*4882a593SmuzhiyunA software package `setcd`, available from the Debian distribution
606*4882a593Smuzhiyunand `sunsite.unc.edu`, allows user level control of these flags.
607*4882a593Smuzhiyun
608*4882a593Smuzhiyun
609*4882a593SmuzhiyunThe need to know the purpose of opening the CD-ROM device
610*4882a593Smuzhiyun=========================================================
611*4882a593Smuzhiyun
612*4882a593SmuzhiyunTraditionally, Unix devices can be used in two different `modes`,
613*4882a593Smuzhiyuneither by reading/writing to the device file, or by issuing
614*4882a593Smuzhiyuncontrolling commands to the device, by the device's *ioctl()*
615*4882a593Smuzhiyuncall. The problem with CD-ROM drives, is that they can be used for
616*4882a593Smuzhiyuntwo entirely different purposes. One is to mount removable
617*4882a593Smuzhiyunfile systems, CD-ROM's, the other is to play audio CD's. Audio commands
618*4882a593Smuzhiyunare implemented entirely through *ioctl()\'s*, presumably because the
619*4882a593Smuzhiyunfirst implementation (SUN?) has been such. In principle there is
620*4882a593Smuzhiyunnothing wrong with this, but a good control of the `CD player` demands
621*4882a593Smuzhiyunthat the device can **always** be opened in order to give the
622*4882a593Smuzhiyun*ioctl* commands, regardless of the state the drive is in.
623*4882a593Smuzhiyun
624*4882a593SmuzhiyunOn the other hand, when used as a removable-media disc drive (what the
625*4882a593Smuzhiyunoriginal purpose of CD-ROM s is) we would like to make sure that the
626*4882a593Smuzhiyundisc drive is ready for operation upon opening the device. In the old
627*4882a593Smuzhiyunscheme, some CD-ROM drivers don't do any integrity checking, resulting
628*4882a593Smuzhiyunin a number of i/o errors reported by the VFS to the kernel when an
629*4882a593Smuzhiyunattempt for mounting a CD-ROM on an empty drive occurs. This is not a
630*4882a593Smuzhiyunparticularly elegant way to find out that there is no CD-ROM inserted;
631*4882a593Smuzhiyunit more-or-less looks like the old IBM-PC trying to read an empty floppy
632*4882a593Smuzhiyundrive for a couple of seconds, after which the system complains it
633*4882a593Smuzhiyuncan't read from it. Nowadays we can **sense** the existence of a
634*4882a593Smuzhiyunremovable medium in a drive, and we believe we should exploit that
635*4882a593Smuzhiyunfact. An integrity check on opening of the device, that verifies the
636*4882a593Smuzhiyunavailability of a CD-ROM and its correct type (data), would be
637*4882a593Smuzhiyundesirable.
638*4882a593Smuzhiyun
639*4882a593SmuzhiyunThese two ways of using a CD-ROM drive, principally for data and
640*4882a593Smuzhiyunsecondarily for playing audio discs, have different demands for the
641*4882a593Smuzhiyunbehavior of the *open()* call. Audio use simply wants to open the
642*4882a593Smuzhiyundevice in order to get a file handle which is needed for issuing
643*4882a593Smuzhiyun*ioctl* commands, while data use wants to open for correct and
644*4882a593Smuzhiyunreliable data transfer. The only way user programs can indicate what
645*4882a593Smuzhiyuntheir *purpose* of opening the device is, is through the *flags*
646*4882a593Smuzhiyunparameter (see `open(2)`). For CD-ROM devices, these flags aren't
647*4882a593Smuzhiyunimplemented (some drivers implement checking for write-related flags,
648*4882a593Smuzhiyunbut this is not strictly necessary if the device file has correct
649*4882a593Smuzhiyunpermission flags). Most option flags simply don't make sense to
650*4882a593SmuzhiyunCD-ROM devices: *O_CREAT*, *O_NOCTTY*, *O_TRUNC*, *O_APPEND*, and
651*4882a593Smuzhiyun*O_SYNC* have no meaning to a CD-ROM.
652*4882a593Smuzhiyun
653*4882a593SmuzhiyunWe therefore propose to use the flag *O_NONBLOCK* to indicate
654*4882a593Smuzhiyunthat the device is opened just for issuing *ioctl*
655*4882a593Smuzhiyuncommands. Strictly, the meaning of *O_NONBLOCK* is that opening and
656*4882a593Smuzhiyunsubsequent calls to the device don't cause the calling process to
657*4882a593Smuzhiyunwait. We could interpret this as don't wait until someone has
658*4882a593Smuzhiyuninserted some valid data-CD-ROM. Thus, our proposal of the
659*4882a593Smuzhiyunimplementation for the *open()* call for CD-ROM s is:
660*4882a593Smuzhiyun
661*4882a593Smuzhiyun- If no other flags are set than *O_RDONLY*, the device is opened
662*4882a593Smuzhiyun  for data transfer, and the return value will be 0 only upon successful
663*4882a593Smuzhiyun  initialization of the transfer. The call may even induce some actions
664*4882a593Smuzhiyun  on the CD-ROM, such as closing the tray.
665*4882a593Smuzhiyun- If the option flag *O_NONBLOCK* is set, opening will always be
666*4882a593Smuzhiyun  successful, unless the whole device doesn't exist. The drive will take
667*4882a593Smuzhiyun  no actions whatsoever.
668*4882a593Smuzhiyun
669*4882a593SmuzhiyunAnd what about standards?
670*4882a593Smuzhiyun-------------------------
671*4882a593Smuzhiyun
672*4882a593SmuzhiyunYou might hesitate to accept this proposal as it comes from the
673*4882a593SmuzhiyunLinux community, and not from some standardizing institute. What
674*4882a593Smuzhiyunabout SUN, SGI, HP and all those other Unix and hardware vendors?
675*4882a593SmuzhiyunWell, these companies are in the lucky position that they generally
676*4882a593Smuzhiyuncontrol both the hardware and software of their supported products,
677*4882a593Smuzhiyunand are large enough to set their own standard. They do not have to
678*4882a593Smuzhiyundeal with a dozen or more different, competing hardware
679*4882a593Smuzhiyunconfigurations\ [#f3]_.
680*4882a593Smuzhiyun
681*4882a593Smuzhiyun.. [#f3]
682*4882a593Smuzhiyun
683*4882a593Smuzhiyun   Incidentally, I think that SUN's approach to mounting CD-ROM s is very
684*4882a593Smuzhiyun   good in origin: under Solaris a volume-daemon automatically mounts a
685*4882a593Smuzhiyun   newly inserted CD-ROM under `/cdrom/*<volume-name>*`.
686*4882a593Smuzhiyun
687*4882a593Smuzhiyun   In my opinion they should have pushed this
688*4882a593Smuzhiyun   further and have **every** CD-ROM on the local area network be
689*4882a593Smuzhiyun   mounted at the similar location, i. e., no matter in which particular
690*4882a593Smuzhiyun   machine you insert a CD-ROM, it will always appear at the same
691*4882a593Smuzhiyun   position in the directory tree, on every system. When I wanted to
692*4882a593Smuzhiyun   implement such a user-program for Linux, I came across the
693*4882a593Smuzhiyun   differences in behavior of the various drivers, and the need for an
694*4882a593Smuzhiyun   *ioctl* informing about media changes.
695*4882a593Smuzhiyun
696*4882a593SmuzhiyunWe believe that using *O_NONBLOCK* to indicate that a device is being opened
697*4882a593Smuzhiyunfor *ioctl* commands only can be easily introduced in the Linux
698*4882a593Smuzhiyuncommunity. All the CD-player authors will have to be informed, we can
699*4882a593Smuzhiyuneven send in our own patches to the programs. The use of *O_NONBLOCK*
700*4882a593Smuzhiyunhas most likely no influence on the behavior of the CD-players on
701*4882a593Smuzhiyunother operating systems than Linux. Finally, a user can always revert
702*4882a593Smuzhiyunto old behavior by a call to
703*4882a593Smuzhiyun*ioctl(file_descriptor, CDROM_CLEAR_OPTIONS, CDO_USE_FFLAGS)*.
704*4882a593Smuzhiyun
705*4882a593SmuzhiyunThe preferred strategy of *open()*
706*4882a593Smuzhiyun----------------------------------
707*4882a593Smuzhiyun
708*4882a593SmuzhiyunThe routines in `cdrom.c` are designed in such a way that run-time
709*4882a593Smuzhiyunconfiguration of the behavior of CD-ROM devices (of **any** type)
710*4882a593Smuzhiyuncan be carried out, by the *CDROM_SET/CLEAR_OPTIONS* *ioctls*. Thus, various
711*4882a593Smuzhiyunmodes of operation can be set:
712*4882a593Smuzhiyun
713*4882a593Smuzhiyun`CDO_AUTO_CLOSE | CDO_USE_FFLAGS | CDO_LOCK`
714*4882a593Smuzhiyun   This is the default setting. (With *CDO_CHECK_TYPE* it will be better, in
715*4882a593Smuzhiyun   the future.) If the device is not yet opened by any other process, and if
716*4882a593Smuzhiyun   the device is being opened for data (*O_NONBLOCK* is not set) and the
717*4882a593Smuzhiyun   tray is found to be open, an attempt to close the tray is made. Then,
718*4882a593Smuzhiyun   it is verified that a disc is in the drive and, if *CDO_CHECK_TYPE* is
719*4882a593Smuzhiyun   set, that it contains tracks of type `data mode 1`. Only if all tests
720*4882a593Smuzhiyun   are passed is the return value zero. The door is locked to prevent file
721*4882a593Smuzhiyun   system corruption. If the drive is opened for audio (*O_NONBLOCK* is
722*4882a593Smuzhiyun   set), no actions are taken and a value of 0 will be returned.
723*4882a593Smuzhiyun
724*4882a593Smuzhiyun`CDO_AUTO_CLOSE | CDO_AUTO_EJECT | CDO_LOCK`
725*4882a593Smuzhiyun   This mimics the behavior of the current sbpcd-driver. The option flags are
726*4882a593Smuzhiyun   ignored, the tray is closed on the first open, if necessary. Similarly,
727*4882a593Smuzhiyun   the tray is opened on the last release, i. e., if a CD-ROM is unmounted,
728*4882a593Smuzhiyun   it is automatically ejected, such that the user can replace it.
729*4882a593Smuzhiyun
730*4882a593SmuzhiyunWe hope that these option can convince everybody (both driver
731*4882a593Smuzhiyunmaintainers and user program developers) to adopt the new CD-ROM
732*4882a593Smuzhiyundriver scheme and option flag interpretation.
733*4882a593Smuzhiyun
734*4882a593SmuzhiyunDescription of routines in `cdrom.c`
735*4882a593Smuzhiyun====================================
736*4882a593Smuzhiyun
737*4882a593SmuzhiyunOnly a few routines in `cdrom.c` are exported to the drivers. In this
738*4882a593Smuzhiyunnew section we will discuss these, as well as the functions that `take
739*4882a593Smuzhiyunover` the CD-ROM interface to the kernel. The header file belonging
740*4882a593Smuzhiyunto `cdrom.c` is called `cdrom.h`. Formerly, some of the contents of this
741*4882a593Smuzhiyunfile were placed in the file `ucdrom.h`, but this file has now been
742*4882a593Smuzhiyunmerged back into `cdrom.h`.
743*4882a593Smuzhiyun
744*4882a593Smuzhiyun::
745*4882a593Smuzhiyun
746*4882a593Smuzhiyun	struct file_operations cdrom_fops
747*4882a593Smuzhiyun
748*4882a593SmuzhiyunThe contents of this structure were described in cdrom_api_.
749*4882a593SmuzhiyunA pointer to this structure is assigned to the *fops* field
750*4882a593Smuzhiyunof the *struct gendisk*.
751*4882a593Smuzhiyun
752*4882a593Smuzhiyun::
753*4882a593Smuzhiyun
754*4882a593Smuzhiyun	int register_cdrom(struct cdrom_device_info *cdi)
755*4882a593Smuzhiyun
756*4882a593SmuzhiyunThis function is used in about the same way one registers *cdrom_fops*
757*4882a593Smuzhiyunwith the kernel, the device operations and information structures,
758*4882a593Smuzhiyunas described in cdrom_api_, should be registered with the
759*4882a593SmuzhiyunUniform CD-ROM Driver::
760*4882a593Smuzhiyun
761*4882a593Smuzhiyun	register_cdrom(&<device>_info);
762*4882a593Smuzhiyun
763*4882a593Smuzhiyun
764*4882a593SmuzhiyunThis function returns zero upon success, and non-zero upon
765*4882a593Smuzhiyunfailure. The structure *<device>_info* should have a pointer to the
766*4882a593Smuzhiyundriver's *<device>_dops*, as in::
767*4882a593Smuzhiyun
768*4882a593Smuzhiyun	struct cdrom_device_info <device>_info = {
769*4882a593Smuzhiyun		<device>_dops;
770*4882a593Smuzhiyun		...
771*4882a593Smuzhiyun	}
772*4882a593Smuzhiyun
773*4882a593SmuzhiyunNote that a driver must have one static structure, *<device>_dops*, while
774*4882a593Smuzhiyunit may have as many structures *<device>_info* as there are minor devices
775*4882a593Smuzhiyunactive. *Register_cdrom()* builds a linked list from these.
776*4882a593Smuzhiyun
777*4882a593Smuzhiyun
778*4882a593Smuzhiyun::
779*4882a593Smuzhiyun
780*4882a593Smuzhiyun	void unregister_cdrom(struct cdrom_device_info *cdi)
781*4882a593Smuzhiyun
782*4882a593SmuzhiyunUnregistering device *cdi* with minor number *MINOR(cdi->dev)* removes
783*4882a593Smuzhiyunthe minor device from the list. If it was the last registered minor for
784*4882a593Smuzhiyunthe low-level driver, this disconnects the registered device-operation
785*4882a593Smuzhiyunroutines from the CD-ROM interface. This function returns zero upon
786*4882a593Smuzhiyunsuccess, and non-zero upon failure.
787*4882a593Smuzhiyun
788*4882a593Smuzhiyun::
789*4882a593Smuzhiyun
790*4882a593Smuzhiyun	int cdrom_open(struct inode * ip, struct file * fp)
791*4882a593Smuzhiyun
792*4882a593SmuzhiyunThis function is not called directly by the low-level drivers, it is
793*4882a593Smuzhiyunlisted in the standard *cdrom_fops*. If the VFS opens a file, this
794*4882a593Smuzhiyunfunction becomes active. A strategy is implemented in this routine,
795*4882a593Smuzhiyuntaking care of all capabilities and options that are set in the
796*4882a593Smuzhiyun*cdrom_device_ops* connected to the device. Then, the program flow is
797*4882a593Smuzhiyuntransferred to the device_dependent *open()* call.
798*4882a593Smuzhiyun
799*4882a593Smuzhiyun::
800*4882a593Smuzhiyun
801*4882a593Smuzhiyun	void cdrom_release(struct inode *ip, struct file *fp)
802*4882a593Smuzhiyun
803*4882a593SmuzhiyunThis function implements the reverse-logic of *cdrom_open()*, and then
804*4882a593Smuzhiyuncalls the device-dependent *release()* routine. When the use-count has
805*4882a593Smuzhiyunreached 0, the allocated buffers are flushed by calls to *sync_dev(dev)*
806*4882a593Smuzhiyunand *invalidate_buffers(dev)*.
807*4882a593Smuzhiyun
808*4882a593Smuzhiyun
809*4882a593Smuzhiyun.. _cdrom_ioctl:
810*4882a593Smuzhiyun
811*4882a593Smuzhiyun::
812*4882a593Smuzhiyun
813*4882a593Smuzhiyun	int cdrom_ioctl(struct inode *ip, struct file *fp,
814*4882a593Smuzhiyun			unsigned int cmd, unsigned long arg)
815*4882a593Smuzhiyun
816*4882a593SmuzhiyunThis function handles all the standard *ioctl* requests for CD-ROM
817*4882a593Smuzhiyundevices in a uniform way. The different calls fall into three
818*4882a593Smuzhiyuncategories: *ioctl()'s* that can be directly implemented by device
819*4882a593Smuzhiyunoperations, ones that are routed through the call *audio_ioctl()*, and
820*4882a593Smuzhiyunthe remaining ones, that are presumable device-dependent. Generally, a
821*4882a593Smuzhiyunnegative return value indicates an error.
822*4882a593Smuzhiyun
823*4882a593SmuzhiyunDirectly implemented *ioctl()'s*
824*4882a593Smuzhiyun--------------------------------
825*4882a593Smuzhiyun
826*4882a593SmuzhiyunThe following `old` CD-ROM *ioctl()*\ 's are implemented by directly
827*4882a593Smuzhiyuncalling device-operations in *cdrom_device_ops*, if implemented and
828*4882a593Smuzhiyunnot masked:
829*4882a593Smuzhiyun
830*4882a593Smuzhiyun`CDROMMULTISESSION`
831*4882a593Smuzhiyun	Requests the last session on a CD-ROM.
832*4882a593Smuzhiyun`CDROMEJECT`
833*4882a593Smuzhiyun	Open tray.
834*4882a593Smuzhiyun`CDROMCLOSETRAY`
835*4882a593Smuzhiyun	Close tray.
836*4882a593Smuzhiyun`CDROMEJECT_SW`
837*4882a593Smuzhiyun	If *arg\not=0*, set behavior to auto-close (close
838*4882a593Smuzhiyun	tray on first open) and auto-eject (eject on last release), otherwise
839*4882a593Smuzhiyun	set behavior to non-moving on *open()* and *release()* calls.
840*4882a593Smuzhiyun`CDROM_GET_MCN`
841*4882a593Smuzhiyun	Get the Media Catalog Number from a CD.
842*4882a593Smuzhiyun
843*4882a593Smuzhiyun*Ioctl*s routed through *audio_ioctl()*
844*4882a593Smuzhiyun---------------------------------------
845*4882a593Smuzhiyun
846*4882a593SmuzhiyunThe following set of *ioctl()'s* are all implemented through a call to
847*4882a593Smuzhiyunthe *cdrom_fops* function *audio_ioctl()*. Memory checks and
848*4882a593Smuzhiyunallocation are performed in *cdrom_ioctl()*, and also sanitization of
849*4882a593Smuzhiyunaddress format (*CDROM_LBA*/*CDROM_MSF*) is done.
850*4882a593Smuzhiyun
851*4882a593Smuzhiyun`CDROMSUBCHNL`
852*4882a593Smuzhiyun	Get sub-channel data in argument *arg* of type
853*4882a593Smuzhiyun	`struct cdrom_subchnl *`.
854*4882a593Smuzhiyun`CDROMREADTOCHDR`
855*4882a593Smuzhiyun	Read Table of Contents header, in *arg* of type
856*4882a593Smuzhiyun	`struct cdrom_tochdr *`.
857*4882a593Smuzhiyun`CDROMREADTOCENTRY`
858*4882a593Smuzhiyun	Read a Table of Contents entry in *arg* and specified by *arg*
859*4882a593Smuzhiyun	of type `struct cdrom_tocentry *`.
860*4882a593Smuzhiyun`CDROMPLAYMSF`
861*4882a593Smuzhiyun	Play audio fragment specified in Minute, Second, Frame format,
862*4882a593Smuzhiyun	delimited by *arg* of type `struct cdrom_msf *`.
863*4882a593Smuzhiyun`CDROMPLAYTRKIND`
864*4882a593Smuzhiyun	Play audio fragment in track-index format delimited by *arg*
865*4882a593Smuzhiyun	of type `struct cdrom_ti *`.
866*4882a593Smuzhiyun`CDROMVOLCTRL`
867*4882a593Smuzhiyun	Set volume specified by *arg* of type `struct cdrom_volctrl *`.
868*4882a593Smuzhiyun`CDROMVOLREAD`
869*4882a593Smuzhiyun	Read volume into by *arg* of type `struct cdrom_volctrl *`.
870*4882a593Smuzhiyun`CDROMSTART`
871*4882a593Smuzhiyun	Spin up disc.
872*4882a593Smuzhiyun`CDROMSTOP`
873*4882a593Smuzhiyun	Stop playback of audio fragment.
874*4882a593Smuzhiyun`CDROMPAUSE`
875*4882a593Smuzhiyun	Pause playback of audio fragment.
876*4882a593Smuzhiyun`CDROMRESUME`
877*4882a593Smuzhiyun	Resume playing.
878*4882a593Smuzhiyun
879*4882a593SmuzhiyunNew *ioctl()'s* in `cdrom.c`
880*4882a593Smuzhiyun----------------------------
881*4882a593Smuzhiyun
882*4882a593SmuzhiyunThe following *ioctl()'s* have been introduced to allow user programs to
883*4882a593Smuzhiyuncontrol the behavior of individual CD-ROM devices. New *ioctl*
884*4882a593Smuzhiyuncommands can be identified by the underscores in their names.
885*4882a593Smuzhiyun
886*4882a593Smuzhiyun`CDROM_SET_OPTIONS`
887*4882a593Smuzhiyun	Set options specified by *arg*. Returns the option flag register
888*4882a593Smuzhiyun	after modification. Use *arg = \rm0* for reading the current flags.
889*4882a593Smuzhiyun`CDROM_CLEAR_OPTIONS`
890*4882a593Smuzhiyun	Clear options specified by *arg*. Returns the option flag register
891*4882a593Smuzhiyun	after modification.
892*4882a593Smuzhiyun`CDROM_SELECT_SPEED`
893*4882a593Smuzhiyun	Select head-rate speed of disc specified as by *arg* in units
894*4882a593Smuzhiyun	of standard cdrom speed (176\,kB/sec raw data or
895*4882a593Smuzhiyun	150kB/sec file system data). The value 0 means `auto-select`,
896*4882a593Smuzhiyun	i. e., play audio discs at real time and data discs at maximum speed.
897*4882a593Smuzhiyun	The value *arg* is checked against the maximum head rate of the
898*4882a593Smuzhiyun	drive found in the *cdrom_dops*.
899*4882a593Smuzhiyun`CDROM_SELECT_DISC`
900*4882a593Smuzhiyun	Select disc numbered *arg* from a juke-box.
901*4882a593Smuzhiyun
902*4882a593Smuzhiyun	First disc is numbered 0. The number *arg* is checked against the
903*4882a593Smuzhiyun	maximum number of discs in the juke-box found in the *cdrom_dops*.
904*4882a593Smuzhiyun`CDROM_MEDIA_CHANGED`
905*4882a593Smuzhiyun	Returns 1 if a disc has been changed since the last call.
906*4882a593Smuzhiyun	For juke-boxes, an extra argument *arg*
907*4882a593Smuzhiyun	specifies the slot for which the information is given. The special
908*4882a593Smuzhiyun	value *CDSL_CURRENT* requests that information about the currently
909*4882a593Smuzhiyun	selected slot be returned.
910*4882a593Smuzhiyun`CDROM_DRIVE_STATUS`
911*4882a593Smuzhiyun	Returns the status of the drive by a call to
912*4882a593Smuzhiyun	*drive_status()*. Return values are defined in cdrom_drive_status_.
913*4882a593Smuzhiyun	Note that this call doesn't return information on the
914*4882a593Smuzhiyun	current playing activity of the drive; this can be polled through
915*4882a593Smuzhiyun	an *ioctl* call to *CDROMSUBCHNL*. For juke-boxes, an extra argument
916*4882a593Smuzhiyun	*arg* specifies the slot for which (possibly limited) information is
917*4882a593Smuzhiyun	given. The special value *CDSL_CURRENT* requests that information
918*4882a593Smuzhiyun	about the currently selected slot be returned.
919*4882a593Smuzhiyun`CDROM_DISC_STATUS`
920*4882a593Smuzhiyun	Returns the type of the disc currently in the drive.
921*4882a593Smuzhiyun	It should be viewed as a complement to *CDROM_DRIVE_STATUS*.
922*4882a593Smuzhiyun	This *ioctl* can provide *some* information about the current
923*4882a593Smuzhiyun	disc that is inserted in the drive. This functionality used to be
924*4882a593Smuzhiyun	implemented in the low level drivers, but is now carried out
925*4882a593Smuzhiyun	entirely in Uniform CD-ROM Driver.
926*4882a593Smuzhiyun
927*4882a593Smuzhiyun	The history of development of the CD's use as a carrier medium for
928*4882a593Smuzhiyun	various digital information has lead to many different disc types.
929*4882a593Smuzhiyun	This *ioctl* is useful only in the case that CDs have \emph {only
930*4882a593Smuzhiyun	one} type of data on them. While this is often the case, it is
931*4882a593Smuzhiyun	also very common for CDs to have some tracks with data, and some
932*4882a593Smuzhiyun	tracks with audio. Because this is an existing interface, rather
933*4882a593Smuzhiyun	than fixing this interface by changing the assumptions it was made
934*4882a593Smuzhiyun	under, thereby breaking all user applications that use this
935*4882a593Smuzhiyun	function, the Uniform CD-ROM Driver implements this *ioctl* as
936*4882a593Smuzhiyun	follows: If the CD in question has audio tracks on it, and it has
937*4882a593Smuzhiyun	absolutely no CD-I, XA, or data tracks on it, it will be reported
938*4882a593Smuzhiyun	as *CDS_AUDIO*. If it has both audio and data tracks, it will
939*4882a593Smuzhiyun	return *CDS_MIXED*. If there are no audio tracks on the disc, and
940*4882a593Smuzhiyun	if the CD in question has any CD-I tracks on it, it will be
941*4882a593Smuzhiyun	reported as *CDS_XA_2_2*. Failing that, if the CD in question
942*4882a593Smuzhiyun	has any XA tracks on it, it will be reported as *CDS_XA_2_1*.
943*4882a593Smuzhiyun	Finally, if the CD in question has any data tracks on it,
944*4882a593Smuzhiyun	it will be reported as a data CD (*CDS_DATA_1*).
945*4882a593Smuzhiyun
946*4882a593Smuzhiyun	This *ioctl* can return::
947*4882a593Smuzhiyun
948*4882a593Smuzhiyun		CDS_NO_INFO	/* no information available */
949*4882a593Smuzhiyun		CDS_NO_DISC	/* no disc is inserted, or tray is opened */
950*4882a593Smuzhiyun		CDS_AUDIO	/* Audio disc (2352 audio bytes/frame) */
951*4882a593Smuzhiyun		CDS_DATA_1	/* data disc, mode 1 (2048 user bytes/frame) */
952*4882a593Smuzhiyun		CDS_XA_2_1	/* mixed data (XA), mode 2, form 1 (2048 user bytes) */
953*4882a593Smuzhiyun		CDS_XA_2_2	/* mixed data (XA), mode 2, form 1 (2324 user bytes) */
954*4882a593Smuzhiyun		CDS_MIXED	/* mixed audio/data disc */
955*4882a593Smuzhiyun
956*4882a593Smuzhiyun	For some information concerning frame layout of the various disc
957*4882a593Smuzhiyun	types, see a recent version of `cdrom.h`.
958*4882a593Smuzhiyun
959*4882a593Smuzhiyun`CDROM_CHANGER_NSLOTS`
960*4882a593Smuzhiyun	Returns the number of slots in a juke-box.
961*4882a593Smuzhiyun`CDROMRESET`
962*4882a593Smuzhiyun	Reset the drive.
963*4882a593Smuzhiyun`CDROM_GET_CAPABILITY`
964*4882a593Smuzhiyun	Returns the *capability* flags for the drive. Refer to section
965*4882a593Smuzhiyun	cdrom_capabilities_ for more information on these flags.
966*4882a593Smuzhiyun`CDROM_LOCKDOOR`
967*4882a593Smuzhiyun	 Locks the door of the drive. `arg == 0` unlocks the door,
968*4882a593Smuzhiyun	 any other value locks it.
969*4882a593Smuzhiyun`CDROM_DEBUG`
970*4882a593Smuzhiyun	 Turns on debugging info. Only root is allowed to do this.
971*4882a593Smuzhiyun	 Same semantics as CDROM_LOCKDOOR.
972*4882a593Smuzhiyun
973*4882a593Smuzhiyun
974*4882a593SmuzhiyunDevice dependent *ioctl()'s*
975*4882a593Smuzhiyun----------------------------
976*4882a593Smuzhiyun
977*4882a593SmuzhiyunFinally, all other *ioctl()'s* are passed to the function *dev_ioctl()*,
978*4882a593Smuzhiyunif implemented. No memory allocation or verification is carried out.
979*4882a593Smuzhiyun
980*4882a593SmuzhiyunHow to update your driver
981*4882a593Smuzhiyun=========================
982*4882a593Smuzhiyun
983*4882a593Smuzhiyun- Make a backup of your current driver.
984*4882a593Smuzhiyun- Get hold of the files `cdrom.c` and `cdrom.h`, they should be in
985*4882a593Smuzhiyun  the directory tree that came with this documentation.
986*4882a593Smuzhiyun- Make sure you include `cdrom.h`.
987*4882a593Smuzhiyun- Change the 3rd argument of *register_blkdev* from `&<your-drive>_fops`
988*4882a593Smuzhiyun  to `&cdrom_fops`.
989*4882a593Smuzhiyun- Just after that line, add the following to register with the Uniform
990*4882a593Smuzhiyun  CD-ROM Driver::
991*4882a593Smuzhiyun
992*4882a593Smuzhiyun	register_cdrom(&<your-drive>_info);*
993*4882a593Smuzhiyun
994*4882a593Smuzhiyun  Similarly, add a call to *unregister_cdrom()* at the appropriate place.
995*4882a593Smuzhiyun- Copy an example of the device-operations *struct* to your
996*4882a593Smuzhiyun  source, e. g., from `cm206.c` *cm206_dops*, and change all
997*4882a593Smuzhiyun  entries to names corresponding to your driver, or names you just
998*4882a593Smuzhiyun  happen to like. If your driver doesn't support a certain function,
999*4882a593Smuzhiyun  make the entry *NULL*. At the entry *capability* you should list all
1000*4882a593Smuzhiyun  capabilities your driver currently supports. If your driver
1001*4882a593Smuzhiyun  has a capability that is not listed, please send me a message.
1002*4882a593Smuzhiyun- Copy the *cdrom_device_info* declaration from the same example
1003*4882a593Smuzhiyun  driver, and modify the entries according to your needs. If your
1004*4882a593Smuzhiyun  driver dynamically determines the capabilities of the hardware, this
1005*4882a593Smuzhiyun  structure should also be declared dynamically.
1006*4882a593Smuzhiyun- Implement all functions in your `<device>_dops` structure,
1007*4882a593Smuzhiyun  according to prototypes listed in  `cdrom.h`, and specifications given
1008*4882a593Smuzhiyun  in cdrom_api_. Most likely you have already implemented
1009*4882a593Smuzhiyun  the code in a large part, and you will almost certainly need to adapt the
1010*4882a593Smuzhiyun  prototype and return values.
1011*4882a593Smuzhiyun- Rename your `<device>_ioctl()` function to *audio_ioctl* and
1012*4882a593Smuzhiyun  change the prototype a little. Remove entries listed in the first
1013*4882a593Smuzhiyun  part in cdrom_ioctl_, if your code was OK, these are
1014*4882a593Smuzhiyun  just calls to the routines you adapted in the previous step.
1015*4882a593Smuzhiyun- You may remove all remaining memory checking code in the
1016*4882a593Smuzhiyun  *audio_ioctl()* function that deals with audio commands (these are
1017*4882a593Smuzhiyun  listed in the second part of cdrom_ioctl_. There is no
1018*4882a593Smuzhiyun  need for memory allocation either, so most *case*s in the *switch*
1019*4882a593Smuzhiyun  statement look similar to::
1020*4882a593Smuzhiyun
1021*4882a593Smuzhiyun	case CDROMREADTOCENTRY:
1022*4882a593Smuzhiyun		get_toc_entry\bigl((struct cdrom_tocentry *) arg);
1023*4882a593Smuzhiyun
1024*4882a593Smuzhiyun- All remaining *ioctl* cases must be moved to a separate
1025*4882a593Smuzhiyun  function, *<device>_ioctl*, the device-dependent *ioctl()'s*. Note that
1026*4882a593Smuzhiyun  memory checking and allocation must be kept in this code!
1027*4882a593Smuzhiyun- Change the prototypes of *<device>_open()* and
1028*4882a593Smuzhiyun  *<device>_release()*, and remove any strategic code (i. e., tray
1029*4882a593Smuzhiyun  movement, door locking, etc.).
1030*4882a593Smuzhiyun- Try to recompile the drivers. We advise you to use modules, both
1031*4882a593Smuzhiyun  for `cdrom.o` and your driver, as debugging is much easier this
1032*4882a593Smuzhiyun  way.
1033*4882a593Smuzhiyun
1034*4882a593SmuzhiyunThanks
1035*4882a593Smuzhiyun======
1036*4882a593Smuzhiyun
1037*4882a593SmuzhiyunThanks to all the people involved. First, Erik Andersen, who has
1038*4882a593Smuzhiyuntaken over the torch in maintaining `cdrom.c` and integrating much
1039*4882a593SmuzhiyunCD-ROM-related code in the 2.1-kernel. Thanks to Scott Snyder and
1040*4882a593SmuzhiyunGerd Knorr, who were the first to implement this interface for SCSI
1041*4882a593Smuzhiyunand IDE-CD drivers and added many ideas for extension of the data
1042*4882a593Smuzhiyunstructures relative to kernel~2.0. Further thanks to Heiko Eißfeldt,
1043*4882a593SmuzhiyunThomas Quinot, Jon Tombs, Ken Pizzini, Eberhard Mönkeberg and Andrew Kroll,
1044*4882a593Smuzhiyunthe Linux CD-ROM device driver developers who were kind
1045*4882a593Smuzhiyunenough to give suggestions and criticisms during the writing. Finally
1046*4882a593Smuzhiyunof course, I want to thank Linus Torvalds for making this possible in
1047*4882a593Smuzhiyunthe first place.
1048