CD-CHANGER Problem Solved!!

CD-CHANGER Problem Solved!!

Post by Greg Kraf » Tue, 10 Aug 1999 04:00:00



I have been posting that I have a nec ide cdchanger, and wanted to be able
to read the other 3 drives. A guy had the same problem as me, and I told
him I would give him the fix if I found it...well I lost his e-mail so I'm
posting this here in hopes he'll see it.

The fix is in a file called ide_cd or something like that right in with
some module docs...right on my system!  It was installed with the Red Hat
6.0 installation.
In the doc it has c++ code for a little util that will change the cd-drive
on your changer...you run this when the drive is not mounted.  It goes
something like this (After I compiled my code with the c++ comand line
compiler I called it "cdchange")
cdchange /dev/cdrom 2 (for drive bay number 2)

Here is what you do:

1.  Copy the code below to a file and compile it by typing c++ myfile
2. take the a.out file rename it to cdchange and set the permissions like
this:
chmod ugo+x,ugo+r cdchange
3. Move the file somewhere in the PATH like /usr/bin
4. Make a script file , if you want that will unmount your cd change the
drive and remount.

Here's the code:

/*
 * cdchange.c  [-v]  <device>  [<slot>]
 *
 * This loads a CDROM from a specified slot in a changer, and displays
 * information about the changer status.  The drive should be unmounted
before
 * using this program.
 *
 * Changer information is displayed if either the -v flag is specified
 * or no slot was specified.
 *
 * Based on code originally from Gerhard Zuber <zu...@berlin.snafu.de>.
 * Changer status information, and rewrite for the new Uniform CDROM driver
 * interface by Erik Andersen <ander...@debian.org>.
 */

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/cdrom.h>

