xref: /freebsd/share/man/man4/cd.4 (revision c11e094d96120a2e0e726ed9705ae0ec08db49b6)
1.\" Copyright (c) 1996
2.\"	Julian Elischer <julian@FreeBSD.org>.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\"
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.\" $FreeBSD$
27.\"
28.Dd October 10, 1998
29.Dt CD 4
30.Os
31.Sh NAME
32.Nm cd
33.Nd SCSI CD-ROM driver
34.Sh SYNOPSIS
35.Cd device cd
36.Cd "options ""CHANGER_MIN_BUSY_SECONDS=3"""
37.Cd "options ""CHANGER_MAX_BUSY_SECONDS=11""
38.Sh DESCRIPTION
39The
40.Nm
41driver provides support for a
42.Tn SCSI
43.Tn CD-ROM
44(Compact Disc-Read Only Memory) drive.
45In an attempt to look like a regular disk, the
46.Nm
47driver synthesizes a partition table, with one partition covering the entire
48.Tn CD-ROM .
49It is possible to modify this partition table using
50.Xr disklabel 8 ,
51but it will only last until the
52.Tn CD-ROM
53is unmounted.
54In general the interfaces are similar to those described by
55.Xr ad 4
56and
57.Xr da 4 .
58.Pp
59As the
60.Tn SCSI
61adapter is probed during boot, the
62.Tn SCSI
63bus is scanned for devices.
64Any devices found which answer as CDROM
65(type 5) or WORM (type 4) type devices will be `attached' to the
66.Nm
67driver.
68Prior to
69.Fx 2.1 ,
70the first device found will be attached as
71.Li cd0
72the next,
73.Li cd1 ,
74etc.
75Beginning in
76.Fx 2.1
77it is possible to specify what cd unit a device should
78come on line as; refer to
79.Xr scsi 4
80for details on kernel configuration.
81.Pp
82The system utility
83.Xr disklabel 8
84may be used to read the synthesized
85disk label
86structure, which will contain correct figures for the size of the
87.Tn CD-ROM
88should that information be required.
89.Sh KERNEL CONFIGURATION
90Any number of
91.Tn CD-ROM
92devices may be attached to the system regardless of system
93configuration as all resources are dynamically allocated.
94.Sh IOCTLS
95The following
96.Xr ioctl 2
97calls which apply to
98.Tn SCSI
99.Tn CD-ROM
100drives are defined
101in the header files
102.Aq Pa sys/cdio.h
103and
104.Aq Pa sys/disklabel.h .
105.Pp
106.Bl -tag -width CDIOCREADSUBCHANNEL
107.It Dv DIOCGDINFO
108.It Dv DIOCSDINFO
109.Pq Li "struct disklabel"
110Read or write the in-core copy of the disklabel for the
111drive.  The disklabel is initialized with information
112read from the scsi inquiry commands, and should be the same as
113the information printed at boot.  This structure is defined in
114.Xr disklabel 5 .
115.It Dv CDIOCCAPABILITY
116.Pq Li "struct ioc_capability"
117Retrieve information from the drive on what features it supports.  The
118information is returned in the following structure:
119.Bd -literal -offset indent
120struct ioc_capability {
121	u_long	play_function;
122#define CDDOPLAYTRK	0x00000001
123	/* Can play tracks/index */
124#define	CDDOPLAYMSF	0x00000002
125	/* Can play msf to msf */
126#define	CDDOPLAYBLOCKS	0x00000004
127	/* Can play range of blocks */
128#define	CDDOPAUSE	0x00000100
129	/* Output can be paused */
130#define	CDDORESUME	0x00000200
131	/* Output can be resumed */
132#define	CDDORESET	0x00000400
133	/* Drive can be completely reset */
134#define	CDDOSTART	0x00000800
135	/* Audio can be started */
136#define CDDOSTOP	0x00001000
137	/* Audio can be stopped */
138#define CDDOPITCH	0x00002000
139	/* Audio pitch can be changed */
140
141	u_long	routing_function;
142#define CDREADVOLUME	0x00000001
143	/* Volume settings can be read */
144#define CDSETVOLUME	0x00000002
145	/* Volume settings can be set */
146#define	CDSETMONO	0x00000100
147	/* Output can be set to mono */
148#define CDSETSTEREO	0x00000200
149	/* Output can be set to stereo (def) */
150#define	CDSETLEFT	0x00000400
151	/* Output can be set to left only */
152#define	CDSETRIGHT	0x00000800
153	/* Output can be set to right only */
154#define	CDSETMUTE	0x00001000
155	/* Output can be muted */
156#define CDSETPATCH	0x00008000
157	/* Direct routing control allowed */
158
159	u_long	special_function;
160#define	CDDOEJECT	0x00000001
161	/* The tray can be opened */
162#define	CDDOCLOSE	0x00000002
163	/* The tray can be closed */
164#define	CDDOLOCK	0x00000004
165	/* The tray can be locked */
166#define CDREADHEADER	0x00000100
167	/* Can read Table of Contents */
168#define	CDREADENTRIES	0x00000200
169	/* Can read TOC Entries */
170#define	CDREADSUBQ	0x00000200
171	/* Can read Subchannel info */
172#define CDREADRW	0x00000400
173	/* Can read subcodes R-W */
174#define	CDHASDEBUG	0x00004000
175	/* The tray has dynamic debugging */
176};
177.Ed
178.It Dv CDIOCPLAYTRACKS
179.Pq Li "struct ioc_play_track"
180Start audio playback given a track address and length.  The structure
181is defined as follows:
182.Bd -literal -offset indent
183struct ioc_play_track
184{
185	u_char	start_track;
186	u_char	start_index;
187	u_char	end_track;
188	u_char	end_index;
189};
190.Ed
191.It Dv CDIOCPLAYBLOCKS
192.Pq Li "struct ioc_play_blocks"
193Start audio playback given a block address and length.  The structure
194is defined as follows:
195.Bd -literal -offset indent
196struct ioc_play_blocks
197{
198	int	blk;
199	int	len;
200};
201.Ed
202.It Dv CDIOCPLAYMSF
203.Pq Li "struct ioc_play_msf"
204Start audio playback given a `minutes-seconds-frames' address and
205length.  The structure is defined as follows:
206.Bd -literal -offset indent
207struct ioc_play_msf
208{
209	u_char	start_m;
210	u_char	start_s;
211	u_char	start_f;
212	u_char	end_m;
213	u_char	end_s;
214	u_char	end_f;
215};
216.Ed
217.It Dv CDIOCREADSUBCHANNEL
218.Pq Li "struct ioc_read_subchannel"
219Read information from the subchannel at the location specified by this
220structure:
221.Bd -literal -offset indent
222struct ioc_read_subchannel {
223	u_char address_format;
224#define CD_LBA_FORMAT	1
225#define CD_MSF_FORMAT	2
226	u_char data_format;
227#define CD_SUBQ_DATA		0
228#define CD_CURRENT_POSITION	1
229#define CD_MEDIA_CATALOG	2
230#define CD_TRACK_INFO		3
231	u_char track;
232	int	data_len;
233	struct  cd_sub_channel_info *data;
234};
235.Ed
236.It Dv CDIOREADTOCHEADER
237.Pq Li "struct ioc_toc_header"
238Return summary information about the table of contents for the mounted
239.Tn CD-ROM .
240The information is returned into the following structure:
241.Bd -literal -offset indent
242struct ioc_toc_header {
243	u_short len;
244	u_char  starting_track;
245	u_char  ending_track;
246};
247.Ed
248.It Dv CDIOREADTOCENTRYS
249.Pq Li "struct ioc_read_toc_entry"
250Return information from the table of contents entries mentioned.  (Yes, this
251command name is misspelled.)  The argument structure is defined as follows:
252.Bd -literal -offset indent
253struct ioc_read_toc_entry {
254	u_char	address_format;
255	u_char	starting_track;
256	u_short	data_len;
257	struct  cd_toc_entry *data;
258};
259.Ed
260The requested data is written into an area of size
261.Li data_len
262and pointed to by
263.Li data .
264.It Dv CDIOCSETPATCH
265.Pq Li "struct ioc_patch"
266Attach various audio channels to various output channels.  The
267argument structure is defined thusly:
268.Bd -literal -offset indent
269struct ioc_patch {
270	u_char	patch[4];
271	/* one for each channel */
272};
273.Ed
274.It Dv CDIOCGETVOL
275.It Dv CDIOCSETVOL
276.Pq Li "struct ioc_vol"
277Get (set) information about the volume settings of the output channels.  The
278argument structure is as follows:
279.Bd -literal -offset indent
280struct	ioc_vol
281{
282	u_char	vol[4];
283	/* one for each channel */
284};
285.Ed
286.It Dv CDIOCSETMONO
287Patch all output channels to all source channels.
288.It Dv CDIOCSETSTEREO
289Patch left source channel to the left output channel and the right
290source channel to the right output channel.
291.It Dv CDIOCSETMUTE
292Mute output without changing the volume settings.
293.It Dv CDIOCSETLEFT
294.It Dv CDIOCSETRIGHT
295Attach both output channels to the left (right) source channel.
296.It Dv CDIOCSETDEBUG
297.It Dv CDIOCCLRDEBUG
298Turn on (off) debugging for the appropriate device.
299.It Dv CDIOCPAUSE
300.It Dv CDIOCRESUME
301Pause (resume) audio play, without resetting the location of the read-head.
302.It Dv CDIOCRESET
303Reset the drive.
304.It Dv CDIOCSTART
305.It Dv CDIOCSTOP
306Tell the drive to spin-up (-down) the
307.Tn CD-ROM .
308.It Dv CDIOCALLOW
309.It Dv CDIOCPREVENT
310Tell the drive to allow (prevent) manual ejection of the
311.Tn CD-ROM
312disc.  Not all drives support this feature.
313.It Dv CDIOCEJECT
314Eject the
315.Tn CD-ROM .
316.It Dv CDIOCCLOSE
317Tell the drive to close its door and load the media.  Not all drives
318support this feature.
319.It Dv CDIOCPITCH
320.Pq Li "struct ioc_pitch"
321For drives that support it, this command instructs the drive to play
322the audio at a faster or slower rate than normal.  Values of
323.Li speed
324between -32767 and -1 result in slower playback; a zero value
325indicates normal speed; and values from 1 to 32767 give faster
326playback.  Drives with less than 16 bits of resolution will silently
327ignore less-significant bits.  The structure is defined thusly:
328.Bd -literal -offset indent
329struct	ioc_pitch
330{
331	short	speed;
332};
333.Ed
334.El
335.Sh NOTES
336When a
337.Tn CD-ROM
338is changed in a drive controlled by the
339.Nm
340driver, then the act of changing the media will invalidate the
341disklabel and information held within the kernel.  To stop corruption,
342all accesses to the device will be discarded until there are no more
343open file descriptors referencing the device.  During this period, all
344new open attempts will be rejected.  When no more open file descriptors
345reference the device, the first next open will load a new set of
346parameters (including disklabel) for the drive.
347.Pp
348The audio code in the
349.Nm
350driver only support
351.Tn SCSI-2
352standard audio commands.
353Because many
354.Tn CD-ROM
355manufacturers have not followed the standard, there are many
356.Tn CD-ROM
357drives for which audio will not work.
358Some work is planned to support
359some of the more common `broken'
360.Tn CD-ROM
361drives; however, this is not yet under way.
362.Sh CHANGER OPERATION
363This driver has built-in support for LUN-based CD changers.  A LUN-based CD
364changer is a drive that can hold two or more CDs, but only has one CD
365player mechanism.  Each CD in the drive shows up as a separate logical unit
366on the
367.Tn SCSI
368bus.  The
369.Nm
370driver automatically recognizes LUN-based changers, and routes commands for
371changers through an internal scheduler.  The scheduler prevents changer
372"thrashing", which is caused by sending commands to different LUNs in the
373changer at the same time.
374.Pp
375The scheduler honors minimum and maximum time
376quanta that the driver will spend on a particular LUN.  The minimum time
377is the guaranteed minimum amount of time that the driver will spend on a
378given LUN, even if there is no outstanding I/O for that LUN.  The maximum
379time is the maximum amount of time the changer will spend on a LUN if there
380is outstanding I/O for another LUN.  If there is no outstanding I/O for
381another LUN, the driver will allow indefinite access to a given LUN.
382.Pp
383The minimum and maximum time quanta are configurable via kernel options and
384also via sysctl variables.  The kernel options are:
385.Pp
386.Bl -item -compact
387.It
388.Cd "options ""CHANGER_MIN_BUSY_SECONDS=3"""
389.It
390.Cd "options ""CHANGER_MAX_BUSY_SECONDS=11"""
391.El
392.Pp
393The sysctl variables are:
394.Pp
395.Bl -item -compact
396.It
397.Va kern.cam.cd.changer.min_busy_seconds
398.It
399.Va kern.cam.cd.changer.max_busy_seconds
400.El
401.Pp
402It is suggested that the user try experimenting with the minimum and
403maximum timeouts via the sysctl variables to arrive at the proper values
404for your changer.  Once you have settled on the proper timeouts for your
405changer, you can then put them in your kernel config file.
406.Pp
407If your system does have a LUN-based changer, you may notice that the
408probe messages for the various LUNs of the changer will continue to appear
409while the boot process is going on.  This is normal, and is caused by the
410changer scheduling code.
411.Sh FILES
412.Bl -tag -width /dev/cd[0-9][a-h] -compact
413.It Pa /dev/cd[0-9][a-h]
414raw mode
415.Tn CD-ROM
416devices
417.El
418.Sh DIAGNOSTICS
419None.
420.Sh SEE ALSO
421.Xr da 4 ,
422.Xr scsi 4 ,
423.Xr disklabel 5 ,
424.Xr disklabel 8 ,
425.Xr cd 9
426.Sh BUGS
427The names of the structures used for the third argument to
428.Fn ioctl
429were poorly chosen, and a number of spelling errors have survived in
430the names of the
431.Fn ioctl
432commands.
433.Pp
434There is no mechanism currently to set different minimum and maximum
435timeouts for different CD changers; the timeout values set by the kernel
436options or the sysctl variables apply to all LUN-based CD changers in the
437system.  It is possible to implement such support, but the sysctl
438implementation at least would be rather inelegant, because of the current
439inability of the sysctl code to handle the addition of nodes after compile
440time.  Thus, it would take one dynamically sized sysctl variable and a
441userland utility to get/set the timeout values.  Implementation of separate
442timeouts for different CD devices in the kernel config file would likely
443require modification of
444.Xr config 8
445to support the two timeouts when hardwiring
446.Nm
447devices.
448.Sh HISTORY
449This
450.Nm
451driver is based upon the
452.Nm
453driver written by Julian Elischer, which appeared in
454.Bx 386 0.1 .
455The
456CAM version of the
457.Nm
458driver was written by Kenneth Merry and first appeared in
459.Fx 3.0 .
460