← Documents Documentation/userspace-api/ioctl/cdrom.rst GitHub 원문 ↗

Linux 6.18.37 · Userspace API

CD-ROM ioctl 호출 요약

CD-ROM ioctl ABI의 audio, TOC, sector·media·drive 제어, DVD 인증과 packet 명령 전체를 설명합니다.

Source pathDocumentation/userspace-api/ioctl/cdrom.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

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, 수식, 오류 코드와 원문 줄 좌표를 보존합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 ============================
2 Summary of CDROM ioctl calls
3 ============================
4
5 - Edward A. Falk <efalk@google.com>
6
7 November, 2004
8
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
12
13 ioctl values are listed in <linux/cdrom.h>. As of this writing, they
14 are as follows:
15
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)
29 (struct cdrom_read)
30 CDROMREADMODE1 Read CDROM mode 1 data (2048 Bytes)
31 (struct cdrom_read)
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)
44 (struct cdrom_read)
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_TIMED_MEDIA_CHANGE Check if media changed
58 since given time
59 (struct cdrom_timed_media_change_info)
60 CDROM_DRIVE_STATUS Get tray position, etc.
61 CDROM_DISC_STATUS Get disc type, etc.
62 CDROM_CHANGER_NSLOTS Get number of slots
63 CDROM_LOCKDOOR lock or unlock door
64 CDROM_DEBUG Turn debug messages on/off
65 CDROM_GET_CAPABILITY get capabilities
66 CDROMAUDIOBUFSIZ set the audio buffer size
67 DVD_READ_STRUCT Read structure
68 DVD_WRITE_STRUCT Write structure
69 DVD_AUTH Authentication
70 CDROM_SEND_PACKET send a packet to the drive
71 CDROM_NEXT_WRITABLE get next writable block
72 CDROM_LAST_WRITTEN get last block written on disc
73 ======================== ===============================================
74
75
76 The information that follows was determined from reading kernel source
77 code. It is likely that some corrections will be made over time.
78
79 ------------------------------------------------------------------------------
80
81 General:
82
83 Unless otherwise specified, all ioctl calls return 0 on success
84 and -1 with errno set to an appropriate value on error. (Some
85 ioctls return non-negative data values.)
86
87 Unless otherwise specified, all ioctl calls return -1 and set
88 errno to EFAULT on a failed attempt to copy data to or from user
89 address space.
90
91 Individual drivers may return error codes not listed here.
92
93 Unless otherwise specified, all data structures and constants
94 are defined in <linux/cdrom.h>
95
96 ------------------------------------------------------------------------------
97
98
99 CDROMPAUSE
100 Pause Audio Operation
101
102
103 usage::
104
105 ioctl(fd, CDROMPAUSE, 0);
106
107
108 inputs:
109 none
110
111
112 outputs:
113 none
114
115
116 error return:
117 - ENOSYS cd drive not audio-capable.
118
119
120 CDROMRESUME
121 Resume paused Audio Operation
122
123
124 usage::
125
126 ioctl(fd, CDROMRESUME, 0);
127
128
129 inputs:
130 none
131
132
133 outputs:
134 none
135
136
137 error return:
138 - ENOSYS cd drive not audio-capable.
139
140
141 CDROMPLAYMSF
142 Play Audio MSF
143
144 (struct cdrom_msf)
145
146
147 usage::
148
149 struct cdrom_msf msf;
150
151 ioctl(fd, CDROMPLAYMSF, &msf);
152
153 inputs:
154 cdrom_msf structure, describing a segment of music to play
155
156
157 outputs:
158 none
159
160
161 error return:
162 - ENOSYS cd drive not audio-capable.
163
164 notes:
165 - MSF stands for minutes-seconds-frames
166 - LBA stands for logical block address
167 - Segment is described as start and end times, where each time
168 is described as minutes:seconds:frames.
169 A frame is 1/75 of a second.
170
171
172 CDROMPLAYTRKIND
173 Play Audio Track/index
174
175 (struct cdrom_ti)
176
177
178 usage::
179
180 struct cdrom_ti ti;
181
182 ioctl(fd, CDROMPLAYTRKIND, &ti);
183
184 inputs:
185 cdrom_ti structure, describing a segment of music to play
186
187
188 outputs:
189 none
190
191
192 error return:
193 - ENOSYS cd drive not audio-capable.
194
195 notes:
196 - Segment is described as start and end times, where each time
197 is described as a track and an index.
198
199
200
201 CDROMREADTOCHDR
202 Read TOC header
203
204 (struct cdrom_tochdr)
205
206
207 usage::
208
209 cdrom_tochdr header;
210
211 ioctl(fd, CDROMREADTOCHDR, &header);
212
213 inputs:
214 cdrom_tochdr structure
215
216
217 outputs:
218 cdrom_tochdr structure
219
220
221 error return:
222 - ENOSYS cd drive not audio-capable.
223
224
225
226 CDROMREADTOCENTRY
227 Read TOC entry
228
229 (struct cdrom_tocentry)
230
231
232 usage::
233
234 struct cdrom_tocentry entry;
235
236 ioctl(fd, CDROMREADTOCENTRY, &entry);
237
238 inputs:
239 cdrom_tocentry structure
240
241
242 outputs:
243 cdrom_tocentry structure
244
245
246 error return:
247 - ENOSYS cd drive not audio-capable.
248 - EINVAL entry.cdte_format not CDROM_MSF or CDROM_LBA
249 - EINVAL requested track out of bounds
250 - EIO I/O error reading TOC
251
252 notes:
253 - TOC stands for Table Of Contents
254 - MSF stands for minutes-seconds-frames
255 - LBA stands for logical block address
256
257
258
259 CDROMSTOP
260 Stop the cdrom drive
261
262
263 usage::
264
265 ioctl(fd, CDROMSTOP, 0);
266
267
268 inputs:
269 none
270
271
272 outputs:
273 none
274
275
276 error return:
277 - ENOSYS cd drive not audio-capable.
278
279 notes:
280 - Exact interpretation of this ioctl depends on the device,
281 but most seem to spin the drive down.
282
283
284 CDROMSTART
285 Start the cdrom drive
286
287
288 usage::
289
290 ioctl(fd, CDROMSTART, 0);
291
292
293 inputs:
294 none
295
296
297 outputs:
298 none
299
300
301 error return:
302 - ENOSYS cd drive not audio-capable.
303
304 notes:
305 - Exact interpretation of this ioctl depends on the device,
306 but most seem to spin the drive up and/or close the tray.
307 Other devices ignore the ioctl completely.
308
309
310 CDROMEJECT
311 - Ejects the cdrom media
312
313
314 usage::
315
316 ioctl(fd, CDROMEJECT, 0);
317
318
319 inputs:
320 none
321
322
323 outputs:
324 none
325
326
327 error returns:
328 - ENOSYS cd drive not capable of ejecting
329 - EBUSY other processes are accessing drive, or door is locked
330
331 notes:
332 - See CDROM_LOCKDOOR, below.
333
334
335
336
337 CDROMCLOSETRAY
338 pendant of CDROMEJECT
339
340
341 usage::
342
343 ioctl(fd, CDROMCLOSETRAY, 0);
344
345
346 inputs:
347 none
348
349
350 outputs:
351 none
352
353
354 error returns:
355 - ENOSYS cd drive not capable of closing the tray
356 - EBUSY other processes are accessing drive, or door is locked
357
358 notes:
359 - See CDROM_LOCKDOOR, below.
360
361
362
363
364 CDROMVOLCTRL
365 Control output volume (struct cdrom_volctrl)
366
367
368 usage::
369
370 struct cdrom_volctrl volume;
371
372 ioctl(fd, CDROMVOLCTRL, &volume);
373
374 inputs:
375 cdrom_volctrl structure containing volumes for up to 4
376 channels.
377
378 outputs:
379 none
380
381
382 error return:
383 - ENOSYS cd drive not audio-capable.
384
385
386
387 CDROMVOLREAD
388 Get the drive's volume setting
389
390 (struct cdrom_volctrl)
391
392
393 usage::
394
395 struct cdrom_volctrl volume;
396
397 ioctl(fd, CDROMVOLREAD, &volume);
398
399 inputs:
400 none
401
402
403 outputs:
404 The current volume settings.
405
406
407 error return:
408 - ENOSYS cd drive not audio-capable.
409
410
411
412 CDROMSUBCHNL
413 Read subchannel data
414
415 (struct cdrom_subchnl)
416
417
418 usage::
419
420 struct cdrom_subchnl q;
421
422 ioctl(fd, CDROMSUBCHNL, &q);
423
424 inputs:
425 cdrom_subchnl structure
426
427
428 outputs:
429 cdrom_subchnl structure
430
431
432 error return:
433 - ENOSYS cd drive not audio-capable.
434 - EINVAL format not CDROM_MSF or CDROM_LBA
435
436 notes:
437 - Format is converted to CDROM_MSF or CDROM_LBA
438 as per user request on return
439
440
441
442 CDROMREADRAW
443 read data in raw mode (2352 Bytes)
444
445 (struct cdrom_read)
446
447 usage::
448
449 union {
450
451 struct cdrom_msf msf; /* input */
452 char buffer[CD_FRAMESIZE_RAW]; /* return */
453 } arg;
454 ioctl(fd, CDROMREADRAW, &arg);
455
456 inputs:
457 cdrom_msf structure indicating an address to read.
458
459 Only the start values are significant.
460
461 outputs:
462 Data written to address provided by user.
463
464
465 error return:
466 - EINVAL address less than 0, or msf less than 0:2:0
467 - ENOMEM out of memory
468
469 notes:
470 - As of 2.6.8.1, comments in <linux/cdrom.h> indicate that this
471 ioctl accepts a cdrom_read structure, but actual source code
472 reads a cdrom_msf structure and writes a buffer of data to
473 the same address.
474
475 - MSF values are converted to LBA values via this formula::
476
477 lba = (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
478
479
480
481
482 CDROMREADMODE1
483 Read CDROM mode 1 data (2048 Bytes)
484
485 (struct cdrom_read)
486
487 notes:
488 Identical to CDROMREADRAW except that block size is
489 CD_FRAMESIZE (2048) bytes
490
491
492
493 CDROMREADMODE2
494 Read CDROM mode 2 data (2336 Bytes)
495
496 (struct cdrom_read)
497
498 notes:
499 Identical to CDROMREADRAW except that block size is
500 CD_FRAMESIZE_RAW0 (2336) bytes
501
502
503
504 CDROMREADAUDIO
505 (struct cdrom_read_audio)
506
507 usage::
508
509 struct cdrom_read_audio ra;
510
511 ioctl(fd, CDROMREADAUDIO, &ra);
512
513 inputs:
514 cdrom_read_audio structure containing read start
515 point and length
516
517 outputs:
518 audio data, returned to buffer indicated by ra
519
520
521 error return:
522 - EINVAL format not CDROM_MSF or CDROM_LBA
523 - EINVAL nframes not in range [1 75]
524 - ENXIO drive has no queue (probably means invalid fd)
525 - ENOMEM out of memory
526
527
528 CDROMEJECT_SW
529 enable(1)/disable(0) auto-ejecting
530
531
532 usage::
533
534 int val;
535
536 ioctl(fd, CDROMEJECT_SW, val);
537
538 inputs:
539 Flag specifying auto-eject flag.
540
541
542 outputs:
543 none
544
545
546 error return:
547 - ENOSYS Drive is not capable of ejecting.
548 - EBUSY Door is locked
549
550
551
552
553 CDROMMULTISESSION
554 Obtain the start-of-last-session address of multi session disks
555
556 (struct cdrom_multisession)
557
558 usage::
559
560 struct cdrom_multisession ms_info;
561
562 ioctl(fd, CDROMMULTISESSION, &ms_info);
563
564 inputs:
565 cdrom_multisession structure containing desired
566
567 format.
568
569 outputs:
570 cdrom_multisession structure is filled with last_session
571 information.
572
573 error return:
574 - EINVAL format not CDROM_MSF or CDROM_LBA
575
576
577 CDROM_GET_MCN
578 Obtain the "Universal Product Code"
579 if available
580
581 (struct cdrom_mcn)
582
583
584 usage::
585
586 struct cdrom_mcn mcn;
587
588 ioctl(fd, CDROM_GET_MCN, &mcn);
589
590 inputs:
591 none
592
593
594 outputs:
595 Universal Product Code
596
597
598 error return:
599 - ENOSYS Drive is not capable of reading MCN data.
600
601 notes:
602 - Source code comments state::
603
604 The following function is implemented, although very few
605 audio discs give Universal Product Code information, which
606 should just be the Medium Catalog Number on the box. Note,
607 that the way the code is written on the CD is /not/ uniform
608 across all discs!
609
610
611
612
613 CDROM_GET_UPC
614 CDROM_GET_MCN (deprecated)
615
616
617 Not implemented, as of 2.6.8.1
618
619
620
621 CDROMRESET
622 hard-reset the drive
623
624
625 usage::
626
627 ioctl(fd, CDROMRESET, 0);
628
629
630 inputs:
631 none
632
633
634 outputs:
635 none
636
637
638 error return:
639 - EACCES Access denied: requires CAP_SYS_ADMIN
640 - ENOSYS Drive is not capable of resetting.
641
642
643
644
645 CDROMREADCOOKED
646 read data in cooked mode
647
648
649 usage::
650
651 u8 buffer[CD_FRAMESIZE]
652
653 ioctl(fd, CDROMREADCOOKED, buffer);
654
655 inputs:
656 none
657
658
659 outputs:
660 2048 bytes of data, "cooked" mode.
661
662
663 notes:
664 Not implemented on all drives.
665
666
667
668
669
670 CDROMREADALL
671 read all 2646 bytes
672
673
674 Same as CDROMREADCOOKED, but reads 2646 bytes.
675
676
677
678 CDROMSEEK
679 seek msf address
680
681
682 usage::
683
684 struct cdrom_msf msf;
685
686 ioctl(fd, CDROMSEEK, &msf);
687
688 inputs:
689 MSF address to seek to.
690
691
692 outputs:
693 none
694
695
696
697
698 CDROMPLAYBLK
699 scsi-cd only
700
701 (struct cdrom_blk)
702
703
704 usage::
705
706 struct cdrom_blk blk;
707
708 ioctl(fd, CDROMPLAYBLK, &blk);
709
710 inputs:
711 Region to play
712
713
714 outputs:
715 none
716
717
718
719
720 CDROMGETSPINDOWN
721 Obsolete, was ide-cd only
722
723
724 usage::
725
726 char spindown;
727
728 ioctl(fd, CDROMGETSPINDOWN, &spindown);
729
730 inputs:
731 none
732
733
734 outputs:
735 The value of the current 4-bit spindown value.
736
737
738
739
740
741 CDROMSETSPINDOWN
742 Obsolete, was ide-cd only
743
744
745 usage::
746
747 char spindown
748
749 ioctl(fd, CDROMSETSPINDOWN, &spindown);
750
751 inputs:
752 4-bit value used to control spindown (TODO: more detail here)
753
754
755 outputs:
756 none
757
758
759
760
761
762
763 CDROM_SET_OPTIONS
764 Set behavior options
765
766
767 usage::
768
769 int options;
770
771 ioctl(fd, CDROM_SET_OPTIONS, options);
772
773 inputs:
774 New values for drive options. The logical 'or' of:
775
776 ============== ==================================
777 CDO_AUTO_CLOSE close tray on first open(2)
778 CDO_AUTO_EJECT open tray on last release
779 CDO_USE_FFLAGS use O_NONBLOCK information on open
780 CDO_LOCK lock tray on open files
781 CDO_CHECK_TYPE check type on open for data
782 ============== ==================================
783
784 outputs:
785 Returns the resulting options settings in the
786 ioctl return value. Returns -1 on error.
787
788 error return:
789 - ENOSYS selected option(s) not supported by drive.
790
791
792
793
794 CDROM_CLEAR_OPTIONS
795 Clear behavior options
796
797
798 Same as CDROM_SET_OPTIONS, except that selected options are
799 turned off.
800
801
802
803 CDROM_SELECT_SPEED
804 Set the CD-ROM speed
805
806
807 usage::
808
809 int speed;
810
811 ioctl(fd, CDROM_SELECT_SPEED, speed);
812
813 inputs:
814 New drive speed.
815
816
817 outputs:
818 none
819
820
821 error return:
822 - ENOSYS speed selection not supported by drive.
823
824
825
826 CDROM_SELECT_DISC
827 Select disc (for juke-boxes)
828
829
830 usage::
831
832 int disk;
833
834 ioctl(fd, CDROM_SELECT_DISC, disk);
835
836 inputs:
837 Disk to load into drive.
838
839
840 outputs:
841 none
842
843
844 error return:
845 - EINVAL Disk number beyond capacity of drive
846
847
848
849 CDROM_MEDIA_CHANGED
850 Check is media changed
851
852
853 usage::
854
855 int slot;
856
857 ioctl(fd, CDROM_MEDIA_CHANGED, slot);
858
859 inputs:
860 Slot number to be tested, always zero except for jukeboxes.
861
862 May also be special values CDSL_NONE or CDSL_CURRENT
863
864 outputs:
865 Ioctl return value is 0 or 1 depending on whether the media
866
867 has been changed, or -1 on error.
868
869 error returns:
870 - ENOSYS Drive can't detect media change
871 - EINVAL Slot number beyond capacity of drive
872 - ENOMEM Out of memory
873
874
875
876 CDROM_DRIVE_STATUS
877 Get tray position, etc.
878
879
880 usage::
881
882 int slot;
883
884 ioctl(fd, CDROM_DRIVE_STATUS, slot);
885
886 inputs:
887 Slot number to be tested, always zero except for jukeboxes.
888
889 May also be special values CDSL_NONE or CDSL_CURRENT
890
891 outputs:
892 Ioctl return value will be one of the following values
893
894 from <linux/cdrom.h>:
895
896 =================== ==========================
897 CDS_NO_INFO Information not available.
898 CDS_NO_DISC
899 CDS_TRAY_OPEN
900 CDS_DRIVE_NOT_READY
901 CDS_DISC_OK
902 -1 error
903 =================== ==========================
904
905 error returns:
906 - ENOSYS Drive can't detect drive status
907 - EINVAL Slot number beyond capacity of drive
908 - ENOMEM Out of memory
909
910
911
912
913 CDROM_DISC_STATUS
914 Get disc type, etc.
915
916
917 usage::
918
919 ioctl(fd, CDROM_DISC_STATUS, 0);
920
921
922 inputs:
923 none
924
925
926 outputs:
927 Ioctl return value will be one of the following values
928
929 from <linux/cdrom.h>:
930
931 - CDS_NO_INFO
932 - CDS_AUDIO
933 - CDS_MIXED
934 - CDS_XA_2_2
935 - CDS_XA_2_1
936 - CDS_DATA_1
937
938 error returns:
939 none at present
940
941 notes:
942 - Source code comments state::
943
944
945 Ok, this is where problems start. The current interface for
946 the CDROM_DISC_STATUS ioctl is flawed. It makes the false
947 assumption that CDs are all CDS_DATA_1 or all CDS_AUDIO, etc.
948 Unfortunately, while this is often the case, it is also
949 very common for CDs to have some tracks with data, and some
950 tracks with audio. Just because I feel like it, I declare
951 the following to be the best way to cope. If the CD has
952 ANY data tracks on it, it will be returned as a data CD.
953 If it has any XA tracks, I will return it as that. Now I
954 could simplify this interface by combining these returns with
955 the above, but this more clearly demonstrates the problem
956 with the current interface. Too bad this wasn't designed
957 to use bitmasks... -Erik
958
959 Well, now we have the option CDS_MIXED: a mixed-type CD.
960 User level programmers might feel the ioctl is not very
961 useful.
962 ---david
963
964
965
966
967 CDROM_CHANGER_NSLOTS
968 Get number of slots
969
970
971 usage::
972
973 ioctl(fd, CDROM_CHANGER_NSLOTS, 0);
974
975
976 inputs:
977 none
978
979
980 outputs:
981 The ioctl return value will be the number of slots in a
982 CD changer. Typically 1 for non-multi-disk devices.
983
984 error returns:
985 none
986
987
988
989 CDROM_LOCKDOOR
990 lock or unlock door
991
992
993 usage::
994
995 int lock;
996
997 ioctl(fd, CDROM_LOCKDOOR, lock);
998
999 inputs:
1000 Door lock flag, 1=lock, 0=unlock
1003 outputs:
1004 none
1007 error returns:
1008 - EDRIVE_CANT_DO_THIS
1010 Door lock function not supported.
1011 - EBUSY
1013 Attempt to unlock when multiple users
1014 have the drive open and not CAP_SYS_ADMIN
1016 notes:
1017 As of 2.6.8.1, the lock flag is a global lock, meaning that
1018 all CD drives will be locked or unlocked together. This is
1019 probably a bug.
1021 The EDRIVE_CANT_DO_THIS value is defined in <linux/cdrom.h>
1022 and is currently (2.6.8.1) the same as EOPNOTSUPP
1026 CDROM_DEBUG
1027 Turn debug messages on/off
1030 usage::
1032 int debug;
1034 ioctl(fd, CDROM_DEBUG, debug);
1036 inputs:
1037 Cdrom debug flag, 0=disable, 1=enable
1040 outputs:
1041 The ioctl return value will be the new debug flag.
1044 error return:
1045 - EACCES Access denied: requires CAP_SYS_ADMIN
1049 CDROM_GET_CAPABILITY
1050 get capabilities
1053 usage::
1055 ioctl(fd, CDROM_GET_CAPABILITY, 0);
1058 inputs:
1059 none
1062 outputs:
1063 The ioctl return value is the current device capability
1064 flags. See CDC_CLOSE_TRAY, CDC_OPEN_TRAY, etc.
1068 CDROMAUDIOBUFSIZ
1069 set the audio buffer size
1072 usage::
1074 int arg;
1076 ioctl(fd, CDROMAUDIOBUFSIZ, val);
1078 inputs:
1079 New audio buffer size
1082 outputs:
1083 The ioctl return value is the new audio buffer size, or -1
1084 on error.
1086 error return:
1087 - ENOSYS Not supported by this driver.
1089 notes:
1090 Not supported by all drivers.
1095 DVD_READ_STRUCT Read structure
1097 usage::
1099 dvd_struct s;
1101 ioctl(fd, DVD_READ_STRUCT, &s);
1103 inputs:
1104 dvd_struct structure, containing:
1106 =================== ==========================================
1107 type specifies the information desired, one of
1108 DVD_STRUCT_PHYSICAL, DVD_STRUCT_COPYRIGHT,
1109 DVD_STRUCT_DISCKEY, DVD_STRUCT_BCA,
1110 DVD_STRUCT_MANUFACT
1111 physical.layer_num desired layer, indexed from 0
1112 copyright.layer_num desired layer, indexed from 0
1113 disckey.agid
1114 =================== ==========================================
1116 outputs:
1117 dvd_struct structure, containing:
1119 =================== ================================
1120 physical for type == DVD_STRUCT_PHYSICAL
1121 copyright for type == DVD_STRUCT_COPYRIGHT
1122 disckey.value for type == DVD_STRUCT_DISCKEY
1123 bca.{len,value} for type == DVD_STRUCT_BCA
1124 manufact.{len,valu} for type == DVD_STRUCT_MANUFACT
1125 =================== ================================
1127 error returns:
1128 - EINVAL physical.layer_num exceeds number of layers
1129 - EIO Received invalid response from drive
1133 DVD_WRITE_STRUCT Write structure
1135 Not implemented, as of 2.6.8.1
1139 DVD_AUTH Authentication
1141 usage::
1143 dvd_authinfo ai;
1145 ioctl(fd, DVD_AUTH, &ai);
1147 inputs:
1148 dvd_authinfo structure. See <linux/cdrom.h>
1151 outputs:
1152 dvd_authinfo structure.
1155 error return:
1156 - ENOTTY ai.type not recognized.
1160 CDROM_SEND_PACKET
1161 send a packet to the drive
1164 usage::
1166 struct cdrom_generic_command cgc;
1168 ioctl(fd, CDROM_SEND_PACKET, &cgc);
1170 inputs:
1171 cdrom_generic_command structure containing the packet to send.
1174 outputs:
1175 none
1177 cdrom_generic_command structure containing results.
1179 error return:
1180 - EIO
1182 command failed.
1183 - EPERM
1185 Operation not permitted, either because a
1186 write command was attempted on a drive which
1187 is opened read-only, or because the command
1188 requires CAP_SYS_RAWIO
1189 - EINVAL
1191 cgc.data_direction not set
1195 CDROM_NEXT_WRITABLE
1196 get next writable block
1199 usage::
1201 long next;
1203 ioctl(fd, CDROM_NEXT_WRITABLE, &next);
1205 inputs:
1206 none
1209 outputs:
1210 The next writable block.
1213 notes:
1214 If the device does not support this ioctl directly, the
1216 ioctl will return CDROM_LAST_WRITTEN + 7.
1220 CDROM_LAST_WRITTEN
1221 get last block written on disc
1224 usage::
1226 long last;
1228 ioctl(fd, CDROM_LAST_WRITTEN, &last);
1230 inputs:
1231 none
1234 outputs:
1235 The last block written on disc
1238 notes:
1239 If the device does not support this ioctl directly, the
1240 result is derived from the disc's table of contents. If the
1241 table of contents can't be read, this ioctl returns an
1242 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 기능을 전제로 합니다.

CD-ROM ioctl 기능군
항목설명
AudioCDROMPAUSE, CDROMRESUME, CDROMPLAYMSF, CDROMPLAYTRKIND
TOC/subchannelCDROMREADTOCHDR, CDROMREADTOCENTRY, CDROMSUBCHNL
Sector readCDROMREADMODE1, CDROMREADMODE2, CDROMREADRAW, CDROMREADCOOKED, CDROMREADALL
Drive/trayCDROMSTOP, CDROMSTART, CDROMEJECT, CDROMCLOSETRAY, CDROM_LOCKDOOR
Media/sessionCDROMMULTISESSION, CDROM_MEDIA_CHANGED, CDROM_TIMED_MEDIA_CHANGE
ConfigurationCDROM_SET_OPTIONS, CDROM_CLEAR_OPTIONS, CDROM_SELECT_SPEED
DVDDVD_READ_STRUCT, DVD_WRITE_STRUCT, DVD_AUTH
Packet/writeCDROM_SEND_PACKET, CDROM_NEXT_WRITABLE, CDROM_LAST_WRITTEN

긴 상수 목록을 동작 영역별로 재구성했습니다.

CD-ROM ioctl 선택
필요한 동작 분류<linux/cdrom.h> 상수 확인입출력 구조체 준비ioctl(fd, command, arg) 호출반환값과 errno 처리

요청 목적에서 관련 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 크기와 의미를 함께 확인해야 합니다.

공통 ioctl 계약
항목설명
성공보통 0, 일부는 0 이상의 데이터 값
일반 실패-1, errno 설정
Userspace copy 실패EFAULT
추가 오류개별 driver가 별도 errno 반환 가능
정의 위치<linux/cdrom.h>

각 명령의 개별 설명보다 먼저 적용되는 기본 규칙입니다.

------------------------------------------------------------------------------

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를 사전에 확인하는 것이 좋습니다.

Audio pause/resume
항목설명
CDROMPAUSEioctl(fd, CDROMPAUSE, 0), audio 일시 정지
CDROMRESUMEioctl(fd, CDROMRESUME, 0), 재생 재개
입력/출력없음
지원하지 않는 driveENOSYS

두 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`입니다.

Audio 구간 지정 방식
항목설명
CDROMPLAYMSFstruct cdrom_msf, minute:second:frame
Frame1/75초
CDROMPLAYTRKINDstruct cdrom_ti, track/index
출력없음
Audio 미지원ENOSYS

같은 재생 목적이지만 주소 표현이 다릅니다.

Audio 구간 재생
MSF 또는 track/index 선택시작 위치 설정끝 위치 설정대응 구조체 포인터로 ioctlENOSYS 여부 확인

주소 표현을 선택해 시작과 끝을 구조체에 채웁니다.

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`를 반환할 수 있습니다.

TOC 조회
항목설명
CDROMREADTOCHDRstruct cdrom_tochdr 입출력
CDROMREADTOCENTRYstruct cdrom_tocentry 입출력
허용 formatCDROM_MSF 또는 CDROM_LBA
잘못된 format/trackEINVAL
TOC 읽기 실패EIO
Audio 미지원ENOSYS

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별 해석 차이를 고려해 상태 확인 명령과 함께 사용해야 합니다.

Drive start/stop
항목설명
CDROMSTOP대개 spin down
CDROMSTART대개 spin up 또는 tray close
인자0
입력/출력없음
Audio 미지원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 상태를 확인해야 합니다.

Eject 실패 조건
항목설명
Eject 미지원ENOSYS
다른 process 접근EBUSY
Door lockedEBUSY
관련 제어CDROM_LOCKDOOR

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` 상태의 영향을 받습니다.

Tray close 결과
항목설명
성공Tray close 요청 수행
Close 미지원ENOSYS
접근 중/door lockedEBUSY
관련 제어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에 따라 달라질 수 있습니다.

Volume ioctl
항목설명
CDROMVOLCTRLcdrom_volctrl 입력, 최대 4 channel 설정
CDROMVOLREADcdrom_volctrl 출력, 현재 설정 조회
Audio 미지원ENOSYS
구조체struct cdrom_volctrl

동일 구조체를 설정과 조회에 반대 방향으로 사용합니다.




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`입니다.

Subchannel 조회
항목설명
구조체struct cdrom_subchnl
허용 formatCDROM_MSF, CDROM_LBA
잘못된 formatEINVAL
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>` 정의를 사용합니다.

Raw frame read
항목설명
명령CDROMREADRAW
입력struct cdrom_msf의 시작 위치
출력2,352-byte CD_FRAMESIZE_RAW data
잘못된 주소EINVAL
Memory 부족ENOMEM
주의Header 주석과 실제 source ABI 차이

입력 구조체와 출력 buffer가 같은 주소를 공유하는 특수 ABI입니다.

CDROMREADRAW in-place buffer
충분한 union/buffer 할당앞부분에 cdrom_msf 기록ioctl 호출Kernel이 MSF를 LBA로 변환같은 주소에 raw frame 반환

동일 주소의 역할이 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`입니다.

CD sector 읽기 크기
항목설명
CDROMREADMODE12,048 bytes, CD_FRAMESIZE
CDROMREADMODE22,336 bytes, CD_FRAMESIZE_RAW0
CDROMREADRAW2,352 bytes, CD_FRAMESIZE_RAW
CDROMREADAUDIO1~75 frames, 지정 buffer
잘못된 format/nframesEINVAL
Drive queue 없음ENXIO
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`입니다.

Auto-eject 제어
항목설명
val=1Auto-eject 활성화
val=0Auto-eject 비활성화
Eject 미지원ENOSYS
Door lockedEBUSY

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`입니다.

Session과 catalog 정보
항목설명
CDROMMULTISESSIONstruct cdrom_multisession, last_session 출력
Session formatCDROM_MSF 또는 CDROM_LBA
잘못된 formatEINVAL
CDROM_GET_MCNstruct cdrom_mcn, catalog code 출력
MCN 미지원ENOSYS
MCN 신뢰성Disc별 기록 방식이 균일하지 않음

Disc metadata 종류에 따라 구조체와 오류가 다릅니다.

Multisession 주소 조회
cdrom_multisession 초기화MSF 또는 LBA format 선택CDROMMULTISESSION 호출last_session field 확인

요청 주소 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에 큰 영향을 줄 수 있으므로 복구 경로에서 제한적으로 사용해야 합니다.

Reset과 폐기 명령
항목설명
CDROM_GET_UPC폐기·미구현, CDROM_GET_MCN 사용
CDROMRESETDrive hard reset
필요 capabilityCAP_SYS_ADMIN
권한 없음EACCES
Reset 미지원ENOSYS

지원 여부와 권한 요구를 확인해야 합니다.

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는 해당 크기를 수용해야 합니다.

Cooked와 all read
항목설명
CDROMREADCOOKED2,048 bytes, CD_FRAMESIZE
CDROMREADALL2,646 bytes
입력없음
출력Userspace buffer
지원Drive별로 다름

반환 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)`를 호출합니다.

위치 이동과 block 재생
항목설명
CDROMSEEKstruct cdrom_msf 입력, MSF 주소로 seek
CDROMPLAYBLKstruct cdrom_blk 입력, region 재생
PLAYBLK 범위SCSI CD 전용
출력없음

일반 MSF seek와 SCSI 전용 block audio를 구분합니다.

Disc 위치 제어
일반 seek인지 audio block 재생인지 판단MSF 또는 cdrom_blk 준비대응 ioctl 호출Device별 결과 확인

원하는 주소 표현과 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를 사용해야 합니다.

폐기된 spindown ioctl
항목설명
CDROMGETSPINDOWN현재 4-bit 값 출력
CDROMSETSPINDOWN4-bit 값 입력
과거 범위ide-cd only
현재 상태Obsolete
세부 의미원문에 TODO로 미완성

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를 확인해야 합니다.

CD-ROM behavior option
항목설명
CDO_AUTO_CLOSE첫 open에서 tray close
CDO_AUTO_EJECT마지막 release에서 tray open
CDO_USE_FFLAGSopen의 O_NONBLOCK 정보 사용
CDO_LOCKOpen file이 있으면 tray lock
CDO_CHECK_TYPEData open에서 media type 검사
지원하지 않는 optionENOSYS
성공 반환적용 후 option bitmask

SET은 bit를 켜고 CLEAR는 같은 bit를 끕니다.

Drive option 갱신
변경할 CDO_* bit 조합SET 또는 CLEAR 선택ioctl에 integer bitmask 전달Drive 지원 여부 검사반환된 결과 option 저장

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에 따라 달라집니다.

Speed 선택
항목설명
입력int speed
출력없음
미지원ENOSYS
해석Drive/driver별 허용 속도

정수 속도 요청의 지원 여부는 장치에 의존합니다.

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만 사용할 수 있습니다.

Jukebox disc 선택
항목설명
입력int disk
대상CD jukebox/changer
출력없음
범위 초과EINVAL

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`입니다.

