From cc92e5a32bb9ac4e11a965e276e9535fb76a4371 Mon Sep 17 00:00:00 2001 From: Chris Lumens Date: Tue, 22 Jan 2008 16:50:08 -0500 Subject: Use the mount program instead of our own code. Also change isys's mount function to take its arguments as a string like would be passed to the mount program, instead of a handful of flags. --- isys/imount.c | 107 +++++++++++++++++++++++---------------------------- isys/imount.h | 2 +- isys/isys.c | 18 +++------ isys/isys.py | 14 ++++++- loader2/cdinstall.c | 6 +-- loader2/driverdisk.c | 21 +++++----- loader2/hdinstall.c | 2 +- loader2/loader.c | 6 +-- loader2/method.c | 18 ++++----- loader2/nfsinstall.c | 11 +++--- 10 files changed, 97 insertions(+), 108 deletions(-) diff --git a/isys/imount.c b/isys/imount.c index 5f0a30447..a167c03c1 100644 --- a/isys/imount.c +++ b/isys/imount.c @@ -1,7 +1,7 @@ /* * imount.c * - * Copyright (C) 2007 Red Hat, Inc. All rights reserved. + * Copyright (C) 2007, 2008 Red Hat, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "imount.h" @@ -33,69 +34,59 @@ static int mkdirIfNone(char * directory); -int doPwMount(char * dev, char * where, char * fs, int options, void *data) { - char * buf = NULL; - int isnfs = 0; - char * mount_opt = NULL; - long int flag; - char * chptr __attribute__ ((unused)); - - if (!strcmp(fs, "nfs")) isnfs = 1; +int doPwMount(char *dev, char *where, char *fs, char *options) { + int rc, child, status; + char *opts = NULL; - /*logMessage(INFO, "mounting %s on %s as type %s", dev, where, fs);*/ - - if (mkdirChain(where)) + if (mkdirChain(where)) { return IMOUNT_ERR_ERRNO; + } + + if (strstr(fs, "nfs")) { + if (options) + rc = asprintf(&opts, "%s,nolock", options); + else + opts = strdup("nolock"); + } + else if (options) { + opts = strdup(options); + } - flag = MS_MGC_VAL; - if (options & IMOUNT_RDONLY) - flag |= MS_RDONLY; - if (options & IMOUNT_BIND) - flag |= MS_BIND; - if (options & IMOUNT_REMOUNT) - flag |= MS_REMOUNT; - - if (!isnfs && (*dev == '/' || !strcmp(dev, "none"))) { - buf = dev; - } else if (!isnfs) { - buf = alloca(200); - strcpy(buf, "/dev/"); - strcat(buf, dev); - } else { -#ifndef DISABLE_NETWORK - char * extra_opts = NULL; - int flags = 0; - - if (data) - extra_opts = strdup(data); - - buf = dev; - /*logMessage(INFO, "calling nfsmount(%s, %s, &flags, &extra_opts, &mount_opt)", - buf, where);*/ - - if (nfsmount(buf, where, &flags, &extra_opts, &mount_opt, 0)) { - /*logMessage(INFO, "\tnfsmount returned non-zero");*/ - /*fprintf(stderr, "nfs mount failed: %s\n", - nfs_error());*/ - return IMOUNT_ERR_OTHER; + if (!(child = fork())) { + int fd; + + /* Close off all these filehandles since we don't want errors + * spewed to tty1. + */ + fd = open("/dev/null", O_RDONLY); + close(STDIN_FILENO); + dup2(fd, STDIN_FILENO); + close(fd); + + fd = open("/dev/null", O_WRONLY); + close(STDOUT_FILENO); + dup2(fd, STDOUT_FILENO); + close(STDERR_FILENO); + dup2(fd, STDERR_FILENO); + close(fd); + + if (opts) { + rc = execl("/bin/mount", + "/bin/mount", "-t", fs, "-o", opts, dev, where, NULL); + exit(1); + } + else { + rc = execl("/bin/mount", "/bin/mount", "-t", fs, dev, where, NULL); + exit(1); } -#endif - } - if (!strncmp(fs, "vfat", 4)) - mount_opt="check=relaxed"; -#ifdef __sparc__ - if (!strncmp(fs, "ufs", 3)) - mount_opt="ufstype=sun"; -#endif - - /*logMessage(INFO, "calling mount(%s, %s, %s, %ld, %p)", buf, where, fs, - flag, mount_opt);*/ - - if (mount(buf, where, fs, flag, mount_opt)) { - /*logMessage(ERROR, "mount failed: %s", strerror(errno));*/ - return IMOUNT_ERR_ERRNO; } + waitpid(child, &status, 0); + + free(opts); + if (status) + return IMOUNT_ERR_OTHER; + return 0; } diff --git a/isys/imount.h b/isys/imount.h index 4870c2787..50ee11600 100644 --- a/isys/imount.h +++ b/isys/imount.h @@ -29,7 +29,7 @@ #define IMOUNT_BIND 2 #define IMOUNT_REMOUNT 4 -int doPwMount(char * dev, char * where, char * fs, int options, void * data); +int doPwMount(char *dev, char *where, char *fs, char *options); int mkdirChain(char * origChain); #endif diff --git a/isys/isys.c b/isys/isys.c index dcfa428ff..37d5d6b98 100644 --- a/isys/isys.c +++ b/isys/isys.c @@ -71,7 +71,7 @@ #include #include "iface.h" -#include "imount.h" +#include "nl.h" #include "isys.h" #include "net.h" #include "smp.h" @@ -435,21 +435,13 @@ static PyObject * doUMount(PyObject * s, PyObject * args) { } static PyObject * doMount(PyObject * s, PyObject * args) { - char * fs, * device, * mntpoint; + char *fs, *device, *mntpoint, *flags; int rc; - int readOnly = 0; - int bindMount = 0; - int reMount = 0; - int flags = 0; - if (!PyArg_ParseTuple(args, "sssiii", &fs, &device, &mntpoint, - &readOnly, &bindMount, &reMount)) return NULL; + if (!PyArg_ParseTuple(args, "ssss", &fs, &device, &mntpoint, + &flags)) return NULL; - if (readOnly) flags |= IMOUNT_RDONLY; - if (bindMount) flags |= IMOUNT_BIND; - if (reMount) flags |= IMOUNT_REMOUNT; - - rc = doPwMount(device, mntpoint, fs, flags, NULL); + rc = doPwMount(device, mntpoint, fs, flags); if (rc == IMOUNT_ERR_ERRNO) PyErr_SetFromErrno(PyExc_SystemError); else if (rc) diff --git a/isys/isys.py b/isys/isys.py index e5d191659..e9b974291 100755 --- a/isys/isys.py +++ b/isys/isys.py @@ -308,6 +308,7 @@ def ddfile(file, megs, pw = None): # @param remount Are we mounting an already mounted filesystem? # @return The return value from the mount system call. def mount(device, location, fstype = "ext2", readOnly = 0, bindMount = 0, remount = 0): + flags = None location = os.path.normpath(location) # We don't need to create device nodes for devices that start with '/' @@ -321,8 +322,19 @@ def mount(device, location, fstype = "ext2", readOnly = 0, bindMount = 0, remoun mountCount[location] = mountCount[location] + 1 return + if readOnly or bindMount or remount: + opts = [] + if readOnly: + opts.append("ro") + if bindMount: + opts.append("bind") + if remount: + opts.append("remount") + + flags = "-o " + ",".join(opts) + log.debug("isys.py:mount()- going to mount %s on %s" %(device, location)) - rc = _isys.mount(fstype, device, location, readOnly, bindMount, remount) + rc = _isys.mount(fstype, device, location, flags) if not rc: mountCount[location] = 1 diff --git a/loader2/cdinstall.c b/loader2/cdinstall.c index 02addff59..9ac338cd4 100644 --- a/loader2/cdinstall.c +++ b/loader2/cdinstall.c @@ -160,8 +160,7 @@ static void mountCdromStage2(char *cddev, char *location) { do { do { - if (doPwMount(cddev, location, - "iso9660", IMOUNT_RDONLY, NULL)) { + if (doPwMount(cddev, location, "iso9660", "ro")) { ejectCdrom(cddev); wrongCDMessage(); } else { @@ -261,8 +260,7 @@ char * setupCdrom(char * location, struct loaderData_s * loaderData, logMessage(INFO,"trying to mount CD device %s on %s", devices[i]->device, location); - if (!(rc=doPwMount(devices[i]->device, location, "iso9660", - IMOUNT_RDONLY, NULL))) { + if (!(rc=doPwMount(devices[i]->device, location, "iso9660", "ro"))) { cddev = devices[i]->device; if (!access(stage2loc, R_OK) && (!requirepkgs || !access(discinfoloc, R_OK))) { diff --git a/loader2/driverdisk.c b/loader2/driverdisk.c index 1ef83e3ca..9672e59d9 100644 --- a/loader2/driverdisk.c +++ b/loader2/driverdisk.c @@ -293,9 +293,9 @@ int loadDriverFromMedia(int class, struct loaderData_s *loaderData, } logMessage(INFO, "trying to mount %s as partition", part); - if (doPwMount(part, "/tmp/dpart", "vfat", IMOUNT_RDONLY, NULL)) { - if (doPwMount(part, "/tmp/dpart", "ext2", IMOUNT_RDONLY, NULL)) { - if (doPwMount(part, "/tmp/dpart", "iso9660", IMOUNT_RDONLY, NULL)) { + if (doPwMount(part, "/tmp/dpart", "vfat", "ro")) { + if (doPwMount(part, "/tmp/dpart", "ext2", "ro")) { + if (doPwMount(part, "/tmp/dpart", "iso9660", "ro")) { newtWinMessage(_("Error"), _("OK"), _("Failed to mount partition.")); stage = DEV_PART; @@ -359,9 +359,9 @@ int loadDriverFromMedia(int class, struct loaderData_s *loaderData, dir = 1; logMessage(INFO, "trying to mount %s", device); - if (doPwMount(device, "/tmp/drivers", "vfat", IMOUNT_RDONLY, NULL)) { - if (doPwMount(device, "/tmp/drivers", "ext2", IMOUNT_RDONLY, NULL)) { - if (doPwMount(device, "/tmp/drivers", "iso9660", IMOUNT_RDONLY, NULL)) { + if (doPwMount(device, "/tmp/drivers", "vfat", "ro")) { + if (doPwMount(device, "/tmp/drivers", "ext2", "ro")) { + if (doPwMount(device, "/tmp/drivers", "iso9660", "ro")) { newtWinMessage(_("Error"), _("OK"), _("Failed to mount driver disk.")); stage = DEV_INSERT; @@ -611,14 +611,13 @@ void useKickstartDD(struct loaderData_s * loaderData, static void getDDFromDev(struct loaderData_s * loaderData, char * dev, char * fstype) { if (fstype) { - if (doPwMount(dev, "/tmp/drivers", fstype, - IMOUNT_RDONLY, NULL)) { + if (doPwMount(dev, "/tmp/drivers", fstype, "ro")) { logMessage(ERROR, "unable to mount %s as %s", dev, fstype); return; } - } else if (doPwMount(dev, "/tmp/drivers", "vfat", IMOUNT_RDONLY, NULL)) { - if (doPwMount(dev, "/tmp/drivers", "ext2", IMOUNT_RDONLY, NULL)) { - if (doPwMount(dev, "/tmp/drivers", "iso9660", IMOUNT_RDONLY, NULL)) { + } else if (doPwMount(dev, "/tmp/drivers", "vfat", "ro")) { + if (doPwMount(dev, "/tmp/drivers", "ext2", "ro")) { + if (doPwMount(dev, "/tmp/drivers", "iso9660", "ro")) { logMessage(ERROR, "unable to mount driver disk %s", dev); return; } diff --git a/loader2/hdinstall.c b/loader2/hdinstall.c index dd928478f..a5dcb53f5 100644 --- a/loader2/hdinstall.c +++ b/loader2/hdinstall.c @@ -155,7 +155,7 @@ static char * setupIsoImages(char * device, char * dirName, char * location) { /* XXX try to mount as ext2 and then vfat */ for (type=typetry; *type; type++) { - if (!doPwMount(device, "/mnt/isodir", *type, IMOUNT_RDONLY, NULL)) + if (!doPwMount(device, "/mnt/isodir", *type, "ro")) break; } diff --git a/loader2/loader.c b/loader2/loader.c index 30b4c83b2..9839fec6e 100644 --- a/loader2/loader.c +++ b/loader2/loader.c @@ -439,10 +439,8 @@ void loadUpdates(struct loaderData_s *loaderData) { logMessage(INFO, "UPDATES device is %s", part); - if (doPwMount(part, "/tmp/update-disk", "ext2", - IMOUNT_RDONLY, NULL) && - doPwMount(part, "/tmp/update-disk", "iso9660", - IMOUNT_RDONLY, NULL)) { + if (doPwMount(part, "/tmp/update-disk", "ext2", "ro") && + doPwMount(part, "/tmp/update-disk", "iso9660", "ro")) { newtWinMessage(_("Error"), _("OK"), _("Failed to mount updates disk")); } else { diff --git a/loader2/method.c b/loader2/method.c index 26e6e426f..c23479de6 100644 --- a/loader2/method.c +++ b/loader2/method.c @@ -127,11 +127,11 @@ int mountLoopback(char * fsystem, char * mntpoint, char * device) { /* FIXME: really, mountLoopback() should take a list of "valid" * filesystems for the specific type of image being mounted */ - if (doPwMount(device, mntpoint, "iso9660", IMOUNT_RDONLY, NULL)) { - if (doPwMount(device, mntpoint, "ext2", IMOUNT_RDONLY, NULL)) { - if (doPwMount(device, mntpoint, "squashfs", IMOUNT_RDONLY, NULL)) { - if (doPwMount(device, mntpoint, "cramfs", IMOUNT_RDONLY, NULL)) { - if (doPwMount(device, mntpoint, "vfat", IMOUNT_RDONLY, NULL)) { + if (doPwMount(device, mntpoint, "iso9660", "ro")) { + if (doPwMount(device, mntpoint, "ext2", "ro")) { + if (doPwMount(device, mntpoint, "squashfs", "ro")) { + if (doPwMount(device, mntpoint, "cramfs", "ro")) { + if (doPwMount(device, mntpoint, "vfat", "ro")) { logMessage(ERROR, "failed to mount loop: %s", strerror(errno)); loopfd = open(device, O_RDONLY); ioctl(loopfd, LOOP_CLR_FD, 0); @@ -219,7 +219,7 @@ int readStampFileFromIso(char *file, char **timestamp, char **releasedescr) { lstat(file, &sb); if (S_ISBLK(sb.st_mode)) { filetype = 1; - if (doPwMount(file, "/tmp/testmnt", "iso9660", IMOUNT_RDONLY, NULL)) { + if (doPwMount(file, "/tmp/testmnt", "iso9660", "ro")) { logMessage(ERROR, "Failed to mount device %s to get description", file); return -1; @@ -628,9 +628,9 @@ int getFileFromBlockDevice(char *device, char *path, char * dest) { logMessage(INFO, "getFileFromBlockDevice(%s, %s)", device, path); - if (doPwMount(device, "/tmp/mnt", "vfat", IMOUNT_RDONLY, NULL) && - doPwMount(device, "/tmp/mnt", "ext2", IMOUNT_RDONLY, NULL) && - doPwMount(device, "/tmp/mnt", "iso9660", IMOUNT_RDONLY, NULL)) { + if (doPwMount(device, "/tmp/mnt", "vfat", "ro") && + doPwMount(device, "/tmp/mnt", "ext2", "ro") && + doPwMount(device, "/tmp/mnt", "iso9660", "ro")) { logMessage(ERROR, "failed to mount /dev/%s: %s", device, strerror(errno)); return 2; diff --git a/loader2/nfsinstall.c b/loader2/nfsinstall.c index 5d27048f3..aaa889d81 100644 --- a/loader2/nfsinstall.c +++ b/loader2/nfsinstall.c @@ -105,7 +105,8 @@ char * mountNfsImage(struct installMethod * method, if (loaderData->method == METHOD_NFS && loaderData->methodData) { host = ((struct nfsInstallData *)loaderData->methodData)->host; directory = ((struct nfsInstallData *)loaderData->methodData)->directory; - mountOpts = ((struct nfsInstallData *)loaderData->methodData)->mountOpts; + + rc = asprintf(&mountOpts, "ro,%s", ((struct nfsInstallData *) loaderData->methodData)->mountOpts); logMessage(INFO, "host is %s, dir is %s, opts are '%s'", host, directory, mountOpts); @@ -153,8 +154,7 @@ char * mountNfsImage(struct installMethod * method, stage = NFS_STAGE_NFS; - if (!doPwMount(fullPath, "/mnt/source", "nfs", - IMOUNT_RDONLY, mountOpts)) { + if (!doPwMount(fullPath, "/mnt/source", "nfs", mountOpts)) { if (!access("/mnt/source/images/stage2.img", R_OK)) { logMessage(INFO, "can access /mnt/source/images/stage2.img"); /* try to see if we're booted off of a CD with stage2 */ @@ -189,8 +189,7 @@ char * mountNfsImage(struct installMethod * method, * again. */ umount("/mnt/source"); - if (!doPwMount(fullPath, "/mnt/isodir", "nfs", IMOUNT_RDONLY, - mountOpts)) { + if (!doPwMount(fullPath, "/mnt/isodir", "nfs", mountOpts)) { } else { newtWinMessage(_("Error"), _("OK"), _("That directory could not be mounted from " @@ -395,7 +394,7 @@ int getFileFromNfs(char * url, char * dest, struct loaderData_s * loaderData) { logMessage(INFO, "file location: nfs://%s/%s", host, file); - if (!doPwMount(host, "/tmp/mnt", "nfs", IMOUNT_RDONLY, opts)) { + if (!doPwMount(host, "/tmp/mnt", "nfs", opts)) { char * buf; i = asprintf(&buf, "/tmp/mnt/%s", file); -- cgit