ide-cd 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. IDE-CD driver documentation
  2. Originally by scott snyder <snyder@fnald0.fnal.gov> (19 May 1996)
  3. Carrying on the torch is: Erik Andersen <andersee@debian.org>
  4. New maintainers (19 Oct 1998): Jens Axboe <axboe@image.dk>
  5. 1. Introduction
  6. ---------------
  7. The ide-cd driver should work with all ATAPI ver 1.2 to ATAPI 2.6 compliant
  8. CDROM drives which attach to an IDE interface. Note that some CDROM vendors
  9. (including Mitsumi, Sony, Creative, Aztech, and Goldstar) have made
  10. both ATAPI-compliant drives and drives which use a proprietary
  11. interface. If your drive uses one of those proprietary interfaces,
  12. this driver will not work with it (but one of the other CDROM drivers
  13. probably will). This driver will not work with `ATAPI' drives which
  14. attach to the parallel port. In addition, there is at least one drive
  15. (CyCDROM CR520ie) which attaches to the IDE port but is not ATAPI;
  16. this driver will not work with drives like that either (but see the
  17. aztcd driver).
  18. This driver provides the following features:
  19. - Reading from data tracks, and mounting ISO 9660 filesystems.
  20. - Playing audio tracks. Most of the CDROM player programs floating
  21. around should work; I usually use Workman.
  22. - Multisession support.
  23. - On drives which support it, reading digital audio data directly
  24. from audio tracks. The program cdda2wav can be used for this.
  25. Note, however, that only some drives actually support this.
  26. - There is now support for CDROM changers which comply with the
  27. ATAPI 2.6 draft standard (such as the NEC CDR-251). This additional
  28. functionality includes a function call to query which slot is the
  29. currently selected slot, a function call to query which slots contain
  30. CDs, etc. A sample program which demonstrates this functionality is
  31. appended to the end of this file. The Sanyo 3-disc changer
  32. (which does not conform to the standard) is also now supported.
  33. Please note the driver refers to the first CD as slot # 0.
  34. 2. Installation
  35. ---------------
  36. 0. The ide-cd relies on the ide disk driver. See
  37. Documentation/ide.txt for up-to-date information on the ide
  38. driver.
  39. 1. Make sure that the ide and ide-cd drivers are compiled into the
  40. kernel you're using. When configuring the kernel, in the section
  41. entitled "Floppy, IDE, and other block devices", say either `Y'
  42. (which will compile the support directly into the kernel) or `M'
  43. (to compile support as a module which can be loaded and unloaded)
  44. to the options:
  45. Enhanced IDE/MFM/RLL disk/cdrom/tape/floppy support
  46. Include IDE/ATAPI CDROM support
  47. and `no' to
  48. Use old disk-only driver on primary interface
  49. Depending on what type of IDE interface you have, you may need to
  50. specify additional configuration options. See
  51. Documentation/ide.txt.
  52. 2. You should also ensure that the iso9660 filesystem is either
  53. compiled into the kernel or available as a loadable module. You
  54. can see if a filesystem is known to the kernel by catting
  55. /proc/filesystems.
  56. 3. The CDROM drive should be connected to the host on an IDE
  57. interface. Each interface on a system is defined by an I/O port
  58. address and an IRQ number, the standard assignments being
  59. 0x1f0 and 14 for the primary interface and 0x170 and 15 for the
  60. secondary interface. Each interface can control up to two devices,
  61. where each device can be a hard drive, a CDROM drive, a floppy drive,
  62. or a tape drive. The two devices on an interface are called `master'
  63. and `slave'; this is usually selectable via a jumper on the drive.
  64. Linux names these devices as follows. The master and slave devices
  65. on the primary IDE interface are called `hda' and `hdb',
  66. respectively. The drives on the secondary interface are called
  67. `hdc' and `hdd'. (Interfaces at other locations get other letters
  68. in the third position; see Documentation/ide.txt.)
  69. If you want your CDROM drive to be found automatically by the
  70. driver, you should make sure your IDE interface uses either the
  71. primary or secondary addresses mentioned above. In addition, if
  72. the CDROM drive is the only device on the IDE interface, it should
  73. be jumpered as `master'. (If for some reason you cannot configure
  74. your system in this manner, you can probably still use the driver.
  75. You may have to pass extra configuration information to the kernel
  76. when you boot, however. See Documentation/ide.txt for more
  77. information.)
  78. 4. Boot the system. If the drive is recognized, you should see a
  79. message which looks like
  80. hdb: NEC CD-ROM DRIVE:260, ATAPI CDROM drive
  81. If you do not see this, see section 5 below.
  82. 5. You may want to create a symbolic link /dev/cdrom pointing to the
  83. actual device. You can do this with the command
  84. ln -s /dev/hdX /dev/cdrom
  85. where X should be replaced by the letter indicating where your
  86. drive is installed.
  87. 6. You should be able to see any error messages from the driver with
  88. the `dmesg' command.
  89. 3. Basic usage
  90. --------------
  91. An ISO 9660 CDROM can be mounted by putting the disc in the drive and
  92. typing (as root)
  93. mount -t iso9660 /dev/cdrom /mnt/cdrom
  94. where it is assumed that /dev/cdrom is a link pointing to the actual
  95. device (as described in step 5 of the last section) and /mnt/cdrom is
  96. an empty directory. You should now be able to see the contents of the
  97. CDROM under the /mnt/cdrom directory. If you want to eject the CDROM,
  98. you must first dismount it with a command like
  99. umount /mnt/cdrom
  100. Note that audio CDs cannot be mounted.
  101. Some distributions set up /etc/fstab to always try to mount a CDROM
  102. filesystem on bootup. It is not required to mount the CDROM in this
  103. manner, though, and it may be a nuisance if you change CDROMs often.
  104. You should feel free to remove the cdrom line from /etc/fstab and
  105. mount CDROMs manually if that suits you better.
  106. Multisession and photocd discs should work with no special handling.
  107. The hpcdtoppm package (ftp.gwdg.de:/pub/linux/hpcdtoppm/) may be
  108. useful for reading photocds.
  109. To play an audio CD, you should first unmount and remove any data
  110. CDROM. Any of the CDROM player programs should then work (workman,
  111. workbone, cdplayer, etc.). Lacking anything else, you could use the
  112. cdtester program in Documentation/cdrom/sbpcd.
  113. On a few drives, you can read digital audio directly using a program
  114. such as cdda2wav. The only types of drive which I've heard support
  115. this are Sony and Toshiba drives. You will get errors if you try to
  116. use this function on a drive which does not support it.
  117. For supported changers, you can use the `cdchange' program (appended to
  118. the end of this file) to switch between changer slots. Note that the
  119. drive should be unmounted before attempting this. The program takes
  120. two arguments: the CDROM device, and the slot number to which you wish
  121. to change. If the slot number is -1, the drive is unloaded.
  122. 4. Compilation options
  123. ----------------------
  124. There are a few additional options which can be set when compiling the
  125. driver. Most people should not need to mess with any of these; they
  126. are listed here simply for completeness. A compilation option can be
  127. enabled by adding a line of the form `#define <option> 1' to the top
  128. of ide-cd.c. All these options are disabled by default.
  129. VERBOSE_IDE_CD_ERRORS
  130. If this is set, ATAPI error codes will be translated into textual
  131. descriptions. In addition, a dump is made of the command which
  132. provoked the error. This is off by default to save the memory used
  133. by the (somewhat long) table of error descriptions.
  134. STANDARD_ATAPI
  135. If this is set, the code needed to deal with certain drives which do
  136. not properly implement the ATAPI spec will be disabled. If you know
  137. your drive implements ATAPI properly, you can turn this on to get a
  138. slightly smaller kernel.
  139. NO_DOOR_LOCKING
  140. If this is set, the driver will never attempt to lock the door of
  141. the drive.
  142. CDROM_NBLOCKS_BUFFER
  143. This sets the size of the buffer to be used for a CDROMREADAUDIO
  144. ioctl. The default is 8.
  145. TEST
  146. This currently enables an additional ioctl which enables a user-mode
  147. program to execute an arbitrary packet command. See the source for
  148. details. This should be left off unless you know what you're doing.
  149. 5. Common problems
  150. ------------------
  151. This section discusses some common problems encountered when trying to
  152. use the driver, and some possible solutions. Note that if you are
  153. experiencing problems, you should probably also review
  154. Documentation/ide.txt for current information about the underlying
  155. IDE support code. Some of these items apply only to earlier versions
  156. of the driver, but are mentioned here for completeness.
  157. In most cases, you should probably check with `dmesg' for any errors
  158. from the driver.
  159. a. Drive is not detected during booting.
  160. - Review the configuration instructions above and in
  161. Documentation/ide.txt, and check how your hardware is
  162. configured.
  163. - If your drive is the only device on an IDE interface, it should
  164. be jumpered as master, if at all possible.
  165. - If your IDE interface is not at the standard addresses of 0x170
  166. or 0x1f0, you'll need to explicitly inform the driver using a
  167. lilo option. See Documentation/ide.txt. (This feature was
  168. added around kernel version 1.3.30.)
  169. - If the autoprobing is not finding your drive, you can tell the
  170. driver to assume that one exists by using a lilo option of the
  171. form `hdX=cdrom', where X is the drive letter corresponding to
  172. where your drive is installed. Note that if you do this and you
  173. see a boot message like
  174. hdX: ATAPI cdrom (?)
  175. this does _not_ mean that the driver has successfully detected
  176. the drive; rather, it means that the driver has not detected a
  177. drive, but is assuming there's one there anyway because you told
  178. it so. If you actually try to do I/O to a drive defined at a
  179. nonexistent or nonresponding I/O address, you'll probably get
  180. errors with a status value of 0xff.
  181. - Some IDE adapters require a nonstandard initialization sequence
  182. before they'll function properly. (If this is the case, there
  183. will often be a separate MS-DOS driver just for the controller.)
  184. IDE interfaces on sound cards often fall into this category.
  185. Support for some interfaces needing extra initialization is
  186. provided in later 1.3.x kernels. You may need to turn on
  187. additional kernel configuration options to get them to work;
  188. see Documentation/ide.txt.
  189. Even if support is not available for your interface, you may be
  190. able to get it to work with the following procedure. First boot
  191. MS-DOS and load the appropriate drivers. Then warm-boot linux
  192. (i.e., without powering off). If this works, it can be automated
  193. by running loadlin from the MS-DOS autoexec.
  194. b. Timeout/IRQ errors.
  195. - If you always get timeout errors, interrupts from the drive are
  196. probably not making it to the host.
  197. - IRQ problems may also be indicated by the message
  198. `IRQ probe failed (<n>)' while booting. If <n> is zero, that
  199. means that the system did not see an interrupt from the drive when
  200. it was expecting one (on any feasible IRQ). If <n> is negative,
  201. that means the system saw interrupts on multiple IRQ lines, when
  202. it was expecting to receive just one from the CDROM drive.
  203. - Double-check your hardware configuration to make sure that the IRQ
  204. number of your IDE interface matches what the driver expects.
  205. (The usual assignments are 14 for the primary (0x1f0) interface
  206. and 15 for the secondary (0x170) interface.) Also be sure that
  207. you don't have some other hardware which might be conflicting with
  208. the IRQ you're using. Also check the BIOS setup for your system;
  209. some have the ability to disable individual IRQ levels, and I've
  210. had one report of a system which was shipped with IRQ 15 disabled
  211. by default.
  212. - Note that many MS-DOS CDROM drivers will still function even if
  213. there are hardware problems with the interrupt setup; they
  214. apparently don't use interrupts.
  215. - If you own a Pioneer DR-A24X, you _will_ get nasty error messages
  216. on boot such as "irq timeout: status=0x50 { DriveReady SeekComplete }"
  217. The Pioneer DR-A24X CDROM drives are fairly popular these days.
  218. Unfortunately, these drives seem to become very confused when we perform
  219. the standard Linux ATA disk drive probe. If you own one of these drives,
  220. you can bypass the ATA probing which confuses these CDROM drives, by
  221. adding `append="hdX=noprobe hdX=cdrom"' to your lilo.conf file and running
  222. lilo (again where X is the drive letter corresponding to where your drive
  223. is installed.)
  224. c. System hangups.
  225. - If the system locks up when you try to access the CDROM, the most
  226. likely cause is that you have a buggy IDE adapter which doesn't
  227. properly handle simultaneous transactions on multiple interfaces.
  228. The most notorious of these is the CMD640B chip. This problem can
  229. be worked around by specifying the `serialize' option when
  230. booting. Recent kernels should be able to detect the need for
  231. this automatically in most cases, but the detection is not
  232. foolproof. See Documentation/ide.txt for more information
  233. about the `serialize' option and the CMD640B.
  234. - Note that many MS-DOS CDROM drivers will work with such buggy
  235. hardware, apparently because they never attempt to overlap CDROM
  236. operations with other disk activity.
  237. d. Can't mount a CDROM.
  238. - If you get errors from mount, it may help to check `dmesg' to see
  239. if there are any more specific errors from the driver or from the
  240. filesystem.
  241. - Make sure there's a CDROM loaded in the drive, and that's it's an
  242. ISO 9660 disc. You can't mount an audio CD.
  243. - With the CDROM in the drive and unmounted, try something like
  244. cat /dev/cdrom | od | more
  245. If you see a dump, then the drive and driver are probably working
  246. OK, and the problem is at the filesystem level (i.e., the CDROM is
  247. not ISO 9660 or has errors in the filesystem structure).
  248. - If you see `not a block device' errors, check that the definitions
  249. of the device special files are correct. They should be as
  250. follows:
  251. brw-rw---- 1 root disk 3, 0 Nov 11 18:48 /dev/hda
  252. brw-rw---- 1 root disk 3, 64 Nov 11 18:48 /dev/hdb
  253. brw-rw---- 1 root disk 22, 0 Nov 11 18:48 /dev/hdc
  254. brw-rw---- 1 root disk 22, 64 Nov 11 18:48 /dev/hdd
  255. Some early Slackware releases had these defined incorrectly. If
  256. these are wrong, you can remake them by running the script
  257. scripts/MAKEDEV.ide. (You may have to make it executable
  258. with chmod first.)
  259. If you have a /dev/cdrom symbolic link, check that it is pointing
  260. to the correct device file.
  261. If you hear people talking of the devices `hd1a' and `hd1b', these
  262. were old names for what are now called hdc and hdd. Those names
  263. should be considered obsolete.
  264. - If mount is complaining that the iso9660 filesystem is not
  265. available, but you know it is (check /proc/filesystems), you
  266. probably need a newer version of mount. Early versions would not
  267. always give meaningful error messages.
  268. e. Directory listings are unpredictably truncated, and `dmesg' shows
  269. `buffer botch' error messages from the driver.
  270. - There was a bug in the version of the driver in 1.2.x kernels
  271. which could cause this. It was fixed in 1.3.0. If you can't
  272. upgrade, you can probably work around the problem by specifying a
  273. blocksize of 2048 when mounting. (Note that you won't be able to
  274. directly execute binaries off the CDROM in that case.)
  275. If you see this in kernels later than 1.3.0, please report it as a
  276. bug.
  277. f. Data corruption.
  278. - Random data corruption was occasionally observed with the Hitachi
  279. CDR-7730 CDROM. If you experience data corruption, using "hdx=slow"
  280. as a command line parameter may work around the problem, at the
  281. expense of low system performance.
  282. 6. cdchange.c
  283. -------------
  284. /*
  285. * cdchange.c [-v] <device> [<slot>]
  286. *
  287. * This loads a CDROM from a specified slot in a changer, and displays
  288. * information about the changer status. The drive should be unmounted before
  289. * using this program.
  290. *
  291. * Changer information is displayed if either the -v flag is specified
  292. * or no slot was specified.
  293. *
  294. * Based on code originally from Gerhard Zuber <zuber@berlin.snafu.de>.
  295. * Changer status information, and rewrite for the new Uniform CDROM driver
  296. * interface by Erik Andersen <andersee@debian.org>.
  297. */
  298. #include <stdio.h>
  299. #include <stdlib.h>
  300. #include <errno.h>
  301. #include <string.h>
  302. #include <unistd.h>
  303. #include <fcntl.h>
  304. #include <sys/ioctl.h>
  305. #include <linux/cdrom.h>
  306. int
  307. main (int argc, char **argv)
  308. {
  309. char *program;
  310. char *device;
  311. int fd; /* file descriptor for CD-ROM device */
  312. int status; /* return status for system calls */
  313. int verbose = 0;
  314. int slot=-1, x_slot;
  315. int total_slots_available;
  316. program = argv[0];
  317. ++argv;
  318. --argc;
  319. if (argc < 1 || argc > 3) {
  320. fprintf (stderr, "usage: %s [-v] <device> [<slot>]\n",
  321. program);
  322. fprintf (stderr, " Slots are numbered 1 -- n.\n");
  323. exit (1);
  324. }
  325. if (strcmp (argv[0], "-v") == 0) {
  326. verbose = 1;
  327. ++argv;
  328. --argc;
  329. }
  330. device = argv[0];
  331. if (argc == 2)
  332. slot = atoi (argv[1]) - 1;
  333. /* open device */
  334. fd = open(device, O_RDONLY | O_NONBLOCK);
  335. if (fd < 0) {
  336. fprintf (stderr, "%s: open failed for `%s': %s\n",
  337. program, device, strerror (errno));
  338. exit (1);
  339. }
  340. /* Check CD player status */
  341. total_slots_available = ioctl (fd, CDROM_CHANGER_NSLOTS);
  342. if (total_slots_available <= 1 ) {
  343. fprintf (stderr, "%s: Device `%s' is not an ATAPI "
  344. "compliant CD changer.\n", program, device);
  345. exit (1);
  346. }
  347. if (slot >= 0) {
  348. if (slot >= total_slots_available) {
  349. fprintf (stderr, "Bad slot number. "
  350. "Should be 1 -- %d.\n",
  351. total_slots_available);
  352. exit (1);
  353. }
  354. /* load */
  355. slot=ioctl (fd, CDROM_SELECT_DISC, slot);
  356. if (slot<0) {
  357. fflush(stdout);
  358. perror ("CDROM_SELECT_DISC ");
  359. exit(1);
  360. }
  361. }
  362. if (slot < 0 || verbose) {
  363. status=ioctl (fd, CDROM_SELECT_DISC, CDSL_CURRENT);
  364. if (status<0) {
  365. fflush(stdout);
  366. perror (" CDROM_SELECT_DISC");
  367. exit(1);
  368. }
  369. slot=status;
  370. printf ("Current slot: %d\n", slot+1);
  371. printf ("Total slots available: %d\n",
  372. total_slots_available);
  373. printf ("Drive status: ");
  374. status = ioctl (fd, CDROM_DRIVE_STATUS, CDSL_CURRENT);
  375. if (status<0) {
  376. perror(" CDROM_DRIVE_STATUS");
  377. } else switch(status) {
  378. case CDS_DISC_OK:
  379. printf ("Ready.\n");
  380. break;
  381. case CDS_TRAY_OPEN:
  382. printf ("Tray Open.\n");
  383. break;
  384. case CDS_DRIVE_NOT_READY:
  385. printf ("Drive Not Ready.\n");
  386. break;
  387. default:
  388. printf ("This Should not happen!\n");
  389. break;
  390. }
  391. for (x_slot=0; x_slot<total_slots_available; x_slot++) {
  392. printf ("Slot %2d: ", x_slot+1);
  393. status = ioctl (fd, CDROM_DRIVE_STATUS, x_slot);
  394. if (status<0) {
  395. perror(" CDROM_DRIVE_STATUS");
  396. } else switch(status) {
  397. case CDS_DISC_OK:
  398. printf ("Disc present.");
  399. break;
  400. case CDS_NO_DISC:
  401. printf ("Empty slot.");
  402. break;
  403. case CDS_TRAY_OPEN:
  404. printf ("CD-ROM tray open.\n");
  405. break;
  406. case CDS_DRIVE_NOT_READY:
  407. printf ("CD-ROM drive not ready.\n");
  408. break;
  409. case CDS_NO_INFO:
  410. printf ("No Information available.");
  411. break;
  412. default:
  413. printf ("This Should not happen!\n");
  414. break;
  415. }
  416. if (slot == x_slot) {
  417. status = ioctl (fd, CDROM_DISC_STATUS);
  418. if (status<0) {
  419. perror(" CDROM_DISC_STATUS");
  420. }
  421. switch (status) {
  422. case CDS_AUDIO:
  423. printf ("\tAudio disc.\t");
  424. break;
  425. case CDS_DATA_1:
  426. case CDS_DATA_2:
  427. printf ("\tData disc type %d.\t", status-CDS_DATA_1+1);
  428. break;
  429. case CDS_XA_2_1:
  430. case CDS_XA_2_2:
  431. printf ("\tXA data disc type %d.\t", status-CDS_XA_2_1+1);
  432. break;
  433. default:
  434. printf ("\tUnknown disc type 0x%x!\t", status);
  435. break;
  436. }
  437. }
  438. status = ioctl (fd, CDROM_MEDIA_CHANGED, x_slot);
  439. if (status<0) {
  440. perror(" CDROM_MEDIA_CHANGED");
  441. }
  442. switch (status) {
  443. case 1:
  444. printf ("Changed.\n");
  445. break;
  446. default:
  447. printf ("\n");
  448. break;
  449. }
  450. }
  451. }
  452. /* close device */
  453. status = close (fd);
  454. if (status != 0) {
  455. fprintf (stderr, "%s: close failed for `%s': %s\n",
  456. program, device, strerror (errno));
  457. exit (1);
  458. }
  459. exit (0);
  460. }