Media change 검사
항목설명
일반 slot0
특수 slotCDSL_NONE, CDSL_CURRENT
변경 없음반환 0
변경 있음반환 1
감지 미지원ENOSYS
잘못된 slotEINVAL
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`입니다.

Drive status 반환
항목설명
CDS_NO_INFO정보 없음
CDS_NO_DISCDisc 없음
CDS_TRAY_OPENTray 열림
CDS_DRIVE_NOT_READYDrive 준비 안 됨
CDS_DISC_OKDisc 사용 가능
오류-1 및 errno

Tray와 media 준비 상태를 단일 enum 값으로 받습니다.

Drive 상태 확인
Slot 또는 CDSL_* 선택CDROM_DRIVE_STATUS 호출-1이면 errno 처리그 외 CDS_* 값 해석

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을 검사해야 합니다.

Disc type enum
항목설명
CDS_NO_INFOType 정보 없음
CDS_AUDIOAudio disc
CDS_MIXEDAudio/data 혼합
CDS_XA_2_2XA mode 2 form 2
CDS_XA_2_1XA mode 2 form 1
CDS_DATA_1Mode 1 data
정밀 판별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 번호 유효성 검사에 사용할 수 있습니다.

Changer slot 수
항목설명
입력없음
반환Changer slot 개수
일반 drive보통 1
용도SELECT_DISC와 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일 가능성이 높다고 봅니다.

Door lock 제약
항목설명
lock=1Door 잠금
lock=0Door 잠금 해제
기능 미지원EDRIVE_CANT_DO_THIS / EOPNOTSUPP
여러 사용자 + 비관리자 unlockEBUSY
관리 capabilityCAP_SYS_ADMIN
과거 구현 주의모든 drive에 적용되는 global lock 가능성

지원 여부, 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`입니다.

