diff options
Diffstat (limited to 'mdk-stage1/tools.c')
| -rw-r--r-- | mdk-stage1/tools.c | 105 |
1 files changed, 30 insertions, 75 deletions
diff --git a/mdk-stage1/tools.c b/mdk-stage1/tools.c index 4a3f0c067..2e27688ea 100644 --- a/mdk-stage1/tools.c +++ b/mdk-stage1/tools.c @@ -1,7 +1,7 @@ /* - * Guillaume Cottenceau (gc@mandrakesoft.com) + * Guillaume Cottenceau (gc) * - * Copyright 2000 Mandrakesoft + * Copyright 2000 Mandriva * * This software may be freely redistributed under the terms of the GNU * public license. @@ -53,6 +53,26 @@ int image_has_stage2() access(IMAGE_LOCATION "/" LIVE_LOCATION_REL, R_OK) == 0; } +enum return_type create_IMAGE_LOCATION(char *location_full) +{ + struct stat statbuf; + int offset = strncmp(location_full, IMAGE_LOCATION_DIR, sizeof(IMAGE_LOCATION_DIR) - 1) == 0 ? sizeof(IMAGE_LOCATION_DIR) - 1 : 0; + char *with_arch = asprintf_("%s/%s", location_full, ARCH); + + log_message("trying %s", with_arch); + + if (stat(with_arch, &statbuf) == 0 && S_ISDIR(statbuf.st_mode)) + location_full = with_arch; + + log_message("assuming %s is a mirror tree", location_full + offset); + + unlink(IMAGE_LOCATION); + if (symlink(location_full + offset, IMAGE_LOCATION) != 0) + return RETURN_ERROR; + + return RETURN_OK; +} + int ramdisk_possible(void) { if (total_memory() > (IS_RESCUE ? MEM_LIMIT_RESCUE : MEM_LIMIT_DRAKX)) @@ -128,65 +148,6 @@ enum return_type copy_file(char * from, char * to, void (*callback_func)(int ove } } -enum return_type recursiveRemove(char *file) -{ - struct stat sb; - - if (lstat(file, &sb) != 0) { - log_message("failed to stat %s: %d", file, errno); - return RETURN_ERROR; - } - - /* only descend into subdirectories if device is same as dir */ - if (S_ISDIR(sb.st_mode)) { - char * strBuf = alloca(strlen(file) + 1024); - DIR * dir; - struct dirent * d; - - if (!(dir = opendir(file))) { - log_message("error opening %s: %d", file, errno); - return RETURN_ERROR; - } - while ((d = readdir(dir))) { - if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) - continue; - - strcpy(strBuf, file); - strcat(strBuf, "/"); - strcat(strBuf, d->d_name); - - if (recursiveRemove(strBuf) != 0) { - closedir(dir); - return RETURN_ERROR; - } - } - closedir(dir); - - if (rmdir(file)) { - log_message("failed to rmdir %s: %d", file, errno); - return RETURN_ERROR; - } - } else { - if (unlink(file) != 0) { - log_message("failed to remove %s: %d", file, errno); - return RETURN_ERROR; - } - } - return RETURN_OK; -} - -enum return_type recursiveRemove_if_it_exists(char *file) -{ - struct stat sb; - - if (lstat(file, &sb) != 0) { - /* if file doesn't exist, simply return OK */ - return RETURN_OK; - } - - return recursiveRemove(file); -} - enum return_type mount_compressed_image(char *compressed_image, char *location_mount) { if (lomount(compressed_image, location_mount, NULL, 1)) { @@ -252,13 +213,7 @@ int try_mount(char * dev, char * location) char device_fullname[50]; snprintf(device_fullname, sizeof(device_fullname), "/dev/%s", dev); - if (my_mount(device_fullname, location, "ext2", 0) == -1 && - my_mount(device_fullname, location, "vfat", 0) == -1 && - my_mount(device_fullname, location, "ntfs", 0) == -1 && - my_mount(device_fullname, location, "reiserfs", 0) == -1 && - my_mount(device_fullname, location, "jfs", 0) == -1 && - my_mount(device_fullname, location, "xfs", 0) == -1 && - my_mount(device_fullname, location, "iso9660", 0) == -1) { + if (my_mount(device_fullname, location, "auto", 0) == -1) { return 1; } @@ -271,8 +226,8 @@ int get_disks(char *** names, char *** models) char ** ptr; int count = 0; - my_insmod("ide-disk", ANY_DRIVER_TYPE, NULL, 0); - my_insmod("sd_mod", ANY_DRIVER_TYPE, NULL, 0); + my_modprobe("ide_disk", ANY_DRIVER_TYPE, NULL); + my_modprobe("sd_mod", ANY_DRIVER_TYPE, NULL); get_medias(DISK, names, models, BUS_ANY); @@ -292,8 +247,8 @@ 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); + my_modprobe("ide_cd_mod", ANY_DRIVER_TYPE, NULL); + my_modprobe("sr_mod", ANY_DRIVER_TYPE, NULL); get_medias(CDROM, names, models, BUS_ANY); @@ -311,7 +266,7 @@ char * floppy_device(void) { char ** names, ** models; int fd; - my_insmod("floppy", ANY_DRIVER_TYPE, NULL, 0); + my_modprobe("floppy", ANY_DRIVER_TYPE, NULL); fd = open("/dev/fd0", O_RDONLY|O_NONBLOCK); if (fd != -1) { char drivtyp[17]; @@ -331,10 +286,10 @@ char * floppy_device(void) close(fd); } log_message("seems that you don't have a regular floppy drive"); - my_insmod("sd_mod", ANY_DRIVER_TYPE, NULL, 0); + my_modprobe("sd_mod", ANY_DRIVER_TYPE, NULL); get_medias(FLOPPY, &names, &models, BUS_ANY); if (names && *names) return asprintf_("/dev/%s", *names); else - return "/dev/fd0"; + return NULL; } |
