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