Re: [PATCH 1/2] Add a method to determine whether a block device is read-only.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, 22 Jul 2009, Chris Lumens wrote:

---
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);
+}

Rather than PyBool_FromLong(is_ro), I would do this:

    if (is_ro)
        Py_RETURN_TRUE;
    else
        Py_RETURN_FALSE;

When we worked on pyparted, I remember the *_FromLong convenience functions
misbehaving on some 64-bit platforms.

+
/* 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)


- -- David Cantrell <dcantrell@xxxxxxxxxx>
Red Hat / Honolulu, HI

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkpnbg8ACgkQ5hsjjIy1Vkm/GwCcDLEDfavOGy6TkNY3tQj2r0P0
2ZgAoOhyoqLLO9oVlPqQMrQCKwL86XzT
=ZHLM
-----END PGP SIGNATURE-----

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux