summaryrefslogtreecommitdiffstats
path: root/isys
diff options
context:
space:
mode:
authorChris Lumens <clumens@redhat.com>2008-01-22 16:50:08 -0500
committerChris Lumens <clumens@redhat.com>2008-02-11 10:44:54 -0500
commitcc92e5a32bb9ac4e11a965e276e9535fb76a4371 (patch)
treee4d8eb9a64f1e7533aa3d2b71b497c8078a825da /isys
parentb97a8e70331e71559e08a684195904c5cb824408 (diff)
downloadanaconda-cc92e5a32bb9ac4e11a965e276e9535fb76a4371.tar.gz
anaconda-cc92e5a32bb9ac4e11a965e276e9535fb76a4371.tar.xz
anaconda-cc92e5a32bb9ac4e11a965e276e9535fb76a4371.zip
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.
Diffstat (limited to 'isys')
-rw-r--r--isys/imount.c107
-rw-r--r--isys/imount.h2
-rw-r--r--isys/isys.c18
-rwxr-xr-xisys/isys.py14
4 files changed, 68 insertions, 73 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 <sys/mount.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/wait.h>
#include <unistd.h>
#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 <blkid/blkid.h>
#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