diff options
Diffstat (limited to 'mdk-stage1')
-rw-r--r-- | mdk-stage1/Makefile | 6 | ||||
-rw-r--r-- | mdk-stage1/cdrom.c | 3 | ||||
-rw-r--r-- | mdk-stage1/config-stage1.h | 17 | ||||
-rw-r--r-- | mdk-stage1/directory.c | 76 | ||||
-rw-r--r-- | mdk-stage1/disk.c | 3 | ||||
-rw-r--r-- | mdk-stage1/network.c | 10 | ||||
-rw-r--r-- | mdk-stage1/tools.c | 116 | ||||
-rw-r--r-- | mdk-stage1/tools.h | 9 |
8 files changed, 73 insertions, 167 deletions
diff --git a/mdk-stage1/Makefile b/mdk-stage1/Makefile index 83672a25c..543115741 100644 --- a/mdk-stage1/Makefile +++ b/mdk-stage1/Makefile @@ -111,10 +111,10 @@ STAGE1_NETWORK_LIBS = /usr/$(LIB)/libresolv.a endif #- stage1 itself -STAGE1SRC = stage1.c log.c tools.c modules.c probing.c mount.c automatic.c frontend-common.c +STAGE1SRC = stage1.c log.c tools.c modules.c probing.c mount.c automatic.c frontend-common.c lomount.c CDROMSRC = cdrom.c -DISKSRC = disk.c directory.c lomount.c -NETWORKSRC = network.c nfsmount.c dhcp.c url.c dns.c adsl.c directory.c lomount.c +DISKSRC = disk.c directory.c +NETWORKSRC = network.c nfsmount.c dhcp.c url.c dns.c adsl.c directory.c # use sort to remove duplicates STAGE1_ALLSRC = $(sort $(STAGE1SRC) $(CDROMSRC) $(DISKSRC) $(NETWORKSRC)) diff --git a/mdk-stage1/cdrom.c b/mdk-stage1/cdrom.c index acb202628..f226020c4 100644 --- a/mdk-stage1/cdrom.c +++ b/mdk-stage1/cdrom.c @@ -65,8 +65,7 @@ static enum return_type do_with_device(char * dev_name, char * dev_model) log_message("found a " DISTRIB_NAME " CDROM, good news!"); #ifndef MANDRAKE_MOVE - if (IS_RESCUE || ramdisk_possible()) - load_ramdisk(); /* we don't care about return code, we'll do it live if we failed */ + may_load_clp(); if (IS_RESCUE) /* in rescue mode, we don't need the media anymore */ diff --git a/mdk-stage1/config-stage1.h b/mdk-stage1/config-stage1.h index df0646855..662ad4fb5 100644 --- a/mdk-stage1/config-stage1.h +++ b/mdk-stage1/config-stage1.h @@ -20,14 +20,15 @@ /* If we have more than that amount of memory (in Mbytes), we assume we can load the second stage as a ramdisk */ #define MEM_LIMIT_DRAKX 68 +/* If we have more than that amount of memory (in Mbytes), we preload the second stage as a ramdisk */ +#define MEM_LIMIT_DRAKX_PRELOAD 100 /* If we have more than that amount of memory (in Mbytes), we assume we can load the rescue as a ramdisk */ #define MEM_LIMIT_RESCUE 40 +/* If we have more than that amount of memory (in Mbytes), we preload the rescue as a ramdisk */ +#define MEM_LIMIT_RESCUE_PRELOAD 100 -#define RAMDISK_COMPRESSION_RATIO 1.95 - -#define RAMDISK_LOCATION_REL "install/stage2/" #define SLASH_LOCATION "/sysroot" #ifdef MANDRAKE_MOVE @@ -53,6 +54,11 @@ #define DISTRIB_NAME "Mandrakelinux" #define LIVE_LOCATION_REL "install/stage2/live/" +#define CLP_LOCATION_REL "install/stage2/" +#define CLP_STAGE2_NAME "mdkinst.clp" +#define CLP_RESCUE_NAME "rescue.clp" +#define CLP_NAME(prefix) (IS_RESCUE ? prefix CLP_RESCUE_NAME : prefix CLP_STAGE2_NAME) +#define CLP_FILE_REL(prefix) CLP_NAME(prefix CLP_LOCATION_REL) /* the remote media is mounted in - IMAGE_LOCATION_DIR "nfsimage", and IMAGE_LOCATION is a symlink image -> nfsimage/mdk/mirror/dir @@ -63,6 +69,11 @@ #define IMAGE_LOCATION_REL "image" #define IMAGE_LOCATION IMAGE_LOCATION_DIR IMAGE_LOCATION_REL +#define CLP_LOCATION IMAGE_LOCATION "/" CLP_LOCATION_REL + +/* - if we use a clp : STAGE2_LOCATION is a the mount point + - if we use the live: STAGE2_LOCATION is a relative symlink to IMAGE_LOCATION_REL/install/stage2/live +*/ #define STAGE2_LOCATION_ROOTED "/tmp/stage2" #define STAGE2_LOCATION SLASH_LOCATION STAGE2_LOCATION_ROOTED diff --git a/mdk-stage1/directory.c b/mdk-stage1/directory.c index b8ced9cff..dd4206986 100644 --- a/mdk-stage1/directory.c +++ b/mdk-stage1/directory.c @@ -117,6 +117,7 @@ enum return_type try_with_directory(char *directory, char *method_live, char *me char location_full[500]; char * loopdev = NULL; struct stat statbuf; + enum return_type ret = RETURN_OK; unlink(IMAGE_LOCATION); strcpy(location_full, directory); @@ -142,63 +143,36 @@ enum return_type try_with_directory(char *directory, char *method_live, char *me symlink(location_full + offset, IMAGE_LOCATION); add_to_env("METHOD", method_live); } -#ifndef MANDRAKE_MOVE - if (IS_RESCUE || ((loopdev || streq(method_live, "disk")) && ramdisk_possible())) { - /* RAMDISK install */ - if (access(IMAGE_LOCATION "/" RAMDISK_LOCATION_REL, R_OK)) { - stg1_error_message("I can't find the " DISTRIB_NAME " Distribution in the specified directory. " - "(I need the subdirectory " RAMDISK_LOCATION_REL ")\n" - "Here's a short extract of the files in the directory:\n" - "%s", extract_list_directory(IMAGE_LOCATION)); - umount(IMAGE_LOCATION); - del_loop(loopdev); - return RETURN_BACK; - } - if (load_ramdisk() != RETURN_OK) { - stg1_error_message("Could not load program into memory."); - umount(IMAGE_LOCATION); - del_loop(loopdev); - return RETURN_ERROR; - } - } else { -#endif - /* LIVE install */ + #ifdef MANDRAKE_MOVE - if (access(IMAGE_LOCATION "/live_tree/etc/fstab", R_OK) && access(IMAGE_LOCATION "/live_tree.clp", R_OK)) { - stg1_error_message("I can't find the " DISTRIB_NAME " Distribution in the specified directory. " - "(I need the subdirectory " IMAGE_LOCATION ")\n" - "Here's a short extract of the files in the directory:\n" - "%s", extract_list_directory(IMAGE_LOCATION)); + if (access(IMAGE_LOCATION "/live_tree/etc/fstab", R_OK) && access(IMAGE_LOCATION "/live_tree.clp", R_OK)) { + stg1_error_message("I can't find the " DISTRIB_NAME " Distribution in the specified directory. " + "(I need the file " IMAGE_LOCATION "/live_tree/etc/fstab" ")\n" + "Here's a short extract of the files in the directory:\n" + "%s", extract_list_directory(IMAGE_LOCATION)); + ret = RETURN_BACK; + } #else - char p; - if (access(IMAGE_LOCATION "/" LIVE_LOCATION_REL, R_OK)) { - stg1_error_message("I can't find the " DISTRIB_NAME " Distribution in the specified directory. " - "(I need the subdirectory " LIVE_LOCATION_REL ")\n" - "Here's a short extract of the files in the directory:\n" - "%s", extract_list_directory(IMAGE_LOCATION)); -#endif - umount(IMAGE_LOCATION); - del_loop(loopdev); - return RETURN_BACK; - } -#ifndef MANDRAKE_MOVE - if (readlink(IMAGE_LOCATION "/" LIVE_LOCATION_REL "/usr/bin/runinstall2", &p, 1) != 1) { - stg1_error_message("The " DISTRIB_NAME " Distribution seems to be copied on a Windows partition. " - "You need more memory to perform an installation from a Windows partition. " - "Another solution is to copy the " DISTRIB_NAME " Distribution on a Linux partition."); - umount(IMAGE_LOCATION); - del_loop(loopdev); - return RETURN_ERROR; - } - log_message("found the " DISTRIB_NAME " Installation, good news!"); + if (access(IMAGE_LOCATION "/" CLP_LOCATION_REL, R_OK)) { + stg1_error_message("I can't find the " DISTRIB_NAME " Distribution in the specified directory. " + "(I need the subdirectory " CLP_LOCATION_REL ")\n" + "Here's a short extract of the files in the directory:\n" + "%s", extract_list_directory(IMAGE_LOCATION)); + ret = RETURN_BACK; + } else if (may_load_clp() != RETURN_OK) { + stg1_error_message("Could not load program into memory."); + ret = RETURN_ERROR; } -#endif - if (IS_RESCUE) { + if (ret == RETURN_OK) + log_message("found the " DISTRIB_NAME " Installation, good news!"); + +#endif + if (IS_RESCUE || ret != RETURN_OK) { /* in rescue mode, we don't need the media anymore */ umount(IMAGE_LOCATION); del_loop(loopdev); - } + } - return RETURN_OK; + return ret; } diff --git a/mdk-stage1/disk.c b/mdk-stage1/disk.c index c45d38412..1060cd199 100644 --- a/mdk-stage1/disk.c +++ b/mdk-stage1/disk.c @@ -370,8 +370,7 @@ process_recovery(void) log_message("going on with a recovery on disk %s partition %s", medias[i], *part); symlink(disk_own_mount, IMAGE_LOCATION); - if (ramdisk_possible()) - load_ramdisk(); /* if load of ramdisk failed, try to continue in live */ + may_load_clp(); /* no error check */ add_to_env("METHOD", "disk"); return 1; diff --git a/mdk-stage1/network.c b/mdk-stage1/network.c index 6ea2b97b7..d47a39650 100644 --- a/mdk-stage1/network.c +++ b/mdk-stage1/network.c @@ -967,7 +967,7 @@ enum return_type ftp_prepare(void) results = RETURN_BACK; continue; } - kernels_list_file = asprintf_("%s/" RAMDISK_LOCATION_REL "mdkinst.kernels", location_full); + kernels_list_file = asprintf_("%s/" CLP_LOCATION_REL "mdkinst.kernels", location_full); log_message("FTP: trying to retrieve %s", kernels_list_file); fd = ftp_start_download(ftp_serv_response, kernels_list_file, &size); @@ -992,7 +992,7 @@ enum return_type ftp_prepare(void) } } - strcat(location_full, get_ramdisk_realname()); + strcat(location_full, CLP_FILE_REL("/")); log_message("FTP: trying to retrieve %s", location_full); @@ -1021,7 +1021,7 @@ enum return_type ftp_prepare(void) log_message("FTP: size of download %d bytes", size); - results = load_ramdisk_fd(fd, size); + results = load_clp_fd(fd, size); if (results == RETURN_OK) { if (!use_http_proxy) ftp_end_data_command(ftp_serv_response); @@ -1087,7 +1087,7 @@ enum return_type http_prepare(void) strcpy(location_full, answers[1][0] == '/' ? "" : "/"); strcat(location_full, answers[1]); - strcat(location_full, get_ramdisk_realname()); + strcat(location_full, CLP_FILE_REL("/")); log_message("HTTP: trying to retrieve %s from %s", location_full, answers[0]); @@ -1106,7 +1106,7 @@ enum return_type http_prepare(void) log_message("HTTP: size of download %d bytes", size); - if (load_ramdisk_fd(fd, size) != RETURN_OK) { + if (load_clp_fd(fd, size) != RETURN_OK) { unset_param(MODE_AUTOMATIC); /* we are in a fallback mode */ return RETURN_ERROR; } diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c index 4e3f17a27..be1043798 100644 --- a/mdk-stage1/tools.c +++ b/mdk-stage1/tools.c @@ -30,7 +30,6 @@ #include <stdio.h> #include <dirent.h> #include <sys/types.h> -#include <bzlib.h> #include <sys/mount.h> #include <sys/poll.h> #include <errno.h> @@ -228,7 +227,8 @@ int image_has_stage2() #ifdef MANDRAKE_MOVE return access(IMAGE_LOCATION "/live_tree.clp", R_OK) == 0; #else - return access(IMAGE_LOCATION "/" LIVE_LOCATION_REL, R_OK) == 0; + return access(CLP_FILE_REL(IMAGE_LOCATION "/"), R_OK) == 0 || + access(IMAGE_LOCATION "/" LIVE_LOCATION_REL, R_OK) == 0; #endif } @@ -242,6 +242,15 @@ int ramdisk_possible(void) } } +int clp_preload(void) +{ + if (total_memory() > (IS_RESCUE ? MEM_LIMIT_RESCUE_PRELOAD : MEM_LIMIT_DRAKX_PRELOAD)) + return 1; + else { + log_message("warning, not preloading clp due to low mem"); + return 0; + } +} enum return_type save_fd(int from_fd, char * to, void (*callback_func)(int overall)) { @@ -298,7 +307,6 @@ enum return_type copy_file(char * from, char * to, void (*callback_func)(int ove } } -#ifdef MANDRAKE_MOVE enum return_type mount_clp(char *clp, char *location_mount) { if (lomount(clp, location_mount, NULL, 1)) { @@ -348,106 +356,22 @@ enum return_type mount_clp_may_preload(char *clp_name, char *location_mount, int return mount_clp(clp, location_mount); } } -#endif #ifndef MANDRAKE_MOVE -enum return_type load_ramdisk_fd(int ramdisk_fd, int size) +enum return_type may_load_clp(void) { - BZFILE * st2; - char * ramdisk = "/dev/ram3"; /* warning, verify that this file exists in the initrd, and that root=/dev/ram3 is actually passed to the kernel at boot time */ - int ram_fd; - char buffer[32768]; - int z_errnum; - char * wait_msg = "Loading program into memory..."; - int bytes_read = 0; - int actually; - int seems_ok = 0; - - st2 = BZ2_bzdopen(ramdisk_fd, "r"); - - if (!st2) { - log_message("Opening compressed ramdisk: %s", BZ2_bzerror(st2, &z_errnum)); - stg1_error_message("Could not open compressed ramdisk file."); - return RETURN_ERROR; - } - - ram_fd = open(ramdisk, O_WRONLY); - if (ram_fd == -1) { - log_perror(ramdisk); - stg1_error_message("Could not open ramdisk device file."); - return RETURN_ERROR; - } - - init_progression(wait_msg, size); - - while ((actually = BZ2_bzread(st2, buffer, sizeof(buffer))) > 0) { - seems_ok = 1; - if (write(ram_fd, buffer, actually) != actually) { - log_perror("writing ramdisk"); - remove_wait_message(); - return RETURN_ERROR; - } - update_progression((int)((bytes_read += actually) / RAMDISK_COMPRESSION_RATIO)); - } - - if (!seems_ok) { - log_message("reading compressed ramdisk: %s", BZ2_bzerror(st2, &z_errnum)); - BZ2_bzclose(st2); /* opened by gzdopen, but also closes the associated fd */ - close(ram_fd); - remove_wait_message(); - stg1_error_message("Could not uncompress second stage ramdisk. " - "This is probably an hardware error while reading the data. " - "(this may be caused by a hardware failure or a Linux kernel bug)"); - return RETURN_ERROR; + if (!IS_RESCUE && access(IMAGE_LOCATION "/" LIVE_LOCATION_REL, R_OK) == 0) { + /* LIVE install */ + return RETURN_OK; + } else { + /* CLP install */ + return mount_clp_may_preload(CLP_NAME(""), STAGE2_LOCATION, clp_preload()); } - - end_progression(); - - BZ2_bzclose(st2); /* opened by gzdopen, but also closes the associated fd */ - close(ram_fd); - - if (my_mount(ramdisk, STAGE2_LOCATION, "ext2", 1)) - return RETURN_ERROR; - - return RETURN_OK; -} - - -char * get_ramdisk_realname(void) -{ - char img_name[500]; - - strcpy(img_name, "/" RAMDISK_LOCATION_REL); - strcat(img_name, IS_RESCUE ? "rescue" : "mdkinst"); - strcat(img_name, "_stage2.bz2"); - - return strdup(img_name); } - -enum return_type load_ramdisk(void) +enum return_type load_clp_fd(int fd, int size) { - int st2_fd; - off_t size; - char img_name[500]; - - strcpy(img_name, IMAGE_LOCATION); - strcat(img_name, get_ramdisk_realname()); - - log_message("trying to load %s as a ramdisk", img_name); - - st2_fd = open(img_name, O_RDONLY); /* to be able to see the progression */ - - if (st2_fd == -1) { - log_message("open ramdisk file (%s) failed", img_name); - stg1_error_message("Could not open compressed ramdisk file (%s).", img_name); - return RETURN_ERROR; - } - - if ((size = file_size(img_name)) == -1) - return RETURN_ERROR; - else - return load_ramdisk_fd(st2_fd, size); + return preload_mount_clp(fd, size, CLP_NAME(""), STAGE2_LOCATION); } #endif diff --git a/mdk-stage1/tools.h b/mdk-stage1/tools.h index 19e0a4ea1..bd4dc7683 100644 --- a/mdk-stage1/tools.h +++ b/mdk-stage1/tools.h @@ -34,13 +34,12 @@ int total_memory(void); int image_has_stage2(); int ramdisk_possible(void); enum return_type copy_file(char * from, char * to, void (*callback_func)(int overall)); -#ifdef MANDRAKE_MOVE +enum return_type preload_mount_clp(int clp_fd, int clp_size, char *clp_name, char *location_mount); +enum return_type mount_clp(char *clp, char *location_mount); enum return_type mount_clp_may_preload(char *clp_name, char *location_mount, int preload); -#endif #ifndef MANDRAKE_MOVE -char * get_ramdisk_realname(void); -enum return_type load_ramdisk(void); -enum return_type load_ramdisk_fd(int ramdisk_fd, int size); +enum return_type load_clp_fd(int fd, int size); +enum return_type may_load_clp(void); #endif void * memdup(void *src, size_t size); void add_to_env(char * name, char * value); |