summaryrefslogtreecommitdiffstats
path: root/loader/cdrom.c
blob: 6a742fe5e802ff915b5330690f2671bd7620d97b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdlib.h>
#include <unistd.h>

#include <newt.h>

#include "cdrom.h"
#include "devices.h"
#include "lang.h"
#include "loader.h"
#include "windows.h"

#define CD_SCSI 2
#define CD_OTHER 3

static struct { char * modname, * devname; } transTable[] = {
	{ "cm206", "cm206cd" },
	{ "sonycd535", "cdu535" },
	{ NULL, NULL }
} ;

static int setupCDdevicePanel(int * type) {
    char * menuItems[2];
    int cdromType = 0, rc;

    menuItems[0] = "SCSI";
    menuItems[1] = NULL;

    if (*type == CD_OTHER)
	cdromType = 1;

    rc = newtWinMenu(_("CDROM type"), _("What type of CDROM do you have?"),
		     30, 5, 5, 7, menuItems,
		     &cdromType, _("OK"), _("Back"), NULL);

    if (rc == 2) return LOADER_BACK;

    if (cdromType == 0)
	*type = CD_SCSI;
    else
	*type = CD_OTHER;

    return 0;
}

int setupCDdevice(struct knownDevices * kd, moduleInfoSet modInfo, 
		  moduleList modLoaded, moduleDeps * modDepsPtr, 
		  char * floppyDevice, int flags) {
    int type = 0, rc = 0;
    int i;
    int done = 0;
    char * devName;

    while (!done) {
	rc = setupCDdevicePanel(&type);
	if (rc) return rc;

	switch (type) {
	  case CD_SCSI:
	    rc = devDeviceMenu(DRIVER_SCSI, modInfo, modLoaded, modDepsPtr, 
	    		       floppyDevice, flags, NULL);
	    if (!rc) {
		kdFindScsiList(kd, 0);
		/* we'll get called again if the scsi bus doesn't have a CDROM
		   drive on it */
		done = 1;
	    }
	    break;

	  case CD_OTHER:
	    rc = devDeviceMenu(DRIVER_CDROM, modInfo, modLoaded, modDepsPtr, 
	    		       floppyDevice, flags, &devName);
	    if (!rc) {
		for (i = 0; transTable[i].modname; i++) {
		    if (!strcmp(devName, transTable[i].devname)) {
			devName = transTable[i].devname;
			break;
		    }
		}

		kdAddDevice(kd, CLASS_CDROM, devName, NULL);

		done = 1;
	    }
	    break;
	}
    } 

    winStatus(35, 3, "CDROM", _("Initializing CDROM..."));
    sleep(2);			/* some drivers need time to initialize */
    newtPopWindow();

    return 0;
}