📄 hdinstall.c
字号:
/* * hdinstall.c - code to set up hard drive installs * * Erik Troan <ewt@redhat.com> * Matt Wilson <msw@redhat.com> * Michael Fulbright <msf@redhat.com> * Jeremy Katz <katzj@redhat.com> * * Copyright 1997 - 2003 Red Hat, Inc. * * This software may be freely redistributed under the terms of the GNU * General Public License. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#include <ctype.h>#include <errno.h>#include <fcntl.h>#include <newt.h>#include <popt.h>#include <stdlib.h>#include <string.h>#include <sys/mount.h>#include <unistd.h>#include "driverdisk.h"#include "hdinstall.h"#include "getparts.h"#include "kickstart.h"#include "loader.h"#include "loadermisc.h"#include "log.h"#include "lang.h"#include "modules.h"#include "method.h"#include "mediacheck.h"#include "../isys/imount.h"#include "../isys/isys.h"#include "../isys/eddsupport.h"/* boot flags */extern int flags;/* pull in second stage image for hard drive install */static int loadHDImages(char * prefix, char * dir, char * device, char * mntpoint) { int fd, rc, idx; char *path, *target, *dest; char *stg2list[] = {"stage2.img", "minstg2.img", NULL}; path = alloca(50 + strlen(prefix) + (dir ? strlen(dir) : 2)); if (totalMemory() < 128000) idx = 1; else idx = 0; target = NULL; for (; stg2list[idx]; idx++) { target = stg2list[idx]; sprintf(path, "%s/%s/images/%s", prefix, dir ? dir : "", target); logMessage(INFO, "Looking for hd stage2 image %s", path); if (!access(path, F_OK)) break; logMessage(INFO, "%s does not exist: %s, trying next target", path, strerror(errno)); } if (!target) { logMessage(ERROR, "failed to find hd stage 2 image%s: %s", path, strerror(errno)); return 1; } logMessage(INFO, "Found hd stage2, copying %s in RAM as stage2", path); if ((fd = open(path, O_RDONLY)) < 0) { logMessage(ERROR, "failed to open %s: %s", path, strerror(errno)); return 1; } /* 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 : ""); copyUpdatesImg(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 : ""); copyProductImg(path); dest = alloca(strlen(target) + 50); sprintf(dest,"/tmp/ramfs/%s", target); rc = copyFileAndLoopbackMount(fd, dest, device, mntpoint); close(fd); if (!verifyStamp(mntpoint)) { char * buf; buf = sdupprintf(_("The %s installation tree in that directory does " "not seem to match your boot media."), getProductName()); newtWinMessage(_("Error"), _("OK"), buf); umountLoopback(mntpoint, device); return 1; } return rc;}/* given a partition device and directory, tries to mount hd install image */static char * setupIsoImages(char * device, char * dirName) { int rc; char * url; char filespec[1024]; char * path; char *typetry[] = {"ext3", "ext2", "vfat", NULL}; char **type; logMessage(INFO, "mounting device %s for hard drive install", device); if (!FL_TESTING(flags)) { if (devMakeInode(device, "/tmp/hddev")) logMessage(WARNING, "devMakeInode failed!"); /* XXX try to mount as ext2 and then vfat */ for (type=typetry; *type; type++) { if (!doPwMount("/tmp/hddev", "/tmp/hdimage", *type, IMOUNT_RDONLY, NULL)) break; } if (!type) return NULL; sprintf(filespec, "/tmp/hdimage/%s", dirName); if ((path = validIsoImages(filespec, 0))) { char updpath[4096]; logMessage(INFO, "Path to valid iso is %s", path); snprintf(updpath, sizeof(updpath), "%s/updates.img", filespec); logMessage(INFO, "Looking for updates for HD in %s", updpath); copyUpdatesImg(updpath); rc = mountLoopback(path, "/tmp/loopimage", "loop0"); if (!rc) { /* This code is for copying small stage2 into ram */ /* and mounting */ rc = loadHDImages("/tmp/loopimage", "/", "loop1", "/mnt/runtime"); if (rc) { newtWinMessage(_("Error"), _("OK"), _("An error occured reading the install " "from the ISO images. Please check your ISO " "images and try again.")); } else { queryIsoMediaCheck(path); } } /* we copied stage2 into RAM so we can now umount image */ umountLoopback("/tmp/loopimage", "loop0"); } else { rc = 1; } /* we copied stage2 into RAM so now umount partition */ umount("/tmp/hdimage"); if (rc) 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;}/* setup hard drive based install from a partition with a filesystem and * ISO images on that filesystem */char * mountHardDrive(struct installMethod * method, char * location, struct loaderData_s * loaderData, moduleInfoSet modInfo, moduleList modLoaded, moduleDeps * modDepsPtr) { int rc; int i; newtComponent listbox, label, dirEntry, form, okay, back, text; struct newtExitStruct es; newtGrid entryGrid, grid, buttons; int done = 0; char * dir = strdup(""); char * tmpDir; char * url = NULL; char * buf; int numPartitions; char **partition_list; char *selpart; char *kspartition, *ksdirectory; /* handle kickstart data first if available */ if (loaderData->method == METHOD_HD && loaderData->methodData) { kspartition = ((struct hdInstallData *)loaderData->methodData)->partition; ksdirectory = ((struct hdInstallData *)loaderData->methodData)->directory; logMessage(INFO, "partition is %s, dir is %s", kspartition, ksdirectory); /* if exist, duplicate */ if (kspartition) kspartition = strdup(kspartition); if (ksdirectory) ksdirectory = strdup(ksdirectory); if (!kspartition || !ksdirectory) { logMessage(ERROR, "missing partition or directory specification"); loaderData->method = -1; } else { /* if we start with /dev, strip it (#121486) */ char *kspart = kspartition; if (!strncmp(kspart, "/dev/", 5)) kspart = kspart + 5; url = setupIsoImages(kspart, ksdirectory); if (!url) { logMessage(ERROR, "unable to find %s installation images on hd", getProductName()); loaderData->method = -1; } else { free(kspartition); free(ksdirectory); return url; } } } else { kspartition = NULL; ksdirectory = NULL; } /* if we're here its either because this is interactive, or the */ /* hd kickstart directive was faulty and we have to prompt for */ /* location of harddrive image */ partition_list = NULL; while (!done) { /* if we're doing another pass free this up first */ if (partition_list) freePartitionsList(partition_list); partition_list = getPartitionsList(NULL); numPartitions = lenPartitionsList(partition_list); /* no partitions found, try to load a device driver disk for storage */ if (!numPartitions) { rc = newtWinChoice(_("Hard Drives"), _("Yes"), _("Back"), _("You don't seem to have any hard drives on " "your system! Would you like to configure " "additional devices?")); if (rc == 2) return NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -