home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 2 / CD ACTUAL VOL 2.iso / docs / kernel.12 / readme.azt < prev    next >
Encoding:
Text File  |  1995-09-10  |  36.4 KB  |  731 lines

  1.                        Readme-File README.aztcd
  2.    for Aztech CD-ROM CDA268-01A, ORCHID CD-3110, OKANO/WEARNES CDD110 
  3.                           CD-ROM  Driver 
  4.                        Version 1.0 and newer
  5.                    (for other drives see 6.-8.)
  6.  
  7. NOTE: THIS DRIVER WILL WORK WITH THE CD-ROM DRIVES LISTED, WHICH HAVE
  8.       A PROPRIETARY INTERFACE (implemented on a sound card or on a
  9.       ISA-AT-bus card). 
  10.       IT WILL DEFINITELY NOT WORK WITH CD-ROM DRIVES WITH *IDE*-INTERFACE,
  11.       such as the Aztech CDA269-031SE !!! IF YOU'RE USING A CD-ROM DRIVE
  12.       WITH IDE-INTERFACE, SOMETIMES ALSO CALLED ATAPI-COMPATIBLE, PLEASE 
  13.       USE THE ide-cd.c DRIVER, WRITTEN BY MARK LORD AND SCOTT SNYDER !!!
  14. ----------------------------------------------------------------------------
  15. Contents of this file:
  16.                          1. NOTE
  17.                          2. INSTALLATION
  18.                          3. CONFIGURING YOUR KERNEL
  19.                          4. RECOMPILING YOUR KERNEL
  20.                          5. KNOWN PROBLEMS, FUTURE DEVELOPMENTS
  21.                          6. BUG REPORTS
  22.                          7. OTHER DRIVES
  23.                          8. IF YOU DON'T SUCCEED ... DEBUGGING  
  24.                          9. TECHNICAL HISTORY OF THE DRIVER
  25.                         10. ACKNOWLEDGMENTS
  26.                         11. PROGRAMMING ADD ONS: CDPLAY.C
  27.                         APPENDIX: Source code of cdplay.c
  28. ----------------------------------------------------------------------------
  29.  
  30. 1. NOTE 
  31. This software has been successfully in alpha and beta test for quite a long
  32. time with AZTECH CDA268-01A, ORCHID CDS-3110 and ORCHID/WEARNES CDD110 
  33. and has proven to be stable with kernel versions 1.0.9 to 1.2.0. But with
  34. any software there still may be bugs in it. So if you encounter problems,
  35. you are invited to help us improve this software. Please send me a detailed
  36. bug report (see chapter BUG REPORTS). You are also invited in helping us to 
  37. increase the number of drives, which are supported.
  38.  
  39. Please read the README-files carefully and always keep a backup copy of your 
  40. old kernel, in order to reboot if something goes wrong!
  41.  
  42.  
  43. 2. INSTALLATION
  44. If you received this software as a standalone package AZTECH.CDROM.Vxx.tgz 
  45. (xx=version number) and not included in the standard Linux kernel, read the 
  46. file AZTECH.CDROM.README included in that package to install it. The 
  47. standalone package's home is 'ftp.gwdg.de : pub/linux/cdrom/drivers/aztech'.
  48. The driver consists of a header file 'aztcd.h', which normally should reside 
  49. in /usr/include/linux and the source code 'aztcd.c', which normally resides in
  50. /usr/src/linux/drivers/block. It uses /dev/aztcd0, which must be a valid block
  51. device with major number 29 and reside in directory /dev. To mount a CD-ROM,
  52. your kernel needs to have the ISO9660-filesystem support included.
  53.  
  54.  
  55. 3.  CONFIGURING YOUR KERNEL
  56. If your kernel is already configured for using the AZTECH driver you will
  57. see the following message while Linux boots:
  58.     Aztech CD-ROM Init: DriverVersion=<version number> BaseAddress=<baseaddress>
  59.     Aztech CD-ROM Init: FirmwareVersion=<firmware version id of your I/O-card>>>
  60.     Aztech CD-ROM Init: <drive type> detected
  61.     Aztech CD-ROM Init: End
  62. If the message looks different and you are sure to have a supported drive,
  63. it may have a different base address. The Aztech driver does look for the 
  64. CD-ROM drive at the base address specified in aztcd.h at compile time. This 
  65. address can be overwritten by boot parameter aztcd=....You should reboot and 
  66. start Linux with boot parameter aztcd=<base address>, e.g. aztcd=0x320. If 
  67. you do not know the base address, start your PC with DOS and look at the boot 
  68. message of your CD-ROM's DOS driver. 
  69.  
  70. If the message looks correct, as user 'root' you should be able to mount the 
  71. drive by
  72.           mount -t iso9660 -r /dev/aztcd0 /mnt
  73. and use it as any other filesystem. (If this does not work, check if
  74.   /dev/aztcd0 and /mnt do exist and create them, if necessary by doing
  75.       mknod /dev/aztcd0 b 29 0
  76.       mkdir /mnt                       
  77.  
  78. If you still get a different message while Linux boots or when you get the 
  79. message, that the ISO9660-filesystem is not supported by your kernel, when
  80. you try to mount the CD-ROM drive, you have to recompile your kernel.
  81.  
  82. If you do *not* have an Aztech/Orchid/Okano/Wearnes drive and want to bypass
  83. drive detection during Linux boot up, start with boot parameter aztcd=0.
  84.  
  85. Joe Nardone has compiled a boot disk with the Aztech driver for installing 
  86. Slackware from CDROM. You can find the disk images at 'sunsite.unc.edu'; 
  87. see file 'aztech.gz.README' for instructions on how to use it.
  88.  
  89.  
  90. 4. RECOMPILING YOUR KERNEL
  91. If your kernel is not yet configured for the AZTECH driver and the ISO9660-
  92. filesystem, you have to recompile your kernel: 
  93.  
  94. - Edit aztcd.h to set the I/O-address to your I/O-Base address (AZT_BASE_ADDR), 
  95.   the driver does not use interrupts or DMA, so if you are using an AZTECH
  96.   CD268, an ORCHID CD-3110 or ORCHID/WEARNES CDD110 that's the only item you 
  97.   have to set up. 
  98.   Users of other drives should read chapter OTHER DRIVES of this file.
  99.   You also can configure that address by LILO boot parameter aztcd=... 
  100. - Build a new kernel, configure it for 'Aztech/Orchid/Okano/Wearnes support' 
  101.   (if you want aztcd to be part of the kernel). Do not configure it for
  102.   'Aztech... support', if you want to use aztcd as a run time loadable module. 
  103.   But in any case you must have the ISO9660-filesystem included in your
  104.   kernel.
  105. - Activate the new kernel, normally this is done by running lilo (don't for-
  106.   get to configure it before and to keep a copy of your old kernel in case
  107.   something goes wrong!).
  108. - Reboot
  109. - If you've included aztcd in your kernel, you now should see during boot 
  110.   some messages like
  111.     Aztech CD-ROM Init: DriverVersion=<version number> BaseAddress=<baseaddress>
  112.     Aztech CD-ROM Init: FirmwareVersion=<firmware version id of your I/O-card>
  113.     Aztech CD-ROM Init: <drive type> detected
  114.     Aztech CD-ROM Init: End
  115. - If you have not included aztcd in your kernel, but want to load aztcd as a 
  116.   run time loadable module see 4.1. 
  117. - If the message looks correct, as user 'root' you should be able to mount 
  118.   the drive by
  119.           mount -t iso9660 -r /dev/aztcd0 /mnt
  120.   and use it as any other filesystem. (If this does not work, check if
  121.   /dev/aztcd0 and /mnt do exist and create them, if necessary by doing
  122.       mknod /dev/aztcd0 b 29 0
  123.       mkdir /mnt                       
  124. - If this still does not help, see chapters OTHER DRIVES and DEBUGGING.
  125.  
  126. 4.1 AZTCD AS A RUN-TIME LOADABLE MODULE
  127. If you do not need aztcd permanently, you can also load and remove the driver
  128. during runtime via insmod and rmmod. To build aztcd as a loadable module you 
  129. must *not* configure your kernel for AZTECH support. But you need to have
  130. the ISO9660-filesystem included! So rebuild your kernel, if necessary.
  131.  
  132. Now edit the base address of your AZTECH interface card in
  133. /usr/src/linux/include/linux/aztcd.h to the appropriate value. Then change
  134. to /usr/src/linux and do a 
  135.                     make modules  
  136.                 make modules_install
  137. After that you can run-time load the driver via
  138.                     insmod /lib/modules/X.X.X/misc/aztcd.o
  139. and remove it via   rmmod  aztcd.
  140. If you have not configured the correct base address, you can also supply the
  141. base address when loading the driver via
  142.                     insmod /lib/modules/X.X.X/misc/aztcd.o aztcd=<base address>
  143. In all commands 'X.X.X' is the current linux kernel version number. For details
  144. see file README.modules in /usr/src/linux.
  145.  
  146.  
  147. 5. KNOWN PROBLEMS, FUTURE DEVELOPMENTS
  148. The driver does not support applications such as photo CD, multi session CD
  149. etc.. I do not plan to include the support for that in the driver, because I
  150. do not use such applications. If you are interested in that stuff and would
  151. like to extend the drivers capability on your own, please contact me, I'll
  152. support you as far as I can. 
  153.  
  154. The drive status recognition does not work correctly in all cases. Changing
  155. a disk or having the door open, when a drive is already mounted, is detected 
  156. by the Aztech driver itself, but nevertheless causes multiple read attempts
  157. by the different layers of the ISO9660-filesystem driver, which finally timeout,
  158. so you have to wait quite a little... But isn't it bad style to change a disk 
  159. in a mounted drive, anyhow ?!
  160.  
  161. The driver uses busy wait in most cases for the drive handshake (macros
  162. STEN_LOW and DTEN_LOW). I tested with a 486/DX2 at 66MHz and a Pentium at
  163. 60MHz. Whenever you use a much faster machine you are likely to get timeout 
  164. messages. In that case edit aztcd.h and increase the timeout value AZT_TIMEOUT. 
  165.  
  166. For some 'slow' drive commands I implemented waiting with a timer waitqueue
  167. (macro STEN_LOW_WAIT). If you get this timeout message, you may also edit
  168. aztcd.h and increase the timeout value AZT_STATUS_DELAY. The waitqueue has
  169. shown to be a little critical. If you get kernel panic messages, edit aztcd.c
  170. and substitute STEN_LOW_WAIT by STEN_LOW. Busy waiting with STEN_LOW is more
  171. stable, but also causes CPU overhead.
  172.  
  173.  
  174. 6. BUG REPORTS
  175. Please send detailed bug reports and bug fixes via EMail to
  176.  
  177.         zimmerma@rz.fht-esslingen.de
  178.  
  179. Please include a description of your CD-ROM drive type and interface card, 
  180. the exact firmware message during Linux bootup, the version number of the 
  181. AZTECH-CDROM-driver and the Linux kernel version. Also a description of your 
  182. system's other hardware could be of interest, especially microprocessor type, 
  183. clock frequency, other interface cards such as soundcards, ethernet adapter, 
  184. game cards etc..
  185.  
  186. I will try to collect the reports and make the necessary modifications from 
  187. time to time. I may also come back to you directly with some bug fixes and 
  188. ask you to do further testing and debugging.
  189.  
  190. Editors of CD-ROMs are invited to send a 'cooperation' copy of their
  191. CD-ROMs to the volunteers, who provided the CD-ROM support for Linux. My
  192. snail mail address for such 'stuff' is
  193.            Prof. Dr. W. Zimmermann
  194.            Fachhochschule fuer Technik Esslingen
  195.            Fachbereich NT
  196.            Flandernstrasse 101
  197.            D-73732 Esslingen
  198.            Germany
  199.  
  200.  
  201. 7. OTHER DRIVES
  202. The following drives ORCHID CDS3110, OKANO CDD110 and WEARNES nearly look 
  203. the same as AZTECH CDA268-01A, especially they seem to use the same command 
  204. codes. So it was quite simple to make the AZTECH driver work with these drives. 
  205.  
  206. Unfortunately I do not have any of these drives available, so I couldn't test
  207. it myself. But I've got reports, that it works with ORCHID CDS3110 and Game-
  208. Wave32 sound cards and also with WEARNES CDD110 in some different combinations. 
  209. In some installations, it seems necessary to initialize the drive with the DOS 
  210. driver before (especially if combined with a sound card) and then do a warm 
  211. boot (CTRL-ALT-RESET) or start Linux from DOS, e.g. with 'loadlin'.
  212.  
  213. If you do not succeed, read chapter DEBUGGING. Thanks in advance!
  214.  
  215. Sorry for the inconvenience, but it is difficult to develop for hardware, 
  216. which you don't have available for testing. So if you like, please help us.
  217.  
  218.  
  219. 8. DEBUGGING : IF YOU DON'T SUCCEED, TRY THE FOLLOWING
  220. -reread the complete README file
  221. -make sure, that your drive is hardware configured for 
  222.     transfer mode: polled
  223.     IRQ:           not used
  224.     DMA:           not used
  225.     Base Address:  something like 300, 320 ...
  226.  You can check this, when you start the DOS driver, which came with your
  227.  drive. By appropriately configuring the drive and the DOS driver you can
  228.  check, whether your drive does operate in this mode correctly under DOS. If
  229.  it does not operate under DOS, it won't under Linux.
  230.  Make sure the Base Address is configured correctly in aztcd.h, also make
  231.  sure, that /dev/aztcd0 exists with the correct major number (compare it with
  232.  the entry in file /usr/include/linux/major.h for the Aztech drive). 
  233. -insert a CD-ROM and close the tray
  234. -cold boot your PC (i.e. via the power on switch or the reset button)
  235. -if you start Linux via DOS, e.g. using loadlin, make sure, that the DOS
  236.  driver for the CD-ROM drive is not loaded (comment out the calling lines 
  237.  in DOS' config.sys!)
  238. -look for the aztcd: init message during Linux init and note them exactly
  239. -log in as root and do a mount -t iso9660 /dev/aztcd0 /mnt
  240. -if you don't succeed in the first time, try several times. Try also to open
  241.  and close the tray, then mount again. Please note carefully all commands
  242.  you typed in and the aztcd-messages, which you get.
  243. -if you get an 'Aztech CD-ROM init: aborted' message, read the remarks about
  244.  the version string below.
  245.  
  246. If this does not help, do the same with the following differences 
  247. -start DOS before; make now sure, that the DOS driver for the CD-ROM is 
  248.  loaded under DOS (i.e. uncomment it again in config.sys)
  249. -warm boot your PC (i.e. via CTRL-ALT-DEL)
  250.  if you have it, you can also start via loadlin (try both).
  251.  ...
  252.  Again note all commands and the aztcd-messages.
  253.  
  254. If you see STEN_LOW or STEN_LOW_WAIT error messages, increase the timeout
  255. values.
  256.  
  257. If this still does not help, 
  258. -look in aztcd.c for the lines  #if 0
  259.                                 #define AZT_TEST1
  260.                                 ...
  261.                                 #endif
  262.  and substitute '#if 0' by '#if 1'.
  263. -recompile your kernel and repeat the above two procedures. You will now get 
  264.  a bundle of debugging messages from the driver. Again note your commands
  265.  and the appropriate messages. If you have syslogd running, these messages
  266.  may also be found in syslogd's kernel log file. Nevertheless in some
  267.  installations syslogd does not yet run, when init() is called, thus look for
  268.  the aztcd-messages during init, before the login-prompt appears.
  269.  Then look in aztcd.c, to find out, what happened. The normal calling sequence 
  270.  is: aztcd_init() during Linux bootup procedure init()
  271.  after doing a 'mount -t iso9660 /dev/aztcd0 /mnt' the normal calling sequence is
  272.      aztcd_open()    -> Status 2c after cold reboot with CDROM or audio CD inserted
  273.                      -> Status 8  after warm reboot with CDROM inserted          
  274.                      -> Status 2e after cold reboot with no disk, closed tray
  275.                      -> Status 6e after cold reboot, mount with door open
  276.      aztUpdateToc()
  277.      aztGetDiskInfo()
  278.      aztGetQChannelInfo()   repeated several times
  279.      aztGetToc()
  280.      aztGetQChannelInfo()   repeated several times
  281.      a list of track informations
  282.      do_aztcd_request()  }  
  283.      azt_transfer()    } repeated several times
  284.      azt_poll          }
  285.  Check, if there is a difference in the calling sequence or the status flags!
  286.  
  287.  There are a lot of other messages, eg. the ACMD-command code (defined in
  288.  aztcd.h), status info from the getAztStatus-command and the state sequence of
  289.  the finite state machine in azt_poll(). The most important are the status
  290.  messages, look how they are defined and try to understand, if they make
  291.  sense in the context where they appear. With a CD-ROM inserted the status 
  292.  should always be 8, except in aztcd_open(). Try to open the tray, insert a
  293.  audio disk, insert no disk or reinsert the CD-ROM and check, if the status
  294.  bits change accordingly. The status bits are the most likely point, where 
  295.  the drive manufacturers may implement changes.
  296.             
  297. If you still don't succeed, a good point to start is to look in aztcd.c in 
  298. function aztcd_init, where the drive should be detected during init. Do the
  299. following:
  300. -reboot the system with boot parameter 'aztcd=<your base address>,0x79'. With
  301.  parameter 0x79 most of the drive version detection is bypassed. After that 
  302.  you should see the complete version string including leading and trailing 
  303.  blanks during init. 
  304.  Now adapt the statement
  305.       if ((result[1]=='A')&&(result[2]=='Z' ...)
  306.  in aztcd_init() to exactly match the first 3 or 4 letters you have seen.
  307. -Another point is the 'smart' card detection feature in aztcd_init(). Normally
  308.  the CD-ROM drive is ready, when aztcd_init is trying to read the version
  309.  string and a time consuming ACMD_SOFT_RESET command can be avoided. This is
  310.  detected by looking, if AFL_OP_OK can be read correctly. If the CD-ROM drive 
  311.  hangs in some unknown state, e.g. because of an error before a warm start or 
  312.  because you first operated under DOS, even the version string may be correct, 
  313.  but the following commands will not. Then change the code in such a way, 
  314.  that the ACMD_SOFT_RESET is issued in any case, by substituting the
  315.  if-statement 'if ( ...=AFL_OP_OK)' by 'if (1)'.
  316.  
  317. If you succeed, please mail may the exact version string of your drive and
  318. the code modifications, you have made together with a short explanation.
  319. If you don't succeed, you may mail me the output of the debugging messages.
  320. But remember, they are only useful, if they are exact and complete and you
  321. describe in detail your hardware setup and what you did (cold/warm reboot,
  322. with/without DOS, DOS-driver started/not started, which Linux-commands etc.)
  323.  
  324.  
  325. 9. TECHNICAL HISTORY OF THE DRIVER
  326. The AZTECH-Driver is a rework of the Mitsumi-Driver. Four major items had to
  327. be reworked:
  328.  
  329. a) The Mitsumi drive does issue complete status information acknowledging
  330. each command, the Aztech drive does only signal that the command was
  331. processed. So whenever the complete status information is needed, an extra
  332. ACMD_GET_STATUS command is issued. The handshake procedure for the drive
  333. can be found in the functions aztSendCmd(), sendAztCmd() and getAztStatus().
  334.  
  335. b) The Aztech Drive does not have a ACMD_GET_DISK_INFO command, so the
  336. necessary info about the number of tracks (firstTrack, lastTrack), disk
  337. length etc. has to be read from the TOC in the lead in track (see function
  338. aztGetDiskInfo()).
  339.  
  340. c) Whenever data is read from the drive, the Mitsumi drive is started with a
  341. command to read an indefinite (0xffffff) number of sectors. When the appropriate 
  342. number of sectors is read, the drive is stopped by a ACDM_STOP command. This
  343. does not work with the Aztech drive. I did not find a way to stop it. The
  344. stop and pause commands do only work in AUDIO mode but not in DATA mode.
  345. Therefore I had to modify the 'finite state machine' in function azt_poll to
  346. only read a certain number of sectors and then start a new read on demand. As I 
  347. have not completely understood, how the buffer/caching scheme of the Mitsumi 
  348. driver was implemented, I am not sure, if I have covered all cases correctly, 
  349. whenever you get timeout messages, the bug is most likely to be in that
  350. function azt_poll() around switch(cmd) .... case ACD_S_DATA. 
  351.  
  352. d) I did not get information about changing drive mode. So I doubt, that the
  353. code around function azt_poll() case AZT_S_MODE does work. In my test I have
  354. not been able to switch to reading in raw mode. For reading raw mode, Aztech
  355. uses a different command than for cooked mode, which I only have implemen-
  356. ted in the ioctl-section but not in the section which is used by the ISO9660- 
  357.  
  358. The driver was developed on an AST PC with Intel 486/DX2, 8MB RAM, 340MB IDE 
  359. hard disk and on an AST PC with Intel Pentium 60MHz, 16MB RAM, 520MB IDE 
  360. running Linux kernel version 1.0.9 from the LST 1.8 Distribution. The kernel 
  361. was compiled with gcc.2.5.8. My CD-ROM drive is an Aztech CDA268-01A. My
  362. drive says, that it has Firmware Version AZT26801A1.3. It came with a ISA-bus
  363. interface card and works with polled I/O without DMA and without interrupts.
  364. The code for all other drives was 'remote' tested and debugged by a number of 
  365. volunteers on the Internet.
  366.  
  367. Points, where I feel that possible problems might be and all points where I 
  368. did not completely understand the drive's behaviour or trust my own code are 
  369. marked with /*???*/ in the source code. There are also some parts in the 
  370. Mitsumi driver, where I did not completely understand their code.
  371.  
  372.  
  373. 10. ACKNOWLEDGMENTS
  374. Without the help of P.Bush, Aztech, who delivered technical information
  375. about the Aztech Drive and without the help of E.Moenkeberg, GWDG, who did a
  376. great job in analyzing the command structure of various CD-ROM drives, this
  377. work would not have been possible. E.Moenkeberg was also a great help in 
  378. making the software 'kernel ready' and in answering many of the CDROM-related 
  379. questions in the newsgroups. He really is *the* Linux CD-ROM guru. Thanks 
  380. also to all the guys on the Internet, who collected valuable technical 
  381. information about CDROMs. 
  382.  
  383. Joe Nardone (nardone@clark.net) was a patient tester even for my first
  384. trial, which was more than slow, and made suggestions for code improvement.
  385. Especially the 'finite state machine' azt_poll() was rewritten by Joe to get
  386. clean C code and avoid the ugly 'gotos', which I copied from mcd.c.
  387.  
  388. Robby Schirmer (schirmer@fmi.uni-passau.de) tested the audio stuff (ioctls) 
  389. and suggested a lot of patches for them.
  390.  
  391. Joseph Piskor and Peter Nugent were the first users with the ORCHID CD3110
  392. and also were very patient with the problems which occurred.
  393.  
  394. Anybody, who is interested in these items should have a look at 'ftp.gwdg.de',
  395. directory 'pub/linux/cdrom' and at 'ftp.cdrom.com', directory 'pub/cdrom'.
  396.  
  397. 11. PROGRAMMING ADD ONs: cdplay.c
  398. You can use the ioctl-functions included in aztcd.c in your own programs. As
  399. an example on how to do this, you will find a tiny CD Player for audio CDs 
  400. named 'cdplay.c'. It allows you to play audio CDs. You can play a specified 
  401. track, pause and resume or skip tracks forward and backwards. If you quit the 
  402. program without stopping the  drive, playing is continued. You can also 
  403. (mis)use cdplay to read and hexdump data disks.
  404. 'cdplay.c' can be found as a separate file in package AZTECH.CDROM.Vxx.tgz.
  405. If you don't have it, you can find the code in the APPENDIX of this file,
  406. which you should cut out with an editor and store in a separate file
  407. 'cdplay.c'. To compile it and make it executable, do
  408.   gcc -s -Wall -O2 -L/usr/lib cdplay.c -o /usr/local/bin/cdplay # compiles it
  409.   chmod +755 /usr/local/bin/cdplay                              # makes it executable
  410.   ln -s /dev/aztcd0 /dev/cdrom                                  # creates a link
  411.    (for /usr/lib substitute the top level directory, where your include files 
  412.     reside,  and for /usr/local/bin the directory, where you want the executable 
  413.     binary to reside )
  414.  
  415. You have to set the correct permissions for cdplay *and* for /dev/mcd0 or
  416. /dev/aztcd0 in order to use it. Remember, that you should not have /dev/cdrom 
  417. mounted, when you're playing audio CDs. 
  418.  
  419. This program is just a hack for testing the ioctl-functions in aztcd.c, I will 
  420. not maintain it, so if you run into problems, discard it or have a look into 
  421. the source code 'cdplay.c'. The program does only contain a minimum of user 
  422. protection and input error detection. If you use the commands in the wrong 
  423. order or if you try to read a CD at wrong addresses, you may get error messages
  424. or even hang your machine. If you get STEN_LOW, STEN_LOW_WAIT or segment violation 
  425. error messages when using cdplay, after that, the system might not be stable 
  426. any more, so you'd better reboot. As the ioctl-functions run in kernel mode,
  427. most normal Linux-multitasking protection features do not work. By using
  428. uninitialized 'wild' pointers etc., it is easy to write to other users data and
  429. program areas, destroy kernel tables etc.. So if you experiment with ioctls
  430. as always when you are doing systems programming and kernel hacking, you
  431. should have a backup copy of your system in a safe place (and you also
  432. should try before, how to restore from a backup copy)!
  433.  
  434.  
  435. Werner Zimmermann
  436. Fachhochschule fuer Technik Esslingen
  437. (EMail: zimmerma@rz.fht-esslingen.de)
  438. Mar 24, 1995
  439.  
  440. ---------------------------------------------------------------------------
  441. APPENDIX: Source code of cdplay.c
  442.  
  443. /* Tiny Audio CD Player
  444.  
  445.    Copyright 1994, 1995 Werner Zimmermann (zimmerma@rz.fht-esslingen.de)
  446.  
  447. This program originally was written to test the audio functions of the
  448. AZTECH.CDROM-driver, but it should work with every CD-ROM drive. Before 
  449. using it, you should set a symlink from /dev/cdrom to your real CDROM
  450. device.
  451.  
  452. The GNU General Public License applies to this program.
  453.  
  454. History:  V0.1  W.Zimmermann: First release. Nov. 8, 1994
  455.           V0.2  W.Zimmermann: Enhanced functionality. Nov. 9, 1994
  456.           V0.3  W.Zimmermann: Additional functions. Nov. 28, 1994          
  457.           V0.4  W.Zimmermann: fixed some bugs. Dec. 17, 1994
  458.           V0.5  W.Zimmermann: clean 'scanf' commands without compiler warnings
  459.                               Jan. 6, 1995
  460.           V0.6  W.Zimmermann: volume control (still experimental). Jan. 24, 1995
  461. */
  462.  
  463. #include <stdio.h>
  464. #include <ctype.h>
  465. #include <sys/ioctl.h>
  466. #include <sys/types.h>
  467. #include <fcntl.h>
  468. #include <unistd.h>
  469. #include <linux/cdrom.h>
  470. #include <linux/aztcd.h>
  471.  
  472. void help(void)
  473. { printf("Available Commands:  STOP         s      EJECT        e       QUIT         q\n");
  474.   printf("                     PLAY TRACK   t      PAUSE        p       RESUME       r\n");
  475.   printf("                     NEXT TRACK   n      REPEAT LAST  l       HELP         h\n");
  476.   printf("                     SUB CHANNEL  c      TRACK INFO   i       PLAY AT      a\n");
  477.   printf("                     READ         d      READ RAW     w       VOLUME       v\n");
  478. }
  479.  
  480. int main(void)
  481. { int handle;
  482.   unsigned char command=' ', ini=0, first=1, last=1;
  483.   unsigned int cmd, i,j,k, arg1,arg2,arg3;
  484.   struct cdrom_ti       ti;
  485.   struct cdrom_tochdr   tocHdr;
  486.   struct cdrom_subchnl  subchnl;
  487.   struct cdrom_tocentry entry;
  488.   struct cdrom_msf      msf;
  489.   union  { struct cdrom_msf msf;
  490.            unsigned char buf[2336];
  491.          } azt;
  492.   struct cdrom_volctrl  volctrl;
  493.  
  494.   printf("\nMini-Audio CD-Player V0.6   (C) 1994,1995  W.Zimmermann\n");
  495.   handle=open("/dev/cdrom",O_RDWR);
  496.   ioctl(handle,CDROMRESUME);
  497.   
  498.   if (handle<=0) 
  499.     { printf("Drive Error: already playing, no audio disk, door open\n");
  500.       printf("             or no permission (you must be ROOT in order to use this program)\n");
  501.     }
  502.   else
  503.     { help();
  504.       while (1)
  505.         { printf("Type command (h = help):  ");
  506.           scanf("%s",&command); 
  507.           switch (command)
  508.             { case 'e':   cmd=CDROMEJECT;
  509.                           ioctl(handle,cmd);
  510.                           break;
  511.               case 'p':   if (!ini)
  512.                              { printf("Command not allowed - play track first\n");
  513.                              }
  514.                           else
  515.                              { cmd=CDROMPAUSE;
  516.                                if (ioctl(handle,cmd)) printf("Drive Error\n");
  517.                              }
  518.                           break;
  519.               case 'r':   if (!ini)
  520.                              { printf("Command not allowed - play track first\n");
  521.                              }
  522.                           else
  523.                              { cmd=CDROMRESUME;
  524.                                if (ioctl(handle,cmd)) printf("Drive Error\n");
  525.                              }
  526.                           break;
  527.               case 's':   cmd=CDROMPAUSE;
  528.                           if (ioctl(handle,cmd)) printf("Drive error or already stopped\n");
  529.                           ini=0;
  530.                           cmd=CDROMSTOP;
  531.                           if (ioctl(handle,cmd)) printf("Drive error\n");
  532.                           ini=0;
  533.                           break;
  534.               case 't':   cmd=CDROMREADTOCHDR;
  535.                           if (ioctl(handle,cmd,&tocHdr)) printf("Drive Error\n");
  536.                           first=tocHdr.cdth_trk0;
  537.                           last= tocHdr.cdth_trk1;
  538.                           if ((first==0)||(first>last))
  539.                             { printf ("--could not read TOC\n");
  540.                             }
  541.                           else
  542.                             { printf("--first track: %d   --last track: %d   --enter track number: ",first,last);
  543.                               cmd=CDROMPLAYTRKIND;
  544.                               scanf("%i",&arg1);
  545.                               ti.cdti_trk0=arg1;
  546.                               if (ti.cdti_trk0<first) ti.cdti_trk0=first;
  547.                               if (ti.cdti_trk0>last)  ti.cdti_trk0=last;
  548.                               ti.cdti_ind0=0;
  549.                               ti.cdti_trk1=last;
  550.                               ti.cdti_ind1=0;
  551.                               if (ioctl(handle,cmd,&ti)) printf("Drive Error\n");
  552.                               ini=1;
  553.                             } 
  554.                           break;
  555.               case 'n':   if (!ini++) 
  556.                             { if (ioctl(handle,CDROMREADTOCHDR,&tocHdr)) printf("Drive Error\n");
  557.                               first=tocHdr.cdth_trk0;
  558.                               last= tocHdr.cdth_trk1;
  559.                               ti.cdti_trk0=first-1;
  560.                             }
  561.                           if ((first==0)||(first>last))
  562.                             { printf ("--could not read TOC\n");
  563.                             }
  564.                           else
  565.                             { cmd=CDROMPLAYTRKIND;
  566.                               if (++ti.cdti_trk0 > last)  ti.cdti_trk0=last;
  567.                               ti.cdti_ind0=0;
  568.                               ti.cdti_trk1=last;
  569.                               ti.cdti_ind1=0;
  570.                               if (ioctl(handle,cmd,&ti)) printf("Drive Error\n");
  571.                               ini=1;
  572.                             }
  573.                           break;
  574.               case 'l':   if (!ini++)
  575.                             { if (ioctl(handle,CDROMREADTOCHDR,&tocHdr)) printf("Drive Error\n");
  576.                               first=tocHdr.cdth_trk0;
  577.                               last= tocHdr.cdth_trk1;
  578.                               ti.cdti_trk0=first+1;
  579.                             }
  580.                           if ((first==0)||(first>last))
  581.                             { printf ("--could not read TOC\n");
  582.                             }
  583.                           else
  584.                             { cmd=CDROMPLAYTRKIND;
  585.                               if (--ti.cdti_trk0 < first) ti.cdti_trk0=first;
  586.                               ti.cdti_ind0=0;
  587.                               ti.cdti_trk1=last;
  588.                               ti.cdti_ind1=0;
  589.                               if (ioctl(handle,cmd,&ti)) printf("Drive Error\n");
  590.                               ini=1;
  591.                             }  
  592.                           break;
  593.               case 'c':   subchnl.cdsc_format=CDROM_MSF;
  594.                           if (ioctl(handle,CDROMSUBCHNL,&subchnl)) 
  595.                             printf("Drive Error\n");
  596.                           else
  597.                             { printf("AudioStatus:%s   Track:%d  Mode:%d   MSF=%d:%d:%d\n", \
  598.                               subchnl.cdsc_audiostatus==CDROM_AUDIO_PLAY ? "PLAYING":"NOT PLAYING",\
  599.                               subchnl.cdsc_trk,subchnl.cdsc_adr, \
  600.                               subchnl.cdsc_absaddr.msf.minute, subchnl.cdsc_absaddr.msf.second, \
  601.                               subchnl.cdsc_absaddr.msf.frame);
  602.                             }
  603.                           break;              
  604.               case 'i':   if (!ini)
  605.                             { printf("Command not allowed - play track first\n");
  606.                             }
  607.                           else
  608.                             { cmd=CDROMREADTOCENTRY;
  609.                               printf("Track No.: ");
  610.                               scanf("%d",&arg1);
  611.                               entry.cdte_track=arg1;
  612.                               if (entry.cdte_track<first) entry.cdte_track=first;
  613.                               if (entry.cdte_track>last)  entry.cdte_track=last;
  614.                   entry.cdte_format=CDROM_MSF;
  615.                               if (ioctl(handle,cmd,&entry)) 
  616.                                { printf("Drive error or invalid track no.\n");
  617.                                }
  618.                               else
  619.                                { printf("Mode %d Track, starts at %d:%d:%d\n", \
  620.                                entry.cdte_adr,entry.cdte_addr.msf.minute, \
  621.                                entry.cdte_addr.msf.second,entry.cdte_addr.msf.frame);
  622.                                }
  623.                             }
  624.                           break;
  625.               case 'a':   cmd=CDROMPLAYMSF;
  626.                           printf("Address (min:sec:frame)  ");
  627.                           scanf("%d:%d:%d",&arg1,&arg2,&arg3);
  628.                           msf.cdmsf_min0  =arg1;
  629.                           msf.cdmsf_sec0  =arg2;
  630.                           msf.cdmsf_frame0=arg3;
  631.                           if (msf.cdmsf_sec0  > 59) msf.cdmsf_sec0  =59;
  632.                           if (msf.cdmsf_frame0> 74) msf.cdmsf_frame0=74;
  633.                           msf.cdmsf_min1=60;
  634.                           msf.cdmsf_sec1=00;
  635.                           msf.cdmsf_frame1=00;
  636.                           if (ioctl(handle,cmd,&msf)) 
  637.                            { printf("Drive error or invalid address\n");
  638.                            }
  639.                           break;
  640. #ifdef AZT_PRIVATE_IOCTLS /*not supported by every CDROM driver*/
  641.               case 'd':   cmd=CDROMREADMODE1;
  642.                           printf("Address (min:sec:frame)  ");
  643.                           scanf("%d:%d:%d",&arg1,&arg2,&arg3);
  644.                           azt.msf.cdmsf_min0  =arg1;
  645.                           azt.msf.cdmsf_sec0  =arg2;
  646.                           azt.msf.cdmsf_frame0=arg3;
  647.                           if (azt.msf.cdmsf_sec0  > 59) azt.msf.cdmsf_sec0  =59;
  648.                           if (azt.msf.cdmsf_frame0> 74) azt.msf.cdmsf_frame0=74;
  649.                           if (ioctl(handle,cmd,&azt.msf)) 
  650.                            { printf("Drive error, invalid address or unsupported command\n");
  651.                            }
  652.                           k=0;
  653.                           getchar();
  654.                           for (i=0;i<128;i++)
  655.                            { printf("%4d:",i*16);
  656.                              for (j=0;j<16;j++)
  657.                                { printf("%2x ",azt.buf[i*16+j]);
  658.                                }
  659.                              for (j=0;j<16;j++)
  660.                                { if (isalnum(azt.buf[i*16+j])) 
  661.                                    printf("%c",azt.buf[i*16+j]);
  662.                                  else
  663.                                    printf(".");
  664.                                }
  665.                              printf("\n"); 
  666.                              k++;
  667.                              if (k>=20)
  668.                               { printf("press ENTER to continue\n");
  669.                                 getchar();
  670.                                 k=0;
  671.                               }
  672.                            } 
  673.                           break;
  674.               case 'w':   cmd=CDROMREADMODE2;
  675.                           printf("Address (min:sec:frame)  ");
  676.                           scanf("%d:%d:%d",&arg1,&arg2,&arg3);
  677.                           azt.msf.cdmsf_min0  =arg1;
  678.                           azt.msf.cdmsf_sec0  =arg2;
  679.                           azt.msf.cdmsf_frame0=arg3;                          
  680.                           if (azt.msf.cdmsf_sec0  > 59) azt.msf.cdmsf_sec0  =59;
  681.                           if (azt.msf.cdmsf_frame0> 74) azt.msf.cdmsf_frame0=74;
  682.                           if (ioctl(handle,cmd,&azt)) 
  683.                            { printf("Drive error, invalid address or unsupported command\n");
  684.                            }
  685.                           k=0;
  686.                           for (i=0;i<146;i++)
  687.                            { printf("%4d:",i*16);
  688.                              for (j=0;j<16;j++)
  689.                                { printf("%2x ",azt.buf[i*16+j]);
  690.                                }
  691.                              for (j=0;j<16;j++)
  692.                                { if (isalnum(azt.buf[i*16+j])) 
  693.                                    printf("%c",azt.buf[i*16+j]);
  694.                                  else
  695.                                    printf(".");
  696.                                }
  697.                              printf("\n"); 
  698.                              k++;
  699.                              if (k>=20)
  700.                               { getchar();
  701.                                 k=0;
  702.                               }
  703.                            } 
  704.                           break;
  705. #endif
  706.               case 'v':   cmd=CDROMVOLCTRL;
  707.                           printf("--Channel 0 Left  (0-255): ");
  708.                           scanf("%d",&arg1);
  709.                           printf("--Channel 1 Right (0-255): ");
  710.                           scanf("%d",&arg2);
  711.                           volctrl.channel0=arg1;
  712.                           volctrl.channel1=arg2;
  713.                           volctrl.channel2=0;
  714.                           volctrl.channel3=0;
  715.                           if (ioctl(handle,cmd,&volctrl)) 
  716.                            { printf("Drive error or unsupported command\n");
  717.                            }
  718.                           break;  
  719.               case 'q':   if (close(handle)) printf("Drive Error: CLOSE\n");
  720.                           exit(0);
  721.               case 'h':   help();
  722.                           break;
  723.               default:    printf("unknown command\n");
  724.                           break;
  725.             }
  726.        }
  727.     }
  728.   return 0;
  729. }
  730.  
  731.