From 890d160fcee9258d6079c64b51a67cccc596cc95 Mon Sep 17 00:00:00 2001 From: Guillaume Cottenceau Date: Mon, 18 Dec 2000 21:16:09 +0000 Subject: add disk install support --- mdk-stage1/disk.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 90 insertions(+), 6 deletions(-) (limited to 'mdk-stage1/disk.c') diff --git a/mdk-stage1/disk.c b/mdk-stage1/disk.c index e539b146a..42943e324 100644 --- a/mdk-stage1/disk.c +++ b/mdk-stage1/disk.c @@ -21,19 +21,108 @@ #include #include +#include +#include +#include #include "stage1.h" #include "frontend.h" #include "modules.h" #include "probing.h" #include "log.h" +#include "mount.h" #include "disk.h" + static enum return_type try_with_device(char *dev_name) { + char * questions_location[] = { "Directory", NULL }; + char ** answers_location; + char device_fullname[50]; + char location_full[50]; + + int major, minor, blocks; + char name[100]; + + char buf[512]; + FILE * f; + char * parts[50]; + char * parts_comments[50]; + int i = 0; + enum return_type results; + char * choice; + + if (!(f = fopen("/proc/partitions", "rb")) || !fgets(buf, sizeof(buf), f) || !fgets(buf, sizeof(buf), f)) { + log_perror(dev_name); + error_message("Could not read partitions information"); + return RETURN_ERROR; + } - /* I have to do the partition check here */ + while (fgets(buf, sizeof(buf), f)) { + sscanf(buf, " %d %d %d %s", &major, &minor, &blocks, name); + if ((strstr(name, dev_name) == name) && (blocks > 1) && (name[strlen(dev_name)] != '\0')) { + parts[i] = strdup(name); + parts_comments[i] = (char *) malloc(sizeof(char) * 25); + snprintf(parts_comments[i], 24, "size: %d blocks", blocks); + i++; + } + } + parts[i] = NULL; + fclose(f); + + results = ask_from_list_comments("Please choose the partition to use for the installation.", parts, parts_comments, &choice); + if (results != RETURN_OK) + return results; + + strcpy(device_fullname, "/dev/"); + strcat(device_fullname, choice); + + if (my_mount(device_fullname, "/tmp/disk", "ext2") == -1 && + my_mount(device_fullname, "/tmp/disk", "vfat") == -1 && + my_mount(device_fullname, "/tmp/disk", "reiserfs") == -1) { + error_message("I can't find a valid filesystem."); + return try_with_device(dev_name); + } + results = ask_from_entries("Please enter the directory containing the Linux-Mandrake installation.", + questions_location, &answers_location, 24); + if (results != RETURN_OK) { + umount("/tmp/disk"); + return try_with_device(dev_name); + } + + strcpy(location_full, "/tmp/disk/"); + strcat(location_full, answers_location[0]); + + if (access(location_full, R_OK)) { + umount("/tmp/disk"); + error_message("Directory could not be found on partition."); + return try_with_device(dev_name); + } + + unlink("/tmp/image"); + symlink(location_full, "/tmp/image"); + + if (access("/tmp/image/Mandrake/mdkinst", R_OK)) { + umount("/tmp/disk"); + unlink("/tmp/image"); + error_message("I can't find the Linux-Mandrake installation in the specified directory."); + return try_with_device(dev_name); + } + + log_message("found the Linux-Mandrake Installation, good news!"); + + if (IS_SPECIAL_STAGE2) { + if (load_ramdisk() != RETURN_OK) { + error_message("Could not load program into memory"); + return try_with_device(dev_name); + } + } + + if (IS_RESCUE) + umount("/tmp/image"); /* TOCHECK */ + + method_name = strdup("disk"); return RETURN_OK; } @@ -44,12 +133,7 @@ enum return_type disk_prepare(void) int i, count = 0; enum return_type results; - error_message("Currently unsupported"); - return RETURN_ERROR; - my_insmod("sd_mod"); - my_insmod("vfat"); - my_insmod("reiserfs"); get_medias(DISK, &medias, &medias_models); -- cgit v1.2.1