CD(4)

๐Ÿ“ฆ
version 15.1 ยท 4 versions
, in freebsd 15.1, nixpkgs unstable

โœจ CD(4) โ€” the SCSI CD-ROM driver, bestie edition ๐ŸŽ€

Okay so real talk, this is the cd manpage from the Kernel Interfaces Manual โ€” yeah, that one. Buckle up, it's a whole vibe. ๐Ÿ’…


๐ŸŒธ NAME ๐ŸŒธ

cd โ€” the SCSI CD-ROM driver. That's it, that's the whole name. Iconic, honestly.


โœจ SYNOPSIS โœจ

device cd

Literally one line. We love a low-effort king. ๐Ÿ‘‘


๐Ÿ’– DESCRIPTION ๐Ÿ’–

So the cd driver is what gives your system support for a SCSI CD-ROM (that's Compact Disc-Read Only Memory, for the uninitiated ๐Ÿ’ฟ) drive. And likeโ€ฆ it really wants to look like a regular disk, so it straight-up synthesizes a partition table for you, with one partition that covers the entire CD-ROM. The audacity, the commitment. ๐Ÿซถ

You can go in and modify this partition table with disklabel(8) if you want โ€” but bestie, be so fr, it will only last until the CD-ROM is unmounted. So it's giving temporary main character moment. In general, the interfaces are similar to the ones described in ada(4) and da(4).

Now, the lore: as the SCSI adapter gets probed during boot, the SCSI bus gets scanned for devices. Any devices that answer as CDROM (type 5) or WORM (type 4) type devices will be attached to the cd driver. Prior to FreeBSD 2.1, the first device found gets attached as cd0, the next as cd1, etc. โ€” first come, first slay. Beginning in FreeBSD 2.1, you can specify what cd unit a device should come on line as; go check scsi(4) for the details on kernel configuration. iykyk. ๐Ÿ”

Oh and also โ€” the system utility disklabel(8) may be used to read the synthesized disk label structure, which will contain correct figures for the size of the CD-ROM, should that information be required. Very demure, very mindful. โœจ


๐Ÿฆ‹ KERNEL CONFIGURATION ๐Ÿฆ‹

Any number of CD-ROM devices may be attached to the system regardless of system configuration, because all resources are dynamically allocated. No gatekeeping here, we're inclusive. ๐ŸŒˆ


๐Ÿ’… IOCTLS ๐Ÿ’…

The following ioctl(2) calls that apply to SCSI CD-ROM drives are defined in the header files <sys/cdio.h> and <sys/disklabel.h>. Let's go through them one by one, no skipping, we're not cowards. ๐ŸŽ€

  • CDIOCPLAYTRACKS (struct ioc_play_track) โ€” Start audio playback given a track address and length. The structure is defined as follows:
struct ioc_play_track
{
        u_char  start_track;
        u_char  start_index;
        u_char  end_track;
        u_char  end_index;
};
  • CDIOCPLAYBLOCKS (struct ioc_play_blocks) โ€” Start audio playback given a block address and length. The structure is defined as follows:
struct ioc_play_blocks
{
        int     blk;
        int     len;
};
  • CDIOCPLAYMSF (struct ioc_play_msf) โ€” Start audio playback given a minutes-seconds-frames address and length. The structure is defined as follows:
struct ioc_play_msf
{
        u_char  start_m;
        u_char  start_s;
        u_char  start_f;
        u_char  end_m;
        u_char  end_s;
        u_char  end_f;
};
  • CDIOCREADSUBCHANNEL (struct ioc_read_subchannel) โ€” Read information from the subchannel at the location specified by this structure:
struct ioc_read_subchannel {
        u_char address_format;
#define CD_LBA_FORMAT   1
#define CD_MSF_FORMAT   2
        u_char data_format;
#define CD_SUBQ_DATA            0
#define CD_CURRENT_POSITION     1
#define CD_MEDIA_CATALOG        2
#define CD_TRACK_INFO           3
        u_char track;
        int     data_len;
        struct  cd_sub_channel_info *data;
};
  • CDIOREADTOCHEADER (struct ioc_toc_header) โ€” Return summary information about the table of contents for the mounted CD-ROM. The information is returned into the following structure:
struct ioc_toc_header {
        u_short len;
        u_char  starting_track;
        u_char  ending_track;
};
  • CDIOREADTOCENTRYS (struct ioc_read_toc_entry) โ€” Return information from the table of contents entries mentioned. (And yes, this command name is misspelled โ€” the typo is canon, we don't fix it. ๐Ÿ’€) The argument structure is defined as follows:
struct ioc_read_toc_entry {
        u_char  address_format;
        u_char  starting_track;
        u_short data_len;
        struct  cd_toc_entry *data;
};

The requested data is written into an area of size data_len and pointed to by data.

  • CDIOCSETPATCH (struct ioc_patch) โ€” Attach various audio channels to various output channels. The argument structure is defined thusly:
struct ioc_patch {
        u_char  patch[4];
        /* one for each channel */
};
  • CDIOCGETVOL
  • CDIOCSETVOL (struct ioc_vol) โ€” Get (set) information about the volume settings of the output channels. The argument structure is as follows:
struct  ioc_vol
{
        u_char  vol[4];
        /* one for each channel */
};
Yeah, CDIOCGETVOL and CDIOCSETVOL are sharing a description up there โ€” that's just how the page rolls, keep scrolling bestie. ๐Ÿ“
  • CDIOCSETMONO โ€” Patch all output channels to all source channels.
  • CDIOCSETSTEREO โ€” Patch left source channel to the left output channel and the right source channel to the right output channel. Balanced, as all things should be. โš–๏ธ
  • CDIOCSETMUTE โ€” Mute output without changing the volume settings.
  • CDIOCSETLEFT
  • CDIOCSETRIGHT โ€” Attach both output channels to the left (right) source channel.
  • CDIOCSETDEBUG
  • CDIOCCLRDEBUG โ€” Turn on (off) debugging for the appropriate device.
  • CDIOCPAUSE
  • CDIOCRESUME โ€” Pause (resume) audio play, without resetting the location of the read-head.
  • CDIOCRESET โ€” Reset the drive.
  • CDIOCSTART
  • CDIOCSTOP โ€” Tell the drive to spin-up (-down) the CD-ROM.
  • CDIOCALLOW
  • CDIOCPREVENT โ€” Tell the drive to allow (prevent) manual ejection of the CD-ROM disc. Heads up: not all drives support this feature. ๐Ÿ™ˆ
  • CDIOCEJECT โ€” Eject the CD-ROM. Bye bestie ๐Ÿ‘‹
  • CDIOCCLOSE โ€” Tell the drive to close its door and load the media. Again, not all drives support this feature.

โญ NOTES โญ

When a CD-ROM is changed in a drive controlled by the cd driver, then the act of changing the media will invalidate the disklabel and information held within the kernel. To stop corruption, all accesses to the device will be discarded until there are no more open file descriptors referencing the device. During this period, all new open attempts will be rejected. When no more open file descriptors reference the device, the first next open will load a new set of parameters (including disklabel) for the drive. It's giving "we're on a break." ๐Ÿ˜ญ

Also: the audio code in the cd driver only supports SCSI-2 standard audio commands. And because so many CD-ROM manufacturers did not follow the standard, there are many CD-ROM drives for which audio will not work โ€” lowkey tragic. Some work is planned to support some of the more common broken CD-ROM drives; however, this is not yet under way. So likeโ€ฆ don't hold your breath. ๐Ÿ’€


๐Ÿ”ฅ SYSCTL VARIABLES ๐Ÿ”ฅ

The following variables are available as both sysctl(8) variables and loader(8) tunables:

  • kern.cam.cd.retry_count โ€” This variable determines how many times the cd driver will retry a READ or WRITE command. This does not affect the number of retries used during probe time or for the cd driver dump routine. This value currently defaults to 4.
  • kern.cam.cd.%d.minimum_cmd_size โ€” Okay so the cd driver attempts to automatically determine whether the drive it is talking to supports 6 byte or 10 byte MODE SENSE/MODE SELECT operations. Many SCSI drives only support 6 byte commands, and ATAPI drives only support 10 byte commands. Here's the whole little dance: the cd driver first attempts to determine whether the protocol in use typically supports 6 byte commands by issuing a CAM Path Inquiry CCB. It will then default to 6 byte or 10 byte commands as appropriate. After that, the cd driver defaults to using 6 byte commands (assuming the protocol the drive speaks claims to support 6 byte commands), until one fails with a SCSI ILLEGAL REQUEST error. Then it tries the 10 byte version of the command to see if that works instead. Users can change the default via per-drive sysctl variables and loader tunables. Where %d is the unit number of the drive in question. Valid minimum command sizes are 6 and 10. Any value above 6 will be rounded to 10, and any value below 6 will be rounded to 6. Math is math. ๐Ÿงฎ

๐Ÿงš FILES ๐Ÿงš

  • /dev/cd[0-9][a-h] โ€” raw mode CD-ROM devices

๐ŸŒˆ DIAGNOSTICS ๐ŸŒˆ

None.

(Truly nothing. Silence. The void. ๐Ÿซฅ)


๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘

cam(4), cd9660(4), da(4), disklabel(8), cd(9)


๐Ÿ’œ HISTORY ๐Ÿ’œ

This cd driver is based upon the cd driver written by Julian Elischer, which appeared in 386BSD 0.1. The CAM version of the cd driver was written by Kenneth Merry and first appeared in FreeBSD 3.0. We stan the OGs. ๐Ÿซถ


๐Ÿ“ BUGS ๐Ÿ“

The names of the structures used for the third argument to ioctl() were poorly chosen, and a number of spelling errors have survived in the names of the ioctl() commands. Not me fossilizing typos foreverโ€ฆ ๐Ÿ’€โœจ


And that's a wrap, bestie! ๐ŸŽ€ This little gem comes to you from Debian, dated April 8, 2022 โ€” so go forth, mount that CD-ROM, and slay. โœจ๐Ÿ’–

๐Ÿ“ฆ where this page comes from