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.\" 28.Dd February 18, 2019 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 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 84.Cd target 85string is followed by the device's standard 86.Tn SCSI 87device ID number. 88The 89.Cd unit 90string is followed by the Logical Unit Number 91.Pq Tn LUN 92of the 93.Tn SCSI 94device's sub-device, if any, or zero. 95.Pp 96The system utility 97.Xr disklabel 8 98may be used to read the synthesized 99disk label 100structure, which will contain correct figures for the size of the 101.Tn CD-ROM 102should that information be required. 103.Sh IOCTLS 104The following 105.Xr ioctl 2 106calls which apply to 107.Tn SCSI 108.Tn CD-ROM 109drives are defined 110in the header files 111.In sys/cdio.h 112and 113.In sys/disklabel.h . 114.Bl -tag -width ".Dv CDIOCREADSUBCHANNEL" 115.It Dv DIOCGDINFO 116.It Dv DIOCSDINFO 117.Pq Li "struct disklabel" 118Read or write the in-core copy of the disklabel for the 119drive. 120The disklabel is initialized with information 121read from the scsi inquiry commands, and should be the same as 122the information printed at boot. 123This structure is defined in 124.Xr disklabel 5 . 125.It Dv CDIOCPLAYTRACKS 126.Pq Li "struct ioc_play_track" 127Start audio playback given a track address and length. 128The structure is defined as follows: 129.Bd -literal -offset indent 130struct ioc_play_track 131{ 132 u_char start_track; 133 u_char start_index; 134 u_char end_track; 135 u_char end_index; 136}; 137.Ed 138.It Dv CDIOCPLAYBLOCKS 139.Pq Li "struct ioc_play_blocks" 140Start audio playback given a block address and length. 141The structure is defined as follows: 142.Bd -literal -offset indent 143struct ioc_play_blocks 144{ 145 int blk; 146 int len; 147}; 148.Ed 149.It Dv CDIOCPLAYMSF 150.Pq Li "struct ioc_play_msf" 151Start audio playback given a `minutes-seconds-frames' address and 152length. 153The structure is defined as follows: 154.Bd -literal -offset indent 155struct ioc_play_msf 156{ 157 u_char start_m; 158 u_char start_s; 159 u_char start_f; 160 u_char end_m; 161 u_char end_s; 162 u_char end_f; 163}; 164.Ed 165.It Dv CDIOCREADSUBCHANNEL 166.Pq Li "struct ioc_read_subchannel" 167Read information from the subchannel at the location specified by this 168structure: 169.Bd -literal -offset indent 170struct ioc_read_subchannel { 171 u_char address_format; 172#define CD_LBA_FORMAT 1 173#define CD_MSF_FORMAT 2 174 u_char data_format; 175#define CD_SUBQ_DATA 0 176#define CD_CURRENT_POSITION 1 177#define CD_MEDIA_CATALOG 2 178#define CD_TRACK_INFO 3 179 u_char track; 180 int data_len; 181 struct cd_sub_channel_info *data; 182}; 183.Ed 184.It Dv CDIOREADTOCHEADER 185.Pq Li "struct ioc_toc_header" 186Return summary information about the table of contents for the mounted 187.Tn CD-ROM . 188The information is returned into the following structure: 189.Bd -literal -offset indent 190struct ioc_toc_header { 191 u_short len; 192 u_char starting_track; 193 u_char ending_track; 194}; 195.Ed 196.It Dv CDIOREADTOCENTRYS 197.Pq Li "struct ioc_read_toc_entry" 198Return information from the table of contents entries mentioned. 199.Pq Yes, this command name is misspelled. 200The argument structure is defined as follows: 201.Bd -literal -offset indent 202struct ioc_read_toc_entry { 203 u_char address_format; 204 u_char starting_track; 205 u_short data_len; 206 struct cd_toc_entry *data; 207}; 208.Ed 209The requested data is written into an area of size 210.Li data_len 211and pointed to by 212.Li data . 213.It Dv CDIOCSETPATCH 214.Pq Li "struct ioc_patch" 215Attach various audio channels to various output channels. 216The argument structure is defined thusly: 217.Bd -literal -offset indent 218struct ioc_patch { 219 u_char patch[4]; 220 /* one for each channel */ 221}; 222.Ed 223.It Dv CDIOCGETVOL 224.It Dv CDIOCSETVOL 225.Pq Li "struct ioc_vol" 226Get (set) information about the volume settings of the output channels. 227The argument structure is as follows: 228.Bd -literal -offset indent 229struct ioc_vol 230{ 231 u_char vol[4]; 232 /* one for each channel */ 233}; 234.Ed 235.It Dv CDIOCSETMONO 236Patch all output channels to all source channels. 237.It Dv CDIOCSETSTEREO 238Patch left source channel to the left output channel and the right 239source channel to the right output channel. 240.It Dv CDIOCSETMUTE 241Mute output without changing the volume settings. 242.It Dv CDIOCSETLEFT 243.It Dv CDIOCSETRIGHT 244Attach both output channels to the left (right) source channel. 245.It Dv CDIOCSETDEBUG 246.It Dv CDIOCCLRDEBUG 247Turn on (off) debugging for the appropriate device. 248.It Dv CDIOCPAUSE 249.It Dv CDIOCRESUME 250Pause (resume) audio play, without resetting the location of the read-head. 251.It Dv CDIOCRESET 252Reset the drive. 253.It Dv CDIOCSTART 254.It Dv CDIOCSTOP 255Tell the drive to spin-up (-down) the 256.Tn CD-ROM . 257.It Dv CDIOCALLOW 258.It Dv CDIOCPREVENT 259Tell the drive to allow (prevent) manual ejection of the 260.Tn CD-ROM 261disc. Not all drives support this feature. 262.It Dv CDIOCEJECT 263Eject the 264.Tn CD-ROM . 265.It Dv CDIOCCLOSE 266Tell the drive to close its door and load the media. 267Not all drives support this feature. 268.El 269.Sh NOTES 270When a 271.Tn CD-ROM 272is changed in a drive controlled by the 273.Nm 274driver, then the act of changing the media will invalidate the 275disklabel and information held within the kernel. 276To stop corruption, 277all accesses to the device will be discarded until there are no more 278open file descriptors referencing the device. 279During this period, all 280new open attempts will be rejected. 281When no more open file descriptors 282reference the device, the first next open will load a new set of 283parameters (including disklabel) for the drive. 284.Pp 285The audio code in the 286.Nm 287driver only support 288.Tn SCSI-2 289standard audio commands. 290Because many 291.Tn CD-ROM 292manufacturers have not followed the standard, there are many 293.Tn CD-ROM 294drives for which audio will not work. 295Some work is planned to support 296some of the more common `broken' 297.Tn CD-ROM 298drives; however, this is not yet under way. 299.Sh CHANGER OPERATION 300This driver has built-in support for LUN-based CD changers. 301A LUN-based CD 302changer is a drive that can hold two or more CDs, but only has one CD 303player mechanism. 304Each CD in the drive shows up as a separate logical unit 305on the 306.Tn SCSI 307bus. The 308.Nm 309driver automatically recognizes LUN-based changers, and routes commands for 310changers through an internal scheduler. 311The scheduler prevents changer 312"thrashing", which is caused by sending commands to different LUNs in the 313changer at the same time. 314.Pp 315The scheduler honors minimum and maximum time 316quanta that the driver will spend on a particular LUN. 317The minimum time 318is the guaranteed minimum amount of time that the driver will spend on a 319given LUN, even if there is no outstanding I/O for that LUN. 320The maximum 321time is the maximum amount of time the changer will spend on a LUN if there 322is outstanding I/O for another LUN. 323If there is no outstanding I/O for 324another LUN, the driver will allow indefinite access to a given LUN. 325.Pp 326The minimum and maximum time quanta are configurable via kernel options and 327also via sysctl variables. 328The kernel options are: 329.Pp 330.Bl -item -compact 331.It 332.Cd "options ""CHANGER_MIN_BUSY_SECONDS=3""" 333.It 334.Cd "options ""CHANGER_MAX_BUSY_SECONDS=11""" 335.El 336.Pp 337The sysctl variables are: 338.Pp 339.Bl -item -compact 340.It 341.Va kern.cam.cd.changer.min_busy_seconds 342.It 343.Va kern.cam.cd.changer.max_busy_seconds 344.El 345.Pp 346It is suggested that the user try experimenting with the minimum and 347maximum timeouts via the sysctl variables to arrive at the proper values 348for your changer. 349Once you have settled on the proper timeouts for your 350changer, you can then put them in your kernel config file. 351.Pp 352If your system does have a LUN-based changer, you may notice that the 353probe messages for the various LUNs of the changer will continue to appear 354while the boot process is going on. 355This is normal, and is caused by the 356changer scheduling code. 357.Sh FILES 358.Bl -tag -width /dev/cd[0-9][a-h] -compact 359.It Pa /dev/cd[0-9][a-h] 360raw mode 361.Tn CD-ROM 362devices 363.El 364.Sh DIAGNOSTICS 365None. 366.Sh SEE ALSO 367.Xr da 4 , 368.Xr scsi 4 , 369.Xr disklabel 5 , 370.Xr disklabel 8 , 371.Xr cd 9 372.Sh HISTORY 373This 374.Nm 375driver is based upon the 376.Nm 377driver written by Julian Elischer, which appeared in 378.Bx 386 0.1 . 379The 380CAM version of the 381.Nm 382driver was written by Kenneth Merry and first appeared in 383.Fx 3.0 . 384.Sh BUGS 385The names of the structures used for the third argument to 386.Fn ioctl 387were poorly chosen, and a number of spelling errors have survived in 388the names of the 389.Fn ioctl 390commands. 391.Pp 392There is no mechanism currently to set different minimum and maximum 393timeouts for different CD changers; the timeout values set by the kernel 394options or the sysctl variables apply to all LUN-based CD changers in the 395system. 396It is possible to implement such support, but the sysctl 397implementation at least would be rather inelegant, because of the current 398inability of the sysctl code to handle the addition of nodes after compile 399time. 400Thus, it would take one dynamically sized sysctl variable and a 401userland utility to get/set the timeout values. 402Implementation of separate 403timeouts for different CD devices in the kernel config file would likely 404require modification of 405.Xr config 8 406to support the two timeouts when hardwiring 407.Nm 408devices. 409