1 ============================
2 Summary of CDROM ioctl calls
3 ============================
5 - Edward A. Falk <efalk@google.com>
9 This document attempts to describe the ioctl(2) calls supported by
10 the CDROM layer. These are by-and-large implemented (as of Linux 2.6)
11 in drivers/cdrom/cdrom.c and drivers/block/scsi_ioctl.c
13 ioctl values are listed in <linux/cdrom.h>. As of this writing, they
16 ====================== ===============================================
17 CDROMPAUSE Pause Audio Operation
18 CDROMRESUME Resume paused Audio Operation
19 CDROMPLAYMSF Play Audio MSF (struct cdrom_msf)
20 CDROMPLAYTRKIND Play Audio Track/index (struct cdrom_ti)
21 CDROMREADTOCHDR Read TOC header (struct cdrom_tochdr)
22 CDROMREADTOCENTRY Read TOC entry (struct cdrom_tocentry)
23 CDROMSTOP Stop the cdrom drive
24 CDROMSTART Start the cdrom drive
25 CDROMEJECT Ejects the cdrom media
26 CDROMVOLCTRL Control output volume (struct cdrom_volctrl)
27 CDROMSUBCHNL Read subchannel data (struct cdrom_subchnl)
28 CDROMREADMODE2 Read CDROM mode 2 data (2336 Bytes)
30 CDROMREADMODE1 Read CDROM mode 1 data (2048 Bytes)
32 CDROMREADAUDIO (struct cdrom_read_audio)
33 CDROMEJECT_SW enable(1)/disable(0) auto-ejecting
34 CDROMMULTISESSION Obtain the start-of-last-session
35 address of multi session disks
36 (struct cdrom_multisession)
37 CDROM_GET_MCN Obtain the "Universal Product Code"
38 if available (struct cdrom_mcn)
39 CDROM_GET_UPC Deprecated, use CDROM_GET_MCN instead.
40 CDROMRESET hard-reset the drive
41 CDROMVOLREAD Get the drive's volume setting
42 (struct cdrom_volctrl)
43 CDROMREADRAW read data in raw mode (2352 Bytes)
45 CDROMREADCOOKED read data in cooked mode
46 CDROMSEEK seek msf address
47 CDROMPLAYBLK scsi-cd only, (struct cdrom_blk)
48 CDROMREADALL read all 2646 bytes
49 CDROMGETSPINDOWN return 4-bit spindown value
50 CDROMSETSPINDOWN set 4-bit spindown value
51 CDROMCLOSETRAY pendant of CDROMEJECT
52 CDROM_SET_OPTIONS Set behavior options
53 CDROM_CLEAR_OPTIONS Clear behavior options
54 CDROM_SELECT_SPEED Set the CD-ROM speed
55 CDROM_SELECT_DISC Select disc (for juke-boxes)
56 CDROM_MEDIA_CHANGED Check is media changed
57 CDROM_DRIVE_STATUS Get tray position, etc.
58 CDROM_DISC_STATUS Get disc type, etc.
59 CDROM_CHANGER_NSLOTS Get number of slots
60 CDROM_LOCKDOOR lock or unlock door
61 CDROM_DEBUG Turn debug messages on/off
62 CDROM_GET_CAPABILITY get capabilities
63 CDROMAUDIOBUFSIZ set the audio buffer size
64 DVD_READ_STRUCT Read structure
65 DVD_WRITE_STRUCT Write structure
66 DVD_AUTH Authentication
67 CDROM_SEND_PACKET send a packet to the drive
68 CDROM_NEXT_WRITABLE get next writable block
69 CDROM_LAST_WRITTEN get last block written on disc
70 ====================== ===============================================
73 The information that follows was determined from reading kernel source
74 code. It is likely that some corrections will be made over time.
76 ------------------------------------------------------------------------------
80 Unless otherwise specified, all ioctl calls return 0 on success
81 and -1 with errno set to an appropriate value on error. (Some
82 ioctls return non-negative data values.)
84 Unless otherwise specified, all ioctl calls return -1 and set
85 errno to EFAULT on a failed attempt to copy data to or from user
88 Individual drivers may return error codes not listed here.
90 Unless otherwise specified, all data structures and constants
91 are defined in <linux/cdrom.h>
93 ------------------------------------------------------------------------------
102 ioctl(fd, CDROMPAUSE, 0);
114 - ENOSYS cd drive not audio-capable.
118 Resume paused Audio Operation
123 ioctl(fd, CDROMRESUME, 0);
135 - ENOSYS cd drive not audio-capable.
146 struct cdrom_msf msf;
148 ioctl(fd, CDROMPLAYMSF, &msf);
151 cdrom_msf structure, describing a segment of music to play
159 - ENOSYS cd drive not audio-capable.
162 - MSF stands for minutes-seconds-frames
163 - LBA stands for logical block address
164 - Segment is described as start and end times, where each time
165 is described as minutes:seconds:frames.
166 A frame is 1/75 of a second.
170 Play Audio Track/index
179 ioctl(fd, CDROMPLAYTRKIND, &ti);
182 cdrom_ti structure, describing a segment of music to play
190 - ENOSYS cd drive not audio-capable.
193 - Segment is described as start and end times, where each time
194 is described as a track and an index.
201 (struct cdrom_tochdr)
208 ioctl(fd, CDROMREADTOCHDR, &header);
211 cdrom_tochdr structure
215 cdrom_tochdr structure
219 - ENOSYS cd drive not audio-capable.
226 (struct cdrom_tocentry)
231 struct cdrom_tocentry entry;
233 ioctl(fd, CDROMREADTOCENTRY, &entry);
236 cdrom_tocentry structure
240 cdrom_tocentry structure
244 - ENOSYS cd drive not audio-capable.
245 - EINVAL entry.cdte_format not CDROM_MSF or CDROM_LBA
246 - EINVAL requested track out of bounds
247 - EIO I/O error reading TOC
250 - TOC stands for Table Of Contents
251 - MSF stands for minutes-seconds-frames
252 - LBA stands for logical block address
262 ioctl(fd, CDROMSTOP, 0);
274 - ENOSYS cd drive not audio-capable.
277 - Exact interpretation of this ioctl depends on the device,
278 but most seem to spin the drive down.
282 Start the cdrom drive
287 ioctl(fd, CDROMSTART, 0);
299 - ENOSYS cd drive not audio-capable.
302 - Exact interpretation of this ioctl depends on the device,
303 but most seem to spin the drive up and/or close the tray.
304 Other devices ignore the ioctl completely.
308 - Ejects the cdrom media
313 ioctl(fd, CDROMEJECT, 0);
325 - ENOSYS cd drive not capable of ejecting
326 - EBUSY other processes are accessing drive, or door is locked
329 - See CDROM_LOCKDOOR, below.
335 pendant of CDROMEJECT
340 ioctl(fd, CDROMCLOSETRAY, 0);
352 - ENOSYS cd drive not capable of closing the tray
353 - EBUSY other processes are accessing drive, or door is locked
356 - See CDROM_LOCKDOOR, below.
362 Control output volume (struct cdrom_volctrl)
367 struct cdrom_volctrl volume;
369 ioctl(fd, CDROMVOLCTRL, &volume);
372 cdrom_volctrl structure containing volumes for up to 4
380 - ENOSYS cd drive not audio-capable.
385 Get the drive's volume setting
387 (struct cdrom_volctrl)
392 struct cdrom_volctrl volume;
394 ioctl(fd, CDROMVOLREAD, &volume);
401 The current volume settings.
405 - ENOSYS cd drive not audio-capable.
412 (struct cdrom_subchnl)
417 struct cdrom_subchnl q;
419 ioctl(fd, CDROMSUBCHNL, &q);
422 cdrom_subchnl structure
426 cdrom_subchnl structure
430 - ENOSYS cd drive not audio-capable.
431 - EINVAL format not CDROM_MSF or CDROM_LBA
434 - Format is converted to CDROM_MSF or CDROM_LBA
435 as per user request on return
440 read data in raw mode (2352 Bytes)
448 struct cdrom_msf msf; /* input */
449 char buffer[CD_FRAMESIZE_RAW]; /* return */
451 ioctl(fd, CDROMREADRAW, &arg);
454 cdrom_msf structure indicating an address to read.
456 Only the start values are significant.
459 Data written to address provided by user.
463 - EINVAL address less than 0, or msf less than 0:2:0
464 - ENOMEM out of memory
467 - As of 2.6.8.1, comments in <linux/cdrom.h> indicate that this
468 ioctl accepts a cdrom_read structure, but actual source code
469 reads a cdrom_msf structure and writes a buffer of data to
472 - MSF values are converted to LBA values via this formula::
474 lba = (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
480 Read CDROM mode 1 data (2048 Bytes)
485 Identical to CDROMREADRAW except that block size is
486 CD_FRAMESIZE (2048) bytes
491 Read CDROM mode 2 data (2336 Bytes)
496 Identical to CDROMREADRAW except that block size is
497 CD_FRAMESIZE_RAW0 (2336) bytes
502 (struct cdrom_read_audio)
506 struct cdrom_read_audio ra;
508 ioctl(fd, CDROMREADAUDIO, &ra);
511 cdrom_read_audio structure containing read start
515 audio data, returned to buffer indicated by ra
519 - EINVAL format not CDROM_MSF or CDROM_LBA
520 - EINVAL nframes not in range [1 75]
521 - ENXIO drive has no queue (probably means invalid fd)
522 - ENOMEM out of memory
526 enable(1)/disable(0) auto-ejecting
533 ioctl(fd, CDROMEJECT_SW, val);
536 Flag specifying auto-eject flag.
544 - ENOSYS Drive is not capable of ejecting.
545 - EBUSY Door is locked
551 Obtain the start-of-last-session address of multi session disks
553 (struct cdrom_multisession)
557 struct cdrom_multisession ms_info;
559 ioctl(fd, CDROMMULTISESSION, &ms_info);
562 cdrom_multisession structure containing desired
567 cdrom_multisession structure is filled with last_session
571 - EINVAL format not CDROM_MSF or CDROM_LBA
575 Obtain the "Universal Product Code"
583 struct cdrom_mcn mcn;
585 ioctl(fd, CDROM_GET_MCN, &mcn);
592 Universal Product Code
596 - ENOSYS Drive is not capable of reading MCN data.
599 - Source code comments state::
601 The following function is implemented, although very few
602 audio discs give Universal Product Code information, which
603 should just be the Medium Catalog Number on the box. Note,
604 that the way the code is written on the CD is /not/ uniform
611 CDROM_GET_MCN (deprecated)
614 Not implemented, as of 2.6.8.1
624 ioctl(fd, CDROMRESET, 0);
636 - EACCES Access denied: requires CAP_SYS_ADMIN
637 - ENOSYS Drive is not capable of resetting.
643 read data in cooked mode
648 u8 buffer[CD_FRAMESIZE]
650 ioctl(fd, CDROMREADCOOKED, buffer);
657 2048 bytes of data, "cooked" mode.
661 Not implemented on all drives.
671 Same as CDROMREADCOOKED, but reads 2646 bytes.
681 struct cdrom_msf msf;
683 ioctl(fd, CDROMSEEK, &msf);
686 MSF address to seek to.
703 struct cdrom_blk blk;
705 ioctl(fd, CDROMPLAYBLK, &blk);
722 ioctl(fd, CDROMGETSPINDOWN, &spindown);
729 The value of the current 4-bit spindown value.
740 ioctl(fd, CDROMSETSPINDOWN, &spindown);
743 4-bit value used to control spindown (TODO: more detail here)
762 ioctl(fd, CDROM_SET_OPTIONS, options);
765 New values for drive options. The logical 'or' of:
767 ============== ==================================
768 CDO_AUTO_CLOSE close tray on first open(2)
769 CDO_AUTO_EJECT open tray on last release
770 CDO_USE_FFLAGS use O_NONBLOCK information on open
771 CDO_LOCK lock tray on open files
772 CDO_CHECK_TYPE check type on open for data
773 ============== ==================================
776 Returns the resulting options settings in the
777 ioctl return value. Returns -1 on error.
780 - ENOSYS selected option(s) not supported by drive.
786 Clear behavior options
789 Same as CDROM_SET_OPTIONS, except that selected options are
802 ioctl(fd, CDROM_SELECT_SPEED, speed);
813 - ENOSYS speed selection not supported by drive.
818 Select disc (for juke-boxes)
825 ioctl(fd, CDROM_SELECT_DISC, disk);
828 Disk to load into drive.
836 - EINVAL Disk number beyond capacity of drive
841 Check is media changed
848 ioctl(fd, CDROM_MEDIA_CHANGED, slot);
851 Slot number to be tested, always zero except for jukeboxes.
853 May also be special values CDSL_NONE or CDSL_CURRENT
856 Ioctl return value is 0 or 1 depending on whether the media
858 has been changed, or -1 on error.
861 - ENOSYS Drive can't detect media change
862 - EINVAL Slot number beyond capacity of drive
863 - ENOMEM Out of memory
868 Get tray position, etc.
875 ioctl(fd, CDROM_DRIVE_STATUS, slot);
878 Slot number to be tested, always zero except for jukeboxes.
880 May also be special values CDSL_NONE or CDSL_CURRENT
883 Ioctl return value will be one of the following values
885 from <linux/cdrom.h>:
887 =================== ==========================
888 CDS_NO_INFO Information not available.
894 =================== ==========================
897 - ENOSYS Drive can't detect drive status
898 - EINVAL Slot number beyond capacity of drive
899 - ENOMEM Out of memory
910 ioctl(fd, CDROM_DISC_STATUS, 0);
918 Ioctl return value will be one of the following values
920 from <linux/cdrom.h>:
933 - Source code comments state::
936 Ok, this is where problems start. The current interface for
937 the CDROM_DISC_STATUS ioctl is flawed. It makes the false
938 assumption that CDs are all CDS_DATA_1 or all CDS_AUDIO, etc.
939 Unfortunately, while this is often the case, it is also
940 very common for CDs to have some tracks with data, and some
941 tracks with audio. Just because I feel like it, I declare
942 the following to be the best way to cope. If the CD has
943 ANY data tracks on it, it will be returned as a data CD.
944 If it has any XA tracks, I will return it as that. Now I
945 could simplify this interface by combining these returns with
946 the above, but this more clearly demonstrates the problem
947 with the current interface. Too bad this wasn't designed
948 to use bitmasks... -Erik
950 Well, now we have the option CDS_MIXED: a mixed-type CD.
951 User level programmers might feel the ioctl is not very
964 ioctl(fd, CDROM_CHANGER_NSLOTS, 0);
972 The ioctl return value will be the number of slots in a
973 CD changer. Typically 1 for non-multi-disk devices.
988 ioctl(fd, CDROM_LOCKDOOR, lock);
991 Door lock flag, 1=lock, 0=unlock
999 - EDRIVE_CANT_DO_THIS
1001 Door lock function not supported.
1004 Attempt to unlock when multiple users
1005 have the drive open and not CAP_SYS_ADMIN
1008 As of 2.6.8.1, the lock flag is a global lock, meaning that
1009 all CD drives will be locked or unlocked together. This is
1012 The EDRIVE_CANT_DO_THIS value is defined in <linux/cdrom.h>
1013 and is currently (2.6.8.1) the same as EOPNOTSUPP
1018 Turn debug messages on/off
1025 ioctl(fd, CDROM_DEBUG, debug);
1028 Cdrom debug flag, 0=disable, 1=enable
1032 The ioctl return value will be the new debug flag.
1036 - EACCES Access denied: requires CAP_SYS_ADMIN
1040 CDROM_GET_CAPABILITY
1046 ioctl(fd, CDROM_GET_CAPABILITY, 0);
1054 The ioctl return value is the current device capability
1055 flags. See CDC_CLOSE_TRAY, CDC_OPEN_TRAY, etc.
1060 set the audio buffer size
1067 ioctl(fd, CDROMAUDIOBUFSIZ, val);
1070 New audio buffer size
1074 The ioctl return value is the new audio buffer size, or -1
1078 - ENOSYS Not supported by this driver.
1081 Not supported by all drivers.
1086 DVD_READ_STRUCT Read structure
1092 ioctl(fd, DVD_READ_STRUCT, &s);
1095 dvd_struct structure, containing:
1097 =================== ==========================================
1098 type specifies the information desired, one of
1099 DVD_STRUCT_PHYSICAL, DVD_STRUCT_COPYRIGHT,
1100 DVD_STRUCT_DISCKEY, DVD_STRUCT_BCA,
1102 physical.layer_num desired layer, indexed from 0
1103 copyright.layer_num desired layer, indexed from 0
1105 =================== ==========================================
1108 dvd_struct structure, containing:
1110 =================== ================================
1111 physical for type == DVD_STRUCT_PHYSICAL
1112 copyright for type == DVD_STRUCT_COPYRIGHT
1113 disckey.value for type == DVD_STRUCT_DISCKEY
1114 bca.{len,value} for type == DVD_STRUCT_BCA
1115 manufact.{len,valu} for type == DVD_STRUCT_MANUFACT
1116 =================== ================================
1119 - EINVAL physical.layer_num exceeds number of layers
1120 - EIO Received invalid response from drive
1124 DVD_WRITE_STRUCT Write structure
1126 Not implemented, as of 2.6.8.1
1130 DVD_AUTH Authentication
1136 ioctl(fd, DVD_AUTH, &ai);
1139 dvd_authinfo structure. See <linux/cdrom.h>
1143 dvd_authinfo structure.
1147 - ENOTTY ai.type not recognized.
1152 send a packet to the drive
1157 struct cdrom_generic_command cgc;
1159 ioctl(fd, CDROM_SEND_PACKET, &cgc);
1162 cdrom_generic_command structure containing the packet to send.
1168 cdrom_generic_command structure containing results.
1176 Operation not permitted, either because a
1177 write command was attempted on a drive which
1178 is opened read-only, or because the command
1179 requires CAP_SYS_RAWIO
1182 cgc.data_direction not set
1187 get next writable block
1194 ioctl(fd, CDROM_NEXT_WRITABLE, &next);
1201 The next writable block.
1205 If the device does not support this ioctl directly, the
1207 ioctl will return CDROM_LAST_WRITTEN + 7.
1212 get last block written on disc
1219 ioctl(fd, CDROM_LAST_WRITTEN, &last);
1226 The last block written on disc
1230 If the device does not support this ioctl directly, the
1231 result is derived from the disc's table of contents. If the
1232 table of contents can't be read, this ioctl returns an