Revision: 1687
http://ipcop.svn.sourceforge.net/ipcop/?rev=1687&view=rev
Author: owes
Date: 2008-08-11 14:00:50 +0000 (Mon, 11 Aug 2008)
Log Message:
-----------
apply Coding Style
Modified Paths:
--------------
ipcop/trunk/src/installer/hardware.c
Modified: ipcop/trunk/src/installer/hardware.c
===================================================================
--- ipcop/trunk/src/installer/hardware.c 2008-08-11 14:00:23 UTC (rev 1686)
+++ ipcop/trunk/src/installer/hardware.c 2008-08-11 14:00:50 UTC (rev 1687)
@@ -49,7 +49,7 @@
static FILE *fhwdetect;
static int have_idedisk = 0;
static int have_idecd = 0;
-static int install_setup = 0; /* 0 when running setup (NIC detection), 1 for installer */
+static int install_setup = 0; /* 0 when running setup (NIC detection), 1 for installer */
/* Retrieve disk capacity from proc or sys.
@@ -58,124 +58,110 @@
*/
static unsigned long getdrivesize(char *procname, char *strsize)
{
- FILE *f;
- uint64_t size; /* using 32bit would limit to 1000 GB, which is not too far away in the future */
- unsigned long mbsize;
+ FILE *f;
+ uint64_t size; /* using 32bit would limit to 1000 GB, which is not too far away in the future */
+ unsigned long mbsize;
- mbsize = 0;
- strcpy(strsize, "? KB");
+ mbsize = 0;
+ strcpy(strsize, "? KB");
- if ( (f = fopen(procname, "r")) != NULL )
- {
- if ( fgets(strsize, STRING_SIZE, f) )
- {
- size = strtoull(strsize, NULL, 10);
- size = size * 512 / 1000; /* use the disk vendor way of specifying KBytes */
- mbsize = size / 1000;
+ if ((f = fopen(procname, "r")) != NULL) {
+ if (fgets(strsize, STRING_SIZE, f)) {
+ size = strtoull(strsize, NULL, 10);
+ size = size * 512 / 1000; /* use the disk vendor way of specifying KBytes */
+ mbsize = size / 1000;
- if ( size >= 4000000 )
- {
- /* Everything larger than 4000 MB */
- snprintf(strsize, STRING_SIZE, "%llu GB", size / 1000000);
- }
- else if ( size >= 4000 )
- {
- /* Everything larger than 4000 KB */
- snprintf(strsize, STRING_SIZE, "%llu MB", size / 1000);
- }
- else
- {
- /* Anything else, unlikely since we need something like 100+ MB anyway */
- snprintf(strsize, STRING_SIZE, "%llu KB", size);
- }
+ if (size >= 4000000) {
+ /* Everything larger than 4000 MB */
+ snprintf(strsize, STRING_SIZE, "%llu GB", size / 1000000);
+ }
+ else if (size >= 4000) {
+ /* Everything larger than 4000 KB */
+ snprintf(strsize, STRING_SIZE, "%llu MB", size / 1000);
+ }
+ else {
+ /* Anything else, unlikely since we need something like 100+ MB anyway */
+ snprintf(strsize, STRING_SIZE, "%llu KB", size);
+ }
+ }
}
- }
- return mbsize;
+ return mbsize;
}
-/*
- Add something to our hardware list
-*/
-static void hardwareadd(supported_media_t type, char *module, char *device, char *vendor, char *description, char *vendorid, char *modelid)
+/* Add something to our hardware list */
+static void hardwareadd(supported_media_t type, char *module, char *device, char *vendor, char *description,
+ char *vendorid, char *modelid)
{
- char vendordesc[STRING_SIZE] = "";
+ char vendordesc[STRING_SIZE] = "";
- if ( (device != NULL) && (numhardwares != 0) )
- {
- /* avoid duplicates */
- int i;
+ if ((device != NULL) && (numhardwares != 0)) {
+ /* avoid duplicates */
+ int i;
- for (i = 0; i < numhardwares; i++)
- {
- if ( !strcmp(device, hardwares[i].device) )
- {
- return;
- }
+ for (i = 0; i < numhardwares; i++) {
+ if (!strcmp(device, hardwares[i].device)) {
+ return;
+ }
+ }
}
- }
- hardwares = realloc(hardwares, sizeof(struct hardware_s) * (numhardwares + 1));
+ hardwares = realloc(hardwares, sizeof(struct hardware_s) * (numhardwares + 1));
- hardwares[numhardwares].type = type;
+ hardwares[numhardwares].type = type;
- if ( module != NULL )
- {
- hardwares[numhardwares].module = strdup(module);
- }
- else
- {
- hardwares[numhardwares].module = strdup("");
- }
+ if (module != NULL) {
+ hardwares[numhardwares].module = strdup(module);
+ }
+ else {
+ hardwares[numhardwares].module = strdup("");
+ }
- if ( device != NULL )
- {
- hardwares[numhardwares].device = strdup(device);
- }
- else
- {
- hardwares[numhardwares].device = strdup("");
- }
+ if (device != NULL) {
+ hardwares[numhardwares].device = strdup(device);
+ }
+ else {
+ hardwares[numhardwares].device = strdup("");
+ }
- // Now build full description from vendor name and description
- // if description is NULL, full description becomes "Unknown" + IDs
- if ( description != NULL )
- {
- if ( vendor != NULL )
- {
- strcpy(vendordesc, vendor);
- strcat(vendordesc, " ");
+ // Now build full description from vendor name and description
+ // if description is NULL, full description becomes "Unknown" + IDs
+ if (description != NULL) {
+ if (vendor != NULL) {
+ strcpy(vendordesc, vendor);
+ strcat(vendordesc, " ");
+ }
+ strcat(vendordesc, description);
}
- strcat(vendordesc, description);
- }
- else
- {
- /* no description, use IDs */
- snprintf(vendordesc, STRING_SIZE, "Unknown %s:%s",
- vendorid == NULL ? "" : vendorid,
- modelid == NULL ? "" : modelid);
- }
- hardwares[numhardwares].description = strdup(vendordesc);
+ else {
+ /* no description, use IDs */
+ snprintf(vendordesc, STRING_SIZE, "Unknown %s:%s",
+ vendorid == NULL ? "" : vendorid, modelid == NULL ? "" : modelid);
+ }
+ hardwares[numhardwares].description = strdup(vendordesc);
- fprintf(flog, " HWadd %3d, %s, %s, %s\n", type, hardwares[numhardwares].module,
- hardwares[numhardwares].device,
- hardwares[numhardwares].description);
- if ( install_setup )
- {
- fprintf(fhwdetect, " HWadd %3d, %s, %s, %s\n", type, hardwares[numhardwares].module,
- hardwares[numhardwares].device,
- hardwares[numhardwares].description);
- }
- // increment tallies
- numhardwares++;
- switch ( type )
- {
- case network: numnetwork++; break;
- case harddisk: numharddisk++; break;
- case cdrom: numcdrom++; break;
- default: break;
- }
+ fprintf(flog, " HWadd %3d, %s, %s, %s\n", type, hardwares[numhardwares].module,
+ hardwares[numhardwares].device, hardwares[numhardwares].description);
+ if (install_setup) {
+ fprintf(fhwdetect, " HWadd %3d, %s, %s, %s\n", type, hardwares[numhardwares].module,
+ hardwares[numhardwares].device, hardwares[numhardwares].description);
+ }
+ // increment tallies
+ numhardwares++;
+ switch (type) {
+ case network:
+ numnetwork++;
+ break;
+ case harddisk:
+ numharddisk++;
+ break;
+ case cdrom:
+ numcdrom++;
+ break;
+ default:
+ break;
+ }
}
@@ -184,618 +170,537 @@
Used by scandir in scanprocdrives function.
Return 0 to skip a device
*/
-int ide_filter (const struct dirent *b)
+int ide_filter(const struct dirent *b)
{
- char string[STRING_SIZE];
+ char string[STRING_SIZE];
- snprintf(string, STRING_SIZE, "/sys/bus/ide/devices/%s/media", b->d_name);
+ snprintf(string, STRING_SIZE, "/sys/bus/ide/devices/%s/media", b->d_name);
- if ( access(string, 0) == 0 )
- {
- return 1;
- }
+ if (access(string, 0) == 0) {
+ return 1;
+ }
- return 0;
+ return 0;
}
-/*
- Scan /sys/bus/ide and /sys/block for drives
-*/
+/* Scan /sys/bus/ide and /sys/block for drives */
static void scanprocdrives(int modprobe)
{
- FILE *f = NULL;
- char procname[STRING_SIZE];
- char media[STRING_SIZE];
- char model[STRING_SIZE];
- supported_media_t type = none;
- char command[STRING_SIZE];
- char deviceletter;
- char strsize[STRING_SIZE];
- struct dirent **names;
- int numdevices = 0;
- int i;
+ FILE *f = NULL;
+ char procname[STRING_SIZE];
+ char media[STRING_SIZE];
+ char model[STRING_SIZE];
+ supported_media_t type = none;
+ char command[STRING_SIZE];
+ char deviceletter;
+ char strsize[STRING_SIZE];
+ struct dirent **names;
+ int numdevices = 0;
+ int i;
- /* look for IDE harddisk and cdrom */
- numdevices = scandir("/sys/bus/ide/devices", &names, &ide_filter, alphasort);
- for (i = 0; i < numdevices; i++)
- {
- snprintf(procname, STRING_SIZE, "/sys/bus/ide/devices/%s/media", names[i]->d_name);
- if ( (f = fopen(procname, "r")) == NULL )
- {
- continue;
- }
+ /* look for IDE harddisk and cdrom */
+ numdevices = scandir("/sys/bus/ide/devices", &names, &ide_filter, alphasort);
+ for (i = 0; i < numdevices; i++) {
+ snprintf(procname, STRING_SIZE, "/sys/bus/ide/devices/%s/media", names[i]->d_name);
+ if ((f = fopen(procname, "r")) == NULL) {
+ continue;
+ }
- /* media holds disk or cdrom */
- if ( fgets(media, STRING_SIZE, f) )
- {
- stripnl(media);
- if ( !strcmp(media, "disk") )
- {
- type = harddisk;
- }
- else if ( !strcmp(media, "cdrom") )
- {
- type = cdrom;
- if ( modprobe && !have_idecd )
- {
- have_idecd = 1;
- snprintf(command, STRING_SIZE, "/sbin/modprobe %s", "ide-cd");
- if ( mysystem(command) )
- {
- /* In kernel 2.6.25 ide-cd is now ide-cd_mod, try & be future safe. */
- snprintf(command, STRING_SIZE, "/sbin/modprobe %s", "ide-cd_mod");
- mysystem(command);
- }
- /* no need to put in hardware list */
+ /* media holds disk or cdrom */
+ if (fgets(media, STRING_SIZE, f)) {
+ stripnl(media);
+ if (!strcmp(media, "disk")) {
+ type = harddisk;
+ }
+ else if (!strcmp(media, "cdrom")) {
+ type = cdrom;
+ if (modprobe && !have_idecd) {
+ have_idecd = 1;
+ snprintf(command, STRING_SIZE, "/sbin/modprobe %s", "ide-cd");
+ if (mysystem(command)) {
+ /* In kernel 2.6.25 ide-cd is now ide-cd_mod, try & be future safe. */
+ snprintf(command, STRING_SIZE, "/sbin/modprobe %s", "ide-cd_mod");
+ mysystem(command);
+ }
+ /* no need to put in hardware list */
- /* give some time to settle */
- sleep(1);
+ /* give some time to settle */
+ sleep(1);
+ }
+ }
}
- }
- }
- fclose(f);
+ fclose(f);
- if ( type != none )
- {
- char device[STRING_SIZE];
- char description[STRING_SIZE] = "Unknown";
+ if (type != none) {
+ char device[STRING_SIZE];
+ char description[STRING_SIZE] = "Unknown";
- /* found something, get device name (hd?), model and size */
- snprintf(procname, STRING_SIZE, "/sys/bus/ide/devices/%s/drivename", names[i]->d_name);
- if ( (f = fopen(procname, "r")) != NULL )
- {
- if ( fgets(device, STRING_SIZE, f) )
- {
- stripnl(device);
- fclose(f);
+ /* found something, get device name (hd?), model and size */
+ snprintf(procname, STRING_SIZE, "/sys/bus/ide/devices/%s/drivename", names[i]->d_name);
+ if ((f = fopen(procname, "r")) != NULL) {
+ if (fgets(device, STRING_SIZE, f)) {
+ stripnl(device);
+ fclose(f);
- snprintf(procname, STRING_SIZE, "/sys/bus/ide/devices/%s/model", names[i]->d_name);
- if ( (f = fopen(procname, "r")) != NULL )
- {
- if ( fgets(model, STRING_SIZE, f) )
- {
- stripnl(model);
- if ( type == harddisk )
- {
- snprintf(procname, STRING_SIZE, "/sys/block/%s/size", device);
- getdrivesize(procname, strsize);
+ snprintf(procname, STRING_SIZE, "/sys/bus/ide/devices/%s/model", names[i]->d_name);
+ if ((f = fopen(procname, "r")) != NULL) {
+ if (fgets(model, STRING_SIZE, f)) {
+ stripnl(model);
+ if (type == harddisk) {
+ snprintf(procname, STRING_SIZE, "/sys/block/%s/size", device);
+ getdrivesize(procname, strsize);
- snprintf(description, STRING_SIZE, "%-30.30s (%s)", model, strsize);
- }
- else
- {
- /* size is not interesting for CDROM */
- strcpy(description, model);
- }
+ snprintf(description, STRING_SIZE, "%-30.30s (%s)", model, strsize);
+ }
+ else {
+ /* size is not interesting for CDROM */
+ strcpy(description, model);
+ }
+ }
+ }
+ }
+ fclose(f);
}
- }
- }
- fclose(f);
- }
- hardwareadd(type, NULL, device, NULL, description, NULL, NULL);
+ hardwareadd(type, NULL, device, NULL, description, NULL, NULL);
+ }
}
- }
- /* Look for SCSI, SATA harddisk, USB attached devices */
- for (deviceletter = 'a'; deviceletter <= 'z'; deviceletter++)
- {
- snprintf(procname, STRING_SIZE, "/sys/block/sd%c/device/model", deviceletter);
+ /* Look for SCSI, SATA harddisk, USB attached devices */
+ for (deviceletter = 'a'; deviceletter <= 'z'; deviceletter++) {
+ snprintf(procname, STRING_SIZE, "/sys/block/sd%c/device/model", deviceletter);
- if ( (f = fopen(procname, "r")) == NULL )
- {
- continue;
- }
+ if ((f = fopen(procname, "r")) == NULL) {
+ continue;
+ }
- /* We need some mechanism to differentiate between installation from USB stick
- or installation on USB device
- */
+ /* We need some mechanism to differentiate between installation from USB stick
+ or installation on USB device
+ */
- if ( fgets(model, STRING_SIZE, f) )
- {
- char device[4];
- char description[STRING_SIZE] = "Unknown";
+ if (fgets(model, STRING_SIZE, f)) {
+ char device[4];
+ char description[STRING_SIZE] = "Unknown";
- stripnl(model);
- sprintf(device, "sd%c", deviceletter);
+ stripnl(model);
+ sprintf(device, "sd%c", deviceletter);
- snprintf(procname, STRING_SIZE, "/sys/block/sd%c/size", deviceletter);
- if ( getdrivesize(procname, strsize) < 64 )
- {
- /* Silently discard anything too small */
- fprintf(flog, " discard sd%c %-30.30s (%s)\n", deviceletter, model, strsize);
- if ( install_setup )
- {
- fprintf(fhwdetect, " discard sd%c %-30.30s (%s)\n", deviceletter, model, strsize);
+ snprintf(procname, STRING_SIZE, "/sys/block/sd%c/size", deviceletter);
+ if (getdrivesize(procname, strsize) < 64) {
+ /* Silently discard anything too small */
+ fprintf(flog, " discard sd%c %-30.30s (%s)\n", deviceletter, model, strsize);
+ if (install_setup) {
+ fprintf(fhwdetect, " discard sd%c %-30.30s (%s)\n", deviceletter, model, strsize);
+ }
+ continue;
+ }
+ snprintf(description, STRING_SIZE, "%-30.30s (%s)", model, strsize);
+
+ hardwareadd(harddisk, NULL, device, NULL, description, NULL, NULL);
}
- continue;
- }
- snprintf(description, STRING_SIZE, "%-30.30s (%s)", model, strsize);
- hardwareadd(harddisk, NULL, device, NULL, description, NULL, NULL);
+ fclose(f);
}
- fclose(f);
- }
+ /* Look for SCSI, SATA, USB cdrom */
+ for (deviceletter = '0'; deviceletter <= '9'; deviceletter++) {
+ snprintf(procname, STRING_SIZE, "/sys/block/sr%c/device/model", deviceletter);
- /* Look for SCSI, SATA, USB cdrom */
- for (deviceletter = '0'; deviceletter <= '9'; deviceletter++)
- {
- snprintf(procname, STRING_SIZE, "/sys/block/sr%c/device/model", deviceletter);
+ if ((f = fopen(procname, "r")) == NULL) {
+ continue;
+ }
- if ( (f = fopen(procname, "r")) == NULL )
- {
- continue;
- }
+ if (fgets(model, STRING_SIZE, f)) {
+ char device[4];
- if ( fgets(model, STRING_SIZE, f) )
- {
- char device[4];
+ stripnl(model);
+ sprintf(device, "sr%c", deviceletter);
+ hardwareadd(cdrom, NULL, device, NULL, model, NULL, NULL);
+ }
- stripnl(model);
- sprintf(device, "sr%c", deviceletter);
- hardwareadd(cdrom, NULL, device, NULL, model, NULL, NULL);
+ fclose(f);
}
-
- fclose(f);
- }
}
-// fill in tables with data
+/* fill in tables with data */
void scan_hardware(int flag_i_s, int nopcmcia, int nousb, int noscsi)
{
- discover_bus_map_t *busmap;
- discover_error_t *status;
- discover_device_t *devices;
- char command[STRING_SIZE];
- int i;
- newtComponent form;
- newtComponent text;
- newtComponent scale;
- char line[STRING_SIZE];
- int numBusses;
- int firstscan;
- int addmodules;
+ discover_bus_map_t *busmap;
+ discover_error_t *status;
+ discover_device_t *devices;
+ char command[STRING_SIZE];
+ int i;
+ newtComponent form;
+ newtComponent text;
+ newtComponent scale;
+ char line[STRING_SIZE];
+ int numBusses;
+ int firstscan;
+ int addmodules;
- numhardwares = 0;
- numharddisk = 0;
- numcdrom = 0;
- numnetwork = 0;
- status = discover_error_new();
+ numhardwares = 0;
+ numharddisk = 0;
+ numcdrom = 0;
+ numnetwork = 0;
+ status = discover_error_new();
- install_setup = flag_i_s;
- if ( install_setup )
- {
- /* also write HW detection to file, for easier reference */
- fhwdetect = fopen("/tmp/hwdetect", "w");
- }
+ install_setup = flag_i_s;
+ if (install_setup) {
+ /* also write HW detection to file, for easier reference */
+ fhwdetect = fopen("/tmp/hwdetect", "w");
+ }
- numBusses = BUS_COUNT;
- /* disable stuff the user does not want or does not need */
- if ( !install_setup )
- {
- busmap = discover_conf_get_bus_map_by_name("ata", status);
- busmap->scan_never = 1;
- numBusses--;
- }
- if ( nopcmcia )
- {
- busmap = discover_conf_get_bus_map_by_name("pcmcia", status);
- busmap->scan_never = 1;
- numBusses--;
- }
- if ( nousb )
- {
- busmap = discover_conf_get_bus_map_by_name("usb", status);
- busmap->scan_never = 1;
- numBusses--;
- }
- if ( noscsi || !install_setup )
- {
- busmap = discover_conf_get_bus_map_by_name("scsi", status);
- busmap->scan_never = 1;
- numBusses--;
- }
+ numBusses = BUS_COUNT;
+ /* disable stuff the user does not want or does not need */
+ if (!install_setup) {
+ busmap = discover_conf_get_bus_map_by_name("ata", status);
+ busmap->scan_never = 1;
+ numBusses--;
+ }
+ if (nopcmcia) {
+ busmap = discover_conf_get_bus_map_by_name("pcmcia", status);
+ busmap->scan_never = 1;
+ numBusses--;
+ }
+ if (nousb) {
+ busmap = discover_conf_get_bus_map_by_name("usb", status);
+ busmap->scan_never = 1;
+ numBusses--;
+ }
+ if (noscsi || !install_setup) {
+ busmap = discover_conf_get_bus_map_by_name("scsi", status);
+ busmap->scan_never = 1;
+ numBusses--;
+ }
- snprintf(line, STRING_SIZE, ipcop_gettext("TR_PROBING_HARDWARE"), "");
- text = newtLabel(1, 1, line);
- scale = newtScale(1, 3, 70, numBusses*10);
- newtCenteredWindow(72, 5, ipcop_gettext("TR_TITLE_HARDWARE"));
- form = newtForm(NULL, NULL, 0);
- newtFormAddComponents(form, text, scale, NULL);
+ snprintf(line, STRING_SIZE, ipcop_gettext("TR_PROBING_HARDWARE"), "");
+ text = newtLabel(1, 1, line);
+ scale = newtScale(1, 3, 70, numBusses * 10);
+ newtCenteredWindow(72, 5, ipcop_gettext("TR_TITLE_HARDWARE"));
+ form = newtForm(NULL, NULL, 0);
+ newtFormAddComponents(form, text, scale, NULL);
- newtDrawForm(form);
- newtRefresh();
-
- /* start bus scan */
- busmap = discover_conf_get_full_bus_map(status);
- for (i = 0; busmap[i].name; i++)
- {
- snprintf(line, STRING_SIZE, ipcop_gettext("TR_PROBING_HARDWARE"), busmap[i].name);
- strcat(line, " ");
- newtLabelSetText(text, line);
+ newtDrawForm(form);
newtRefresh();
- if ( busmap[i].scan_never )
- {
- fprintf(flog, "Noscan %s\n", busmap[i].name);
- if ( install_setup )
- {
- fprintf(fhwdetect, "Noscan %s\n", busmap[i].name);
- }
- newtScaleSet(scale, (i+1)*10);
- newtRefresh();
- continue;
- }
+ /* start bus scan */
+ busmap = discover_conf_get_full_bus_map(status);
+ for (i = 0; busmap[i].name; i++) {
+ snprintf(line, STRING_SIZE, ipcop_gettext("TR_PROBING_HARDWARE"), busmap[i].name);
+ strcat(line, " ");
+ newtLabelSetText(text, line);
+ newtRefresh();
- /* not really necessary, but with our nice screen the user probably won't mind waiting an extra second */
- sleep(1);
+ if (busmap[i].scan_never) {
+ fprintf(flog, "Noscan %s\n", busmap[i].name);
+ if (install_setup) {
+ fprintf(fhwdetect, "Noscan %s\n", busmap[i].name);
+ }
+ newtScaleSet(scale, (i + 1) * 10);
+ newtRefresh();
+ continue;
+ }
- fprintf(flog, "Scan %s\n", busmap[i].name);
- if ( install_setup )
- {
- fprintf(fhwdetect, "Scan %s\n", busmap[i].name);
- }
- devices = discover_get_devices(i, status);
+ /* not really necessary, but with our nice screen the user probably won't mind waiting an extra second */
+ sleep(1);
- newtScaleSet(scale, i*10+1);
- newtRefresh();
+ fprintf(flog, "Scan %s\n", busmap[i].name);
+ if (install_setup) {
+ fprintf(fhwdetect, "Scan %s\n", busmap[i].name);
+ }
+ devices = discover_get_devices(i, status);
- /* walk list of devices */
- for (; devices; devices = discover_device_get_next(devices))
- {
- char *busclass;
- char *module;
- char *description;
- supported_media_t type = none;
+ newtScaleSet(scale, i * 10 + 1);
+ newtRefresh();
- if ( (busclass = discover_device_get_busclass(devices)) == NULL )
- continue;
-
- module = discover_device_get_data(devices, "linux/module/name", KERNEL_VERSION, status);
- description = discover_device_get_model_name(devices);
+ /* walk list of devices */
+ for (; devices; devices = discover_device_get_next(devices)) {
+ char *busclass;
+ char *module;
+ char *description;
+ supported_media_t type = none;
- /*
- Busclass found, now go hunt for NIC, mass storage and PCMCIA/Cardbus.
- We'll leave out some special hardware.
- */
- if ( !strcmp(busclass, "0200") || /* Ethernet */
- !strcmp(busclass, "0201") || /* Token Ring */
+ if ((busclass = discover_device_get_busclass(devices)) == NULL)
+ continue;
+
+ module = discover_device_get_data(devices, "linux/module/name", KERNEL_VERSION, status);
+ description = discover_device_get_model_name(devices);
+
+ /*
+ Busclass found, now go hunt for NIC, mass storage and PCMCIA/Cardbus.
+ We'll leave out some special hardware.
+ */
+ if (!strcmp(busclass, "0200") || /* Ethernet */
+ !strcmp(busclass, "0201") || /* Token Ring */
// !strcmp(busclass, "0202") || /* FDDI */
// !strcmp(busclass, "0203") || /* ATM */
- !strcmp(busclass, "0280") /* Other */
- )
- {
- type = network;
- }
- else if ( !strcmp(busclass, "0680") )
- {
- /* onboard forcedeth seems to identify as 0680 instead of 0200 */
- if ( module && !strcmp(module, "forcedeth") )
- {
- type = network;
- }
- }
- else if ( install_setup && (
- ( !strcmp(busclass, "0100") && !noscsi ) || /* SCSI controller */
- !strcmp(busclass, "0101") || /* IDE controller */
+ !strcmp(busclass, "0280") /* Other */
+ ) {
+ type = network;
+ }
+ else if (!strcmp(busclass, "0680")) {
+ /* onboard forcedeth seems to identify as 0680 instead of 0200 */
+ if (module && !strcmp(module, "forcedeth")) {
+ type = network;
+ }
+ }
+ else if (install_setup && ((!strcmp(busclass, "0100") && !noscsi) || /* SCSI controller */
+ !strcmp(busclass, "0101") || /* IDE controller */
// !strcmp(busclass, "0102") || /* Floppy controller */
// !strcmp(busclass, "0103") || /* IPI controller (anyone using this ?) */
- !strcmp(busclass, "0104") || /* RAID controller */
- !strcmp(busclass, "0180") /* Other mass storage controller */
- ) )
- {
- type = specialmodule;
- }
- else if ( install_setup && (
- ( !strcmp(busclass, "0605") && !nopcmcia) || /* PCMCIA bridge */
- ( !strcmp(busclass, "0607") && !nopcmcia) /* Cardbus bridge */
- ) )
- {
- type = specialmodule;
- }
- else if ( install_setup && (
- ( !strcmp(busclass, "0c03") && !nousb) /* USB controller */
- ) )
- {
- type = specialmodule;
- /* in some cases the modulename is empty ? */
- }
+ !strcmp(busclass, "0104") || /* RAID controller */
+ !strcmp(busclass, "0180") /* Other mass storage controller */
+ )) {
+ type = specialmodule;
+ }
+ else if (install_setup && ((!strcmp(busclass, "0605") && !nopcmcia) || /* PCMCIA bridge */
+ (!strcmp(busclass, "0607") && !nopcmcia) /* Cardbus bridge */
+ )) {
+ type = specialmodule;
+ }
+ else if (install_setup && ((!strcmp(busclass, "0c03") && !nousb) /* USB controller */
+ )) {
+ type = specialmodule;
+ /* in some cases the modulename is empty ? */
+ }
- /*
- If we found something interesting, add to our module list.
- We probably do not really need IDE, SCSI etc. things in here,
- since we will build initrd from lsmod output.
- */
- if ( type == none )
- {
- /* owes: keep logging for now */
- fprintf(flog, " Skip %s %s, %s\n",
- busclass,
- module == NULL ? "---" : module,
- description == NULL ? "---" : description);
- if ( install_setup )
- {
- fprintf(fhwdetect, " Skip %s %s, %s\n",
- busclass,
- module == NULL ? "---" : module,
- description == NULL ? "---" : description);
- }
- }
- else
- {
- if ( (module == NULL) && !strcmp(busmap[i].name, "pci") )
- {
- /* This is a totally impossible hack, maybe the future will bring something better or different.
- Anyway, if discover found a PCI device without naming a module, go hunting in pcimap.
- */
- FILE *p;
+ /*
+ If we found something interesting, add to our module list.
+ We probably do not really need IDE, SCSI etc. things in here,
+ since we will build initrd from lsmod output.
+ */
+ if (type == none) {
+ /* owes: keep logging for now */
+ fprintf(flog, " Skip %s %s, %s\n",
+ busclass, module == NULL ? "---" : module, description == NULL ? "---" : description);
+ if (install_setup) {
+ fprintf(fhwdetect, " Skip %s %s, %s\n",
+ busclass, module == NULL ? "---" : module, description == NULL ? "---" : description);
+ }
+ }
+ else {
+ if ((module == NULL) && !strcmp(busmap[i].name, "pci")) {
+ /* This is a totally impossible hack, maybe the future will bring something better or different.
+ Anyway, if discover found a PCI device without naming a module, go hunting in pcimap.
+ */
+ FILE *p;
- snprintf(command, STRING_SIZE, "/bin/grep \"%s 0x0000%s\" /lib/modules/"KERNEL_VERSION"/modules.pcimap",
- discover_device_get_vendor_id(devices),
- discover_device_get_model_id(devices));
+ snprintf(command, STRING_SIZE,
+ "/bin/grep \"%s 0x0000%s\" /lib/modules/" KERNEL_VERSION "/modules.pcimap",
+ discover_device_get_vendor_id(devices), discover_device_get_model_id(devices));
- if ( install_setup )
- {
- fprintf(fhwdetect, "*****\n%s\n", command);
- }
+ if (install_setup) {
+ fprintf(fhwdetect, "*****\n%s\n", command);
+ }
- p = popen(command, "r");
- if ( fgets(line, STRING_SIZE, p) )
- {
- if ( install_setup )
- {
- fprintf(fhwdetect, "%s\n", line);
+ p = popen(command, "r");
+ if (fgets(line, STRING_SIZE, p)) {
+ if (install_setup) {
+ fprintf(fhwdetect, "%s\n", line);
+ }
+ if ((module = strchr(line, ' ')) != NULL) {
+ *module = 0;
+ module = line;
+ }
+ }
+ pclose(p);
+ if (install_setup) {
+ fprintf(fhwdetect, "%s\n*****\n", module == NULL ? "still unknown" : module);
+ }
+ }
+
+ fprintf(flog, " Add %s %s, %s\n",
+ busclass, module == NULL ? "---" : module, description == NULL ? "---" : description);
+ if (install_setup) {
+ fprintf(fhwdetect, " Add %s %s, %s\n",
+ busclass, module == NULL ? "---" : module, description == NULL ? "---" : description);
+ }
+ hardwareadd(type, module, NULL, discover_device_get_vendor_name(devices), description,
+ discover_device_get_vendor_id(devices), discover_device_get_model_id(devices));
}
- if ( (module = strchr(line, ' ')) != NULL )
- {
- *module = 0;
- module = line;
- }
- }
- pclose(p);
- if ( install_setup )
- {
- fprintf(fhwdetect, "%s\n*****\n", module == NULL ? "still unknown" : module);
- }
- }
- fprintf(flog, " Add %s %s, %s\n",
- busclass,
- module == NULL ? "---" : module,
- description == NULL ? "---" : description);
- if ( install_setup )
- {
- fprintf(fhwdetect, " Add %s %s, %s\n",
- busclass,
- module == NULL ? "---" : module,
- description == NULL ? "---" : description);
- }
- hardwareadd(type, module, NULL, discover_device_get_vendor_name(devices), description, discover_device_get_vendor_id(devices), discover_device_get_model_id(devices));
- }
+ /* Some special handling for special devices */
+ if (install_setup && (type == specialmodule)) {
+ if (module != NULL) {
+ snprintf(command, STRING_SIZE, "/sbin/modprobe %s", module);
+ mysystem(command);
+ }
- /*
- Some special handling for special devices
- */
- if ( install_setup && (type == specialmodule) )
- {
- if ( module != NULL )
- {
- snprintf(command, STRING_SIZE, "/sbin/modprobe %s", module);
- mysystem(command);
- }
+ /* SCSI, add some modules */
+ if (!strcmp(busclass, "0100")) {
+ snprintf(command, STRING_SIZE, "/sbin/modprobe %s", "sd_mod");
+ mysystem(command);
+ hardwareadd(specialmodule, "sd_mod", NULL, NULL, NULL, NULL, NULL);
- /* SCSI, add some modules */
- if ( !strcmp(busclass, "0100") )
- {
- snprintf(command, STRING_SIZE, "/sbin/modprobe %s", "sd_mod");
- mysystem(command);
- hardwareadd(specialmodule, "sd_mod", NULL, NULL, NULL, NULL, NULL);
+ snprintf(command, STRING_SIZE, "/sbin/modprobe %s", "sr_mod");
+ mysystem(command);
+ /* no need to put in hardware list */
+ }
- snprintf(command, STRING_SIZE, "/sbin/modprobe %s", "sr_mod");
- mysystem(command);
- /* no need to put in hardware list */
- }
+ /* IDE, add some modules */
+ if (!strcmp(busclass, "0101") && !have_idedisk) {
+ have_idedisk = 1;
+ snprintf(command, STRING_SIZE, "/sbin/modprobe %s", "ide-generic");
+ mysystem(command);
+ hardwareadd(specialmodule, "ide-generic", NULL, NULL, NULL, NULL, NULL);
+ snprintf(command, STRING_SIZE, "/sbin/modprobe %s", "ide-disk");
+ mysystem(command);
+ hardwareadd(specialmodule, "ide-disk", NULL, NULL, NULL, NULL, NULL);
+ }
- /* IDE, add some modules */
- if ( !strcmp(busclass, "0101") && !have_idedisk )
- {
- have_idedisk = 1;
- snprintf(command, STRING_SIZE, "/sbin/modprobe %s", "ide-generic");
- mysystem(command);
- hardwareadd(specialmodule, "ide-generic", NULL, NULL, NULL, NULL, NULL);
- snprintf(command, STRING_SIZE, "/sbin/modprobe %s", "ide-disk");
- mysystem(command);
- hardwareadd(specialmodule, "ide-disk", NULL, NULL, NULL, NULL, NULL);
+ /* USB, probe */
+ if (!strcmp(busclass, "0c03")) {
+ /*
+ Dependancies will load sd_mod, but sd_mod will not be in initramfs .
+ Not sure if installing onto USB stick is a good idea though.
+ */
+ snprintf(command, STRING_SIZE, "/sbin/modprobe %s", "sd_mod");
+ mysystem(command);
+ hardwareadd(specialmodule, "sd_mod", NULL, NULL, NULL, NULL, NULL);
+ snprintf(command, STRING_SIZE, "/sbin/modprobe %s", "usb-storage");
+ mysystem(command);
+ hardwareadd(specialmodule, "usb-storage", NULL, NULL, NULL, NULL, NULL);
+ }
+ }
}
- /* USB, probe */
- if ( !strcmp(busclass, "0c03") )
- {
- /*
- Dependancies will load sd_mod, but sd_mod will not be in initramfs .
- Not sure if installing onto USB stick is a good idea though.
- */
- snprintf(command, STRING_SIZE, "/sbin/modprobe %s", "sd_mod");
- mysystem(command);
- hardwareadd(specialmodule, "sd_mod", NULL, NULL, NULL, NULL, NULL);
- snprintf(command, STRING_SIZE, "/sbin/modprobe %s", "usb-storage");
- mysystem(command);
- hardwareadd(specialmodule, "usb-storage", NULL, NULL, NULL, NULL, NULL);
- }
- }
+ /* not really necessary, but with our nice screen the user probably won't mind waiting a bit */
+ sleep(1);
+ newtScaleSet(scale, (i + 1) * 10);
+ newtRefresh();
}
- /* not really necessary, but with our nice screen the user probably won't mind waiting a bit */
- sleep(1);
- newtScaleSet(scale, (i+1)*10);
- newtRefresh();
- }
+ discover_error_free(status);
+ newtFormDestroy(form);
+ newtPopWindow();
- discover_error_free(status);
- newtFormDestroy(form);
- newtPopWindow();
+ /* testing (not for NIC detection), eventually we may need some function like this */
+ addmodules = 1;
+ while (install_setup && addmodules) {
+ newtComponent button_done, button_add;
+ newtComponent module, moduleentry;
+ struct newtExitStruct exitstruct;
+ const char *modulename;
+ int numLines;
- /* testing (not for NIC detection), eventually we may need some function like this */
- addmodules = 1;
- while ( install_setup && addmodules )
- {
- newtComponent button_done, button_add;
- newtComponent module, moduleentry;
- struct newtExitStruct exitstruct;
- const char *modulename;
- int numLines;
+ text = newtTextboxReflowed(1, 1, "TESTTESTTEST. Add a specific module.", 68, 0, 0, 0);
+ numLines = newtTextboxGetNumLines(text);
+ newtCenteredWindow(72, numLines + 10, ipcop_gettext("TR_TITLE_HARDWARE"));
+ form = newtForm(NULL, NULL, 0);
+ newtFormAddComponent(form, text);
- text = newtTextboxReflowed(1, 1, "TESTTESTTEST. Add a specific module.", 68, 0, 0, 0);
- numLines = newtTextboxGetNumLines(text);
- newtCenteredWindow(72, numLines + 10, ipcop_gettext("TR_TITLE_HARDWARE"));
- form = newtForm(NULL, NULL, 0);
- newtFormAddComponent(form, text);
+ module = newtTextbox(2, numLines + 2, 25, 1, 0);
+ newtTextboxSetText(module, "Module (without .ko):");
+ newtFormAddComponent(form, module);
+ moduleentry = newtEntry(12, numLines + 3, "", 20, &modulename, 0);
+ newtFormAddComponent(form, moduleentry);
- module = newtTextbox(2, numLines + 2, 25, 1, 0);
- newtTextboxSetText(module, "Module (without .ko):");
- newtFormAddComponent(form, module);
- moduleentry = newtEntry(12, numLines + 3, "", 20, &modulename, 0);
- newtFormAddComponent(form, moduleentry);
+ button_add = newtButton(6, numLines + 5, "Add");
+ button_done = newtButton(26, numLines + 5, ipcop_gettext("TR_OK"));
+ newtFormAddComponents(form, button_add, button_done, NULL);
- button_add = newtButton(6, numLines + 5, "Add");
- button_done = newtButton(26, numLines + 5, ipcop_gettext("TR_OK"));
- newtFormAddComponents(form, button_add, button_done, NULL);
+ newtRefresh();
+ newtDrawForm(form);
+ newtFormRun(form, &exitstruct);
- newtRefresh();
- newtDrawForm(form);
- newtFormRun(form, &exitstruct);
+ if (exitstruct.u.co == button_add) {
+ snprintf(command, STRING_SIZE, "/sbin/modprobe %s", modulename);
+ if (!mysystem(command)) {
+ hardwareadd(specialmodule, (char *) modulename, NULL, NULL, NULL, NULL, NULL);
+ }
+ else {
+ /* owes: show errorbox here */
+ }
+ }
- if ( exitstruct.u.co == button_add )
- {
- snprintf(command, STRING_SIZE, "/sbin/modprobe %s", modulename);
- if ( !mysystem(command) )
- {
- hardwareadd(specialmodule, (char *)modulename, NULL, NULL, NULL, NULL, NULL);
- }
- else
- {
- /* owes: show errorbox here */
- }
- }
+ newtFormDestroy(form);
+ newtPopWindow();
- newtFormDestroy(form);
- newtPopWindow();
-
- if ( exitstruct.u.co == button_done )
- {
- addmodules = 0;
+ if (exitstruct.u.co == button_done) {
+ addmodules = 0;
+ }
}
- }
- firstscan = TRUE;
- while ( install_setup && (numharddisk == 0) )
- {
- if ( install_setup )
- {
- fflush(fhwdetect);
- }
- statuswindow(72, 5, ipcop_gettext("TR_TITLE_HARDWARE"), ipcop_gettext("TR_PROBING_HARDWARE"), "drives");
+ firstscan = TRUE;
+ while (install_setup && (numharddisk == 0)) {
+ if (install_setup) {
+ fflush(fhwdetect);
+ }
+ statuswindow(72, 5, ipcop_gettext("TR_TITLE_HARDWARE"), ipcop_gettext("TR_PROBING_HARDWARE"), "drives");
- if ( !firstscan )
- {
- /* since we've not yet waited since last modprobe, sleep now */
- sleep(2);
- }
- firstscan = FALSE;
+ if (!firstscan) {
+ /* since we've not yet waited since last modprobe, sleep now */
+ sleep(2);
+ }
+ firstscan = FALSE;
- /* go hunting for drives */
- fprintf(flog, "Scan for drives\n");
- if ( install_setup )
- {
- fprintf(fhwdetect, "Scan for drives\n");
- }
- scanprocdrives(1);
+ /* go hunting for drives */
+ fprintf(flog, "Scan for drives\n");
+ if (install_setup) {
+ fprintf(fhwdetect, "Scan for drives\n");
+ }
+ scanprocdrives(1);
- newtPopWindow();
+ newtPopWindow();
- if ( numharddisk == 0 )
- {
- newtComponent button_rescan, button_modprobe, button_cancel;
- newtComponent module, moduleentry;
- struct newtExitStruct exitstruct;
- const char *modulename;
- int numLines;
+ if (numharddisk == 0) {
+ newtComponent button_rescan, button_modprobe, button_cancel;
+ newtComponent module, moduleentry;
+ struct newtExitStruct exitstruct;
+ const char *modulename;
+ int numLines;
- text = newtTextboxReflowed(1, 1, ipcop_gettext("TR_NO_HARDDISK_MODPROBE"), 68, 0, 0, 0);
- numLines = newtTextboxGetNumLines(text);
- newtCenteredWindow(72, numLines + 9, ipcop_gettext("TR_TITLE_HARDWARE"));
- form = newtForm(NULL, NULL, 0);
- newtFormAddComponent(form, text);
+ text = newtTextboxReflowed(1, 1, ipcop_gettext("TR_NO_HARDDISK_MODPROBE"), 68, 0, 0, 0);
+ numLines = newtTextboxGetNumLines(text);
+ newtCenteredWindow(72, numLines + 9, ipcop_gettext("TR_TITLE_HARDWARE"));
+ form = newtForm(NULL, NULL, 0);
+ newtFormAddComponent(form, text);
- module = newtTextbox(2, numLines + 2, 10, 1, 0);
- newtTextboxSetText(module, "Module:");
- newtFormAddComponent(form, module);
- moduleentry = newtEntry(12, numLines + 2, "", 20, &modulename, 0);
- newtFormAddComponent(form, moduleentry);
+ module = newtTextbox(2, numLines + 2, 10, 1, 0);
+ newtTextboxSetText(module, "Module:");
+ newtFormAddComponent(form, module);
+ moduleentry = newtEntry(12, numLines + 2, "", 20, &modulename, 0);
+ newtFormAddComponent(form, moduleentry);
- button_rescan = newtButton(6, numLines + 4, ipcop_gettext("TR_RESCAN"));
- button_modprobe = newtButton(26, numLines + 4, "Modprobe");
- button_cancel = newtButton(46, numLines + 4, ipcop_gettext("TR_CANCEL"));
- newtFormAddComponents(form, button_rescan, button_modprobe, button_cancel, NULL);
+ button_rescan = newtButton(6, numLines + 4, ipcop_gettext("TR_RESCAN"));
+ button_modprobe = newtButton(26, numLines + 4, "Modprobe");
+ button_cancel = newtButton(46, numLines + 4, ipcop_gettext("TR_CANCEL"));
+ newtFormAddComponents(form, button_rescan, button_modprobe, button_cancel, NULL);
- newtRefresh();
- newtDrawForm(form);
- newtFormRun(form, &exitstruct);
+ newtRefresh();
+ newtDrawForm(form);
+ newtFormRun(form, &exitstruct);
- if ( exitstruct.u.co == button_modprobe )
- {
- snprintf(command, STRING_SIZE, "/sbin/modprobe %s", modulename);
- if ( !mysystem(command) )
- {
- hardwareadd(specialmodule, (char *)modulename, NULL, NULL, NULL, NULL, NULL);
- }
- else
- {
- /* owes: show errorbox here */
- }
- }
+ if (exitstruct.u.co == button_modprobe) {
+ snprintf(command, STRING_SIZE, "/sbin/modprobe %s", modulename);
+ if (!mysystem(command)) {
+ hardwareadd(specialmodule, (char *) modulename, NULL, NULL, NULL, NULL, NULL);
+ }
+ else {
+ /* owes: show errorbox here */
+ }
+ }
- newtFormDestroy(form);
- newtPopWindow();
+ newtFormDestroy(form);
+ newtPopWindow();
- if ( exitstruct.u.co == button_cancel )
- {
- return;
- }
+ if (exitstruct.u.co == button_cancel) {
+ return;
+ }
+ }
}
- }
- fprintf(flog, "Scan complete. Hardware %d, Harddisk %d, CDROM %d, Network %d\n", numhardwares, numharddisk, numcdrom, numnetwork);
- if ( install_setup )
- {
- fprintf(fhwdetect, "Scan complete. Hardware %d, Harddisk %d, CDROM %d, Network %d\n", numhardwares, numharddisk, numcdrom, numnetwork);
- fclose(fhwdetect);
- }
+ fprintf(flog, "Scan complete. Hardware %d, Harddisk %d, CDROM %d, Network %d\n", numhardwares, numharddisk,
+ numcdrom, numnetwork);
+ if (install_setup) {
+ fprintf(fhwdetect, "Scan complete. Hardware %d, Harddisk %d, CDROM %d, Network %d\n", numhardwares, numharddisk,
+ numcdrom, numnetwork);
+ fclose(fhwdetect);
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|