CD-ROM debug
항목설명
debug=0Debug message 비활성화
debug=1Debug message 활성화
성공 반환새 debug flag
권한 없음EACCES
필요 capabilityCAP_SYS_ADMIN

관리자 권한으로 진단 출력을 제어합니다.

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 등의 지원 여부를 확인할 수 있습니다.

Capability 조회
항목설명
입력없음
반환현재 device capability flags
CDC_CLOSE_TRAY, CDC_OPEN_TRAY
용도기능별 ioctl 사전 검사

반환 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`을 사용하므로 실제 코드는 일관된 변수명을 사용해야 합니다.

Audio buffer 크기
항목설명
입력새 integer buffer size
성공 반환적용된 새 크기
실패-1
Driver 미지원ENOSYS
문서 예제 주의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`입니다.

DVD structure type
항목설명
DVD_STRUCT_PHYSICALphysical.layer_num -> physical
DVD_STRUCT_COPYRIGHTcopyright.layer_num -> copyright
DVD_STRUCT_DISCKEYdisckey.agid -> disckey.value
DVD_STRUCT_BCAbca.len/value
DVD_STRUCT_MANUFACTmanufact.len/value
Layer 범위 초과EINVAL
Drive response 오류EIO

type에 따라 입력 field와 출력 union member가 달라집니다.

