diff options
Diffstat (limited to 'mdk-stage1/rescue-gui.c')
| -rw-r--r-- | mdk-stage1/rescue-gui.c | 111 |
1 files changed, 93 insertions, 18 deletions
diff --git a/mdk-stage1/rescue-gui.c b/mdk-stage1/rescue-gui.c index 240d7ccba..c7aae6126 100644 --- a/mdk-stage1/rescue-gui.c +++ b/mdk-stage1/rescue-gui.c @@ -1,7 +1,7 @@ /* - * Guillaume Cottenceau (gc@mandrakesoft.com) + * Guillaume Cottenceau (gc) * - * Copyright 2001 MandrakeSoft + * Copyright 2001 Mandriva * * * This software may be freely redistributed under the terms of the GNU @@ -27,25 +27,53 @@ #include <sys/ioctl.h> #include <linux/unistd.h> #include <sys/select.h> +#include <linux/reboot.h> #include "config-stage1.h" #include "frontend.h" -#include "tools.h" +#include "utils.h" +#include "params.h" + +#include <sys/syscall.h> + +static inline long reboot(void) +{ + return (long) syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART, 0); +} + +#if defined(__i386__) || defined(__x86_64__) +#define ENABLE_RESCUE_MS_BOOT 1 +#endif char * env[] = { "PATH=/usr/bin:/bin:/sbin:/usr/sbin:/mnt/sbin:/mnt/usr/sbin:/mnt/bin:/mnt/usr/bin", - "LD_LIBRARY_PATH=/lib:/usr/lib:/mnt/lib:/mnt/usr/lib:/usr/X11R6/lib:/mnt/usr/X11R6/lib", + "LD_LIBRARY_PATH=/lib:/usr/lib:/mnt/lib:/mnt/usr/lib" +#if defined(__x86_64__) + ":/lib64:/usr/lib64:/mnt/lib64:/mnt/usr/lib64" +#endif + , "HOME=/", "TERM=linux", "TERMINFO=/etc/terminfo", NULL }; -void pause(void) { unsigned char t; fflush(stdout); read(0, &t, 1); } +/* pause() already exists and causes the invoking process to sleep + until a signal is received */ +static void PAUSE(void) { + unsigned char t; + fflush(stdout); + read(0, &t, 1); +} /* ------ UUURGH this is duplicated from `init.c', don't edit here........ */ -static inline _syscall3(int, reboot, int, magic, int, magic2, int, flag); +void fatal_error(char *msg) +{ + printf("FATAL ERROR IN RESCUE: %s\n\nI can't recover from this.\nYou may reboot your system.\n", msg); + while (1); +} + #define LOOP_CLR_FD 0x4C01 void del_loop(char *device) { @@ -125,7 +153,7 @@ void unmount_filesystems(void) for (i = nb = 0; i < numfs; i++) if (fs[i].mounted) { printf("\t%s umount failed\n", fs[i].name); - if (strcmp(fs[i].fs, "ext2") == 0) nb++; /* don't count not-ext2 umount failed */ + if (strcmp(fs[i].fs, "ext4") == 0) nb++; /* don't count not-ext4 umount failed */ } if (nb) { @@ -145,7 +173,7 @@ int main(int argc __attribute__ ((unused)), char **argv __attribute__ ((unused)) enum return_type results; char install_bootloader[] = "Re-install Boot Loader"; -#ifdef __i386__ +#if ENABLE_RESCUE_MS_BOOT char restore_ms_boot[] = "Restore Windows Boot Loader"; #endif char mount_parts[] = "Mount your partitions under /mnt"; @@ -153,14 +181,35 @@ int main(int argc __attribute__ ((unused)), char **argv __attribute__ ((unused)) char reboot_[] = "Reboot"; char doc[] = "Doc: what's addressed by this Rescue?"; - char * actions[] = { install_bootloader, -#ifdef __i386__ - restore_ms_boot, + char upgrade[] = "Upgrade to New Version"; + char rootpass[] = "Reset Root Password"; + char userpass[] = "Reset User Password"; + char factory[] = "Reset to Factory Defaults"; + char backup[] = "Backup User Files"; + char restore[] = "Restore User Files from Backup"; + char badblocks[] = "Test Key for Badblocks"; + + char * actions_default[] = { install_bootloader, +#if ENABLE_RESCUE_MS_BOOT + restore_ms_boot, #endif - mount_parts, go_to_console, reboot_, doc, NULL }; + mount_parts, go_to_console, reboot_, doc, NULL }; + char * actions_flash_rescue[] = { rootpass, userpass, factory, backup, restore, + badblocks, go_to_console, reboot_, NULL }; + char * actions_flash_upgrade[] = { upgrade, go_to_console, reboot_, NULL }; + + + char * flash_mode; + char ** actions; char * choice; - init_frontend("Welcome to " DISTRIB_NAME " Rescue (" VERSION ") " __DATE__ " " __TIME__); + process_cmdline(); + flash_mode = get_param_valued("flash"); + actions = !flash_mode ? + actions_default : + streq(flash_mode, "upgrade") ? actions_flash_upgrade : actions_flash_rescue; + + init_frontend("Welcome to " DISTRIB_NAME " Rescue (" DISTRIB_VERSION ") " __DATE__ " " __TIME__); do { int pid; @@ -172,7 +221,7 @@ int main(int argc __attribute__ ((unused)), char **argv __attribute__ ((unused)) if (ptr_begins_static_str(choice, install_bootloader)) { binary = "/usr/bin/install_bootloader"; } -#ifdef __i386__ +#if ENABLE_RESCUE_MS_BOOT if (ptr_begins_static_str(choice, restore_ms_boot)) { binary = "/usr/bin/restore_ms_boot"; } @@ -182,15 +231,41 @@ int main(int argc __attribute__ ((unused)), char **argv __attribute__ ((unused)) } if (ptr_begins_static_str(choice, reboot_)) { finish_frontend(); + sync(); sync(); + sleep(2); unmount_filesystems(); + sync(); sync(); printf("rebooting system\n"); sleep(2); - reboot(0xfee1dead, 672274793, 0x01234567); + reboot(); } if (ptr_begins_static_str(choice, doc)) { binary = "/usr/bin/rescue-doc"; } + /* Mandriva Flash entries */ + if (ptr_begins_static_str(choice, rootpass)) { + binary = "/usr/bin/reset_rootpass"; + } + if (ptr_begins_static_str(choice, userpass)) { + binary = "/usr/bin/reset_userpass"; + } + if (ptr_begins_static_str(choice, factory)) { + binary = "/usr/bin/clear_systemloop"; + } + if (ptr_begins_static_str(choice, backup)) { + binary = "/usr/bin/backup_systemloop"; + } + if (ptr_begins_static_str(choice, restore)) { + binary = "/usr/bin/restore_systemloop"; + } + if (ptr_begins_static_str(choice, badblocks)) { + binary = "/usr/bin/test_badblocks"; + } + if (ptr_begins_static_str(choice, upgrade)) { + binary = "/usr/bin/upgrade"; + } + if (binary) { int wait_status; suspend_to_console(); @@ -202,13 +277,13 @@ int main(int argc __attribute__ ((unused)), char **argv __attribute__ ((unused)) execve(child_argv[0], child_argv, env); printf("Can't execute binary (%s)\n<press Enter>\n", binary); - pause(); + PAUSE(); return 33; } while (wait4(-1, &wait_status, 0, NULL) != pid) {}; - printf("<press Enter to return to Rescue GUI>"); - pause(); + printf("<press Enter to return to Rescue menu>"); + PAUSE(); resume_from_suspend(); if (!WIFEXITED(wait_status) || WEXITSTATUS(wait_status) != 0) { error_message("Program exited abnormally (return code %d).", WEXITSTATUS(wait_status)); |
