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