summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--isys/isys.c44
-rw-r--r--isys/isys.py7
-rwxr-xr-xisys/testprobe6
3 files changed, 56 insertions, 1 deletions
diff --git a/isys/isys.c b/isys/isys.c
index 0fac82d2f..322c9c22b 100644
--- a/isys/isys.c
+++ b/isys/isys.c
@@ -1,4 +1,5 @@
#include <stdio.h>
+#include <dirent.h>
#include <errno.h>
#include <linux/ext2_fs.h>
#include <ext2fs/ext2fs.h>
@@ -75,6 +76,7 @@ static PyObject * doLoadKeymap(PyObject * s, PyObject * args);
static PyObject * doReadE2fsLabel(PyObject * s, PyObject * args);
static PyObject * doExt2Dirty(PyObject * s, PyObject * args);
static PyObject * doIsScsiRemovable(PyObject * s, PyObject * args);
+static PyObject * doIsIdeRemovable(PyObject * s, PyObject * args);
static PyMethodDef isysModuleMethods[] = {
{ "e2dirty", (PyCFunction) doExt2Dirty, METH_VARARGS, NULL },
@@ -116,6 +118,7 @@ static PyMethodDef isysModuleMethods[] = {
{ "loadFont", (PyCFunction) doLoadFont, METH_VARARGS, NULL },
{ "loadKeymap", (PyCFunction) doLoadKeymap, METH_VARARGS, NULL },
{ "isScsiRemovable", (PyCFunction) doIsScsiRemovable, METH_VARARGS, NULL},
+ { "isIdeRemovable", (PyCFunction) doIsIdeRemovable, METH_VARARGS, NULL},
{ NULL }
} ;
@@ -1225,3 +1228,44 @@ static PyObject * doIsScsiRemovable(PyObject * s, PyObject * args) {
return Py_BuildValue("i", rc);
}
+
+
+
+static PyObject * doIsIdeRemovable(PyObject * s, PyObject * args) {
+ char *path;
+ char str[100];
+ char *devpath[250];
+ char *t;
+ int fd;
+ int rc, i;
+ DIR * dir;
+
+ if (!PyArg_ParseTuple(args, "s", &path)) return NULL;
+
+ if (access("/proc/ide", R_OK))
+ return Py_BuildValue("i", -1);
+
+ if (!(dir = opendir("/proc/ide")))
+ return Py_BuildValue("i", -1);
+
+ t = strrchr(path, '/');
+ if (!t)
+ return Py_BuildValue("i", -1);
+
+ /* set errno to 0, so we can tell when readdir() fails */
+ snprintf(devpath, sizeof(devpath), "/proc/ide/%s/media", t+1);
+ if ((fd = open(devpath, O_RDONLY)) >= 0) {
+ i = read(fd, str, sizeof(str));
+ close(fd);
+ str[i - 1] = '\0'; /* chop off trailing \n */
+
+ if (!strcmp(str, "floppy"))
+ rc = 1;
+ else
+ rc = 0;
+ } else {
+ rc = -1;
+ }
+
+ return Py_BuildValue("i", rc);
+}
diff --git a/isys/isys.py b/isys/isys.py
index 65ee2a275..2edbc3ef9 100644
--- a/isys/isys.py
+++ b/isys/isys.py
@@ -251,3 +251,10 @@ def ext2IsDirty(device):
label = _isys.e2dirty("/tmp/disk");
os.unlink("/tmp/disk")
return label
+
+def driveIsRemovable(device):
+ # assume ide if starts with 'hd'
+ if device[:1] == "hd":
+ return _isys.isIdeRemovable("/dev/"+device)
+ else:
+ return _isys.isScsiRemovable("/dev/"+device)
diff --git a/isys/testprobe b/isys/testprobe
index 2c49fcea7..ebfe2f09a 100755
--- a/isys/testprobe
+++ b/isys/testprobe
@@ -20,6 +20,10 @@ for i in p:
print "Removable test"
for (dclass, path, comment) in p:
- print path,_isys.isScsiRemovable("/dev/"+path)
+# print "IDE Test-> ",path,_isys.isIdeRemovable("/dev/"+path)
+# print "SCSI Test-> ",path,_isys.isScsiRemovable("/dev/"+path)
+ import isys
+
+ print path, isys.driveIsRemovable(path)