diff options
-rw-r--r-- | isys/isys.c | 30 | ||||
-rw-r--r-- | isys/isys.py | 17 |
2 files changed, 41 insertions, 6 deletions
diff --git a/isys/isys.c b/isys/isys.c index 3af649d0a..59798f12f 100644 --- a/isys/isys.c +++ b/isys/isys.c @@ -39,7 +39,7 @@ long long llseek(int fd, long long offset, int whence); /* FIXME: this is such a hack -- moduleInfoList ought to be a proper object */ -moduleInfoSet modInfoList; +moduleInfoSet modInfoList = NULL; static PyObject * doFindModInfo(PyObject * s, PyObject * args); static PyObject * doGetOpt(PyObject * s, PyObject * args); @@ -62,6 +62,7 @@ static PyObject * doPoptParse(PyObject * s, PyObject * args); static PyObject * doFbconProbe(PyObject * s, PyObject * args); static PyObject * doLoSetup(PyObject * s, PyObject * args); static PyObject * doUnLoSetup(PyObject * s, PyObject * args); +static PyObject * doLoChangeFd(PyObject * s, PyObject * args); static PyObject * doDdFile(PyObject * s, PyObject * args); static PyObject * doGetRaidSuperblock(PyObject * s, PyObject * args); static PyObject * doDevSpaceFree(PyObject * s, PyObject * args); @@ -85,6 +86,7 @@ static PyMethodDef isysModuleMethods[] = { { "raidstop", (PyCFunction) doRaidStop, METH_VARARGS, NULL }, { "raidstart", (PyCFunction) doRaidStart, METH_VARARGS, NULL }, { "getraidsb", (PyCFunction) doGetRaidSuperblock, METH_VARARGS, NULL }, + { "lochangefd", (PyCFunction) doLoChangeFd, METH_VARARGS, NULL }, { "losetup", (PyCFunction) doLoSetup, METH_VARARGS, NULL }, { "unlosetup", (PyCFunction) doUnLoSetup, METH_VARARGS, NULL }, { "ddfile", (PyCFunction) doDdFile, METH_VARARGS, NULL }, @@ -230,6 +232,9 @@ static PyObject * getModuleList(PyObject * s, PyObject * args) { return NULL; } + if (!modInfoList) + modInfoList = isysNewModuleInfoSet(); + modules = isysGetModuleList(modInfoList, major); if (!modules) { Py_INCREF(Py_None); @@ -352,6 +357,21 @@ static PyObject * doUnLoSetup(PyObject * s, PyObject * args) { return Py_None; } +static PyObject * doLoChangeFd(PyObject * s, PyObject * args) { + int loopfd; + int targfd; + + if (!PyArg_ParseTuple(args, "ii", &loopfd, &targfd)) + return NULL; + if (ioctl(loopfd, LOOP_CHANGE_FD, targfd)) { + PyErr_SetFromErrno(PyExc_SystemError); + return NULL; + } + + Py_INCREF(Py_None); + return Py_None; +} + static PyObject * doLoSetup(PyObject * s, PyObject * args) { int loopfd; int targfd; @@ -383,6 +403,9 @@ static PyObject * doFindModInfo(PyObject * s, PyObject * args) { if (!PyArg_ParseTuple(args, "s", &mod)) return NULL; + if (!modInfoList) + modInfoList = isysNewModuleInfoSet(); + mi = isysFindModuleInfo(modInfoList, mod); if (!mi) { Py_INCREF(Py_None); @@ -541,6 +564,9 @@ static PyObject * doReadModInfo(PyObject * s, PyObject * args) { if (!PyArg_ParseTuple(args, "s", &fn)) return NULL; + if (!modInfoList) + modInfoList = isysNewModuleInfoSet(); + if (isysReadModuleInfo(fn, modInfoList, MI_LOCATION_NONE, NULL)) { PyErr_SetFromErrno(PyExc_IOError); return NULL; @@ -714,8 +740,6 @@ static PyObject * smpAvailable(PyObject * s, PyObject * args) { } void init_isys(void) { - modInfoList = isysNewModuleInfoSet(); - Py_InitModule("_isys", isysModuleMethods); } diff --git a/isys/isys.py b/isys/isys.py index d810b9139..56fa8a649 100644 --- a/isys/isys.py +++ b/isys/isys.py @@ -35,13 +35,24 @@ def raidsb(mdDevice): os.close(fd) return rc -def losetup(device, file): - loop = os.open(device, os.O_RDONLY) - targ = os.open(file, os.O_RDWR) +def losetup(device, file, readonly = 0): + if readonly: + mode = os.O_RDONLY + else: + mode = os.O_RDWR + targ = os.open(file, mode) + loop = os.open(device, mode) _isys.losetup(loop, targ, file) os.close(loop) os.close(targ) +def lochangefd(device, file): + loop = os.open(device, os.O_RDONLY) + targ = os.open(file, os.O_RDONLY) + _isys.lochangefd(loop, targ) + os.close(loop) + os.close(targ) + def unlosetup(device): loop = os.open(device, os.O_RDONLY) _isys.unlosetup(loop) |