summaryrefslogtreecommitdiffstats
path: root/isys
diff options
context:
space:
mode:
authorErik Troan <ewt@redhat.com>1999-05-05 17:17:58 +0000
committerErik Troan <ewt@redhat.com>1999-05-05 17:17:58 +0000
commit79ebb2cf474e61eebc6074752a95f072bc99c86f (patch)
tree1cc3192c7daeb644768e9deaa3516373e95da4b4 /isys
parentea77c9194962d9ba82b8a9f95de5ec4c24a6b612 (diff)
downloadanaconda-79ebb2cf474e61eebc6074752a95f072bc99c86f.tar.gz
anaconda-79ebb2cf474e61eebc6074752a95f072bc99c86f.tar.xz
anaconda-79ebb2cf474e61eebc6074752a95f072bc99c86f.zip
added lilo, filesystem magic
Diffstat (limited to 'isys')
-rw-r--r--isys/imount.c66
-rw-r--r--isys/imount.h8
-rw-r--r--isys/isys.c23
-rw-r--r--isys/isys.py3
4 files changed, 91 insertions, 9 deletions
diff --git a/isys/imount.c b/isys/imount.c
index fb2c9bae2..0d7e24d26 100644
--- a/isys/imount.c
+++ b/isys/imount.c
@@ -3,11 +3,15 @@
#include <string.h>
#include <sys/errno.h>
#include <sys/mount.h>
+#include <unistd.h>
#include "imount.h"
#define _(foo) foo
+static int mkdirChain(char * chain);
+static int mkdirIfNone(char * directory);
+
int doPwMount(char * dev, char * where, char * fs, int rdonly, int istty,
char * acct, char * pw) {
char * buf = NULL;
@@ -22,7 +26,7 @@ int doPwMount(char * dev, char * where, char * fs, int rdonly, int istty,
if (!strcmp(fs, "smb")) {
#if 0 /* disabled for now */
- /*mkdirChain(where);*/
+ mkdirChain(where);
if (!acct) acct = "guest";
if (!pw) pw = "";
@@ -33,7 +37,7 @@ int doPwMount(char * dev, char * where, char * fs, int rdonly, int istty,
while (*chptr && *chptr != ':') chptr++;
if (!*chptr) {
/*logMessage("bad smb mount point %s", where);*/
- return 0;
+ return IMOUNT_ERR_OTHER;
}
*chptr = '\0';
@@ -48,7 +52,8 @@ int doPwMount(char * dev, char * where, char * fs, int rdonly, int istty,
#endif
#endif /* disabled */
} else {
- /*mkdirChain(where);*/
+ if (mkdirChain(where))
+ return IMOUNT_ERR_ERRNO;
if (!isnfs && *dev == '/') {
buf = dev;
@@ -67,9 +72,9 @@ int doPwMount(char * dev, char * where, char * fs, int rdonly, int istty,
if (nfsmount(buf, where, &flags, &extra_opts, &mount_opt)) {
/*logMessage("\tnfsmount returned non-zero");*/
- fprintf(stderr, "nfs mount failed: %s\n",
- nfs_error());
- return 1;
+ /*fprintf(stderr, "nfs mount failed: %s\n",
+ nfs_error());*/
+ return IMOUNT_ERR_OTHER;
}
#endif
}
@@ -84,11 +89,56 @@ int doPwMount(char * dev, char * where, char * fs, int rdonly, int istty,
flag, mount_opt);*/
if (mount(buf, where, fs, flag, mount_opt)) {
- fprintf(stderr, "mount failed: %s\n", strerror(errno));
- return 1;
+ return IMOUNT_ERR_ERRNO;
}
}
return 0;
}
+static int mkdirChain(char * origChain) {
+ char * chain;
+ char * chptr;
+
+ chain = alloca(strlen(origChain) + 1);
+ strcpy(chain, origChain);
+ chptr = chain;
+
+ while ((chptr = strchr(chptr, '/'))) {
+ *chptr = '\0';
+ if (mkdirIfNone(chain)) {
+ *chptr = '/';
+ return IMOUNT_ERR_ERRNO;
+ }
+
+ *chptr = '/';
+ chptr++;
+ }
+
+ if (mkdirIfNone(chain))
+ return IMOUNT_ERR_ERRNO;
+
+ return 0;
+}
+
+static int mkdirIfNone(char * directory) {
+ int rc, mkerr;
+ char * chptr;
+
+ /* If the file exists it *better* be a directory -- I'm not going to
+ actually check or anything */
+ if (!access(directory, X_OK)) return 0;
+
+ /* if the path is '/' we get ENOFILE not found" from mkdir, rather
+ then EEXIST which is weird */
+ for (chptr = directory; *chptr; chptr++)
+ if (*chptr != '/') break;
+ if (!*chptr) return 0;
+
+ rc = mkdir(directory, 0755);
+ mkerr = errno;
+
+ if (!rc || mkerr == EEXIST) return 0;
+
+ return IMOUNT_ERR_ERRNO;
+}
diff --git a/isys/imount.h b/isys/imount.h
index 409fd2302..c7647ffab 100644
--- a/isys/imount.h
+++ b/isys/imount.h
@@ -1,2 +1,10 @@
+#ifndef H_IMOUNT
+#define H_IMOUNT
+
+#define IMOUNT_ERR_ERRNO 1
+#define IMOUNT_ERR_OTHER 2
+
int doPwMount(char * dev, char * where, char * fs, int rdonly, int istty,
char * acct, char * pw);
+
+#endif
diff --git a/isys/isys.c b/isys/isys.c
index 402d1e16a..8fba620ee 100644
--- a/isys/isys.c
+++ b/isys/isys.c
@@ -9,18 +9,39 @@
#include "imount.h"
static PyObject * doMount(PyObject * s, PyObject * args);
+static PyObject * doUMount(PyObject * s, PyObject * args);
static PyMethodDef balkanModuleMethods[] = {
{ "mount", (PyCFunction) doMount, METH_VARARGS, NULL },
+ { "umount", (PyCFunction) doUMount, METH_VARARGS, NULL },
{ NULL }
} ;
+static PyObject * doUMount(PyObject * s, PyObject * args) {
+ char * fs;
+
+ if (!PyArg_ParseTuple(args, "s", &fs)) return NULL;
+
+ if (umount(fs)) {
+ PyErr_SetFromErrno(PyExc_SystemError);
+ return NULL;
+ }
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
static PyObject * doMount(PyObject * s, PyObject * args) {
char * fs, * device, * mntpoint;
+ int rc;
if (!PyArg_ParseTuple(args, "sss", &fs, &device, &mntpoint)) return NULL;
- doPwMount(device, mntpoint, fs, 0, 0, NULL, NULL);
+ rc = doPwMount(device, mntpoint, fs, 0, 0, NULL, NULL);
+ if (rc == IMOUNT_ERR_ERRNO)
+ PyErr_SetFromErrno(PyExc_SystemError);
+ else if (rc)
+ PyErr_SetString(PyExc_SystemError, "mount failed");
Py_INCREF(Py_None);
return Py_None;
diff --git a/isys/isys.py b/isys/isys.py
index 7e9e4860d..44d2d6dde 100644
--- a/isys/isys.py
+++ b/isys/isys.py
@@ -2,3 +2,6 @@ import _isys
def mount(device, location, fstype = "ext2"):
return _isys.mount(fstype, device, location)
+
+def umount(what):
+ return _isys.umount(what)