From adb289a23d9cec1ed29877d58614e33246fe20ba Mon Sep 17 00:00:00 2001 From: Guillaume Cottenceau Date: Sat, 6 Jan 2001 23:29:29 +0000 Subject: uglyfy my shiny modules-loading code to save some stuff in /etc/modules.conf (scsi, net, modules options) --- mdk-stage1/cdrom.c | 4 +-- mdk-stage1/disk.c | 2 +- mdk-stage1/modules.c | 95 +++++++++++++++++++++++++++++++++++++++++++++------- mdk-stage1/modules.h | 2 +- mdk-stage1/mount.c | 8 ++--- mdk-stage1/network.c | 2 +- mdk-stage1/probing.c | 14 ++++---- mdk-stage1/probing.h | 2 +- 8 files changed, 100 insertions(+), 29 deletions(-) diff --git a/mdk-stage1/cdrom.c b/mdk-stage1/cdrom.c index 99fd4b7d1..d5f8aafa3 100644 --- a/mdk-stage1/cdrom.c +++ b/mdk-stage1/cdrom.c @@ -79,8 +79,8 @@ enum return_type cdrom_prepare(void) int i, count = 0; enum return_type results; - my_insmod("ide-cd"); - my_insmod("sr_mod"); + my_insmod("ide-cd", ANY_DRIVER_TYPE, NULL); + my_insmod("sr_mod", ANY_DRIVER_TYPE, NULL); get_medias(CDROM, &medias, &medias_models); diff --git a/mdk-stage1/disk.c b/mdk-stage1/disk.c index 05501f2d3..ea4161653 100644 --- a/mdk-stage1/disk.c +++ b/mdk-stage1/disk.c @@ -133,7 +133,7 @@ enum return_type disk_prepare(void) int i, count = 0; enum return_type results; - my_insmod("sd_mod"); + my_insmod("sd_mod", ANY_DRIVER_TYPE, NULL); get_medias(DISK, &medias, &medias_models); diff --git a/mdk-stage1/modules.c b/mdk-stage1/modules.c index 76d364d76..5e3d26ee9 100644 --- a/mdk-stage1/modules.c +++ b/mdk-stage1/modules.c @@ -49,7 +49,7 @@ static int ensure_archive_opened(void) /* unarchive and insmod given module * WARNING: module must not contain the trailing ".o" */ -static int insmod_archived_file(const char * mod_name, char * params) +static int insmod_archived_file(const char * mod_name, char * options) { char module_name[50]; char final_name[50] = "/tmp/"; @@ -71,7 +71,7 @@ static int insmod_archived_file(const char * mod_name, char * params) strcat(final_name, mod_name); strcat(final_name, ".o"); - rc = insmod_call(final_name, params); + rc = insmod_call(final_name, options); if (rc) log_message("\tfailed."); unlink(final_name); /* sucking no space left on device */ @@ -167,7 +167,33 @@ int load_modules_dependencies(void) } -static int insmod_with_deps(const char * mod_name) +static void add_modules_conf(char * str) +{ + static char data[500] = ""; + char * target = "/etc/modules.conf"; + int fd; + + if (strlen(data) + strlen(str) >= sizeof(data)) + return; + + strcat(data, str); + strcat(data, "\n"); + + fd = open(target, O_CREAT|O_WRONLY|O_TRUNC, 00660); + + if (fd == -1) { + log_perror(str); + return; + } + + if (write(fd, data, strlen(data) + 1) != strlen(data) + 1) + log_perror(str); + + close(fd); +} + + +static int insmod_with_deps(const char * mod_name, char * options) { struct module_deps_elem * dep; @@ -180,46 +206,91 @@ static int insmod_with_deps(const char * mod_name) while (*one_dep) { /* here, we can fail but we don't care, if the error is * important, the desired module will fail also */ - insmod_with_deps(*one_dep); + insmod_with_deps(*one_dep, NULL); one_dep++; } } log_message("needs %s", mod_name); - return insmod_archived_file(mod_name, NULL); + return insmod_archived_file(mod_name, options); } -int my_insmod(const char * mod_name) +int my_insmod(const char * mod_name, enum driver_type type, char * options) { + char alias[500]; int i; +#ifndef DISABLE_MEDIAS + static int number_scsi = 0; +#endif +#ifndef DISABLE_NETWORK + char ** net_devices = NULL; /* fucking compiler */ + if (type == NETWORK_DEVICES) + net_devices = get_net_devices(); +#endif log_message("have to insmod %s", mod_name); if (IS_TESTING) return 0; - i = insmod_with_deps(mod_name); - if (i == 0) + i = insmod_with_deps(mod_name, options); + if (i == 0) { log_message("\tsucceeded %s.", mod_name); +#ifndef DISABLE_MEDIAS + if (type == SCSI_ADAPTERS) { + if (number_scsi > 0) + sprintf(alias, "alias scsi_hostadapter%d %s", number_scsi, mod_name); + else + sprintf(alias, "alias scsi_hostadapter %s", mod_name); + number_scsi++; + add_modules_conf(alias); + } +#endif +#ifndef DISABLE_NETWORK + if (type == NETWORK_DEVICES) { + char ** new_net_devices = get_net_devices(); + while (new_net_devices && *new_net_devices) { + char ** ptr = net_devices; + while (ptr && *ptr) { + if (!strcmp(*new_net_devices, *ptr)) + goto already_present; + ptr++; + } + sprintf(alias, "alias %s %s", *new_net_devices, mod_name); + add_modules_conf(alias); + log_message("NET: %s", alias); + already_present: + new_net_devices++; + } + } +#endif + } return i; } -enum return_type insmod_with_params(char * mod) +static enum return_type insmod_with_options(char * mod, enum driver_type type) { char * questions[] = { "Options", NULL }; char ** answers; enum return_type results; + char options[500] = "options "; results = ask_from_entries("Please enter the parameters to give to the kernel:", questions, &answers, 24); if (results != RETURN_OK) return results; - if (insmod_archived_file(mod, answers[0])) { + strcat(options, mod); + strcat(options, " "); + strcat(options, answers[0]); // because my_insmod will eventually modify the string + + if (my_insmod(mod, type, answers[0])) { error_message("Insmod failed."); return RETURN_ERROR; } + add_modules_conf(options); + return RETURN_OK; } @@ -248,13 +319,13 @@ enum return_type ask_insmod(enum driver_type type) if (results == RETURN_OK) { choice[strlen(choice)-2] = '\0'; /* remove trailing .o */ - if (my_insmod(choice)) { + if (my_insmod(choice, type, NULL)) { enum return_type results; unset_param(MODE_AUTOMATIC); /* we are in a fallback mode */ results = ask_yes_no("Insmod failed.\nTry with parameters?"); if (results == RETURN_OK) - return insmod_with_params(choice); + return insmod_with_options(choice, type); return RETURN_ERROR; } else return RETURN_OK; diff --git a/mdk-stage1/modules.h b/mdk-stage1/modules.h index 29914f5fc..db90d832d 100644 --- a/mdk-stage1/modules.h +++ b/mdk-stage1/modules.h @@ -19,7 +19,7 @@ #include "probing.h" int load_modules_dependencies(void); -int my_insmod(const char * mod_name); +int my_insmod(const char * mod_name, enum driver_type type, char * options); enum return_type ask_insmod(enum driver_type); diff --git a/mdk-stage1/mount.c b/mdk-stage1/mount.c index 93500a34f..7ee55832f 100644 --- a/mdk-stage1/mount.c +++ b/mdk-stage1/mount.c @@ -139,16 +139,16 @@ int my_mount(char *dev, char *location, char *fs) #ifndef DISABLE_MEDIAS if (!strcmp(fs, "vfat")) { - my_insmod("vfat"); + my_insmod("vfat", ANY_DRIVER_TYPE, NULL); opts = "check=relaxed"; } if (!strcmp(fs, "reiserfs")) { - my_insmod("reiserfs"); + my_insmod("reiserfs", ANY_DRIVER_TYPE, NULL); } if (!strcmp(fs, "iso9660")) { - my_insmod("isofs"); + my_insmod("isofs", ANY_DRIVER_TYPE, NULL); flags |= MS_RDONLY; } #endif @@ -157,7 +157,7 @@ int my_mount(char *dev, char *location, char *fs) if (!strcmp(fs, "nfs")) { int flags = 0; - my_insmod("nfs"); + my_insmod("nfs", ANY_DRIVER_TYPE, NULL); flags |= MS_RDONLY; log_message("preparing nfsmount for %s", dev); diff --git a/mdk-stage1/network.c b/mdk-stage1/network.c index 2e0870a43..92f832e26 100644 --- a/mdk-stage1/network.c +++ b/mdk-stage1/network.c @@ -396,7 +396,7 @@ static enum return_type bringup_networking(struct interface_info * intf) static struct interface_info loopback; enum { BRINGUP_NET, BRINGUP_CONF, BRINGUP_DONE } step = BRINGUP_NET; - my_insmod("af_packet"); + my_insmod("af_packet", ANY_DRIVER_TYPE, NULL); // if (intf->is_up == 1) // log_message("interface already up (with IP %s)", inet_ntoa(intf->ip)); diff --git a/mdk-stage1/probing.c b/mdk-stage1/probing.c index fdfc7d097..6e95dc143 100644 --- a/mdk-stage1/probing.c +++ b/mdk-stage1/probing.c @@ -100,7 +100,7 @@ void probe_that_type(enum driver_type type) if (type == SCSI_ADAPTERS) { /* insmod takes time, let's use the wait message */ wait_message("Installing %s", pcidb[i].name); - my_insmod(pcidb[i].module); + my_insmod(pcidb[i].module, SCSI_ADAPTERS, NULL); remove_wait_message(); } #endif @@ -108,7 +108,7 @@ void probe_that_type(enum driver_type type) if (type == NETWORK_DEVICES) { /* insmod is quick, let's use the info message */ info_message("Found %s", pcidb[i].name); - my_insmod(pcidb[i].module); + my_insmod(pcidb[i].module, NETWORK_DEVICES, NULL); } #endif } @@ -376,6 +376,7 @@ int net_device_available(char * device) { close(s); return 0; } + close(s); return 1; } @@ -394,15 +395,14 @@ char ** get_net_devices(void) int i = 0; static int already_probed = 0; - if (!already_probed) + if (!already_probed) { + already_probed = 1; /* cut off loop brought by: probe_that_type => my_insmod => get_net_devices */ probe_that_type(NETWORK_DEVICES); - already_probed = 1; + } while (ptr && *ptr) { - if (net_device_available(*ptr)) { - log_message("NET: %s is available", *ptr); + if (net_device_available(*ptr)) tmp[i++] = strdup(*ptr); - } ptr++; } tmp[i++] = NULL; diff --git a/mdk-stage1/probing.h b/mdk-stage1/probing.h index 98b5a75f1..cb01d4fa6 100644 --- a/mdk-stage1/probing.h +++ b/mdk-stage1/probing.h @@ -35,7 +35,7 @@ struct media_info { enum media_query_type { QUERY_NAME, QUERY_MODEL }; -enum driver_type { SCSI_ADAPTERS, NETWORK_DEVICES }; +enum driver_type { SCSI_ADAPTERS, NETWORK_DEVICES, ANY_DRIVER_TYPE }; void probe_that_type(enum driver_type type); -- cgit v1.2.1