요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
============================
Summary of CDROM ioctl calls
============================
- Edward A. Falk <efalk@google.com>
November, 2004
This document attempts to describe the ioctl(2) calls supported by
the CDROM layer. These are by-and-large implemented (as of Linux 2.6)
in drivers/cdrom/cdrom.c and drivers/block/scsi_ioctl.c
ioctl values are listed in <linux/cdrom.h>. As of this writing, they
are as follows:
======================== ===============================================
CDROMPAUSE Pause Audio Operation
CDROMRESUME Resume paused Audio Operation
CDROMPLAYMSF Play Audio MSF (struct cdrom_msf)
CDROMPLAYTRKIND Play Audio Track/index (struct cdrom_ti)
CDROMREADTOCHDR Read TOC header (struct cdrom_tochdr)
CDROMREADTOCENTRY Read TOC entry (struct cdrom_tocentry)
CDROMSTOP Stop the cdrom drive
CDROMSTART Start the cdrom drive
CDROMEJECT Ejects the cdrom media
CDROMVOLCTRL Control output volume (struct cdrom_volctrl)
CDROMSUBCHNL Read subchannel data (struct cdrom_subchnl)
CDROMREADMODE2 Read CDROM mode 2 data (2336 Bytes)
(struct cdrom_read)
CDROMREADMODE1 Read CDROM mode 1 data (2048 Bytes)
(struct cdrom_read)
CDROMREADAUDIO (struct cdrom_read_audio)
CDROMEJECT_SW enable(1)/disable(0) auto-ejecting
CDROMMULTISESSION Obtain the start-of-last-session
address of multi session disks
(struct cdrom_multisession)
CDROM_GET_MCN Obtain the "Universal Product Code"
if available (struct cdrom_mcn)
CDROM_GET_UPC Deprecated, use CDROM_GET_MCN instead.
CDROMRESET hard-reset the drive
CDROMVOLREAD Get the drive's volume setting
(struct cdrom_volctrl)
CDROMREADRAW read data in raw mode (2352 Bytes)
(struct cdrom_read)
CDROMREADCOOKED read data in cooked mode
CDROMSEEK seek msf address
CDROMPLAYBLK scsi-cd only, (struct cdrom_blk)
CDROMREADALL read all 2646 bytes
CDROMGETSPINDOWN return 4-bit spindown value
CDROMSETSPINDOWN set 4-bit spindown value
CDROMCLOSETRAY pendant of CDROMEJECT
CDROM_SET_OPTIONS Set behavior options
CDROM_CLEAR_OPTIONS Clear behavior options
CDROM_SELECT_SPEED Set the CD-ROM speed
CDROM_SELECT_DISC Select disc (for juke-boxes)
CDROM_MEDIA_CHANGED Check is media changed
CDROM_TIMED_MEDIA_CHANGE Check if media changed
since given time
(struct cdrom_timed_media_change_info)
CDROM_DRIVE_STATUS Get tray position, etc.
CDROM_DISC_STATUS Get disc type, etc.
CDROM_CHANGER_NSLOTS Get number of slots
CDROM_LOCKDOOR lock or unlock door
CDROM_DEBUG Turn debug messages on/off
CDROM_GET_CAPABILITY get capabilities
CDROMAUDIOBUFSIZ set the audio buffer size
DVD_READ_STRUCT Read structure
DVD_WRITE_STRUCT Write structure
DVD_AUTH Authentication
CDROM_SEND_PACKET send a packet to the drive
CDROM_NEXT_WRITABLE get next writable block
CDROM_LAST_WRITTEN get last block written on disc
======================== ===============================================
The information that follows was determined from reading kernel source
code. It is likely that some corrections will be made over time.
------------------------------------------------------------------------------
General:
Unless otherwise specified, all ioctl calls return 0 on success
and -1 with errno set to an appropriate value on error. (Some
ioctls return non-negative data values.)
Unless otherwise specified, all ioctl calls return -1 and set
errno to EFAULT on a failed attempt to copy data to or from user
address space.
Individual drivers may return error codes not listed here.
Unless otherwise specified, all data structures and constants
are defined in <linux/cdrom.h>
------------------------------------------------------------------------------
CDROMPAUSE
Pause Audio Operation
usage::
ioctl(fd, CDROMPAUSE, 0);
inputs:
none
outputs:
none
error return:
- ENOSYS cd drive not audio-capable.
CDROMRESUME
Resume paused Audio Operation
usage::
ioctl(fd, CDROMRESUME, 0);
inputs:
none
outputs:
none
error return:
- ENOSYS cd drive not audio-capable.
CDROMPLAYMSF
Play Audio MSF
(struct cdrom_msf)
usage::
struct cdrom_msf msf;
ioctl(fd, CDROMPLAYMSF, &msf);
inputs:
cdrom_msf structure, describing a segment of music to play
outputs:
none
error return:
- ENOSYS cd drive not audio-capable.
notes:
- MSF stands for minutes-seconds-frames
- LBA stands for logical block address
- Segment is described as start and end times, where each time
is described as minutes:seconds:frames.
A frame is 1/75 of a second.
CDROMPLAYTRKIND
Play Audio Track/index
(struct cdrom_ti)
usage::
struct cdrom_ti ti;
ioctl(fd, CDROMPLAYTRKIND, &ti);
inputs:
cdrom_ti structure, describing a segment of music to play
outputs:
none
error return:
- ENOSYS cd drive not audio-capable.
notes:
- Segment is described as start and end times, where each time
is described as a track and an index.
CDROMREADTOCHDR
Read TOC header
(struct cdrom_tochdr)
usage::
cdrom_tochdr header;
ioctl(fd, CDROMREADTOCHDR, &header);
inputs:
cdrom_tochdr structure
outputs:
cdrom_tochdr structure
error return:
- ENOSYS cd drive not audio-capable.
CDROMREADTOCENTRY
Read TOC entry
(struct cdrom_tocentry)
usage::
struct cdrom_tocentry entry;
ioctl(fd, CDROMREADTOCENTRY, &entry);
inputs:
cdrom_tocentry structure
outputs:
cdrom_tocentry structure
error return:
- ENOSYS cd drive not audio-capable.
- EINVAL entry.cdte_format not CDROM_MSF or CDROM_LBA
- EINVAL requested track out of bounds
- EIO I/O error reading TOC
notes:
- TOC stands for Table Of Contents
- MSF stands for minutes-seconds-frames
- LBA stands for logical block address
CDROMSTOP
Stop the cdrom drive
usage::
ioctl(fd, CDROMSTOP, 0);
inputs:
none
outputs:
none
error return:
- ENOSYS cd drive not audio-capable.
notes:
- Exact interpretation of this ioctl depends on the device,
but most seem to spin the drive down.
CDROMSTART
Start the cdrom drive
usage::
ioctl(fd, CDROMSTART, 0);
inputs:
none
outputs:
none
error return:
- ENOSYS cd drive not audio-capable.
notes:
- Exact interpretation of this ioctl depends on the device,
but most seem to spin the drive up and/or close the tray.
Other devices ignore the ioctl completely.
CDROMEJECT
- Ejects the cdrom media
usage::
ioctl(fd, CDROMEJECT, 0);
inputs:
none
outputs:
none
error returns:
- ENOSYS cd drive not capable of ejecting
- EBUSY other processes are accessing drive, or door is locked
notes:
- See CDROM_LOCKDOOR, below.
CDROMCLOSETRAY
pendant of CDROMEJECT
usage::
ioctl(fd, CDROMCLOSETRAY, 0);
inputs:
none
outputs:
none
error returns:
- ENOSYS cd drive not capable of closing the tray
- EBUSY other processes are accessing drive, or door is locked
notes:
- See CDROM_LOCKDOOR, below.
CDROMVOLCTRL
Control output volume (struct cdrom_volctrl)
usage::
struct cdrom_volctrl volume;
ioctl(fd, CDROMVOLCTRL, &volume);
inputs:
cdrom_volctrl structure containing volumes for up to 4
channels.
outputs:
none
error return:
- ENOSYS cd drive not audio-capable.
CDROMVOLREAD
Get the drive's volume setting
(struct cdrom_volctrl)
usage::
struct cdrom_volctrl volume;
ioctl(fd, CDROMVOLREAD, &volume);
inputs:
none
outputs:
The current volume settings.
error return:
- ENOSYS cd drive not audio-capable.
CDROMSUBCHNL
Read subchannel data
(struct cdrom_subchnl)
usage::
struct cdrom_subchnl q;
ioctl(fd, CDROMSUBCHNL, &q);
inputs:
cdrom_subchnl structure
outputs:
cdrom_subchnl structure
error return:
- ENOSYS cd drive not audio-capable.
- EINVAL format not CDROM_MSF or CDROM_LBA
notes:
- Format is converted to CDROM_MSF or CDROM_LBA
as per user request on return
CDROMREADRAW
read data in raw mode (2352 Bytes)
(struct cdrom_read)
usage::
union {
struct cdrom_msf msf; /* input */
char buffer[CD_FRAMESIZE_RAW]; /* return */
} arg;
ioctl(fd, CDROMREADRAW, &arg);
inputs:
cdrom_msf structure indicating an address to read.
Only the start values are significant.
outputs:
Data written to address provided by user.
error return:
- EINVAL address less than 0, or msf less than 0:2:0
- ENOMEM out of memory
notes:
- As of 2.6.8.1, comments in <linux/cdrom.h> indicate that this
ioctl accepts a cdrom_read structure, but actual source code
reads a cdrom_msf structure and writes a buffer of data to
the same address.
- MSF values are converted to LBA values via this formula::
lba = (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
CDROMREADMODE1
Read CDROM mode 1 data (2048 Bytes)
(struct cdrom_read)
notes:
Identical to CDROMREADRAW except that block size is
CD_FRAMESIZE (2048) bytes
CDROMREADMODE2
Read CDROM mode 2 data (2336 Bytes)
(struct cdrom_read)
notes:
Identical to CDROMREADRAW except that block size is
CD_FRAMESIZE_RAW0 (2336) bytes
CDROMREADAUDIO
(struct cdrom_read_audio)
usage::
struct cdrom_read_audio ra;
ioctl(fd, CDROMREADAUDIO, &ra);
inputs:
cdrom_read_audio structure containing read start
point and length
outputs:
audio data, returned to buffer indicated by ra
error return:
- EINVAL format not CDROM_MSF or CDROM_LBA
- EINVAL nframes not in range [1 75]
- ENXIO drive has no queue (probably means invalid fd)
- ENOMEM out of memory
CDROMEJECT_SW
enable(1)/disable(0) auto-ejecting
usage::
int val;
ioctl(fd, CDROMEJECT_SW, val);
inputs:
Flag specifying auto-eject flag.
outputs:
none
error return:
- ENOSYS Drive is not capable of ejecting.
- EBUSY Door is locked
CDROMMULTISESSION
Obtain the start-of-last-session address of multi session disks
(struct cdrom_multisession)
usage::
struct cdrom_multisession ms_info;
ioctl(fd, CDROMMULTISESSION, &ms_info);
inputs:
cdrom_multisession structure containing desired
format.
outputs:
cdrom_multisession structure is filled with last_session
information.
error return:
- EINVAL format not CDROM_MSF or CDROM_LBA
CDROM_GET_MCN
Obtain the "Universal Product Code"
if available
(struct cdrom_mcn)
usage::
struct cdrom_mcn mcn;
ioctl(fd, CDROM_GET_MCN, &mcn);
inputs:
none
outputs:
Universal Product Code
error return:
- ENOSYS Drive is not capable of reading MCN data.
notes:
- Source code comments state::
The following function is implemented, although very few
audio discs give Universal Product Code information, which
should just be the Medium Catalog Number on the box. Note,
that the way the code is written on the CD is /not/ uniform
across all discs!
CDROM_GET_UPC
CDROM_GET_MCN (deprecated)
Not implemented, as of 2.6.8.1
CDROMRESET
hard-reset the drive
usage::
ioctl(fd, CDROMRESET, 0);
inputs:
none
outputs:
none
error return:
- EACCES Access denied: requires CAP_SYS_ADMIN
- ENOSYS Drive is not capable of resetting.
CDROMREADCOOKED
read data in cooked mode
usage::
u8 buffer[CD_FRAMESIZE]
ioctl(fd, CDROMREADCOOKED, buffer);
inputs:
none
outputs:
2048 bytes of data, "cooked" mode.
notes:
Not implemented on all drives.
CDROMREADALL
read all 2646 bytes
Same as CDROMREADCOOKED, but reads 2646 bytes.
CDROMSEEK
seek msf address
usage::
struct cdrom_msf msf;
ioctl(fd, CDROMSEEK, &msf);
inputs:
MSF address to seek to.
outputs:
none
CDROMPLAYBLK
scsi-cd only
(struct cdrom_blk)
usage::
struct cdrom_blk blk;
ioctl(fd, CDROMPLAYBLK, &blk);
inputs:
Region to play
outputs:
none
CDROMGETSPINDOWN
Obsolete, was ide-cd only
usage::
char spindown;
ioctl(fd, CDROMGETSPINDOWN, &spindown);
inputs:
none
outputs:
The value of the current 4-bit spindown value.
CDROMSETSPINDOWN
Obsolete, was ide-cd only
usage::
char spindown
ioctl(fd, CDROMSETSPINDOWN, &spindown);
inputs:
4-bit value used to control spindown (TODO: more detail here)
outputs:
none
CDROM_SET_OPTIONS
Set behavior options
usage::
int options;
ioctl(fd, CDROM_SET_OPTIONS, options);
inputs:
New values for drive options. The logical 'or' of:
============== ==================================
CDO_AUTO_CLOSE close tray on first open(2)
CDO_AUTO_EJECT open tray on last release
CDO_USE_FFLAGS use O_NONBLOCK information on open
CDO_LOCK lock tray on open files
CDO_CHECK_TYPE check type on open for data
============== ==================================
outputs:
Returns the resulting options settings in the
ioctl return value. Returns -1 on error.
error return:
- ENOSYS selected option(s) not supported by drive.
CDROM_CLEAR_OPTIONS
Clear behavior options
Same as CDROM_SET_OPTIONS, except that selected options are
turned off.
CDROM_SELECT_SPEED
Set the CD-ROM speed
usage::
int speed;
ioctl(fd, CDROM_SELECT_SPEED, speed);
inputs:
New drive speed.
outputs:
none
error return:
- ENOSYS speed selection not supported by drive.
CDROM_SELECT_DISC
Select disc (for juke-boxes)
usage::
int disk;
ioctl(fd, CDROM_SELECT_DISC, disk);
inputs:
Disk to load into drive.
outputs:
none
error return:
- EINVAL Disk number beyond capacity of drive
CDROM_MEDIA_CHANGED
Check is media changed
usage::
int slot;
ioctl(fd, CDROM_MEDIA_CHANGED, slot);
inputs:
Slot number to be tested, always zero except for jukeboxes.
May also be special values CDSL_NONE or CDSL_CURRENT
outputs:
Ioctl return value is 0 or 1 depending on whether the media
has been changed, or -1 on error.
error returns:
- ENOSYS Drive can't detect media change
- EINVAL Slot number beyond capacity of drive
- ENOMEM Out of memory
CDROM_DRIVE_STATUS
Get tray position, etc.
usage::
int slot;
ioctl(fd, CDROM_DRIVE_STATUS, slot);
inputs:
Slot number to be tested, always zero except for jukeboxes.
May also be special values CDSL_NONE or CDSL_CURRENT
outputs:
Ioctl return value will be one of the following values
from <linux/cdrom.h>:
=================== ==========================
CDS_NO_INFO Information not available.
CDS_NO_DISC
CDS_TRAY_OPEN
CDS_DRIVE_NOT_READY
CDS_DISC_OK
-1 error
=================== ==========================
error returns:
- ENOSYS Drive can't detect drive status
- EINVAL Slot number beyond capacity of drive
- ENOMEM Out of memory
CDROM_DISC_STATUS
Get disc type, etc.
usage::
ioctl(fd, CDROM_DISC_STATUS, 0);
inputs:
none
outputs:
Ioctl return value will be one of the following values
from <linux/cdrom.h>:
- CDS_NO_INFO
- CDS_AUDIO
- CDS_MIXED
- CDS_XA_2_2
- CDS_XA_2_1
- CDS_DATA_1
error returns:
none at present
notes:
- Source code comments state::
Ok, this is where problems start. The current interface for
the CDROM_DISC_STATUS ioctl is flawed. It makes the false
assumption that CDs are all CDS_DATA_1 or all CDS_AUDIO, etc.
Unfortunately, while this is often the case, it is also
very common for CDs to have some tracks with data, and some
tracks with audio. Just because I feel like it, I declare
the following to be the best way to cope. If the CD has
ANY data tracks on it, it will be returned as a data CD.
If it has any XA tracks, I will return it as that. Now I
could simplify this interface by combining these returns with
the above, but this more clearly demonstrates the problem
with the current interface. Too bad this wasn't designed
to use bitmasks... -Erik
Well, now we have the option CDS_MIXED: a mixed-type CD.
User level programmers might feel the ioctl is not very
useful.
---david
CDROM_CHANGER_NSLOTS
Get number of slots
usage::
ioctl(fd, CDROM_CHANGER_NSLOTS, 0);
inputs:
none
outputs:
The ioctl return value will be the number of slots in a
CD changer. Typically 1 for non-multi-disk devices.
error returns:
none
CDROM_LOCKDOOR
lock or unlock door
usage::
int lock;
ioctl(fd, CDROM_LOCKDOOR, lock);
inputs:
Door lock flag, 1=lock, 0=unlock
outputs:
none
error returns:
- EDRIVE_CANT_DO_THIS
Door lock function not supported.
- EBUSY
Attempt to unlock when multiple users
have the drive open and not CAP_SYS_ADMIN
notes:
As of 2.6.8.1, the lock flag is a global lock, meaning that
all CD drives will be locked or unlocked together. This is
probably a bug.
The EDRIVE_CANT_DO_THIS value is defined in <linux/cdrom.h>
and is currently (2.6.8.1) the same as EOPNOTSUPP
CDROM_DEBUG
Turn debug messages on/off
usage::
int debug;
ioctl(fd, CDROM_DEBUG, debug);
inputs:
Cdrom debug flag, 0=disable, 1=enable
outputs:
The ioctl return value will be the new debug flag.
error return:
- EACCES Access denied: requires CAP_SYS_ADMIN
CDROM_GET_CAPABILITY
get capabilities
usage::
ioctl(fd, CDROM_GET_CAPABILITY, 0);
inputs:
none
outputs:
The ioctl return value is the current device capability
flags. See CDC_CLOSE_TRAY, CDC_OPEN_TRAY, etc.
CDROMAUDIOBUFSIZ
set the audio buffer size
usage::
int arg;
ioctl(fd, CDROMAUDIOBUFSIZ, val);
inputs:
New audio buffer size
outputs:
The ioctl return value is the new audio buffer size, or -1
on error.
error return:
- ENOSYS Not supported by this driver.
notes:
Not supported by all drivers.
DVD_READ_STRUCT Read structure
usage::
dvd_struct s;
ioctl(fd, DVD_READ_STRUCT, &s);
inputs:
dvd_struct structure, containing:
=================== ==========================================
type specifies the information desired, one of
DVD_STRUCT_PHYSICAL, DVD_STRUCT_COPYRIGHT,
DVD_STRUCT_DISCKEY, DVD_STRUCT_BCA,
DVD_STRUCT_MANUFACT
physical.layer_num desired layer, indexed from 0
copyright.layer_num desired layer, indexed from 0
disckey.agid
=================== ==========================================
outputs:
dvd_struct structure, containing:
=================== ================================
physical for type == DVD_STRUCT_PHYSICAL
copyright for type == DVD_STRUCT_COPYRIGHT
disckey.value for type == DVD_STRUCT_DISCKEY
bca.{len,value} for type == DVD_STRUCT_BCA
manufact.{len,valu} for type == DVD_STRUCT_MANUFACT
=================== ================================
error returns:
- EINVAL physical.layer_num exceeds number of layers
- EIO Received invalid response from drive
DVD_WRITE_STRUCT Write structure
Not implemented, as of 2.6.8.1
DVD_AUTH Authentication
usage::
dvd_authinfo ai;
ioctl(fd, DVD_AUTH, &ai);
inputs:
dvd_authinfo structure. See <linux/cdrom.h>
outputs:
dvd_authinfo structure.
error return:
- ENOTTY ai.type not recognized.
CDROM_SEND_PACKET
send a packet to the drive
usage::
struct cdrom_generic_command cgc;
ioctl(fd, CDROM_SEND_PACKET, &cgc);
inputs:
cdrom_generic_command structure containing the packet to send.
outputs:
none
cdrom_generic_command structure containing results.
error return:
- EIO
command failed.
- EPERM
Operation not permitted, either because a
write command was attempted on a drive which
is opened read-only, or because the command
requires CAP_SYS_RAWIO
- EINVAL
cgc.data_direction not set
CDROM_NEXT_WRITABLE
get next writable block
usage::
long next;
ioctl(fd, CDROM_NEXT_WRITABLE, &next);
inputs:
none
outputs:
The next writable block.
notes:
If the device does not support this ioctl directly, the
ioctl will return CDROM_LAST_WRITTEN + 7.
CDROM_LAST_WRITTEN
get last block written on disc
usage::
long last;
ioctl(fd, CDROM_LAST_WRITTEN, &last);
inputs:
none
outputs:
The last block written on disc
notes:
If the device does not support this ioctl directly, the
result is derived from the disc's table of contents. If the
table of contents can't be read, this ioctl returns an
error.
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
문서 범위와 ioctl 목록
1-78이 문서는 CD-ROM layer가 지원하는 `ioctl(2)` 호출을 정리합니다. 2004년 11월 기준으로 주 구현 위치는 `drivers/cdrom/cdrom.c`와 `drivers/block/scsi_ioctl.c`이며 ioctl 값과 관련 구조체는 `<linux/cdrom.h>`에 정의됩니다.
목록은 audio 재생, TOC와 subchannel 조회, mode별 sector 읽기, tray·door 제어, multisession과 media 상태, drive capability, DVD structure와 authentication, raw packet 전송, writable block 조회를 포괄합니다.
`CDROM_GET_UPC`는 폐기되었고 `CDROM_GET_MCN`을 사용해야 합니다. 일부 명령은 SCSI CD에만 적용되거나 jukebox·DVD처럼 특정 hardware 기능을 전제로 합니다.
긴 상수 목록을 동작 영역별로 재구성했습니다.
요청 목적에서 관련 ioctl과 구조체를 찾는 흐름입니다.
============================
Summary of CDROM ioctl calls
============================
- Edward A. Falk <efalk@google.com>
November, 2004
This document attempts to describe the ioctl(2) calls supported by
the CDROM layer. These are by-and-large implemented (as of Linux 2.6)
in drivers/cdrom/cdrom.c and drivers/block/scsi_ioctl.c
ioctl values are listed in <linux/cdrom.h>. As of this writing, they
are as follows:
======================== ===============================================
CDROMPAUSE Pause Audio Operation
CDROMRESUME Resume paused Audio Operation
CDROMPLAYMSF Play Audio MSF (struct cdrom_msf)
CDROMPLAYTRKIND Play Audio Track/index (struct cdrom_ti)
CDROMREADTOCHDR Read TOC header (struct cdrom_tochdr)
CDROMREADTOCENTRY Read TOC entry (struct cdrom_tocentry)
CDROMSTOP Stop the cdrom drive
CDROMSTART Start the cdrom drive
CDROMEJECT Ejects the cdrom media
CDROMVOLCTRL Control output volume (struct cdrom_volctrl)
CDROMSUBCHNL Read subchannel data (struct cdrom_subchnl)
CDROMREADMODE2 Read CDROM mode 2 data (2336 Bytes)
(struct cdrom_read)
CDROMREADMODE1 Read CDROM mode 1 data (2048 Bytes)
(struct cdrom_read)
CDROMREADAUDIO (struct cdrom_read_audio)
CDROMEJECT_SW enable(1)/disable(0) auto-ejecting
CDROMMULTISESSION Obtain the start-of-last-session
address of multi session disks
(struct cdrom_multisession)
CDROM_GET_MCN Obtain the "Universal Product Code"
if available (struct cdrom_mcn)
CDROM_GET_UPC Deprecated, use CDROM_GET_MCN instead.
CDROMRESET hard-reset the drive
CDROMVOLREAD Get the drive's volume setting
(struct cdrom_volctrl)
CDROMREADRAW read data in raw mode (2352 Bytes)
(struct cdrom_read)
CDROMREADCOOKED read data in cooked mode
CDROMSEEK seek msf address
CDROMPLAYBLK scsi-cd only, (struct cdrom_blk)
CDROMREADALL read all 2646 bytes
CDROMGETSPINDOWN return 4-bit spindown value
CDROMSETSPINDOWN set 4-bit spindown value
CDROMCLOSETRAY pendant of CDROMEJECT
CDROM_SET_OPTIONS Set behavior options
CDROM_CLEAR_OPTIONS Clear behavior options
CDROM_SELECT_SPEED Set the CD-ROM speed
CDROM_SELECT_DISC Select disc (for juke-boxes)
CDROM_MEDIA_CHANGED Check is media changed
CDROM_TIMED_MEDIA_CHANGE Check if media changed
since given time
(struct cdrom_timed_media_change_info)
CDROM_DRIVE_STATUS Get tray position, etc.
CDROM_DISC_STATUS Get disc type, etc.
CDROM_CHANGER_NSLOTS Get number of slots
CDROM_LOCKDOOR lock or unlock door
CDROM_DEBUG Turn debug messages on/off
CDROM_GET_CAPABILITY get capabilities
CDROMAUDIOBUFSIZ set the audio buffer size
DVD_READ_STRUCT Read structure
DVD_WRITE_STRUCT Write structure
DVD_AUTH Authentication
CDROM_SEND_PACKET send a packet to the drive
CDROM_NEXT_WRITABLE get next writable block
CDROM_LAST_WRITTEN get last block written on disc
======================== ===============================================
The information that follows was determined from reading kernel source
code. It is likely that some corrections will be made over time.
공통 반환값과 오류 규칙
79-98별도 설명이 없으면 모든 ioctl은 성공 시 0, 실패 시 -1을 반환하고 `errno`를 설정합니다. 일부 ioctl은 성공 결과로 0 이상의 데이터 값을 직접 반환합니다.
Userspace 주소 공간과 데이터를 복사하는 과정이 실패하면 별도 설명이 없는 한 -1과 `EFAULT`를 반환합니다. 개별 driver는 이 문서에 없는 추가 오류 코드를 반환할 수 있습니다.
특별한 언급이 없으면 모든 구조체와 상수는 `<linux/cdrom.h>`에 정의됩니다. 따라서 userspace ABI를 사용할 때는 해당 header의 field 크기와 의미를 함께 확인해야 합니다.
각 명령의 개별 설명보다 먼저 적용되는 기본 규칙입니다.
------------------------------------------------------------------------------
General:
Unless otherwise specified, all ioctl calls return 0 on success
and -1 with errno set to an appropriate value on error. (Some
ioctls return non-negative data values.)
Unless otherwise specified, all ioctl calls return -1 and set
errno to EFAULT on a failed attempt to copy data to or from user
address space.
Individual drivers may return error codes not listed here.
Unless otherwise specified, all data structures and constants
are defined in <linux/cdrom.h>
------------------------------------------------------------------------------
CDROMPAUSE와 CDROMRESUME
99-140`CDROMPAUSE`는 현재 audio 재생을 일시 정지합니다. `ioctl(fd, CDROMPAUSE, 0)`으로 호출하며 별도 입력과 출력은 없습니다.
`CDROMRESUME`은 일시 정지된 audio 재생을 다시 시작합니다. `ioctl(fd, CDROMRESUME, 0)`으로 호출하며 역시 입력과 출력 구조체가 없습니다.
두 명령 모두 drive가 audio를 지원하지 않으면 `ENOSYS`를 반환합니다. 파일 디스크립터가 가리키는 drive의 audio capability를 사전에 확인하는 것이 좋습니다.
두 ioctl은 인자 없이 현재 drive audio 상태를 제어합니다.
CDROMPAUSE
Pause Audio Operation
usage::
ioctl(fd, CDROMPAUSE, 0);
inputs:
none
outputs:
none
error return:
- ENOSYS cd drive not audio-capable.
CDROMRESUME
Resume paused Audio Operation
usage::
ioctl(fd, CDROMRESUME, 0);
inputs:
none
outputs:
none
error return:
- ENOSYS cd drive not audio-capable.
CDROMPLAYMSF와 CDROMPLAYTRKIND
141-200`CDROMPLAYMSF`는 `struct cdrom_msf`로 지정한 audio 구간을 재생합니다. `ioctl(fd, CDROMPLAYMSF, &msf)`를 호출하며 구조체는 시작과 끝을 각각 minutes:seconds:frames로 표현합니다.
MSF는 minutes-seconds-frames의 약자이고 frame 하나는 1/75초입니다. LBA는 logical block address를 뜻하며, 이 명령 자체는 MSF 시각 표현을 사용합니다.
`CDROMPLAYTRKIND`는 `struct cdrom_ti`로 지정한 track/index 구간을 재생합니다. 시작과 끝을 track과 index 쌍으로 기술하고 `ioctl(fd, CDROMPLAYTRKIND, &ti)`를 호출합니다.
두 명령은 성공 결과 구조체를 반환하지 않으며 audio를 지원하지 않는 drive에서는 `ENOSYS`입니다.
같은 재생 목적이지만 주소 표현이 다릅니다.
주소 표현을 선택해 시작과 끝을 구조체에 채웁니다.
CDROMPLAYMSF
Play Audio MSF
(struct cdrom_msf)
usage::
struct cdrom_msf msf;
ioctl(fd, CDROMPLAYMSF, &msf);
inputs:
cdrom_msf structure, describing a segment of music to play
outputs:
none
error return:
- ENOSYS cd drive not audio-capable.
notes:
- MSF stands for minutes-seconds-frames
- LBA stands for logical block address
- Segment is described as start and end times, where each time
is described as minutes:seconds:frames.
A frame is 1/75 of a second.
CDROMPLAYTRKIND
Play Audio Track/index
(struct cdrom_ti)
usage::
struct cdrom_ti ti;
ioctl(fd, CDROMPLAYTRKIND, &ti);
inputs:
cdrom_ti structure, describing a segment of music to play
outputs:
none
error return:
- ENOSYS cd drive not audio-capable.
notes:
- Segment is described as start and end times, where each time
is described as a track and an index.
CDROMREADTOCHDR와 CDROMREADTOCENTRY
201-258`CDROMREADTOCHDR`는 disc의 TOC header를 읽습니다. `cdrom_tochdr header`를 준비해 `ioctl(fd, CDROMREADTOCHDR, &header)`로 호출하며 같은 구조체가 입력과 출력으로 사용됩니다.
`CDROMREADTOCENTRY`는 `struct cdrom_tocentry`로 특정 TOC entry를 읽습니다. 요청할 track과 주소 format을 구조체에 채워 호출하면 kernel이 결과 field를 갱신합니다.
TOC는 Table Of Contents, MSF는 minutes-seconds-frames, LBA는 logical block address입니다. `entry.cdte_format`은 `CDROM_MSF` 또는 `CDROM_LBA`여야 합니다.
두 명령 모두 audio 미지원 drive에서는 `ENOSYS`입니다. Entry 명령은 잘못된 format이나 범위를 벗어난 track에 `EINVAL`, TOC I/O 실패에 `EIO`를 반환할 수 있습니다.
Header 조회와 개별 entry 조회의 입력·오류를 구분합니다.
CDROMREADTOCHDR
Read TOC header
(struct cdrom_tochdr)
usage::
cdrom_tochdr header;
ioctl(fd, CDROMREADTOCHDR, &header);
inputs:
cdrom_tochdr structure
outputs:
cdrom_tochdr structure
error return:
- ENOSYS cd drive not audio-capable.
CDROMREADTOCENTRY
Read TOC entry
(struct cdrom_tocentry)
usage::
struct cdrom_tocentry entry;
ioctl(fd, CDROMREADTOCENTRY, &entry);
inputs:
cdrom_tocentry structure
outputs:
cdrom_tocentry structure
error return:
- ENOSYS cd drive not audio-capable.
- EINVAL entry.cdte_format not CDROM_MSF or CDROM_LBA
- EINVAL requested track out of bounds
- EIO I/O error reading TOC
notes:
- TOC stands for Table Of Contents
- MSF stands for minutes-seconds-frames
- LBA stands for logical block address
CDROMSTOP과 CDROMSTART
259-309`CDROMSTOP`은 `ioctl(fd, CDROMSTOP, 0)`으로 drive를 정지합니다. 정확한 의미는 device마다 다르지만 대부분 drive의 회전을 낮추거나 멈춥니다.
`CDROMSTART`는 `ioctl(fd, CDROMSTART, 0)`으로 drive를 시작합니다. 많은 device에서 회전을 올리거나 tray를 닫지만, 일부 device는 이 ioctl을 완전히 무시합니다.
두 명령 모두 별도 입력과 출력이 없고 audio를 지원하지 않는 drive에서는 `ENOSYS`를 반환합니다. Device별 해석 차이를 고려해 상태 확인 명령과 함께 사용해야 합니다.
명령 이름은 같아도 실제 mechanical 동작은 device에 의존합니다.
CDROMSTOP
Stop the cdrom drive
usage::
ioctl(fd, CDROMSTOP, 0);
inputs:
none
outputs:
none
error return:
- ENOSYS cd drive not audio-capable.
notes:
- Exact interpretation of this ioctl depends on the device,
but most seem to spin the drive down.
CDROMSTART
Start the cdrom drive
usage::
ioctl(fd, CDROMSTART, 0);
inputs:
none
outputs:
none
error return:
- ENOSYS cd drive not audio-capable.
notes:
- Exact interpretation of this ioctl depends on the device,
but most seem to spin the drive up and/or close the tray.
Other devices ignore the ioctl completely.
CDROMEJECT
310-336`CDROMEJECT`는 `ioctl(fd, CDROMEJECT, 0)`으로 CD-ROM media를 eject합니다. 별도 입력과 출력은 없습니다.
Drive가 eject를 지원하지 않으면 `ENOSYS`입니다. 다른 process가 drive에 접근 중이거나 door가 잠겨 있으면 `EBUSY`를 반환합니다.
Door 잠금 상태는 뒤에서 설명하는 `CDROM_LOCKDOOR`와 관련됩니다. Eject 전에 open 사용자와 door lock 상태를 확인해야 합니다.
Mechanical capability와 동시 접근 상태를 구분합니다.
CDROMEJECT
- Ejects the cdrom media
usage::
ioctl(fd, CDROMEJECT, 0);
inputs:
none
outputs:
none
error returns:
- ENOSYS cd drive not capable of ejecting
- EBUSY other processes are accessing drive, or door is locked
notes:
- See CDROM_LOCKDOOR, below.
CDROMCLOSETRAY
337-360`CDROMCLOSETRAY`는 `CDROMEJECT`의 반대 동작으로 tray를 닫습니다. `ioctl(fd, CDROMCLOSETRAY, 0)`으로 호출하며 별도 입력과 출력은 없습니다.
Drive가 tray close를 지원하지 않으면 `ENOSYS`, 다른 process가 접근 중이거나 door가 잠겼으면 `EBUSY`입니다. 이 명령도 `CDROM_LOCKDOOR` 상태의 영향을 받습니다.
Eject와 같은 capability·busy 조건을 적용합니다.
CDROMCLOSETRAY
pendant of CDROMEJECT
usage::
ioctl(fd, CDROMCLOSETRAY, 0);
inputs:
none
outputs:
none
error returns:
- ENOSYS cd drive not capable of closing the tray
- EBUSY other processes are accessing drive, or door is locked
notes:
- See CDROM_LOCKDOOR, below.
CDROMVOLCTRL과 CDROMVOLREAD
361-410`CDROMVOLCTRL`은 최대 4개 audio channel의 출력 volume을 설정합니다. `struct cdrom_volctrl volume`에 channel별 값을 채우고 `ioctl(fd, CDROMVOLCTRL, &volume)`을 호출하며 별도 출력은 없습니다.
`CDROMVOLREAD`은 drive의 현재 volume 설정을 같은 `struct cdrom_volctrl`로 읽습니다. 입력 값은 없고 `ioctl(fd, CDROMVOLREAD, &volume)`이 성공하면 구조체에 현재 channel volume이 채워집니다.
두 명령 모두 drive가 audio를 지원하지 않으면 `ENOSYS`입니다. 지원 channel 수가 4보다 적은 장치에서는 실제 의미가 있는 field가 driver와 hardware에 따라 달라질 수 있습니다.
동일 구조체를 설정과 조회에 반대 방향으로 사용합니다.
CDROMVOLCTRL
Control output volume (struct cdrom_volctrl)
usage::
struct cdrom_volctrl volume;
ioctl(fd, CDROMVOLCTRL, &volume);
inputs:
cdrom_volctrl structure containing volumes for up to 4
channels.
outputs:
none
error return:
- ENOSYS cd drive not audio-capable.
CDROMVOLREAD
Get the drive's volume setting
(struct cdrom_volctrl)
usage::
struct cdrom_volctrl volume;
ioctl(fd, CDROMVOLREAD, &volume);
inputs:
none
outputs:
The current volume settings.
error return:
- ENOSYS cd drive not audio-capable.
CDROMSUBCHNL
411-440`CDROMSUBCHNL`은 `struct cdrom_subchnl`을 사용해 subchannel 데이터를 읽습니다. Userspace가 원하는 주소 format을 구조체에 지정하고 `ioctl(fd, CDROMSUBCHNL, &q)`를 호출하면 같은 구조체에 결과가 반환됩니다.
반환 주소는 요청에 따라 `CDROM_MSF` 또는 `CDROM_LBA`로 변환됩니다. Format이 둘 중 하나가 아니면 `EINVAL`, drive가 audio를 지원하지 않으면 `ENOSYS`입니다.
요청 format과 반환 format이 일치하도록 kernel이 변환합니다.
CDROMSUBCHNL
Read subchannel data
(struct cdrom_subchnl)
usage::
struct cdrom_subchnl q;
ioctl(fd, CDROMSUBCHNL, &q);
inputs:
cdrom_subchnl structure
outputs:
cdrom_subchnl structure
error return:
- ENOSYS cd drive not audio-capable.
- EINVAL format not CDROM_MSF or CDROM_LBA
notes:
- Format is converted to CDROM_MSF or CDROM_LBA
as per user request on return
CDROMREADRAW
441-481`CDROMREADRAW`는 2,352-byte raw frame을 읽습니다. 실제 ABI는 같은 userspace 주소를 먼저 `struct cdrom_msf` 입력으로 읽고, 이후 `CD_FRAMESIZE_RAW` 크기의 data buffer 출력으로 덮어씁니다.
입력 MSF에서는 시작 위치만 의미가 있습니다. 주소가 음수이거나 MSF가 0:2:0보다 작으면 `EINVAL`, memory 확보에 실패하면 `ENOMEM`입니다.
Linux 2.6.8.1 당시 `<linux/cdrom.h>` 주석은 `struct cdrom_read`를 받는다고 했지만 실제 source는 `cdrom_msf`를 읽고 같은 주소에 data를 씁니다. Userspace는 이 실제 in-place ABI와 충분한 buffer 크기를 따라야 합니다.
MSF는 `lba = (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET` 공식으로 LBA에 변환됩니다. 이 수식의 상수와 integer 범위는 `<linux/cdrom.h>` 정의를 사용합니다.
입력 구조체와 출력 buffer가 같은 주소를 공유하는 특수 ABI입니다.
동일 주소의 역할이 ioctl 전후에 바뀝니다.
CDROMREADRAW
read data in raw mode (2352 Bytes)
(struct cdrom_read)
usage::
union {
struct cdrom_msf msf; /* input */
char buffer[CD_FRAMESIZE_RAW]; /* return */
} arg;
ioctl(fd, CDROMREADRAW, &arg);
inputs:
cdrom_msf structure indicating an address to read.
Only the start values are significant.
outputs:
Data written to address provided by user.
error return:
- EINVAL address less than 0, or msf less than 0:2:0
- ENOMEM out of memory
notes:
- As of 2.6.8.1, comments in <linux/cdrom.h> indicate that this
ioctl accepts a cdrom_read structure, but actual source code
reads a cdrom_msf structure and writes a buffer of data to
the same address.
- MSF values are converted to LBA values via this formula::
lba = (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
CDROMREADMODE1, CDROMREADMODE2, CDROMREADAUDIO
482-527`CDROMREADMODE1`은 `CDROMREADRAW`와 같은 방식이지만 block 크기가 `CD_FRAMESIZE`, 즉 2,048 bytes입니다. `CDROMREADMODE2`도 같은 방식이며 `CD_FRAMESIZE_RAW0`, 즉 2,336 bytes를 읽습니다.
`CDROMREADAUDIO`는 `struct cdrom_read_audio`에 시작 위치, 주소 format, frame 수와 출력 buffer를 지정해 audio data를 읽습니다. 호출은 `ioctl(fd, CDROMREADAUDIO, &ra)`입니다.
Audio read format은 `CDROM_MSF` 또는 `CDROM_LBA`여야 하고 `nframes`는 1~75 범위여야 합니다. 위반하면 `EINVAL`입니다.
Drive queue가 없으면 `ENXIO`이며 이는 잘못된 fd일 가능성이 큽니다. Memory 부족은 `ENOMEM`입니다.
명령별 반환 block과 추가 제약입니다.
CDROMREADMODE1
Read CDROM mode 1 data (2048 Bytes)
(struct cdrom_read)
notes:
Identical to CDROMREADRAW except that block size is
CD_FRAMESIZE (2048) bytes
CDROMREADMODE2
Read CDROM mode 2 data (2336 Bytes)
(struct cdrom_read)
notes:
Identical to CDROMREADRAW except that block size is
CD_FRAMESIZE_RAW0 (2336) bytes
CDROMREADAUDIO
(struct cdrom_read_audio)
usage::
struct cdrom_read_audio ra;
ioctl(fd, CDROMREADAUDIO, &ra);
inputs:
cdrom_read_audio structure containing read start
point and length
outputs:
audio data, returned to buffer indicated by ra
error return:
- EINVAL format not CDROM_MSF or CDROM_LBA
- EINVAL nframes not in range [1 75]
- ENXIO drive has no queue (probably means invalid fd)
- ENOMEM out of memory
CDROMEJECT_SW
528-552`CDROMEJECT_SW`는 drive의 자동 eject 동작을 켜거나 끕니다. `int val`을 세 번째 인자로 직접 전달하며 1은 활성화, 0은 비활성화입니다.
별도 출력은 없습니다. Drive가 eject를 지원하지 않으면 `ENOSYS`, door가 잠겨 있으면 `EBUSY`입니다.
Pointer가 아니라 integer flag 자체를 ioctl 인자로 전달합니다.
CDROMEJECT_SW
enable(1)/disable(0) auto-ejecting
usage::
int val;
ioctl(fd, CDROMEJECT_SW, val);
inputs:
Flag specifying auto-eject flag.
outputs:
none
error return:
- ENOSYS Drive is not capable of ejecting.
- EBUSY Door is locked
CDROMMULTISESSION과 CDROM_GET_MCN
553-612`CDROMMULTISESSION`은 multisession disc의 마지막 session 시작 주소를 얻습니다. `struct cdrom_multisession`에 원하는 format을 지정하고 호출하면 `last_session` 정보가 같은 구조체에 채워집니다.
요청 format은 `CDROM_MSF` 또는 `CDROM_LBA`여야 하며 그 외에는 `EINVAL`입니다.
`CDROM_GET_MCN`은 사용 가능한 경우 `struct cdrom_mcn`으로 Medium Catalog Number, 문서 표현으로는 Universal Product Code를 읽습니다. 입력은 없고 결과 code가 구조체에 반환됩니다.
Audio disc 가운데 MCN 정보를 제공하는 경우는 매우 적고, disc에 기록하는 방식도 균일하지 않습니다. Drive가 MCN data를 읽지 못하면 `ENOSYS`입니다.
Disc metadata 종류에 따라 구조체와 오류가 다릅니다.
요청 주소 format을 유지해 마지막 session 위치를 받습니다.
CDROMMULTISESSION
Obtain the start-of-last-session address of multi session disks
(struct cdrom_multisession)
usage::
struct cdrom_multisession ms_info;
ioctl(fd, CDROMMULTISESSION, &ms_info);
inputs:
cdrom_multisession structure containing desired
format.
outputs:
cdrom_multisession structure is filled with last_session
information.
error return:
- EINVAL format not CDROM_MSF or CDROM_LBA
CDROM_GET_MCN
Obtain the "Universal Product Code"
if available
(struct cdrom_mcn)
usage::
struct cdrom_mcn mcn;
ioctl(fd, CDROM_GET_MCN, &mcn);
inputs:
none
outputs:
Universal Product Code
error return:
- ENOSYS Drive is not capable of reading MCN data.
notes:
- Source code comments state::
The following function is implemented, although very few
audio discs give Universal Product Code information, which
should just be the Medium Catalog Number on the box. Note,
that the way the code is written on the CD is /not/ uniform
across all discs!
CDROM_GET_UPC와 CDROMRESET
613-644`CDROM_GET_UPC`는 `CDROM_GET_MCN`의 폐기된 별칭이며 Linux 2.6.8.1 당시 구현되지 않았습니다. 새 코드에서는 `CDROM_GET_MCN`을 사용해야 합니다.
`CDROMRESET`은 `ioctl(fd, CDROMRESET, 0)`으로 drive를 hard reset합니다. 입력과 출력은 없지만 `CAP_SYS_ADMIN` capability가 필요합니다.
권한이 없으면 `EACCES`, drive가 reset을 지원하지 않으면 `ENOSYS`입니다. Hard reset은 진행 중인 I/O와 device state에 큰 영향을 줄 수 있으므로 복구 경로에서 제한적으로 사용해야 합니다.
지원 여부와 권한 요구를 확인해야 합니다.
CDROM_GET_UPC
CDROM_GET_MCN (deprecated)
Not implemented, as of 2.6.8.1
CDROMRESET
hard-reset the drive
usage::
ioctl(fd, CDROMRESET, 0);
inputs:
none
outputs:
none
error return:
- EACCES Access denied: requires CAP_SYS_ADMIN
- ENOSYS Drive is not capable of resetting.
CDROMREADCOOKED와 CDROMREADALL
645-677`CDROMREADCOOKED`는 userspace가 제공한 `u8 buffer[CD_FRAMESIZE]`에 cooked-mode data 2,048 bytes를 읽습니다. 별도 입력 구조체는 없으며 모든 drive에서 구현되는 것은 아닙니다.
`CDROMREADALL`은 호출 방식은 `CDROMREADCOOKED`와 같지만 2,646 bytes 전체를 읽습니다. Userspace buffer는 해당 크기를 수용해야 합니다.
반환 byte 수와 지원 범위를 구분합니다.
CDROMREADCOOKED
read data in cooked mode
usage::
u8 buffer[CD_FRAMESIZE]
ioctl(fd, CDROMREADCOOKED, buffer);
inputs:
none
outputs:
2048 bytes of data, "cooked" mode.
notes:
Not implemented on all drives.
CDROMREADALL
read all 2646 bytes
Same as CDROMREADCOOKED, but reads 2646 bytes.
CDROMSEEK과 CDROMPLAYBLK
678-719`CDROMSEEK`은 `struct cdrom_msf`의 MSF 주소로 drive 위치를 이동합니다. `ioctl(fd, CDROMSEEK, &msf)`를 호출하며 별도 출력은 없습니다.
`CDROMPLAYBLK`는 SCSI CD 전용 명령입니다. `struct cdrom_blk`에 재생할 block region을 지정하고 `ioctl(fd, CDROMPLAYBLK, &blk)`를 호출합니다.
일반 MSF seek와 SCSI 전용 block audio를 구분합니다.
원하는 주소 표현과 drive 종류에 맞는 명령을 선택합니다.
CDROMSEEK
seek msf address
usage::
struct cdrom_msf msf;
ioctl(fd, CDROMSEEK, &msf);
inputs:
MSF address to seek to.
outputs:
none
CDROMPLAYBLK
scsi-cd only
(struct cdrom_blk)
usage::
struct cdrom_blk blk;
ioctl(fd, CDROMPLAYBLK, &blk);
inputs:
Region to play
outputs:
none
CDROMGETSPINDOWN과 CDROMSETSPINDOWN
720-760`CDROMGETSPINDOWN`과 `CDROMSETSPINDOWN`은 과거 IDE CD에서만 사용하던 폐기된 명령입니다.
GET은 `char spindown` 포인터에 현재 4-bit spindown 값을 반환합니다. SET은 같은 형식의 4-bit 값을 입력으로 받아 spindown 동작을 제어하지만 원문에도 세부 의미가 TODO로 남아 있습니다.
두 ioctl은 obsolete이며 새 userspace 프로그램이 의존해서는 안 됩니다. 지원되지 않는 hardware에서 동작을 추정하지 말고 현대적인 power-management interface를 사용해야 합니다.
IDE CD에 국한된 과거 4-bit 제어입니다.
CDROMGETSPINDOWN
Obsolete, was ide-cd only
usage::
char spindown;
ioctl(fd, CDROMGETSPINDOWN, &spindown);
inputs:
none
outputs:
The value of the current 4-bit spindown value.
CDROMSETSPINDOWN
Obsolete, was ide-cd only
usage::
char spindown
ioctl(fd, CDROMSETSPINDOWN, &spindown);
inputs:
4-bit value used to control spindown (TODO: more detail here)
outputs:
none
CDROM_SET_OPTIONS와 CDROM_CLEAR_OPTIONS
761-802`CDROM_SET_OPTIONS`는 integer bitmask로 drive 동작 option을 켭니다. `CDO_AUTO_CLOSE`는 첫 `open(2)` 때 tray를 닫고, `CDO_AUTO_EJECT`는 마지막 release 때 tray를 엽니다.
`CDO_USE_FFLAGS`는 open 시 `O_NONBLOCK` 정보를 사용하고, `CDO_LOCK`은 열린 파일이 있을 때 tray를 잠급니다. `CDO_CHECK_TYPE`은 data open에서 media type을 검사합니다.
성공 시 ioctl 반환값 자체가 적용 후 option bitmask입니다. 선택한 option을 drive가 지원하지 않으면 `ENOSYS`, 기타 오류는 -1입니다.
`CDROM_CLEAR_OPTIONS`는 호출과 반환 규칙이 같지만 선택된 bit를 끕니다. 따라서 현재 설정을 갱신할 때 반환된 결과 bitmask를 확인해야 합니다.
SET은 bit를 켜고 CLEAR는 같은 bit를 끕니다.
Bitmask를 제출하고 실제 적용 결과를 반환값으로 확인합니다.
CDROM_SET_OPTIONS
Set behavior options
usage::
int options;
ioctl(fd, CDROM_SET_OPTIONS, options);
inputs:
New values for drive options. The logical 'or' of:
============== ==================================
CDO_AUTO_CLOSE close tray on first open(2)
CDO_AUTO_EJECT open tray on last release
CDO_USE_FFLAGS use O_NONBLOCK information on open
CDO_LOCK lock tray on open files
CDO_CHECK_TYPE check type on open for data
============== ==================================
outputs:
Returns the resulting options settings in the
ioctl return value. Returns -1 on error.
error return:
- ENOSYS selected option(s) not supported by drive.
CDROM_CLEAR_OPTIONS
Clear behavior options
Same as CDROM_SET_OPTIONS, except that selected options are
turned off.
CDROM_SELECT_SPEED
803-825`CDROM_SELECT_SPEED`는 integer `speed`를 직접 전달해 CD-ROM drive 속도를 설정합니다. `ioctl(fd, CDROM_SELECT_SPEED, speed)`로 호출하며 별도 출력 구조체는 없습니다.
Drive가 속도 선택을 지원하지 않으면 `ENOSYS`입니다. 실제 허용 단위와 범위는 drive와 driver capability에 따라 달라집니다.
정수 속도 요청의 지원 여부는 장치에 의존합니다.
CDROM_SELECT_SPEED
Set the CD-ROM speed
usage::
int speed;
ioctl(fd, CDROM_SELECT_SPEED, speed);
inputs:
New drive speed.
outputs:
none
error return:
- ENOSYS speed selection not supported by drive.
CDROM_SELECT_DISC
826-848`CDROM_SELECT_DISC`는 jukebox에서 drive에 넣을 disc slot을 선택합니다. `int disk`를 직접 전달하고 별도 출력은 없습니다.
요청한 disc 번호가 changer 용량을 벗어나면 `EINVAL`입니다. 일반 단일-disc device에서는 이 명령이 의미가 없거나 slot 0만 사용할 수 있습니다.
Changer capacity 안의 slot 번호를 지정합니다.
CDROM_SELECT_DISC
Select disc (for juke-boxes)
usage::
int disk;
ioctl(fd, CDROM_SELECT_DISC, disk);
inputs:
Disk to load into drive.
outputs:
none
error return:
- EINVAL Disk number beyond capacity of drive
CDROM_MEDIA_CHANGED
849-875`CDROM_MEDIA_CHANGED`는 지정 slot의 media가 바뀌었는지 검사합니다. 일반 drive는 slot 0을 사용하고 jukebox만 다른 slot 번호를 사용합니다. `CDSL_NONE`과 `CDSL_CURRENT` 특수 값도 전달할 수 있습니다.
Ioctl 반환값은 변경되지 않았으면 0, 변경됐으면 1, 오류면 -1입니다. 일반적인 성공 규칙과 달리 boolean data를 반환값으로 직접 전달합니다.
Drive가 변경 감지를 지원하지 않으면 `ENOSYS`, slot이 용량을 벗어나면 `EINVAL`, memory 부족은 `ENOMEM`입니다.
Slot 입력과 직접 반환되는 boolean 결과를 구분합니다.
CDROM_MEDIA_CHANGED
Check is media changed
usage::
int slot;
ioctl(fd, CDROM_MEDIA_CHANGED, slot);
inputs:
Slot number to be tested, always zero except for jukeboxes.
May also be special values CDSL_NONE or CDSL_CURRENT
outputs:
Ioctl return value is 0 or 1 depending on whether the media
has been changed, or -1 on error.
error returns:
- ENOSYS Drive can't detect media change
- EINVAL Slot number beyond capacity of drive
- ENOMEM Out of memory
CDROM_DRIVE_STATUS
876-912`CDROM_DRIVE_STATUS`는 tray와 drive 준비 상태를 조회합니다. 입력 slot 규칙은 `CDROM_MEDIA_CHANGED`와 같아서 일반 drive는 0, jukebox는 실제 slot, 또는 `CDSL_NONE`·`CDSL_CURRENT`를 사용합니다.
반환값은 `<linux/cdrom.h>`의 `CDS_NO_INFO`, `CDS_NO_DISC`, `CDS_TRAY_OPEN`, `CDS_DRIVE_NOT_READY`, `CDS_DISC_OK` 중 하나이며 오류는 -1입니다.
Status 감지 미지원은 `ENOSYS`, 범위를 벗어난 slot은 `EINVAL`, memory 부족은 `ENOMEM`입니다.
Tray와 media 준비 상태를 단일 enum 값으로 받습니다.
Slot을 선택하고 enum 반환을 오류와 분리합니다.
CDROM_DRIVE_STATUS
Get tray position, etc.
usage::
int slot;
ioctl(fd, CDROM_DRIVE_STATUS, slot);
inputs:
Slot number to be tested, always zero except for jukeboxes.
May also be special values CDSL_NONE or CDSL_CURRENT
outputs:
Ioctl return value will be one of the following values
from <linux/cdrom.h>:
=================== ==========================
CDS_NO_INFO Information not available.
CDS_NO_DISC
CDS_TRAY_OPEN
CDS_DRIVE_NOT_READY
CDS_DISC_OK
-1 error
=================== ==========================
error returns:
- ENOSYS Drive can't detect drive status
- EINVAL Slot number beyond capacity of drive
- ENOMEM Out of memory
CDROM_DISC_STATUS
913-966`CDROM_DISC_STATUS`는 인자 없이 disc type을 반환합니다. 가능한 값은 `CDS_NO_INFO`, `CDS_AUDIO`, `CDS_MIXED`, `CDS_XA_2_2`, `CDS_XA_2_1`, `CDS_DATA_1`입니다.
원문은 이 interface가 disc 전체를 하나의 type으로 표현한다는 근본적 한계를 지적합니다. 실제 CD에는 data track과 audio track이 섞일 수 있으며 단일 enum은 이를 충분히 표현하지 못합니다.
구현은 data track이 하나라도 있으면 data CD로 보고, XA track이 있으면 XA type을 우선 반환하는 정책을 사용했습니다. 이후 mixed-type CD를 위한 `CDS_MIXED`가 추가됐지만 userspace에는 여전히 유용성이 제한적일 수 있습니다.
정확한 track별 유형이 필요하면 이 ioctl의 단일 분류에만 의존하지 말고 TOC를 읽어 각 track을 검사해야 합니다.
단일 반환값이 mixed disc를 완전하게 설명하지 못할 수 있습니다.
CDROM_DISC_STATUS
Get disc type, etc.
usage::
ioctl(fd, CDROM_DISC_STATUS, 0);
inputs:
none
outputs:
Ioctl return value will be one of the following values
from <linux/cdrom.h>:
- CDS_NO_INFO
- CDS_AUDIO
- CDS_MIXED
- CDS_XA_2_2
- CDS_XA_2_1
- CDS_DATA_1
error returns:
none at present
notes:
- Source code comments state::
Ok, this is where problems start. The current interface for
the CDROM_DISC_STATUS ioctl is flawed. It makes the false
assumption that CDs are all CDS_DATA_1 or all CDS_AUDIO, etc.
Unfortunately, while this is often the case, it is also
very common for CDs to have some tracks with data, and some
tracks with audio. Just because I feel like it, I declare
the following to be the best way to cope. If the CD has
ANY data tracks on it, it will be returned as a data CD.
If it has any XA tracks, I will return it as that. Now I
could simplify this interface by combining these returns with
the above, but this more clearly demonstrates the problem
with the current interface. Too bad this wasn't designed
to use bitmasks... -Erik
Well, now we have the option CDS_MIXED: a mixed-type CD.
User level programmers might feel the ioctl is not very
useful.
---david
CDROM_CHANGER_NSLOTS
967-988`CDROM_CHANGER_NSLOTS`는 CD changer의 slot 수를 ioctl 반환값으로 직접 제공합니다. 입력은 없고 일반적인 단일-disc device에서는 보통 1을 반환합니다.
원문 기준으로 별도 오류 반환은 정의되어 있지 않습니다. 결과는 jukebox용 slot 번호 유효성 검사에 사용할 수 있습니다.
구조체 없이 반환값 자체가 개수입니다.
CDROM_CHANGER_NSLOTS
Get number of slots
usage::
ioctl(fd, CDROM_CHANGER_NSLOTS, 0);
inputs:
none
outputs:
The ioctl return value will be the number of slots in a
CD changer. Typically 1 for non-multi-disk devices.
error returns:
none
CDROM_LOCKDOOR
989-1025`CDROM_LOCKDOOR`는 integer flag로 door를 잠그거나 해제합니다. 1은 lock, 0은 unlock이며 별도 출력은 없습니다.
Door lock을 지원하지 않으면 `EDRIVE_CANT_DO_THIS`를 반환합니다. 이 값은 `<linux/cdrom.h>`에 정의되고 당시 `EOPNOTSUPP`와 같았습니다.
여러 사용자가 drive를 열어 둔 상태에서 `CAP_SYS_ADMIN` 없이 unlock하려 하면 `EBUSY`입니다. Linux 2.6.8.1 당시 lock flag가 모든 CD drive를 함께 잠그는 global lock이었다는 주석이 있으며 원문은 이를 bug일 가능성이 높다고 봅니다.
지원 여부, open 사용자 수와 capability가 unlock을 제한합니다.
CDROM_LOCKDOOR
lock or unlock door
usage::
int lock;
ioctl(fd, CDROM_LOCKDOOR, lock);
inputs:
Door lock flag, 1=lock, 0=unlock
outputs:
none
error returns:
- EDRIVE_CANT_DO_THIS
Door lock function not supported.
- EBUSY
Attempt to unlock when multiple users
have the drive open and not CAP_SYS_ADMIN
notes:
As of 2.6.8.1, the lock flag is a global lock, meaning that
all CD drives will be locked or unlocked together. This is
probably a bug.
The EDRIVE_CANT_DO_THIS value is defined in <linux/cdrom.h>
and is currently (2.6.8.1) the same as EOPNOTSUPP
CDROM_DEBUG
1026-1048`CDROM_DEBUG`는 CD-ROM layer debug message를 켜거나 끕니다. `debug=0`은 비활성화, `debug=1`은 활성화이며 호출 성공 시 새 debug flag가 반환됩니다.
이 전역 진단 설정에는 `CAP_SYS_ADMIN`이 필요합니다. 권한이 없으면 `EACCES`입니다.
관리자 권한으로 진단 출력을 제어합니다.
CDROM_DEBUG
Turn debug messages on/off
usage::
int debug;
ioctl(fd, CDROM_DEBUG, debug);
inputs:
Cdrom debug flag, 0=disable, 1=enable
outputs:
The ioctl return value will be the new debug flag.
error return:
- EACCES Access denied: requires CAP_SYS_ADMIN
CDROM_GET_CAPABILITY
1049-1067`CDROM_GET_CAPABILITY`는 입력 없이 현재 device capability bitmask를 ioctl 반환값으로 제공합니다. `CDC_CLOSE_TRAY`, `CDC_OPEN_TRAY` 같은 `CDC_*` flag를 검사해 지원 기능을 판단합니다.
개별 명령을 호출해 실패를 추정하기 전에 이 bitmask로 tray, eject, lock, speed 등의 지원 여부를 확인할 수 있습니다.
반환 bitmask의 CDC_* flag를 검사합니다.
CDROM_GET_CAPABILITY
get capabilities
usage::
ioctl(fd, CDROM_GET_CAPABILITY, 0);
inputs:
none
outputs:
The ioctl return value is the current device capability
flags. See CDC_CLOSE_TRAY, CDC_OPEN_TRAY, etc.
CDROMAUDIOBUFSIZ
1068-1094`CDROMAUDIOBUFSIZ`는 새 audio buffer 크기를 integer로 전달합니다. 성공 시 실제 새 buffer 크기를 ioctl 반환값으로 제공하고 실패 시 -1입니다.
모든 driver가 이 기능을 지원하지는 않습니다. 미지원 driver는 `ENOSYS`를 반환합니다. 원문 usage의 선언은 `int arg`인데 호출 예는 `val`을 사용하므로 실제 코드는 일관된 변수명을 사용해야 합니다.
지원하는 driver에서만 동적으로 조정됩니다.
CDROMAUDIOBUFSIZ
set the audio buffer size
usage::
int arg;
ioctl(fd, CDROMAUDIOBUFSIZ, val);
inputs:
New audio buffer size
outputs:
The ioctl return value is the new audio buffer size, or -1
on error.
error return:
- ENOSYS Not supported by this driver.
notes:
Not supported by all drivers.
DVD_READ_STRUCT
1095-1132`DVD_READ_STRUCT`는 `dvd_struct` union으로 DVD 구조 정보를 읽습니다. `type`에 `DVD_STRUCT_PHYSICAL`, `DVD_STRUCT_COPYRIGHT`, `DVD_STRUCT_DISCKEY`, `DVD_STRUCT_BCA`, `DVD_STRUCT_MANUFACT` 중 원하는 종류를 지정합니다.
Physical과 copyright 정보는 0부터 시작하는 `layer_num`을 지정하고 disc key는 `disckey.agid`를 입력합니다.
반환 union member는 type에 따라 `physical`, `copyright`, `disckey.value`, `bca.{len,value}`, `manufact.{len,value}`입니다. 원문 표의 `manufact.{len,valu}`는 문서 오탈자로 보이지만 원문은 그대로 보존합니다.
요청 layer가 실제 layer 수를 넘으면 `EINVAL`, drive가 잘못된 response를 보내면 `EIO`입니다.
type에 따라 입력 field와 출력 union member가 달라집니다.
Union type과 대응 member를 일치시켜야 합니다.
DVD_READ_STRUCT Read structure
usage::
dvd_struct s;
ioctl(fd, DVD_READ_STRUCT, &s);
inputs:
dvd_struct structure, containing:
=================== ==========================================
type specifies the information desired, one of
DVD_STRUCT_PHYSICAL, DVD_STRUCT_COPYRIGHT,
DVD_STRUCT_DISCKEY, DVD_STRUCT_BCA,
DVD_STRUCT_MANUFACT
physical.layer_num desired layer, indexed from 0
copyright.layer_num desired layer, indexed from 0
disckey.agid
=================== ==========================================
outputs:
dvd_struct structure, containing:
=================== ================================
physical for type == DVD_STRUCT_PHYSICAL
copyright for type == DVD_STRUCT_COPYRIGHT
disckey.value for type == DVD_STRUCT_DISCKEY
bca.{len,value} for type == DVD_STRUCT_BCA
manufact.{len,valu} for type == DVD_STRUCT_MANUFACT
=================== ================================
error returns:
- EINVAL physical.layer_num exceeds number of layers
- EIO Received invalid response from drive
DVD_WRITE_STRUCT와 DVD_AUTH
1133-1159`DVD_WRITE_STRUCT`는 DVD 구조 쓰기 명령이지만 Linux 2.6.8.1 당시 구현되지 않았습니다.
`DVD_AUTH`는 `dvd_authinfo` 구조체로 DVD authentication 절차를 수행합니다. 구조체의 자세한 request/response variant는 `<linux/cdrom.h>`를 따라야 하며 같은 구조체가 입력과 출력에 사용됩니다.
`ai.type`을 kernel이 인식하지 못하면 `ENOTTY`입니다. Authentication은 여러 단계의 state exchange일 수 있으므로 각 호출 뒤 반환된 type과 field를 확인해야 합니다.
미구현 구조 쓰기와 type 기반 인증을 구분합니다.
DVD_WRITE_STRUCT Write structure
Not implemented, as of 2.6.8.1
DVD_AUTH Authentication
usage::
dvd_authinfo ai;
ioctl(fd, DVD_AUTH, &ai);
inputs:
dvd_authinfo structure. See <linux/cdrom.h>
outputs:
dvd_authinfo structure.
error return:
- ENOTTY ai.type not recognized.
CDROM_SEND_PACKET
1160-1194`CDROM_SEND_PACKET`은 `struct cdrom_generic_command`에 packet, data buffer, 방향과 sense/result 정보를 구성해 drive로 raw command를 보냅니다. 호출 뒤 같은 구조체에 결과가 반환됩니다.
Command 실행 실패는 `EIO`입니다. Read-only로 연 drive에서 write command를 시도하거나 명령에 필요한 `CAP_SYS_RAWIO`가 없으면 `EPERM`입니다.
`cgc.data_direction`을 설정하지 않으면 `EINVAL`입니다. Raw packet interface는 일반 ioctl보다 권한과 ABI 오용 위험이 크므로 capability, open mode, buffer 방향을 모두 명시적으로 검증해야 합니다.
Command 방향, open mode와 raw-I/O 권한이 핵심입니다.
Userspace가 command와 memory 방향을 완전히 기술합니다.
CDROM_SEND_PACKET
send a packet to the drive
usage::
struct cdrom_generic_command cgc;
ioctl(fd, CDROM_SEND_PACKET, &cgc);
inputs:
cdrom_generic_command structure containing the packet to send.
outputs:
none
cdrom_generic_command structure containing results.
error return:
- EIO
command failed.
- EPERM
Operation not permitted, either because a
write command was attempted on a drive which
is opened read-only, or because the command
requires CAP_SYS_RAWIO
- EINVAL
cgc.data_direction not set
CDROM_NEXT_WRITABLE과 CDROM_LAST_WRITTEN
1195-1242`CDROM_NEXT_WRITABLE`은 다음에 쓸 수 있는 block 번호를 `long`에 반환합니다. Device가 이 ioctl을 직접 지원하지 않으면 `CDROM_LAST_WRITTEN` 결과에 7을 더한 값을 반환합니다.
`CDROM_LAST_WRITTEN`은 disc에 마지막으로 기록된 block 번호를 `long`에 반환합니다. Direct 지원이 없으면 disc TOC에서 결과를 유도합니다.
Fallback 과정에서 TOC를 읽을 수 없으면 `CDROM_LAST_WRITTEN`은 오류를 반환하고, 이에 의존하는 next-writable 계산도 신뢰할 수 없습니다.
Direct 지원이 없을 때 두 명령은 TOC 기반 fallback을 사용합니다.
직접 명령 지원 여부에 따라 계산 경로가 갈립니다.
CDROM_NEXT_WRITABLE
get next writable block
usage::
long next;
ioctl(fd, CDROM_NEXT_WRITABLE, &next);
inputs:
none
outputs:
The next writable block.
notes:
If the device does not support this ioctl directly, the
ioctl will return CDROM_LAST_WRITTEN + 7.
CDROM_LAST_WRITTEN
get last block written on disc
usage::
long last;
ioctl(fd, CDROM_LAST_WRITTEN, &last);
inputs:
none
outputs:
The last block written on disc
notes:
If the device does not support this ioctl directly, the
result is derived from the disc's table of contents. If the
table of contents can't be read, this ioctl returns an
error.
요약·해설
cdrom.rst:1-1242이 장문은 `<linux/cdrom.h>`의 CD-ROM ioctl을 audio, TOC, sector·media·drive 제어, DVD structure·authentication, raw packet과 writable block 조회까지 명령별로 설명합니다.
원문 1,242줄 전체를 연속 절로 전문 번역했으며 구조체, 상수, source path, 수식, 오류 코드와 원문 줄 좌표를 보존합니다.