blob: bdccb74fc92d705fe2a23764fcbc79191c1ab9aa [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001IDE-CD driver documentation
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -03002===========================
3
4:Originally by: scott snyder <snyder@fnald0.fnal.gov> (19 May 1996)
5:Carrying on the torch is: Erik Andersen <andersee@debian.org>
6:New maintainers (19 Oct 1998): Jens Axboe <axboe@image.dk>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
81. Introduction
9---------------
10
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -030011The ide-cd driver should work with all ATAPI ver 1.2 to ATAPI 2.6 compliant
Linus Torvalds1da177e2005-04-16 15:20:36 -070012CDROM drives which attach to an IDE interface. Note that some CDROM vendors
13(including Mitsumi, Sony, Creative, Aztech, and Goldstar) have made
14both ATAPI-compliant drives and drives which use a proprietary
15interface. If your drive uses one of those proprietary interfaces,
16this driver will not work with it (but one of the other CDROM drivers
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -030017probably will). This driver will not work with `ATAPI` drives which
Linus Torvalds1da177e2005-04-16 15:20:36 -070018attach to the parallel port. In addition, there is at least one drive
19(CyCDROM CR520ie) which attaches to the IDE port but is not ATAPI;
20this driver will not work with drives like that either (but see the
21aztcd driver).
22
23This driver provides the following features:
24
25 - Reading from data tracks, and mounting ISO 9660 filesystems.
26
27 - Playing audio tracks. Most of the CDROM player programs floating
28 around should work; I usually use Workman.
29
30 - Multisession support.
31
32 - On drives which support it, reading digital audio data directly
33 from audio tracks. The program cdda2wav can be used for this.
34 Note, however, that only some drives actually support this.
35
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -030036 - There is now support for CDROM changers which comply with the
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 ATAPI 2.6 draft standard (such as the NEC CDR-251). This additional
38 functionality includes a function call to query which slot is the
39 currently selected slot, a function call to query which slots contain
40 CDs, etc. A sample program which demonstrates this functionality is
41 appended to the end of this file. The Sanyo 3-disc changer
42 (which does not conform to the standard) is also now supported.
43 Please note the driver refers to the first CD as slot # 0.
44
45
462. Installation
47---------------
48
490. The ide-cd relies on the ide disk driver. See
Mauro Carvalho Chehabd7b461c52019-06-12 14:52:47 -030050 Documentation/ide/ide.rst for up-to-date information on the ide
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 driver.
52
531. Make sure that the ide and ide-cd drivers are compiled into the
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -030054 kernel you're using. When configuring the kernel, in the section
55 entitled "Floppy, IDE, and other block devices", say either `Y`
56 (which will compile the support directly into the kernel) or `M`
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 (to compile support as a module which can be loaded and unloaded)
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -030058 to the options::
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Finn Thain1ad6e3b2017-10-12 15:00:06 +110060 ATA/ATAPI/MFM/RLL support
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 Include IDE/ATAPI CDROM support
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 Depending on what type of IDE interface you have, you may need to
64 specify additional configuration options. See
Mauro Carvalho Chehabd7b461c52019-06-12 14:52:47 -030065 Documentation/ide/ide.rst.
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
672. You should also ensure that the iso9660 filesystem is either
68 compiled into the kernel or available as a loadable module. You
69 can see if a filesystem is known to the kernel by catting
70 /proc/filesystems.
71
723. The CDROM drive should be connected to the host on an IDE
73 interface. Each interface on a system is defined by an I/O port
74 address and an IRQ number, the standard assignments being
75 0x1f0 and 14 for the primary interface and 0x170 and 15 for the
76 secondary interface. Each interface can control up to two devices,
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -030077 where each device can be a hard drive, a CDROM drive, a floppy drive,
78 or a tape drive. The two devices on an interface are called `master`
79 and `slave`; this is usually selectable via a jumper on the drive.
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81 Linux names these devices as follows. The master and slave devices
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -030082 on the primary IDE interface are called `hda` and `hdb`,
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 respectively. The drives on the secondary interface are called
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -030084 `hdc` and `hdd`. (Interfaces at other locations get other letters
Mauro Carvalho Chehabd7b461c52019-06-12 14:52:47 -030085 in the third position; see Documentation/ide/ide.rst.)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87 If you want your CDROM drive to be found automatically by the
88 driver, you should make sure your IDE interface uses either the
89 primary or secondary addresses mentioned above. In addition, if
90 the CDROM drive is the only device on the IDE interface, it should
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -030091 be jumpered as `master`. (If for some reason you cannot configure
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 your system in this manner, you can probably still use the driver.
93 You may have to pass extra configuration information to the kernel
Mauro Carvalho Chehabd7b461c52019-06-12 14:52:47 -030094 when you boot, however. See Documentation/ide/ide.rst for more
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 information.)
96
974. Boot the system. If the drive is recognized, you should see a
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -030098 message which looks like::
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100 hdb: NEC CD-ROM DRIVE:260, ATAPI CDROM drive
101
102 If you do not see this, see section 5 below.
103
1045. You may want to create a symbolic link /dev/cdrom pointing to the
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300105 actual device. You can do this with the command::
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107 ln -s /dev/hdX /dev/cdrom
108
109 where X should be replaced by the letter indicating where your
110 drive is installed.
111
1126. You should be able to see any error messages from the driver with
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300113 the `dmesg` command.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115
1163. Basic usage
117--------------
118
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300119An ISO 9660 CDROM can be mounted by putting the disc in the drive and
120typing (as root)::
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122 mount -t iso9660 /dev/cdrom /mnt/cdrom
123
124where it is assumed that /dev/cdrom is a link pointing to the actual
125device (as described in step 5 of the last section) and /mnt/cdrom is
126an empty directory. You should now be able to see the contents of the
127CDROM under the /mnt/cdrom directory. If you want to eject the CDROM,
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300128you must first dismount it with a command like::
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 umount /mnt/cdrom
131
132Note that audio CDs cannot be mounted.
133
134Some distributions set up /etc/fstab to always try to mount a CDROM
135filesystem on bootup. It is not required to mount the CDROM in this
136manner, though, and it may be a nuisance if you change CDROMs often.
137You should feel free to remove the cdrom line from /etc/fstab and
138mount CDROMs manually if that suits you better.
139
140Multisession and photocd discs should work with no special handling.
141The hpcdtoppm package (ftp.gwdg.de:/pub/linux/hpcdtoppm/) may be
142useful for reading photocds.
143
144To play an audio CD, you should first unmount and remove any data
145CDROM. Any of the CDROM player programs should then work (workman,
Randy Dunlapb911e472008-10-10 08:22:44 +0200146workbone, cdplayer, etc.).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148On a few drives, you can read digital audio directly using a program
149such as cdda2wav. The only types of drive which I've heard support
150this are Sony and Toshiba drives. You will get errors if you try to
151use this function on a drive which does not support it.
152
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300153For supported changers, you can use the `cdchange` program (appended to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154the end of this file) to switch between changer slots. Note that the
155drive should be unmounted before attempting this. The program takes
156two arguments: the CDROM device, and the slot number to which you wish
157to change. If the slot number is -1, the drive is unloaded.
158
159
Thadeu Lima de Souza Cascardo1c8a3752009-12-13 20:41:53 -08001604. Common problems
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161------------------
162
163This section discusses some common problems encountered when trying to
164use the driver, and some possible solutions. Note that if you are
165experiencing problems, you should probably also review
Mauro Carvalho Chehabd7b461c52019-06-12 14:52:47 -0300166Documentation/ide/ide.rst for current information about the underlying
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167IDE support code. Some of these items apply only to earlier versions
168of the driver, but are mentioned here for completeness.
169
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300170In most cases, you should probably check with `dmesg` for any errors
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171from the driver.
172
173a. Drive is not detected during booting.
174
175 - Review the configuration instructions above and in
Mauro Carvalho Chehabd7b461c52019-06-12 14:52:47 -0300176 Documentation/ide/ide.rst, and check how your hardware is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 configured.
178
179 - If your drive is the only device on an IDE interface, it should
180 be jumpered as master, if at all possible.
181
182 - If your IDE interface is not at the standard addresses of 0x170
183 or 0x1f0, you'll need to explicitly inform the driver using a
Mauro Carvalho Chehabd7b461c52019-06-12 14:52:47 -0300184 lilo option. See Documentation/ide/ide.rst. (This feature was
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 added around kernel version 1.3.30.)
186
187 - If the autoprobing is not finding your drive, you can tell the
188 driver to assume that one exists by using a lilo option of the
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300189 form `hdX=cdrom`, where X is the drive letter corresponding to
190 where your drive is installed. Note that if you do this and you
191 see a boot message like::
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193 hdX: ATAPI cdrom (?)
194
195 this does _not_ mean that the driver has successfully detected
196 the drive; rather, it means that the driver has not detected a
197 drive, but is assuming there's one there anyway because you told
198 it so. If you actually try to do I/O to a drive defined at a
199 nonexistent or nonresponding I/O address, you'll probably get
200 errors with a status value of 0xff.
201
202 - Some IDE adapters require a nonstandard initialization sequence
203 before they'll function properly. (If this is the case, there
204 will often be a separate MS-DOS driver just for the controller.)
205 IDE interfaces on sound cards often fall into this category.
206
207 Support for some interfaces needing extra initialization is
208 provided in later 1.3.x kernels. You may need to turn on
209 additional kernel configuration options to get them to work;
Mauro Carvalho Chehabd7b461c52019-06-12 14:52:47 -0300210 see Documentation/ide/ide.rst.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212 Even if support is not available for your interface, you may be
213 able to get it to work with the following procedure. First boot
214 MS-DOS and load the appropriate drivers. Then warm-boot linux
215 (i.e., without powering off). If this works, it can be automated
216 by running loadlin from the MS-DOS autoexec.
217
218
219b. Timeout/IRQ errors.
220
221 - If you always get timeout errors, interrupts from the drive are
222 probably not making it to the host.
223
224 - IRQ problems may also be indicated by the message
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300225 `IRQ probe failed (<n>)` while booting. If <n> is zero, that
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 means that the system did not see an interrupt from the drive when
227 it was expecting one (on any feasible IRQ). If <n> is negative,
228 that means the system saw interrupts on multiple IRQ lines, when
229 it was expecting to receive just one from the CDROM drive.
230
231 - Double-check your hardware configuration to make sure that the IRQ
232 number of your IDE interface matches what the driver expects.
233 (The usual assignments are 14 for the primary (0x1f0) interface
234 and 15 for the secondary (0x170) interface.) Also be sure that
235 you don't have some other hardware which might be conflicting with
236 the IRQ you're using. Also check the BIOS setup for your system;
237 some have the ability to disable individual IRQ levels, and I've
238 had one report of a system which was shipped with IRQ 15 disabled
239 by default.
240
241 - Note that many MS-DOS CDROM drivers will still function even if
242 there are hardware problems with the interrupt setup; they
243 apparently don't use interrupts.
244
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300245 - If you own a Pioneer DR-A24X, you _will_ get nasty error messages
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 on boot such as "irq timeout: status=0x50 { DriveReady SeekComplete }"
247 The Pioneer DR-A24X CDROM drives are fairly popular these days.
248 Unfortunately, these drives seem to become very confused when we perform
249 the standard Linux ATA disk drive probe. If you own one of these drives,
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300250 you can bypass the ATA probing which confuses these CDROM drives, by
251 adding `append="hdX=noprobe hdX=cdrom"` to your lilo.conf file and running
252 lilo (again where X is the drive letter corresponding to where your drive
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 is installed.)
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255c. System hangups.
256
257 - If the system locks up when you try to access the CDROM, the most
258 likely cause is that you have a buggy IDE adapter which doesn't
259 properly handle simultaneous transactions on multiple interfaces.
260 The most notorious of these is the CMD640B chip. This problem can
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300261 be worked around by specifying the `serialize` option when
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 booting. Recent kernels should be able to detect the need for
263 this automatically in most cases, but the detection is not
Mauro Carvalho Chehabd7b461c52019-06-12 14:52:47 -0300264 foolproof. See Documentation/ide/ide.rst for more information
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300265 about the `serialize` option and the CMD640B.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267 - Note that many MS-DOS CDROM drivers will work with such buggy
268 hardware, apparently because they never attempt to overlap CDROM
269 operations with other disk activity.
270
271
272d. Can't mount a CDROM.
273
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300274 - If you get errors from mount, it may help to check `dmesg` to see
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 if there are any more specific errors from the driver or from the
276 filesystem.
277
278 - Make sure there's a CDROM loaded in the drive, and that's it's an
279 ISO 9660 disc. You can't mount an audio CD.
280
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300281 - With the CDROM in the drive and unmounted, try something like::
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283 cat /dev/cdrom | od | more
284
285 If you see a dump, then the drive and driver are probably working
286 OK, and the problem is at the filesystem level (i.e., the CDROM is
287 not ISO 9660 or has errors in the filesystem structure).
288
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300289 - If you see `not a block device` errors, check that the definitions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 of the device special files are correct. They should be as
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300291 follows::
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293 brw-rw---- 1 root disk 3, 0 Nov 11 18:48 /dev/hda
294 brw-rw---- 1 root disk 3, 64 Nov 11 18:48 /dev/hdb
295 brw-rw---- 1 root disk 22, 0 Nov 11 18:48 /dev/hdc
296 brw-rw---- 1 root disk 22, 64 Nov 11 18:48 /dev/hdd
297
298 Some early Slackware releases had these defined incorrectly. If
299 these are wrong, you can remake them by running the script
300 scripts/MAKEDEV.ide. (You may have to make it executable
301 with chmod first.)
302
303 If you have a /dev/cdrom symbolic link, check that it is pointing
304 to the correct device file.
305
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300306 If you hear people talking of the devices `hd1a` and `hd1b`, these
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 were old names for what are now called hdc and hdd. Those names
308 should be considered obsolete.
309
310 - If mount is complaining that the iso9660 filesystem is not
311 available, but you know it is (check /proc/filesystems), you
312 probably need a newer version of mount. Early versions would not
313 always give meaningful error messages.
314
315
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300316e. Directory listings are unpredictably truncated, and `dmesg` shows
317 `buffer botch` error messages from the driver.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
319 - There was a bug in the version of the driver in 1.2.x kernels
320 which could cause this. It was fixed in 1.3.0. If you can't
321 upgrade, you can probably work around the problem by specifying a
322 blocksize of 2048 when mounting. (Note that you won't be able to
323 directly execute binaries off the CDROM in that case.)
324
325 If you see this in kernels later than 1.3.0, please report it as a
326 bug.
327
328
329f. Data corruption.
330
331 - Random data corruption was occasionally observed with the Hitachi
332 CDR-7730 CDROM. If you experience data corruption, using "hdx=slow"
333 as a command line parameter may work around the problem, at the
334 expense of low system performance.
335
336
Thadeu Lima de Souza Cascardo1c8a3752009-12-13 20:41:53 -08003375. cdchange.c
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338-------------
339
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300340::
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300342 /*
343 * cdchange.c [-v] <device> [<slot>]
344 *
345 * This loads a CDROM from a specified slot in a changer, and displays
346 * information about the changer status. The drive should be unmounted before
347 * using this program.
348 *
349 * Changer information is displayed if either the -v flag is specified
350 * or no slot was specified.
351 *
352 * Based on code originally from Gerhard Zuber <zuber@berlin.snafu.de>.
353 * Changer status information, and rewrite for the new Uniform CDROM driver
354 * interface by Erik Andersen <andersee@debian.org>.
355 */
356
357 #include <stdio.h>
358 #include <stdlib.h>
359 #include <errno.h>
360 #include <string.h>
361 #include <unistd.h>
362 #include <fcntl.h>
363 #include <sys/ioctl.h>
364 #include <linux/cdrom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
366
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300367 int
368 main (int argc, char **argv)
369 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 char *program;
371 char *device;
372 int fd; /* file descriptor for CD-ROM device */
373 int status; /* return status for system calls */
374 int verbose = 0;
375 int slot=-1, x_slot;
376 int total_slots_available;
377
378 program = argv[0];
379
380 ++argv;
381 --argc;
382
383 if (argc < 1 || argc > 3) {
384 fprintf (stderr, "usage: %s [-v] <device> [<slot>]\n",
385 program);
386 fprintf (stderr, " Slots are numbered 1 -- n.\n");
387 exit (1);
388 }
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 if (strcmp (argv[0], "-v") == 0) {
391 verbose = 1;
392 ++argv;
393 --argc;
394 }
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300395
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 device = argv[0];
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 if (argc == 2)
399 slot = atoi (argv[1]) - 1;
400
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300401 /* open device */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 fd = open(device, O_RDONLY | O_NONBLOCK);
403 if (fd < 0) {
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300404 fprintf (stderr, "%s: open failed for `%s`: %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 program, device, strerror (errno));
406 exit (1);
407 }
408
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300409 /* Check CD player status */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 total_slots_available = ioctl (fd, CDROM_CHANGER_NSLOTS);
411 if (total_slots_available <= 1 ) {
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300412 fprintf (stderr, "%s: Device `%s` is not an ATAPI "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 "compliant CD changer.\n", program, device);
414 exit (1);
415 }
416
417 if (slot >= 0) {
418 if (slot >= total_slots_available) {
419 fprintf (stderr, "Bad slot number. "
420 "Should be 1 -- %d.\n",
421 total_slots_available);
422 exit (1);
423 }
424
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300425 /* load */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 slot=ioctl (fd, CDROM_SELECT_DISC, slot);
427 if (slot<0) {
428 fflush(stdout);
429 perror ("CDROM_SELECT_DISC ");
430 exit(1);
431 }
432 }
433
434 if (slot < 0 || verbose) {
435
436 status=ioctl (fd, CDROM_SELECT_DISC, CDSL_CURRENT);
437 if (status<0) {
438 fflush(stdout);
439 perror (" CDROM_SELECT_DISC");
440 exit(1);
441 }
442 slot=status;
443
444 printf ("Current slot: %d\n", slot+1);
445 printf ("Total slots available: %d\n",
446 total_slots_available);
447
448 printf ("Drive status: ");
449 status = ioctl (fd, CDROM_DRIVE_STATUS, CDSL_CURRENT);
450 if (status<0) {
451 perror(" CDROM_DRIVE_STATUS");
452 } else switch(status) {
453 case CDS_DISC_OK:
454 printf ("Ready.\n");
455 break;
456 case CDS_TRAY_OPEN:
457 printf ("Tray Open.\n");
458 break;
459 case CDS_DRIVE_NOT_READY:
460 printf ("Drive Not Ready.\n");
461 break;
462 default:
463 printf ("This Should not happen!\n");
464 break;
465 }
466
467 for (x_slot=0; x_slot<total_slots_available; x_slot++) {
468 printf ("Slot %2d: ", x_slot+1);
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300469 status = ioctl (fd, CDROM_DRIVE_STATUS, x_slot);
470 if (status<0) {
471 perror(" CDROM_DRIVE_STATUS");
472 } else switch(status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 case CDS_DISC_OK:
474 printf ("Disc present.");
475 break;
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300476 case CDS_NO_DISC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 printf ("Empty slot.");
478 break;
479 case CDS_TRAY_OPEN:
480 printf ("CD-ROM tray open.\n");
481 break;
482 case CDS_DRIVE_NOT_READY:
483 printf ("CD-ROM drive not ready.\n");
484 break;
485 case CDS_NO_INFO:
486 printf ("No Information available.");
487 break;
488 default:
489 printf ("This Should not happen!\n");
490 break;
491 }
492 if (slot == x_slot) {
493 status = ioctl (fd, CDROM_DISC_STATUS);
494 if (status<0) {
495 perror(" CDROM_DISC_STATUS");
496 }
497 switch (status) {
498 case CDS_AUDIO:
499 printf ("\tAudio disc.\t");
500 break;
501 case CDS_DATA_1:
502 case CDS_DATA_2:
503 printf ("\tData disc type %d.\t", status-CDS_DATA_1+1);
504 break;
505 case CDS_XA_2_1:
506 case CDS_XA_2_2:
507 printf ("\tXA data disc type %d.\t", status-CDS_XA_2_1+1);
508 break;
509 default:
510 printf ("\tUnknown disc type 0x%x!\t", status);
511 break;
512 }
513 }
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300514 status = ioctl (fd, CDROM_MEDIA_CHANGED, x_slot);
515 if (status<0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 perror(" CDROM_MEDIA_CHANGED");
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300517 }
518 switch (status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 case 1:
520 printf ("Changed.\n");
521 break;
522 default:
523 printf ("\n");
524 break;
525 }
526 }
527 }
528
529 /* close device */
530 status = close (fd);
531 if (status != 0) {
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300532 fprintf (stderr, "%s: close failed for `%s`: %s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 program, device, strerror (errno));
534 exit (1);
535 }
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 exit (0);
Mauro Carvalho Chehab8ea61882019-06-12 14:52:40 -0300538 }