--- isys/isys.c | 24 ++++++++++++++++++++++++ isys/isys.py | 6 ++++++ 2 files changed, 30 insertions(+), 0 deletions(-) diff --git a/isys/isys.c b/isys/isys.c index fcec6fd..90a697c 100644 --- a/isys/isys.c +++ b/isys/isys.c @@ -124,6 +124,7 @@ static PyObject * doGetBiosDisk(PyObject * s, PyObject * args); static PyObject * doSegvHandler(PyObject *s, PyObject *args); static PyObject * doAuditDaemon(PyObject *s); static PyObject * doPrefixToNetmask(PyObject *s, PyObject *args); +static PyObject * doDeviceReadOnly(PyObject *s, PyObject *args); static PyMethodDef isysModuleMethods[] = { { "ejectcdrom", (PyCFunction) doEjectCdrom, METH_VARARGS, NULL }, @@ -180,6 +181,7 @@ static PyMethodDef isysModuleMethods[] = { { "handleSegv", (PyCFunction) doSegvHandler, METH_VARARGS, NULL }, { "auditdaemon", (PyCFunction) doAuditDaemon, METH_NOARGS, NULL }, { "prefix2netmask", (PyCFunction) doPrefixToNetmask, METH_VARARGS, NULL }, + { "deviceIsReadOnly", (PyCFunction) doDeviceReadOnly, METH_VARARGS, NULL }, { NULL, NULL, 0, NULL } } ; @@ -1416,4 +1418,26 @@ static PyObject * doAuditDaemon(PyObject *s) { return Py_None; } +static PyObject * doDeviceReadOnly(PyObject *s, PyObject *args) { + char *diskname = NULL; + int fd, is_ro; + + if (!PyArg_ParseTuple(args, "s", &diskname)) return NULL; + + fd = open(diskname, O_RDONLY); + if (fd == -1) { + Py_INCREF(Py_None); + return Py_None; + } + + if (ioctl(fd, BLKROGET, &is_ro)) { + close(fd); + PyErr_SetFromErrno(PyExc_SystemError); + return NULL; + } + + close(fd); + return PyBool_FromLong(is_ro); +} + /* vim:set shiftwidth=4 softtabstop=4: */ diff --git a/isys/isys.py b/isys/isys.py index 4063130..189a6c1 100644 --- a/isys/isys.py +++ b/isys/isys.py @@ -804,6 +804,12 @@ def driveUsesModule(device, modules): pass return rc +def deviceIsReadOnly(device): + if not device.startswith("/dev/"): + return _isys.deviceIsReadOnly("/dev/" + device) + else: + return _isys.deviceIsReadOnly(device) + def mediaPresent(device): try: fd = os.open("/dev/%s" % device, os.O_RDONLY) -- 1.6.1.3 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list