DVD structure 읽기
dvd_struct 초기화type 선택필요한 layer_num 또는 agid 설정DVD_READ_STRUCT 호출type에 대응하는 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를 확인해야 합니다.

DVD write/auth
항목설명
DVD_WRITE_STRUCT당시 미구현
DVD_AUTHdvd_authinfo 입출력
상세 variant<linux/cdrom.h>
알 수 없는 ai.typeENOTTY

미구현 구조 쓰기와 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 방향을 모두 명시적으로 검증해야 합니다.

Generic packet 오류
항목설명
구조체struct cdrom_generic_command
Command 실패EIO
Read-only fd의 writeEPERM
Raw-I/O 권한 부족EPERM, CAP_SYS_RAWIO 필요
data_direction 미설정EINVAL
출력같은 cgc 구조체의 result/sense

Command 방향, open mode와 raw-I/O 권한이 핵심입니다.

Raw packet 제출
cgc와 packet 초기화data buffer와 data_direction 지정Write이면 fd mode 확인CAP_SYS_RAWIO 요구 확인CDROM_SEND_PACKET 호출result와 sense 해석

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 계산도 신뢰할 수 없습니다.

Writable block 위치
항목설명
CDROM_NEXT_WRITABLE다음 writable block 출력
NEXT fallbackCDROM_LAST_WRITTEN + 7
CDROM_LAST_WRITTEN마지막 written block 출력
LAST fallbackDisc TOC에서 유도
TOC 읽기 실패오류 반환

Direct 지원이 없을 때 두 명령은 TOC 기반 fallback을 사용합니다.

Writable 위치 fallback
NEXT_WRITABLE 직접 지원 확인미지원이면 LAST_WRITTEN 조회LAST 미지원이면 TOC 읽기마지막 block 계산+7로 다음 writable 위치 산출

직접 명령 지원 여부에 따라 계산 경로가 갈립니다.

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.