int
main (int argc, char **argv)
{
        char *program;
        char *device;
        int fd;           /* file descriptor for CD-ROM device */
        int status;       /* return status for system calls */
        int verbose = 0;
        int slot=-1, x_slot;
        int total_slots_available;

        program = argv[0];

        ++argv;
        --argc;

        if (argc < 1 || argc > 3) {
                fprintf (stderr, "usage: %s [-v] <device> [<slot>]\n",
                         program);
                fprintf (stderr, "       Slots are numbered 1 -- n.\n");
                exit (1);
        }

       if (strcmp (argv[0], "-v") == 0) {
                verbose = 1;
                ++argv;
                --argc;
        }

        device = argv[0];

        if (argc == 2)
                slot = atoi (argv[1]) - 1;

        /* open device */
        fd = open(device, O_RDONLY | O_NONBLOCK);
        if (fd < 0) {
                fprintf (stderr, "%s: open failed for `%s': %s\n",
                         program, device, strerror (errno));
                exit (1);
        }

        /* Check CD player status */
        total_slots_available = ioctl (fd, CDROM_CHANGER_NSLOTS);
        if (total_slots_available <= 1 ) {
                fprintf (stderr, "%s: Device `%s' is not an ATAPI "
                        "compliant CD changer.\n", program, device);
                exit (1);
        }

        if (slot >= 0) {
                if (slot >= total_slots_available) {
                        fprintf (stderr, "Bad slot number.  "
                                 "Should be 1 -- %d.\n",
                                 total_slots_available);
                        exit (1);
                }

                /* load */
                slot=ioctl (fd, CDROM_SELECT_DISC, slot);
                if (slot<0) {
                        fflush(stdout);
                                perror ("CDROM_SELECT_DISC ");
                        exit(1);
                }
        }

        if (slot < 0 || verbose) {

                status=ioctl (fd, CDROM_SELECT_DISC, CDSL_CURRENT);
                if (status<0) {
                        fflush(stdout);
                        perror (" CDROM_SELECT_DISC");
                        exit(1);
                }
                slot=status;

                printf ("Current slot: %d\n", slot+1);
                printf ("Total slots available: %d\n",
                        total_slots_available);

                printf ("Drive status: ");
                status = ioctl (fd, CDROM_DRIVE_STATUS, CDSL_CURRENT);
                if (status<0) {
                  perror(" CDROM_DRIVE_STATUS");
                } else switch(status) {
                case CDS_DISC_OK:
                        printf ("Ready.\n");
                        break;
                case CDS_TRAY_OPEN:
                        printf ("Tray Open.\n");
                        break;
                case CDS_DRIVE_NOT_READY:
                        printf ("Drive Not Ready.\n");
                        break;
                default:
                        printf ("This Should not happen!\n");
                        break;
                }

                for (x_slot=0; x_slot<total_slots_available; x_slot++) {
                        printf ("Slot %2d: ", x_slot+1);
                        status = ioctl (fd, CDROM_DRIVE_STATUS, x_slot);
                        if (status<0) {
                             perror(" CDROM_DRIVE_STATUS");
                        } else switch(status) {
                        case CDS_DISC_OK:
                                printf ("Disc present.");
                                break;
                        case CDS_NO_DISC:
                                printf ("Empty slot.");
                                break;
                        case CDS_TRAY_OPEN:
                                printf ("CD-ROM tray open.\n");
                                break;
                        case CDS_DRIVE_NOT_READY:
                                printf ("CD-ROM drive not ready.\n");
                                break;
                        case CDS_NO_INFO:
                                printf ("No Information available.");
                                break;
                        default:
                                printf ("This Should not happen!\n");
                                break;
                        }
                  if (slot == x_slot) {
                  status = ioctl (fd, CDROM_DISC_STATUS);
                  if (status<0) {
                        perror(" CDROM_DISC_STATUS");
                  }
                  switch (status) {
                        case CDS_AUDIO:
                                printf ("\tAudio disc.\t");
                                break;
                        case CDS_DATA_1:
                        case CDS_DATA_2:
                                printf ("\tData disc type %d.\t", status-CDS_DATA_1+1);
                                break;
                        case CDS_XA_2_1:
                        case CDS_XA_2_2:
                                printf ("\tXA data disc type %d.\t", status-CDS_XA_2_1+1);
                                break;
                        default:
                                printf ("\tUnknown disc type 0x%x!\t", status);
                                break;
                        }
                        }
                        status = ioctl (fd, CDROM_MEDIA_CHANGED, x_slot);
                        if (status<0) {
                                perror(" CDROM_MEDIA_CHANGED");
                        }
                        switch (status) {
                        case 1:
                                printf ("Changed.\n");
                                break;
                        default:
                                printf ("\n");
                                break;
                        }
                }
        }

        /* close device */
        status = close (fd);
        if (status != 0) {
                fprintf (stderr, "%s: close failed for `%s': %s\n",
                         program, device, strerror (errno));
                exit (1);
        }

        exit (0);

}

 
 
 

1. Problem with Kernel 2.2.5 and Regal CD-Changer

Hello,

I just upgraded from RedHat 5.2/i386 (Kernel 2.0.36) to RedHat 6.0/i386
(Kernel 2.2.5) and now I can only boot when my Regal SCSI CD changer is
switched of, or I have not compiled it with "probe all LUNs". If I try
to boot it with "probe all LUNs" and the Regal CD changer is switched
on, it stops when the NCR8xx driver recognizes the Regal CD Changer.
With 2.0.36 I did not have this problem.
What can I do to get my CD changer working with 2.2.x ?

Bye,
Henning

2. win98se -> ICS -> Redhat 6.2

3. TEAC CD-C68E CD-Changer, 6 Discs, ATAPI.

4. Coming from the darkside... couple of questions (newbie)

5. CD-CHANGER CD-ROM

6. AMD K6-specs

7. cd-changer CD-C68E

8. Alias' messages are returned as user unknown - desperate for help

9. Sol-2.4 CD-Changer DRM-624x

10. 2.4.18 and cd-changer Nakamichi MBR-7

11. (Q) Nakamichi CD-Changer MJ-5.16

12. CD-changer support in Linux

13. cd-changer+amd: system locks sometimes