summaryrefslogtreecommitdiffstats
path: root/mdk-stage1
diff options
context:
space:
mode:
Diffstat (limited to 'mdk-stage1')
-rw-r--r--mdk-stage1/Makefile2
-rw-r--r--mdk-stage1/cdrom.c8
-rw-r--r--mdk-stage1/config-stage1.h7
-rw-r--r--mdk-stage1/disk.c47
-rw-r--r--mdk-stage1/network.c145
-rw-r--r--mdk-stage1/newt-frontend.c61
-rw-r--r--mdk-stage1/stage1.c8
-rw-r--r--mdk-stage1/stage1.h3
-rw-r--r--mdk-stage1/stdio-frontend.c35
-rw-r--r--mdk-stage1/tools.c123
-rw-r--r--mdk-stage1/tools.h6
11 files changed, 346 insertions, 99 deletions
diff --git a/mdk-stage1/Makefile b/mdk-stage1/Makefile
index 73a18e87c..7ee40bf05 100644
--- a/mdk-stage1/Makefile
+++ b/mdk-stage1/Makefile
@@ -81,7 +81,7 @@ STAGE1_NETWORK_LIBS = /usr/lib/libresolv.a
STAGE1SRC = stage1.c log.c tools.c modules.c probing.c mount.c automatic.c
CDROMSRC = cdrom.c
DISKSRC = disk.c
-NETWORKSRC = network.c dns.c nfsmount.c dhcp.c
+NETWORKSRC = network.c dns.c nfsmount.c dhcp.c url.c
ALLSRC = $(INITSRC) $(STAGE1SRC) $(CDROMSRC) $(DISKSRC) $(NETWORKSRC)
diff --git a/mdk-stage1/cdrom.c b/mdk-stage1/cdrom.c
index 1c400726d..eb5977153 100644
--- a/mdk-stage1/cdrom.c
+++ b/mdk-stage1/cdrom.c
@@ -41,7 +41,7 @@ static enum return_type try_with_device(char *dev_name)
strcpy(device_fullname, "/dev/");
strcat(device_fullname, dev_name);
- if (my_mount(device_fullname, "/tmp/image", "iso9660") == -1) {
+ if (my_mount(device_fullname, IMAGE_LOCATION, "iso9660") == -1) {
enum return_type results;
unset_param(MODE_AUTOMATIC); /* we are in a fallback mode */
@@ -51,9 +51,9 @@ static enum return_type try_with_device(char *dev_name)
return results;
}
- if (access("/tmp/image" LIVE_LOCATION, R_OK)) {
+ if (access(IMAGE_LOCATION LIVE_LOCATION, R_OK)) {
enum return_type results;
- umount("/tmp/image");
+ umount(IMAGE_LOCATION);
results = ask_yes_no("That CDROM disc does not seem to be a " DISTRIB_NAME " Installation CDROM.\nRetry with another disc?");
if (results == RETURN_OK)
return try_with_device(dev_name);
@@ -66,7 +66,7 @@ static enum return_type try_with_device(char *dev_name)
load_ramdisk(); /* we don't care about return code, we'll do it live if we failed */
if (IS_RESCUE)
- umount("/tmp/image");
+ umount(IMAGE_LOCATION);
method_name = strdup("cdrom");
return RETURN_OK;
diff --git a/mdk-stage1/config-stage1.h b/mdk-stage1/config-stage1.h
index ca8755fd3..d2503d642 100644
--- a/mdk-stage1/config-stage1.h
+++ b/mdk-stage1/config-stage1.h
@@ -23,6 +23,13 @@
#define DISTRIB_NAME "Linux-Mandrake"
+#define RAMDISK_COMPRESSION_RATIO 1.9
+
+#define LIVE_LOCATION "/Mandrake/mdkinst/"
+#define RAMDISK_LOCATION "/Mandrake/base/"
+#define IMAGE_LOCATION "/tmp/image"
+#define STAGE2_LOCATION "/tmp/stage2"
+
/* user-definable (in Makefile): DISABLE_NETWORK, DISABLE_DISK, DISABLE_CDROM, DISABLE_PCMCIA */
diff --git a/mdk-stage1/disk.c b/mdk-stage1/disk.c
index 2465e7442..b154f8d0b 100644
--- a/mdk-stage1/disk.c
+++ b/mdk-stage1/disk.c
@@ -58,7 +58,9 @@ 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];
+ char location_full[500];
+
+ char * disk_own_mount = "/tmp/disk";
int major, minor, blocks;
char name[100];
@@ -97,42 +99,43 @@ static enum return_type try_with_device(char *dev_name)
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) {
+ if (my_mount(device_fullname, disk_own_mount, "ext2") == -1 &&
+ my_mount(device_fullname, disk_own_mount, "vfat") == -1 &&
+ my_mount(device_fullname, disk_own_mount, "reiserfs") == -1) {
error_message("I can't find a valid filesystem.");
return try_with_device(dev_name);
}
if (ask_from_entries("Please enter the directory containing the " DISTRIB_NAME " Distribution.",
questions_location, &answers_location, 24) != RETURN_OK) {
- umount("/tmp/disk");
+ umount(disk_own_mount);
return try_with_device(dev_name);
}
- strcpy(location_full, "/tmp/disk/");
+ strcpy(location_full, disk_own_mount);
+ strcat(location_full, "/");
strcat(location_full, answers_location[0]);
if (access(location_full, R_OK)) {
error_message("Directory could not be found on partition.\n"
"Here's a short extract of the files in the root of the partition:\n"
- "%s", list_directory("/tmp/disk"));
- umount("/tmp/disk");
+ "%s", list_directory(disk_own_mount));
+ umount(disk_own_mount);
return try_with_device(dev_name);
}
- unlink("/tmp/image");
- symlink(location_full, "/tmp/image");
+ unlink(IMAGE_LOCATION);
+ symlink(location_full, IMAGE_LOCATION);
if (IS_SPECIAL_STAGE2 || ramdisk_possible()) {
/* RAMDISK install */
- if (access("/tmp/image" RAMDISK_LOCATION, R_OK)) {
+ if (access(IMAGE_LOCATION RAMDISK_LOCATION, R_OK)) {
error_message("I can't find the " DISTRIB_NAME " Distribution in the specified directory. "
"(I need the directory " RAMDISK_LOCATION ")\n"
"Here's a short extract of the files in the directory:\n"
- "%s", list_directory("/tmp/image"));
- umount("/tmp/disk");
- unlink("/tmp/image");
+ "%s", list_directory(IMAGE_LOCATION));
+ umount(disk_own_mount);
+ unlink(IMAGE_LOCATION);
return try_with_device(dev_name);
}
if (load_ramdisk() != RETURN_OK) {
@@ -142,28 +145,28 @@ static enum return_type try_with_device(char *dev_name)
} else {
/* LIVE install */
char p;
- if (access("/tmp/image" LIVE_LOCATION, R_OK)) {
+ if (access(IMAGE_LOCATION LIVE_LOCATION, R_OK)) {
error_message("I can't find the " DISTRIB_NAME " Distribution in the specified directory. "
"(I need the directory " LIVE_LOCATION ")\n"
"Here's a short extract of the files in the directory:\n"
- "%s", list_directory("/tmp/image"));
- umount("/tmp/disk");
- unlink("/tmp/image");
+ "%s", list_directory(IMAGE_LOCATION));
+ umount(disk_own_mount);
+ unlink(IMAGE_LOCATION);
return try_with_device(dev_name);
}
- if (readlink("/tmp/image" LIVE_LOCATION "/usr/bin/runinstall2", &p, 1) != 1) {
+ if (readlink(IMAGE_LOCATION LIVE_LOCATION "/usr/bin/runinstall2", &p, 1) != 1) {
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 if to copy the " DISTRIB_NAME " Distribution on a Linux partition.");
- umount("/tmp/disk");
- unlink("/tmp/image");
+ umount(disk_own_mount);
+ unlink(IMAGE_LOCATION);
return try_with_device(dev_name);
}
log_message("found the " DISTRIB_NAME " Installation, good news!");
}
if (IS_RESCUE)
- umount("/tmp/image");
+ umount(IMAGE_LOCATION);
method_name = strdup("disk");
return RETURN_OK;
diff --git a/mdk-stage1/network.c b/mdk-stage1/network.c
index 91e954508..b6256de47 100644
--- a/mdk-stage1/network.c
+++ b/mdk-stage1/network.c
@@ -40,6 +40,7 @@
#include "mount.h"
#include "automatic.h"
#include "dhcp.h"
+#include "url.h"
#include "network.h"
@@ -578,15 +579,15 @@ enum return_type nfs_prepare(void)
strcat(nfsmount_location, ":");
strcat(nfsmount_location, answers[1]);
- if (my_mount(nfsmount_location, "/tmp/image", "nfs") == -1) {
+ if (my_mount(nfsmount_location, IMAGE_LOCATION, "nfs") == -1) {
error_message("I can't mount the directory from the NFS server.");
results = RETURN_BACK;
continue;
}
- if (access("/tmp/image/Mandrake/mdkinst", R_OK)) {
+ if (access(IMAGE_LOCATION LIVE_LOCATION, R_OK)) {
error_message("That NFS volume does not seem to contain the " DISTRIB_NAME " Distribution.");
- umount("/tmp/image");
+ umount(IMAGE_LOCATION);
results = RETURN_BACK;
}
}
@@ -602,7 +603,7 @@ enum return_type nfs_prepare(void)
}
if (IS_RESCUE)
- umount("/tmp/image");
+ umount(IMAGE_LOCATION);
method_name = strdup("nfs");
return RETURN_OK;
@@ -611,12 +612,140 @@ enum return_type nfs_prepare(void)
enum return_type ftp_prepare(void)
{
- error_message("Currently unsupported");
- return RETURN_ERROR;
+ char * questions[] = { "FTP server", DISTRIB_NAME " directory", "Login", "Password", NULL };
+ char * questions_auto[] = { "server", "directory", "user", "pass", NULL };
+ char ** answers;
+ enum return_type results;
+
+ if (!ramdisk_possible()) {
+ error_message("FTP install needs more than %d Mbytes of memory (detected %d Mbytes).",
+ MEM_LIMIT_RAMDISK >> 10, total_memory() >> 10);
+ return RETURN_ERROR;
+ }
+
+ results = intf_select_and_up();
+
+ if (results != RETURN_OK)
+ return results;
+
+ do {
+ char location_full[500];
+ int ftp_serv_response;
+ int fd, size;
+
+ results = ask_from_entries_auto("Please enter the name or IP address of the FTP server, "
+ "the directory containing the " DISTRIB_NAME " Distribution, "
+ "and the login/pass if necessary (leave blank for anonymous).",
+ questions, &answers, 40, questions_auto);
+ if (results != RETURN_OK)
+ return ftp_prepare();
+
+ log_message("FTP: trying to connect to %s", answers[0]);
+
+ ftp_serv_response = ftp_open_connection(answers[0], answers[2], answers[3], "");
+ if (ftp_serv_response < 0) {
+ log_message("FTP: error connect %d", ftp_serv_response);
+ if (ftp_serv_response == FTPERR_BAD_HOSTNAME)
+ error_message("Error: bad hostname.");
+ else if (ftp_serv_response == FTPERR_FAILED_CONNECT)
+ error_message("Error: failed to connect to remote host.");
+ else
+ error_message("Error: couldn't connect.");
+ results = RETURN_BACK;
+ continue;
+ }
+
+ strcpy(location_full, answers[1]);
+ strcat(location_full, get_ramdisk_realname());
+
+ log_message("FTP: trying to retrieve %s", location_full);
+
+ fd = ftp_start_download(ftp_serv_response, location_full, &size);
+ if (fd < 0) {
+ log_message("FTP: error get %d", fd);
+ if (fd == FTPERR_PASSIVE_ERROR)
+ error_message("Error: error with passive connection.");
+ else if (fd == FTPERR_FILE_NOT_FOUND)
+ error_message("Error: file not found (%s).", location_full);
+ else if (fd == FTPERR_BAD_SERVER_RESPONSE)
+ error_message("Error: bad server response (server too busy?).");
+ else
+ error_message("Error: couldn't retrieve Installation program.");
+ results = RETURN_BACK;
+ continue;
+ }
+
+ log_message("FTP: size of download %d bytes", size);
+
+ results = load_ramdisk_fd(fd, size);
+ if (results == RETURN_OK)
+ ftp_end_data_command(fd);
+
+ method_name = strdup("ftp");
+ add_to_env("HOST", answers[0]);
+ add_to_env("PREFIX", answers[1]);
+ if (strcmp(answers[2], "")) {
+ add_to_env("LOGIN", answers[2]);
+ add_to_env("PASSWORD", answers[3]);
+ }
+ }
+ while (results == RETURN_BACK);
+
+ return RETURN_OK;
}
enum return_type http_prepare(void)
{
- error_message("Currently unsupported");
- return RETURN_ERROR;
+ char * questions[] = { "HTTP server", DISTRIB_NAME " directory", NULL };
+ char * questions_auto[] = { "server", "directory", NULL };
+ char ** answers;
+ enum return_type results;
+
+ if (!ramdisk_possible()) {
+ error_message("HTTP install needs more than %d Mbytes of memory (detected %d Mbytes).",
+ MEM_LIMIT_RAMDISK >> 10, total_memory() >> 10);
+ return RETURN_ERROR;
+ }
+
+ results = intf_select_and_up();
+
+ if (results != RETURN_OK)
+ return results;
+
+ do {
+ char location_full[500];
+ int fd;
+
+ results = ask_from_entries_auto("Please enter the name or IP address of the HTTP server, "
+ "and the directory containing the " DISTRIB_NAME " Distribution.",
+ questions, &answers, 40, questions_auto);
+ if (results != RETURN_OK)
+ return http_prepare();
+
+ strcpy(location_full, answers[1]);
+ strcat(location_full, get_ramdisk_realname());
+
+ log_message("HTTP: trying to retrieve %s", location_full);
+
+ fd = http_download_file(answers[0], location_full);
+ if (fd < 0) {
+ log_message("HTTP: error %d", fd);
+ if (fd == FTPERR_FAILED_CONNECT)
+ error_message("Error: couldn't connect to server.");
+ else
+ error_message("Error: couldn't get file (%s).", location_full);
+ results = RETURN_BACK;
+ continue;
+ }
+
+ results = load_ramdisk_fd(fd, 0);
+
+ method_name = strdup("http");
+ sprintf(location_full, "http://%s/%s", answers[0], answers[1]);
+ add_to_env("URLPREFIX", location_full);
+ }
+ while (results == RETURN_BACK);
+
+ return RETURN_OK;
+
}
diff --git a/mdk-stage1/newt-frontend.c b/mdk-stage1/newt-frontend.c
index e30a5a5c7..640ff9f0c 100644
--- a/mdk-stage1/newt-frontend.c
+++ b/mdk-stage1/newt-frontend.c
@@ -30,6 +30,7 @@
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
+#include <sys/time.h>
#include "stage1.h"
#include "log.h"
#include "newt.h"
@@ -74,12 +75,13 @@ void info_message(char *msg, ...)
vlog_message(msg, args);
}
+
void wait_message(char *msg, ...)
{
int width = 8;
int height = 3;
char * title = "Please wait...";
- newtComponent t, f;
+ newtComponent c, f;
char * buf = NULL;
int size = 0;
int i = 0;
@@ -99,13 +101,13 @@ void wait_message(char *msg, ...)
newtCenteredWindow(width, height, title);
- t = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP);
- newtTextboxSetText(t, buf);
+ c = newtTextbox(1, 1, width - 2, height - 2, NEWT_TEXTBOX_WRAP);
+ newtTextboxSetText(c, buf);
f = newtForm(NULL, NULL, 0);
free(buf);
- newtFormAddComponent(f, t);
+ newtFormAddComponent(f, c);
newtDrawForm(f);
newtRefresh();
@@ -121,30 +123,57 @@ void remove_wait_message(void)
static newtComponent form = NULL, scale = NULL;
static int size_progress;
static int actually_drawn;
+static char * msg_progress;
void init_progression(char *msg, int size)
{
size_progress = size;
- actually_drawn = 0;
- newtCenteredWindow(70, 5, "Please wait...");
- form = newtForm(NULL, NULL, 0);
- newtFormAddComponent(form, newtLabel(1, 1, msg));
- scale = newtScale(1, 3, 68, size);
- newtFormAddComponent(form, scale);
- newtDrawForm(form);
- newtRefresh();
+ if (size) {
+ actually_drawn = 0;
+ newtCenteredWindow(70, 5, "Please wait...");
+ form = newtForm(NULL, NULL, 0);
+ newtFormAddComponent(form, newtLabel(1, 1, msg));
+ scale = newtScale(1, 3, 68, size);
+ newtFormAddComponent(form, scale);
+ newtDrawForm(form);
+ newtRefresh();
+ }
+ else {
+ wait_message(msg);
+ msg_progress = msg;
+ }
}
void update_progression(int current_size)
{
- newtScaleSet(scale, current_size);
- newtRefresh();
+ if (size_progress) {
+ newtScaleSet(scale, current_size);
+ newtRefresh();
+ }
+ else {
+ struct timeval t;
+ int time;
+ static int last_time = -1;
+ gettimeofday(&t, NULL);
+ time = t.tv_sec*3 + t.tv_usec/300000;
+ if (time != last_time) {
+ char msg_prog_final[500];
+ sprintf(msg_prog_final, "%s (%d bytes read) ", msg_progress, current_size);
+ remove_wait_message();
+ wait_message(msg_prog_final);
+ }
+ last_time = time;
+ }
}
void end_progression(void)
{
- newtPopWindow();
- newtFormDestroy(form);
+ if (size_progress) {
+ newtPopWindow();
+ newtFormDestroy(form);
+ }
+ else
+ remove_wait_message();
}
diff --git a/mdk-stage1/stage1.c b/mdk-stage1/stage1.c
index 935d92810..d18d0d93a 100644
--- a/mdk-stage1/stage1.c
+++ b/mdk-stage1/stage1.c
@@ -189,6 +189,7 @@ int main(int argc, char **argv, char **env)
open_log();
log_message("welcome to the " DISTRIB_NAME " install (stage1, version " VERSION " built " __DATE__ " " __TIME__")");
process_cmdline();
+ handle_env(env);
spawn_shell();
if (load_modules_dependencies())
fatal_error("could not open and parse modules dependencies");
@@ -203,8 +204,8 @@ int main(int argc, char **argv, char **env)
fatal_error("could not select an installation method");
if (!IS_RAMDISK) {
- if (symlink("/tmp/image/Mandrake/mdkinst", "/tmp/stage2") != 0)
- fatal_error("symlink to /tmp/stage2 failed");
+ if (symlink(IMAGE_LOCATION LIVE_LOCATION, STAGE2_LOCATION) != 0)
+ fatal_error("symlink to " STAGE2_LOCATION " failed");
}
if (IS_RESCUE) {
@@ -223,10 +224,11 @@ int main(int argc, char **argv, char **env)
argptr = stage2_args;
*argptr++ = "/usr/bin/runinstall2";
+ *argptr++ = "--method";
*argptr++ = method_name;
*argptr++ = NULL;
- execve(stage2_args[0], stage2_args, env);
+ execve(stage2_args[0], stage2_args, grab_env());
printf("error in exec of stage2 :-(\n");
fatal_error(strerror(errno));
diff --git a/mdk-stage1/stage1.h b/mdk-stage1/stage1.h
index ad96e32c6..736fa6924 100644
--- a/mdk-stage1/stage1.h
+++ b/mdk-stage1/stage1.h
@@ -48,7 +48,4 @@ extern char * method_name;
void fatal_error(char *msg);
-#define LIVE_LOCATION "/Mandrake/mdkinst"
-#define RAMDISK_LOCATION "/Mandrake/base"
-
#endif
diff --git a/mdk-stage1/stdio-frontend.c b/mdk-stage1/stdio-frontend.c
index 9fe110ca9..277c47da1 100644
--- a/mdk-stage1/stdio-frontend.c
+++ b/mdk-stage1/stdio-frontend.c
@@ -127,31 +127,42 @@ void remove_wait_message(void)
static int size_progress;
static int actually_drawn;
-
+#define PROGRESS_SIZE 60
void init_progression(char *msg, int size)
{
int i;
size_progress = size;
- actually_drawn = 0;
- printf("%s\n[", msg);
- for (i=0; i<60; i++)
- printf(".");
- printf("]\033[G["); /* only works on ANSI-compatibles */
- fflush(stdout);
+ printf("%s\n", msg);
+ if (size) {
+ printf("[");
+ actually_drawn = 0;
+ for (i=0; i<PROGRESS_SIZE; i++)
+ printf(".");
+ printf("]\033[G["); /* only works on ANSI-compatibles */
+ fflush(stdout);
+ }
}
void update_progression(int current_size)
{
- while ((int)((current_size*60)/size_progress) > actually_drawn) {
- printf("*");
- actually_drawn++;
- }
+ if (size_progress) {
+ while ((int)((current_size*PROGRESS_SIZE)/size_progress) > actually_drawn) {
+ printf("*");
+ actually_drawn++;
+ }
+ } else
+ printf("\033[G%d bytes read", current_size);
+
fflush(stdout);
}
void end_progression(void)
{
- printf("]\n");
+ if (size_progress) {
+ update_progression(size_progress);
+ printf("]\n");
+ } else
+ printf(" done.\n");
}
diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c
index 26d92d3e7..7266409c5 100644
--- a/mdk-stage1/tools.c
+++ b/mdk-stage1/tools.c
@@ -26,6 +26,7 @@
#include <fcntl.h>
#include <string.h>
#include <ctype.h>
+#include <stdio.h>
#include <zlib.h>
#include "stage1.h"
#include "log.h"
@@ -137,6 +138,15 @@ void unset_param(int i)
stage1_mode &= ~i;
}
+int charstar_to_int(char * s)
+{
+ int number = 0;
+ while (*s && isdigit(*s)) {
+ number = (number * 10) + (*s - '0');
+ s++;
+ }
+ return number;
+}
int total_memory(void)
{
@@ -167,10 +177,7 @@ int total_memory(void)
if (buf[i] == 0 || buf[i] == '\n')
fatal_error("could not read MemTotal");
- while (buf[i] != 0 && isdigit(buf[i])) {
- memtotal = (memtotal * 10) + (buf[i] - '0');
- i++;
- }
+ memtotal = charstar_to_int(&(buf[i]));
log_message("%s %d kB", memtotal_tag, memtotal);
@@ -189,34 +196,17 @@ int ramdisk_possible(void)
}
-enum return_type load_ramdisk(void)
+enum return_type load_ramdisk_fd(int ramdisk_fd, int size)
{
- char * img_name;
gzFile st2;
char * ramdisk = "/dev/ram3"; /* warning, verify that this file exists in the initrd (and actually is a ramdisk device file) */
- int ram_fd, st2_fd;
+ int ram_fd;
char buffer[4096];
- char * stg2_name = get_param_valued("special_stage2");
- char * begin_img = "/tmp/image/Mandrake/base/";
- char * end_img = "_stage2.gz";
int gz_errnum;
- struct stat statr;
+ char * wait_msg = "Loading program into memory...";
+ int bytes_read = 0;
- if (!stg2_name)
- stg2_name = "mdkinst";
-
- if (IS_RESCUE)
- stg2_name = "rescue";
-
- img_name = malloc(strlen(begin_img) + strlen(stg2_name) + strlen(end_img) + 1);
- strcpy(img_name, begin_img);
- strcat(img_name, stg2_name);
- strcat(img_name, end_img);
-
- 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 */
- st2 = gzdopen(st2_fd, "r");
+ st2 = gzdopen(ramdisk_fd, "r");
if (!st2) {
log_message("Opening compressed ramdisk: %s", gzerror(st2, &gz_errnum));
@@ -231,8 +221,7 @@ enum return_type load_ramdisk(void)
return RETURN_ERROR;
}
- stat(img_name, &statr);
- init_progression("Loading program into memory...", statr.st_size);
+ init_progression(wait_msg, size);
while (!gzeof(st2)) {
int actually = gzread(st2, buffer, sizeof(buffer));
@@ -246,7 +235,7 @@ enum return_type load_ramdisk(void)
remove_wait_message();
return RETURN_ERROR;
}
- update_progression(lseek(st2_fd, 0L, SEEK_CUR));
+ update_progression((int)((bytes_read += actually) / RAMDISK_COMPRESSION_RATIO));
}
end_progression();
@@ -257,7 +246,7 @@ enum return_type load_ramdisk(void)
if (IS_RESCUE)
return RETURN_OK; /* fucksike, I lost several hours wondering why the kernel won't see the rescue if it is alreay mounted */
- if (my_mount(ramdisk, "/tmp/stage2", "ext2"))
+ if (my_mount(ramdisk, STAGE2_LOCATION, "ext2"))
return RETURN_ERROR;
set_param(MODE_RAMDISK);
@@ -266,6 +255,52 @@ enum return_type load_ramdisk(void)
}
+char * get_ramdisk_realname(void)
+{
+ char img_name[500];
+ char * stg2_name = get_param_valued("special_stage2");
+ char * begin_img = RAMDISK_LOCATION;
+ char * end_img = "_stage2.gz";
+
+ if (!stg2_name)
+ stg2_name = "mdkinst";
+
+ if (IS_RESCUE)
+ stg2_name = "rescue";
+
+ strcpy(img_name, begin_img);
+ strcat(img_name, stg2_name);
+ strcat(img_name, end_img);
+
+ return strdup(img_name);
+}
+
+
+enum return_type load_ramdisk(void)
+{
+ int st2_fd;
+ struct stat statr;
+ 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);
+ error_message("Could not open compressed ramdisk file (%s).", img_name);
+ return RETURN_ERROR;
+ }
+
+ if (stat(img_name, &statr))
+ return RETURN_ERROR;
+ else
+ return load_ramdisk_fd(st2_fd, statr.st_size);
+}
+
/* pixel's */
void * memdup(void *src, size_t size)
{
@@ -274,3 +309,31 @@ void * memdup(void *src, size_t size)
memcpy(r, src, size);
return r;
}
+
+
+static char ** my_env = NULL;
+static int env_size = 0;
+
+void handle_env(char ** env)
+{
+ char ** ptr = env;
+ while (ptr && *ptr) {
+ ptr++;
+ env_size++;
+ }
+ my_env = malloc(sizeof(char *) * 100);
+ memcpy(my_env, env, sizeof(char *) * (env_size+1));
+}
+
+char ** grab_env(void) {
+ return my_env;
+}
+
+void add_to_env(char * name, char * value)
+{
+ char tmp[500];
+ sprintf(tmp, "%s=%s", name, value);
+ my_env[env_size] = strdup(tmp);
+ env_size++;
+ my_env[env_size] = NULL;
+}
diff --git a/mdk-stage1/tools.h b/mdk-stage1/tools.h
index e91c4acf5..5efe5a64f 100644
--- a/mdk-stage1/tools.h
+++ b/mdk-stage1/tools.h
@@ -28,10 +28,16 @@ void process_cmdline(void);
int get_param(int i);
void set_param(int i);
void unset_param(int i);
+int charstar_to_int(char * s);
int total_memory(void);
int ramdisk_possible(void);
+char * get_ramdisk_realname(void);
enum return_type load_ramdisk(void);
+enum return_type load_ramdisk_fd(int ramdisk_fd, int size);
void * memdup(void *src, size_t size);
+void add_to_env(char * name, char * value);
+void handle_env(char ** env);
+char ** grab_env(void);
struct param_elem
{