1 Summary of CDROM ioctl calls.
2 ============================
4 Edward A. Falk <efalk@google.com>
8 This document attempts to describe the ioctl(2) calls supported by
9 the CDROM layer. These are by-and-large implemented (as of Linux 2.6)
10 in drivers/cdrom/cdrom.c and drivers/block/scsi_ioctl.c
12 ioctl values are listed in <linux/cdrom.h>. As of this writing, they
15 CDROMPAUSE Pause Audio Operation
16 CDROMRESUME Resume paused Audio Operation
17 CDROMPLAYMSF Play Audio MSF (struct cdrom_msf)
18 CDROMPLAYTRKIND Play Audio Track/index (struct cdrom_ti)
19 CDROMREADTOCHDR Read TOC header (struct cdrom_tochdr)
20 CDROMREADTOCENTRY Read TOC entry (struct cdrom_tocentry)
21 CDROMSTOP Stop the cdrom drive
22 CDROMSTART Start the cdrom drive
23 CDROMEJECT Ejects the cdrom media
24 CDROMVOLCTRL Control output volume (struct cdrom_volctrl)
25 CDROMSUBCHNL Read subchannel data (struct cdrom_subchnl)
26 CDROMREADMODE2 Read CDROM mode 2 data (2336 Bytes)
28 CDROMREADMODE1 Read CDROM mode 1 data (2048 Bytes)
30 CDROMREADAUDIO (struct cdrom_read_audio)
31 CDROMEJECT_SW enable(1)/disable(0) auto-ejecting
32 CDROMMULTISESSION Obtain the start-of-last-session
33 address of multi session disks
34 (struct cdrom_multisession)
35 CDROM_GET_MCN Obtain the "Universal Product Code"
36 if available (struct cdrom_mcn)
37 CDROM_GET_UPC Deprecated, use CDROM_GET_MCN instead.
38 CDROMRESET hard-reset the drive
39 CDROMVOLREAD Get the drive's volume setting
40 (struct cdrom_volctrl)
41 CDROMREADRAW read data in raw mode (2352 Bytes)
43 CDROMREADCOOKED read data in cooked mode
44 CDROMSEEK seek msf address
45 CDROMPLAYBLK scsi-cd only, (struct cdrom_blk)
46 CDROMREADALL read all 2646 bytes
47 CDROMGETSPINDOWN return 4-bit spindown value
48 CDROMSETSPINDOWN set 4-bit spindown value
49 CDROMCLOSETRAY pendant of CDROMEJECT
50 CDROM_SET_OPTIONS Set behavior options
51 CDROM_CLEAR_OPTIONS Clear behavior options
52 CDROM_SELECT_SPEED Set the CD-ROM speed
53 CDROM_SELECT_DISC Select disc (for juke-boxes)
54 CDROM_MEDIA_CHANGED Check is media changed
55 CDROM_DRIVE_STATUS Get tray position, etc.
56 CDROM_DISC_STATUS Get disc type, etc.
57 CDROM_CHANGER_NSLOTS Get number of slots
58 CDROM_LOCKDOOR lock or unlock door
59 CDROM_DEBUG Turn debug messages on/off
60 CDROM_GET_CAPABILITY get capabilities
61 CDROMAUDIOBUFSIZ set the audio buffer size
62 DVD_READ_STRUCT Read structure
63 DVD_WRITE_STRUCT Write structure
64 DVD_AUTH Authentication
65 CDROM_SEND_PACKET send a packet to the drive
66 CDROM_NEXT_WRITABLE get next writable block
67 CDROM_LAST_WRITTEN get last block written on disc
70 The information that follows was determined from reading kernel source
71 code. It is likely that some corrections will be made over time.
81 Unless otherwise specified, all ioctl calls return 0 on success
82 and -1 with errno set to an appropriate value on error. (Some
83 ioctls return non-negative data values.)
85 Unless otherwise specified, all ioctl calls return -1 and set
86 errno to EFAULT on a failed attempt to copy data to or from user
89 Individual drivers may return error codes not listed here.
91 Unless otherwise specified, all data structures and constants
92 are defined in <linux/cdrom.h>
97 CDROMPAUSE Pause Audio Operation
101 ioctl(fd, CDROMPAUSE, 0);
108 ENOSYS cd drive not audio-capable.
111 CDROMRESUME Resume paused Audio Operation
115 ioctl(fd, CDROMRESUME, 0);
122 ENOSYS cd drive not audio-capable.
125 CDROMPLAYMSF Play Audio MSF (struct cdrom_msf)
129 struct cdrom_msf msf;
130 ioctl(fd, CDROMPLAYMSF, &msf);
133 cdrom_msf structure, describing a segment of music to play
138 ENOSYS cd drive not audio-capable.
141 MSF stands for minutes-seconds-frames
142 LBA stands for logical block address
144 Segment is described as start and end times, where each time
145 is described as minutes:seconds:frames. A frame is 1/75 of
149 CDROMPLAYTRKIND Play Audio Track/index (struct cdrom_ti)
154 ioctl(fd, CDROMPLAYTRKIND, &ti);
157 cdrom_ti structure, describing a segment of music to play
162 ENOSYS cd drive not audio-capable.
165 Segment is described as start and end times, where each time
166 is described as a track and an index.
170 CDROMREADTOCHDR Read TOC header (struct cdrom_tochdr)
175 ioctl(fd, CDROMREADTOCHDR, &header);
178 cdrom_tochdr structure
181 cdrom_tochdr structure
184 ENOSYS cd drive not audio-capable.
188 CDROMREADTOCENTRY Read TOC entry (struct cdrom_tocentry)
192 struct cdrom_tocentry entry;
193 ioctl(fd, CDROMREADTOCENTRY, &entry);
196 cdrom_tocentry structure
199 cdrom_tocentry structure
202 ENOSYS cd drive not audio-capable.
203 EINVAL entry.cdte_format not CDROM_MSF or CDROM_LBA
204 EINVAL requested track out of bounds
205 EIO I/O error reading TOC
208 TOC stands for Table Of Contents
209 MSF stands for minutes-seconds-frames
210 LBA stands for logical block address
214 CDROMSTOP Stop the cdrom drive
218 ioctl(fd, CDROMSTOP, 0);
225 ENOSYS cd drive not audio-capable.
228 Exact interpretation of this ioctl depends on the device,
229 but most seem to spin the drive down.
232 CDROMSTART Start the cdrom drive
236 ioctl(fd, CDROMSTART, 0);
243 ENOSYS cd drive not audio-capable.
246 Exact interpretation of this ioctl depends on the device,
247 but most seem to spin the drive up and/or close the tray.
248 Other devices ignore the ioctl completely.
251 CDROMEJECT Ejects the cdrom media
255 ioctl(fd, CDROMEJECT, 0);
262 ENOSYS cd drive not capable of ejecting
263 EBUSY other processes are accessing drive, or door is locked
266 See CDROM_LOCKDOOR, below.
270 CDROMCLOSETRAY pendant of CDROMEJECT
274 ioctl(fd, CDROMEJECT, 0);
281 ENOSYS cd drive not capable of ejecting
282 EBUSY other processes are accessing drive, or door is locked
285 See CDROM_LOCKDOOR, below.
289 CDROMVOLCTRL Control output volume (struct cdrom_volctrl)
293 struct cdrom_volctrl volume;
294 ioctl(fd, CDROMVOLCTRL, &volume);
297 cdrom_volctrl structure containing volumes for up to 4
303 ENOSYS cd drive not audio-capable.
307 CDROMVOLREAD Get the drive's volume setting
308 (struct cdrom_volctrl)
312 struct cdrom_volctrl volume;
313 ioctl(fd, CDROMVOLREAD, &volume);
318 The current volume settings.
321 ENOSYS cd drive not audio-capable.
325 CDROMSUBCHNL Read subchannel data (struct cdrom_subchnl)
329 struct cdrom_subchnl q;
330 ioctl(fd, CDROMSUBCHNL, &q);
333 cdrom_subchnl structure
336 cdrom_subchnl structure
339 ENOSYS cd drive not audio-capable.
340 EINVAL format not CDROM_MSF or CDROM_LBA
343 Format is converted to CDROM_MSF on return
347 CDROMREADRAW read data in raw mode (2352 Bytes)
353 struct cdrom_msf msf; /* input */
354 char buffer[CD_FRAMESIZE_RAW]; /* return */
356 ioctl(fd, CDROMREADRAW, &arg);
359 cdrom_msf structure indicating an address to read.
360 Only the start values are significant.
363 Data written to address provided by user.
366 EINVAL address less than 0, or msf less than 0:2:0
370 As of 2.6.8.1, comments in <linux/cdrom.h> indicate that this
371 ioctl accepts a cdrom_read structure, but actual source code
372 reads a cdrom_msf structure and writes a buffer of data to
375 MSF values are converted to LBA values via this formula:
377 lba = (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
382 CDROMREADMODE1 Read CDROM mode 1 data (2048 Bytes)
386 Identical to CDROMREADRAW except that block size is
387 CD_FRAMESIZE (2048) bytes
391 CDROMREADMODE2 Read CDROM mode 2 data (2336 Bytes)
395 Identical to CDROMREADRAW except that block size is
396 CD_FRAMESIZE_RAW0 (2336) bytes
400 CDROMREADAUDIO (struct cdrom_read_audio)
404 struct cdrom_read_audio ra;
405 ioctl(fd, CDROMREADAUDIO, &ra);
408 cdrom_read_audio structure containing read start
412 audio data, returned to buffer indicated by ra
415 EINVAL format not CDROM_MSF or CDROM_LBA
416 EINVAL nframes not in range [1 75]
417 ENXIO drive has no queue (probably means invalid fd)
421 CDROMEJECT_SW enable(1)/disable(0) auto-ejecting
426 ioctl(fd, CDROMEJECT_SW, val);
429 Flag specifying auto-eject flag.
434 ENOSYS Drive is not capable of ejecting.
440 CDROMMULTISESSION Obtain the start-of-last-session
441 address of multi session disks
442 (struct cdrom_multisession)
445 struct cdrom_multisession ms_info;
446 ioctl(fd, CDROMMULTISESSION, &ms_info);
449 cdrom_multisession structure containing desired
453 cdrom_multisession structure is filled with last_session
457 EINVAL format not CDROM_MSF or CDROM_LBA
460 CDROM_GET_MCN Obtain the "Universal Product Code"
461 if available (struct cdrom_mcn)
465 struct cdrom_mcn mcn;
466 ioctl(fd, CDROM_GET_MCN, &mcn);
471 Universal Product Code
474 ENOSYS Drive is not capable of reading MCN data.
477 Source code comments state:
479 The following function is implemented, although very few
480 audio discs give Universal Product Code information, which
481 should just be the Medium Catalog Number on the box. Note,
482 that the way the code is written on the CD is /not/ uniform
488 CDROM_GET_UPC CDROM_GET_MCN (deprecated)
490 Not implemented, as of 2.6.8.1
494 CDROMRESET hard-reset the drive
498 ioctl(fd, CDROMRESET, 0);
505 EACCES Access denied: requires CAP_SYS_ADMIN
506 ENOSYS Drive is not capable of resetting.
511 CDROMREADCOOKED read data in cooked mode
515 u8 buffer[CD_FRAMESIZE]
516 ioctl(fd, CDROMREADCOOKED, buffer);
521 2048 bytes of data, "cooked" mode.
524 Not implemented on all drives.
529 CDROMREADALL read all 2646 bytes
531 Same as CDROMREADCOOKED, but reads 2646 bytes.
535 CDROMSEEK seek msf address
539 struct cdrom_msf msf;
540 ioctl(fd, CDROMSEEK, &msf);
543 MSF address to seek to.
549 CDROMPLAYBLK scsi-cd only, (struct cdrom_blk)
553 struct cdrom_blk blk;
554 ioctl(fd, CDROMPLAYBLK, &blk);
568 ioctl(fd, CDROMGETSPINDOWN, &spindown);
573 The value of the current 4-bit spindown value.
583 ioctl(fd, CDROMSETSPINDOWN, &spindown);
586 4-bit value used to control spindown (TODO: more detail here)
594 CDROM_SET_OPTIONS Set behavior options
599 ioctl(fd, CDROM_SET_OPTIONS, options);
602 New values for drive options. The logical 'or' of:
603 CDO_AUTO_CLOSE close tray on first open(2)
604 CDO_AUTO_EJECT open tray on last release
605 CDO_USE_FFLAGS use O_NONBLOCK information on open
606 CDO_LOCK lock tray on open files
607 CDO_CHECK_TYPE check type on open for data
610 Returns the resulting options settings in the
611 ioctl return value. Returns -1 on error.
614 ENOSYS selected option(s) not supported by drive.
619 CDROM_CLEAR_OPTIONS Clear behavior options
621 Same as CDROM_SET_OPTIONS, except that selected options are
626 CDROM_SELECT_SPEED Set the CD-ROM speed
631 ioctl(fd, CDROM_SELECT_SPEED, speed);
639 ENOSYS speed selection not supported by drive.
643 CDROM_SELECT_DISC Select disc (for juke-boxes)
648 ioctl(fd, CDROM_SELECT_DISC, disk);
651 Disk to load into drive.
656 EINVAL Disk number beyond capacity of drive
660 CDROM_MEDIA_CHANGED Check is media changed
665 ioctl(fd, CDROM_MEDIA_CHANGED, slot);
668 Slot number to be tested, always zero except for jukeboxes.
669 May also be special values CDSL_NONE or CDSL_CURRENT
672 Ioctl return value is 0 or 1 depending on whether the media
673 has been changed, or -1 on error.
676 ENOSYS Drive can't detect media change
677 EINVAL Slot number beyond capacity of drive
682 CDROM_DRIVE_STATUS Get tray position, etc.
687 ioctl(fd, CDROM_DRIVE_STATUS, slot);
690 Slot number to be tested, always zero except for jukeboxes.
691 May also be special values CDSL_NONE or CDSL_CURRENT
694 Ioctl return value will be one of the following values
695 from <linux/cdrom.h>:
697 CDS_NO_INFO Information not available.
705 ENOSYS Drive can't detect drive status
706 EINVAL Slot number beyond capacity of drive
712 CDROM_DISC_STATUS Get disc type, etc.
716 ioctl(fd, CDROM_DISC_STATUS, 0);
721 Ioctl return value will be one of the following values
722 from <linux/cdrom.h>:
730 error returns: none at present
733 Source code comments state:
735 Ok, this is where problems start. The current interface for
736 the CDROM_DISC_STATUS ioctl is flawed. It makes the false
737 assumption that CDs are all CDS_DATA_1 or all CDS_AUDIO, etc.
738 Unfortunatly, while this is often the case, it is also
739 very common for CDs to have some tracks with data, and some
740 tracks with audio. Just because I feel like it, I declare
741 the following to be the best way to cope. If the CD has
742 ANY data tracks on it, it will be returned as a data CD.
743 If it has any XA tracks, I will return it as that. Now I
744 could simplify this interface by combining these returns with
745 the above, but this more clearly demonstrates the problem
746 with the current interface. Too bad this wasn't designed
747 to use bitmasks... -Erik
749 Well, now we have the option CDS_MIXED: a mixed-type CD.
750 User level programmers might feel the ioctl is not very
757 CDROM_CHANGER_NSLOTS Get number of slots
761 ioctl(fd, CDROM_CHANGER_NSLOTS, 0);
766 The ioctl return value will be the number of slots in a
767 CD changer. Typically 1 for non-multi-disk devices.
773 CDROM_LOCKDOOR lock or unlock door
778 ioctl(fd, CDROM_LOCKDOOR, lock);
781 Door lock flag, 1=lock, 0=unlock
786 EDRIVE_CANT_DO_THIS Door lock function not supported.
787 EBUSY Attempt to unlock when multiple users
788 have the drive open and not CAP_SYS_ADMIN
791 As of 2.6.8.1, the lock flag is a global lock, meaning that
792 all CD drives will be locked or unlocked together. This is
795 The EDRIVE_CANT_DO_THIS value is defined in <linux/cdrom.h>
796 and is currently (2.6.8.1) the same as EOPNOTSUPP
800 CDROM_DEBUG Turn debug messages on/off
805 ioctl(fd, CDROM_DEBUG, debug);
808 Cdrom debug flag, 0=disable, 1=enable
811 The ioctl return value will be the new debug flag.
814 EACCES Access denied: requires CAP_SYS_ADMIN
818 CDROM_GET_CAPABILITY get capabilities
822 ioctl(fd, CDROM_GET_CAPABILITY, 0);
827 The ioctl return value is the current device capability
828 flags. See CDC_CLOSE_TRAY, CDC_OPEN_TRAY, etc.
832 CDROMAUDIOBUFSIZ set the audio buffer size
837 ioctl(fd, CDROMAUDIOBUFSIZ, val);
840 New audio buffer size
843 The ioctl return value is the new audio buffer size, or -1
847 ENOSYS Not supported by this driver.
850 Not supported by all drivers.
854 DVD_READ_STRUCT Read structure
859 ioctl(fd, DVD_READ_STRUCT, &s);
862 dvd_struct structure, containing:
863 type specifies the information desired, one of
864 DVD_STRUCT_PHYSICAL, DVD_STRUCT_COPYRIGHT,
865 DVD_STRUCT_DISCKEY, DVD_STRUCT_BCA,
867 physical.layer_num desired layer, indexed from 0
868 copyright.layer_num desired layer, indexed from 0
872 dvd_struct structure, containing:
873 physical for type == DVD_STRUCT_PHYSICAL
874 copyright for type == DVD_STRUCT_COPYRIGHT
875 disckey.value for type == DVD_STRUCT_DISCKEY
876 bca.{len,value} for type == DVD_STRUCT_BCA
877 manufact.{len,valu} for type == DVD_STRUCT_MANUFACT
880 EINVAL physical.layer_num exceeds number of layers
881 EIO Recieved invalid response from drive
885 DVD_WRITE_STRUCT Write structure
887 Not implemented, as of 2.6.8.1
891 DVD_AUTH Authentication
896 ioctl(fd, DVD_AUTH, &ai);
899 dvd_authinfo structure. See <linux/cdrom.h>
902 dvd_authinfo structure.
905 ENOTTY ai.type not recognized.
909 CDROM_SEND_PACKET send a packet to the drive
913 struct cdrom_generic_command cgc;
914 ioctl(fd, CDROM_SEND_PACKET, &cgc);
917 cdrom_generic_command structure containing the packet to send.
920 cdrom_generic_command structure containing results.
924 EPERM Operation not permitted, either because a
925 write command was attempted on a drive which
926 is opened read-only, or because the command
927 requires CAP_SYS_RAWIO
928 EINVAL cgc.data_direction not set
932 CDROM_NEXT_WRITABLE get next writable block
937 ioctl(fd, CDROM_NEXT_WRITABLE, &next);
942 The next writable block.
945 If the device does not support this ioctl directly, the
946 ioctl will return CDROM_LAST_WRITTEN + 7.
950 CDROM_LAST_WRITTEN get last block written on disc
955 ioctl(fd, CDROM_LAST_WRITTEN, &last);
960 The last block written on disc
963 If the device does not support this ioctl directly, the
964 result is derived from the disc's table of contents. If the
965 table of contents can't be read, this ioctl returns an