diff options
Diffstat (limited to 'mdk-stage1')
-rw-r--r-- | mdk-stage1/thirdparty.c | 188 | ||||
-rw-r--r-- | mdk-stage1/tools.c | 25 | ||||
-rw-r--r-- | mdk-stage1/tools.h | 5 |
3 files changed, 156 insertions, 62 deletions
diff --git a/mdk-stage1/thirdparty.c b/mdk-stage1/thirdparty.c index aaeedde7a..1212ea70c 100644 --- a/mdk-stage1/thirdparty.c +++ b/mdk-stage1/thirdparty.c @@ -28,76 +28,145 @@ #include "thirdparty.h" -static enum return_type third_party_get_device(char ** device) +static enum return_type third_party_choose_device(char ** device, char *mount_location) { char ** medias, ** medias_models; - char * floppy_dev; - enum return_type results; + char ** ptr, ** ptr_models; +#ifndef DISABLE_DISK + char ** disk_medias, ** disk_medias_models; + int disk_count; char * parts[50]; char * parts_comments[50]; - int count; - - wait_message("Looking for floppy and disk devices ..."); - - count = get_disks(&medias, &medias_models); - floppy_dev = floppy_device(); - if (strstr(floppy_dev, "/dev/") == floppy_dev) { - floppy_dev = floppy_dev + 5; - } +#endif +#ifndef DISABLE_CDROM + char ** cdrom_medias, ** cdrom_medias_models; + int cdrom_count; +#endif + char * floppy_dev; + enum return_type results; + int count = 0; + + wait_message("Looking for floppy, disk and cdrom devices ..."); + +#ifndef DISABLE_DISK + disk_count = get_disks(&disk_medias, &disk_medias_models); + count += disk_count; +#endif +#ifndef DISABLE_CDROM + cdrom_count = get_cdroms(&cdrom_medias, &cdrom_medias_models); + count += cdrom_count; +#endif + + floppy_dev = floppy_device(); + if (strstr(floppy_dev, "/dev/") == floppy_dev) { + floppy_dev = floppy_dev + 5; + } - remove_wait_message(); + remove_wait_message(); if (count == 0) { - if (floppy_dev) { - log_message("third party : no DISK drive found, trying with floppy"); - *device = floppy_dev; - return RETURN_OK; - } else { - stg1_error_message("I can't find any floppy or disk on this system. " - "No third-party kernel modules will be used."); - return RETURN_ERROR; - } + if (floppy_dev) { + log_message("third party : no disk or cdrom drive found, trying with floppy"); + *device = floppy_dev; + return RETURN_OK; + } else { + stg1_error_message("I can't find any floppy, disk or cdrom on this system. " + "No third-party kernel modules will be used."); + return RETURN_ERROR; + } } - if (floppy_dev) { - medias = realloc(medias, (count + 2) * sizeof(char *)); - medias[count] = floppy_dev; - medias[count+1] = NULL; - medias_models = realloc(medias_models, (count + 2) * sizeof(char *)); - medias_models[count] = "Floppy device"; - medias_models[count+1] = NULL; - } - - results = ask_from_list_comments("If you want to insert third-party kernel modules, " - "please select the disk containing the modules.", - medias, medias_models, device); - if (results != RETURN_OK) - return results; + if (floppy_dev) + count += 1; + + ptr = medias = malloc((count + 1) * sizeof(char *)); + ptr_models =medias_models = malloc((count + 1) * sizeof(char *)); +#ifndef DISABLE_DISK + memcpy(ptr, disk_medias, disk_count * sizeof(char *)); + memcpy(ptr_models, disk_medias_models, disk_count * sizeof(char *)); + free(disk_medias); + free(disk_medias_models); + ptr += disk_count; + ptr_models += disk_count; +#endif +#ifndef DISABLE_CDROM + memcpy(ptr, cdrom_medias, cdrom_count * sizeof(char *)); + memcpy(ptr_models, cdrom_medias_models, cdrom_count * sizeof(char *)); + free(cdrom_medias); + free(cdrom_medias_models); + cdrom_medias = ptr; /* used later to know if a cdrom is selected */ + ptr += cdrom_count; + ptr_models += cdrom_count; +#endif + if (floppy_dev) { + ptr[0] = floppy_dev; + ptr_models[0] = "Floppy device"; + ptr++; + ptr_models++; + } + ptr[0] = NULL; + ptr_models[0] = NULL; + + results = ask_from_list_comments("If you want to insert third-party kernel modules, " + "please select the disk containing the modules.", + medias, medias_models, device); + if (results != RETURN_OK) + return results; + + /* a floppy is selected, don't try to list partitions */ + if (streq(*device, floppy_dev)) { + if (try_mount(floppy_dev, mount_location) == -1) { + stg1_error_message("I can't mount the selected floppy."); + return RETURN_ERROR; + } + return RETURN_OK; + } - /* floppy is selected, don't try to list partitions */ - if (streq(*device, floppy_dev)) - return RETURN_OK; +#ifndef DISABLE_CDROM + /* a cdrom is selected, mount it as iso9660 */ + if (device >= cdrom_medias) { + char device_fullname[50]; + strcpy(device_fullname, "/dev/"); + strcat(device_fullname, *device); + if (my_mount(device_fullname, mount_location, "iso9660", 0)) { + stg1_error_message("I can't mount the selected cdrom."); + return RETURN_ERROR; + } + return RETURN_OK; + } +#endif - if (list_partitions(*device, parts, parts_comments)) { +#ifndef DISABLE_DISK + /* a disk or usb key is selected */ + if (list_partitions(*device, parts, parts_comments)) { stg1_error_message("Could not read partitions information."); return RETURN_ERROR; - } + } - if (parts[0] == NULL) { - stg1_error_message("No partition found."); - return RETURN_ERROR; - } + if (parts[0] == NULL) { + stg1_error_message("No partition found."); + return RETURN_ERROR; + } - /* only one partition has been discovered, don't ask which one to use */ - if (parts[1] == NULL) { - *device = parts[0]; - return RETURN_OK; + /* only one partition has been discovered, don't ask which one to use */ + if (parts[1] == NULL) { + *device = parts[0]; + return RETURN_OK; } - results = ask_from_list_comments("Please select the partition containing " - "the third party modules.", - parts, parts_comments, device); - return results; + results = ask_from_list_comments("Please select the partition containing " + "the third party modules.", + parts, parts_comments, device); + if (results == RETURN_OK) { + if (try_mount(*device, mount_location) == -1) { + stg1_error_message("I can't mount the selected partition."); + return RETURN_ERROR; + } + return RETURN_OK; + } +#endif + + return results; } void thirdparty_load_modules(void) @@ -111,17 +180,14 @@ void thirdparty_load_modules(void) char * questions[] = { "Options", NULL }; static char ** answers = NULL; - results = third_party_get_device(&choice); - if (results != RETURN_OK) - return; + do { + results = third_party_choose_device(&choice, mount_location); + if (results == RETURN_BACK) + return; + } while (results == RETURN_ERROR); log_message("third party : using device %s", choice); - if (try_mount(choice, mount_location) == -1) { - stg1_error_message("I can't mount the selected partition."); - return thirdparty_load_modules(); - } - modules = list_directory(mount_location); if (!modules || !*modules) { diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c index 042eab53b..d2ace065c 100644 --- a/mdk-stage1/tools.c +++ b/mdk-stage1/tools.c @@ -459,13 +459,14 @@ int try_mount(char * dev, char * location) return 0; } +#ifndef DISABLE_DISK int get_disks(char *** names, char *** models) { char ** ptr; int count = 0; my_insmod("sd_mod", ANY_DRIVER_TYPE, NULL, 0); - + get_medias(DISK, names, models, BUS_ANY); ptr = *names; @@ -476,6 +477,28 @@ int get_disks(char *** names, char *** models) return count; } +#endif + +#ifndef DISABLE_CDROM +int get_cdroms(char *** names, char *** models) +{ + char ** ptr; + int count = 0; + + my_insmod("ide-cd", ANY_DRIVER_TYPE, NULL, 0); + my_insmod("sr_mod", ANY_DRIVER_TYPE, NULL, 0); + + get_medias(CDROM, names, models, BUS_ANY); + + ptr = *names; + while (ptr && *ptr) { + count++; + ptr++; + } + + return count; +} +#endif char * floppy_device(void) { diff --git a/mdk-stage1/tools.h b/mdk-stage1/tools.h index a4aedfea1..b7681a16b 100644 --- a/mdk-stage1/tools.h +++ b/mdk-stage1/tools.h @@ -49,7 +49,12 @@ char ** list_directory(char * direct); int string_array_length(char ** a); int kernel_version(void); int try_mount(char * dev, char * location); +#ifndef DISABLE_DISK int get_disks(char *** names, char *** models); +#endif +#ifndef DISABLE_CDROM +int get_cdroms(char *** names, char *** models); +#endif char * floppy_device(void); char * asprintf_(const char *msg, ...); int scall_(int retval, char * msg, char * file, int line); |