--- loader2/hdinstall.c | 90 ++++++++++++++++++++++++++++++++------------------ 1 files changed, 57 insertions(+), 33 deletions(-) diff --git a/loader2/hdinstall.c b/loader2/hdinstall.c index 7780df6..4c3d851 100644 --- a/loader2/hdinstall.c +++ b/loader2/hdinstall.c @@ -58,12 +58,10 @@ extern uint64_t flags; static int loadHDImages(char * prefix, char * dir, char * device, char * mntpoint, char * location) { - int fd = 0, rc, idx; + int fd = 0, rc, idx, tmp; char *path, *target = NULL, *dest, *cdurl = NULL; char *stg2list[] = {"stage2.img", "minstg2.img", NULL}; - path = alloca(50 + strlen(prefix) + (dir ? strlen(dir) : 2)); - if (totalMemory() < 128000) idx = 1; else @@ -88,9 +86,9 @@ static int loadHDImages(char * prefix, char * dir, target = stg2list[idx]; if (!dir || (dir && (!strcmp(dir, "/") || strcmp(dir, "")))) - sprintf(path, "%s/images/%s", prefix, target); + tmp = asprintf(&path, "%s/images/%s", prefix, target); else - sprintf(path, "%s/%s/images/%s", prefix, dir ? dir : "", target); + tmp = asprintf(&path, "%s/%s/images/%s", prefix, dir ? dir : "", target); logMessage(INFO, "Looking for hd stage2 image %s", path); if (!access(path, F_OK)) @@ -111,15 +109,19 @@ static int loadHDImages(char * prefix, char * dir, } } + free(path); + /* handle updates.img now before we copy stage2 over... this allows * us to keep our ramdisk size as small as possible */ - sprintf(path, "%s/%s/images/updates.img", prefix, dir ? dir : ""); + tmp = asprintf(&path, "%s/%s/images/updates.img", prefix, dir ? dir : ""); copyUpdatesImg(path); + free(path); /* handle product.img now before we copy stage2 over... this allows * us to keep our ramdisk size as small as possible */ - sprintf(path, "%s/%s/images/product.img", prefix, dir ? dir : ""); + tmp = asprintf(&path, "%s/%s/images/product.img", prefix, dir ? dir : ""); copyProductImg(path); + free(path); if (!cdurl) { dest = alloca(strlen(target) + 50); @@ -133,7 +135,7 @@ static int loadHDImages(char * prefix, char * dir, _("The %s installation tree in that directory does " "not seem to match your boot media."), getProductName()); - + newtWinMessage(_("Error"), _("OK"), buf); free(buf); umountLoopback(mntpoint, device); @@ -147,16 +149,14 @@ static int loadHDImages(char * prefix, char * dir, /* given a partition device and directory, tries to mount hd install image */ static char * setupIsoImages(char * device, char * dirName, char * location) { int rc; - char * url; - char filespec[1024]; - char * path; + char *url = NULL, *filespec, *updpath; + char *path; char *typetry[] = {"ext3", "ext2", "vfat", NULL}; char **type; logMessage(INFO, "mounting device %s for hard drive install", device); if (!FL_TESTING(flags)) { - /* XXX try to mount as ext2 and then vfat */ for (type=typetry; *type; type++) { if (!doPwMount(device, "/mnt/isodir", *type, "ro")) @@ -166,20 +166,46 @@ static char * setupIsoImages(char * device, char * dirName, char * location) { if (!type) return NULL; - if (*dirName == '/') - sprintf(filespec, "/mnt/isodir%s", dirName); - else - sprintf(filespec, "/mnt/isodir/%s", dirName); + if (FL_STAGE2(flags)) { + rc = asprintf(&filespec, "/mnt/isodir%.*s", (int) (strrchr(dirName, '/') - dirName), dirName); + path = strdup(filespec); + } else { + path = validIsoImages(filespec, 0); - if ((path = validIsoImages(filespec, 0))) { - char updpath[4096]; + if (*dirName == '/') + rc = asprintf(&filespec, "/mnt/isodir%s", dirName); + else + rc = asprintf(&filespec, "/mnt/isodir/%s", dirName); + } + if (path) { logMessage(INFO, "Path to valid iso is %s", path); - snprintf(updpath, sizeof(updpath), "%s/updates.img", filespec); + rc = asprintf(&updpath, "%s/updates.img", filespec); logMessage(INFO, "Looking for updates for HD in %s", updpath); copyUpdatesImg(updpath); + free(updpath); + free(filespec); + + if (FL_STAGE2(flags)) { + if (!copyFile(dirName, "/tmp/stage2.img")) { + rc = mountStage2("/tmp/stage2.img", dirName); + umount("/mnt/isodir"); + + if (rc) { + umountLoopback("/mnt/runtime", "/dev/loop0"); + goto err; + } else { + return url; + } + } + else { + umount("/mnt/isodir"); + goto err; + } + } + rc = mountLoopback(path, "/mnt/source", "/dev/loop1"); if (!rc) { /* This code is for copying small stage2 into ram */ @@ -187,33 +213,31 @@ static char * setupIsoImages(char * device, char * dirName, char * location) { rc = loadHDImages("/mnt/source", "/", "/dev/loop0", "/mnt/runtime", location); if (rc) { - newtWinMessage(_("Error"), _("OK"), - _("An error occured reading the install " - "from the ISO images. Please check your ISO " - "images and try again.")); umountLoopback("/mnt/source", "/dev/loop0"); umount("/mnt/isodir"); + goto err; } else { queryIsoMediaCheck(path); + return url; } } } else { - rc = 1; - } - - if (rc) { - umount("/mnt/isodir"); - return NULL; + if (rc) { + umount("/mnt/isodir"); + return NULL; + } } } else { /* in test mode I dont know what to do - just pretend I guess */ type = typetry; } - url = malloc(50 + strlen(dirName ? dirName : "")); - sprintf(url, "hd://%s:%s:/%s", device, *type, dirName ? dirName : "."); - - return url; +err: + newtWinMessage(_("Error"), _("OK"), + _("An error occured reading the install " + "from the ISO images. Please check your ISO " + "images and try again.")); + return NULL; } /* setup hard drive based install from a partition with a filesystem and -- 1.5.3.7 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list