home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1998 February
/
CHIP_2_98.iso
/
misc
/
src
/
install
/
cdrom.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-11-05
|
4KB
|
181 lines
#include <fcntl.h>
#include <linux/types.h>
#include <linux/cdrom.h>
#include <sys/ioctl.h>
#include <strings.h>
#include <newt.h>
#include <stdlib.h>
#include <unistd.h>
#include "devices.h"
#include "install.h"
#include "log.h"
#include "newt.h"
#include "scsi.h"
#include "windows.h"
#define CD_IDE 1
#define CD_SCSI 2
#define CD_OTHER 3
static struct { char * modname, * devname; } transTable[] = {
{ "cm206", "cm206cd" },
{ "sonycd535", "cdu535" },
{ NULL, NULL }
} ;
#ifdef __i386__
static int setupCDdevicePanel(int * type) {
newtComponent form, label, listbox, okay, cancel, answer;
newtCenteredWindow(35, 11, "CDROM type");
label = newtLabel(1, 1, "What type of CDROM do you have?");
listbox = newtListbox(10, 3, 0, NEWT_LISTBOX_RETURNEXIT);
newtListboxAddEntry(listbox, "SCSI", (void *) CD_SCSI);
newtListboxAddEntry(listbox, "Other CDROM", (void *) CD_OTHER);
okay = newtButton(5, 7, "Ok");
cancel = newtButton(20, 7, "Cancel");
form = newtForm(NULL, NULL, 0);
newtFormAddComponents(form, label, listbox, okay, cancel, NULL);
answer = newtRunForm(form);
if (answer != cancel)
*type = (int) newtListboxGetCurrent(listbox);
newtFormDestroy(form);
newtPopWindow();
if (answer == cancel) return INST_CANCEL;
return 0;
}
#endif /* __i386__ */
#ifndef __sparc__
int findAtapi(char ** cddev) {
struct deviceInfo * ide;
int i;
if (ideGetDevices(&ide)) return INST_ERROR;
i = 0;
while (ide[i].deviceName) {
if (ide[i].type == DEVICE_CDROM) {
*cddev = ide[i].deviceName;
return 0;
}
i++;
}
return INST_ERROR;
}
#endif /* ! __sparc__ */
int setupCDdevice(char ** cddev, struct driversLoaded ** dl) {
int type, rc = 0;
struct driversLoaded * d;
int i;
int done = 0;
#ifndef __sparc__
/* Let's see if any CDROM's are already available */
if (!findAtapi(cddev)) {
logMessage("using device %s", *cddev);
done = 1;
}
#endif
if (!done) {
#if defined(__sparc__) || defined(__alpha__)
/* It must be SCSI -- we'll give an error later if this is wrong */
setupSCSIInterfaces(1, dl);
*cddev = "scd0";
done =1;
#else
if (!findSCSIcdrom(cddev)) {
done = 1;
} else if (kickstart) {
setupSCSIInterfaces(1, dl);
if (!findSCSIcdrom(cddev)) done = 1;
}
#endif
}
#ifdef __i386__
while (rc || !done) {
rc = setupCDdevicePanel(&type);
if (rc) return rc;
switch (type) {
case CD_SCSI:
setupSCSIInterfaces(1, dl);
*cddev = "scd0";
done = 1;
break;
case CD_OTHER:
rc = loadDeviceDriver(DRIVER_CDROM, dl, 0);
if (!rc) {
d = *dl;
*cddev = "bad_device";
while (d) {
if (d->type == DRIVER_CDROM) {
*cddev = d->module;
break;
}
d = d->next;
}
for (i = 0; transTable[i].modname; i++) {
if (!strcmp(*cddev, transTable[i].modname)) {
*cddev = transTable[i].devname;
break;
}
}
done = 1;
}
break;
}
}
#endif /* __i386__ */
winStatus(35, 3, "CDROM", "Initializing CDROM...");
sleep(2);
newtPopWindow();
return 0;
}
int removeCDmodule(struct driversLoaded ** dl) {
/* this wil fail silently if no CD module has been loaded */
removeDeviceDriver(DRIVER_CDROM, dl);
return 0;
}
int findSCSIcdrom(char ** cddev) {
struct deviceInfo * scsi;
int i;
if (!scsiDeviceAvailable()) return INST_ERROR;
if (scsiGetDevices(&scsi)) return INST_ERROR;
i = 0;
while (scsi[i].deviceName) {
if (scsi[i].type == DEVICE_CDROM) {
*cddev = scsi[i].deviceName;
return 0;
}
i++;
}
return INST_ERROR;
}