diff options
-rw-r--r-- | isys/isys.c | 22 | ||||
-rw-r--r-- | isys/isys.py | 10 |
2 files changed, 27 insertions, 5 deletions
diff --git a/isys/isys.c b/isys/isys.c index 2a87adc22..286f3a590 100644 --- a/isys/isys.c +++ b/isys/isys.c @@ -36,6 +36,10 @@ #include "lang.h" #include "../balkan/byteswap.h" +#ifndef CDROMEJECT +#define CDROMEJECT 0x5309 +#endif + long long llseek(int fd, long long offset, int whence); /* FIXME: this is such a hack -- moduleInfoList ought to be a proper object */ @@ -78,8 +82,10 @@ 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 PyObject * doEjectCdrom(PyObject * s, PyObject * args); static PyMethodDef isysModuleMethods[] = { + { "ejectcdrom", (PyCFunction) doEjectCdrom, METH_VARARGS, NULL }, { "e2dirty", (PyCFunction) doExt2Dirty, METH_VARARGS, NULL }, { "e2fslabel", (PyCFunction) doReadE2fsLabel, METH_VARARGS, NULL }, { "devSpaceFree", (PyCFunction) doDevSpaceFree, METH_VARARGS, NULL }, @@ -1260,8 +1266,6 @@ static PyObject * doIsScsiRemovable(PyObject * s, PyObject * args) { return Py_BuildValue("i", rc); } - - static PyObject * doIsIdeRemovable(PyObject * s, PyObject * args) { char *path; char str[100]; @@ -1300,3 +1304,17 @@ static PyObject * doIsIdeRemovable(PyObject * s, PyObject * args) { return Py_BuildValue("i", rc); } + +static PyObject * doEjectCdrom(PyObject * s, PyObject * args) { + int fd; + + if (!PyArg_ParseTuple(args, "i", &fd)) return NULL; + + if (ioctl(fd, CDROMEJECT, 1)) { + PyErr_SetFromErrno(PyExc_SystemError); + return NULL; + } + + Py_INCREF(Py_None); + return Py_None; +} diff --git a/isys/isys.py b/isys/isys.py index 2cd417cdd..94dbddd0d 100644 --- a/isys/isys.py +++ b/isys/isys.py @@ -263,19 +263,23 @@ def ext2IsDirty(device): os.unlink("/tmp/disk") return label +def ejectCdrom(device): + makeDevInode(device, "/tmp/cdrom") + fd = os.open("/tmp/cdrom", os.O_RDONLY) + _isys.ejectcdrom(fd) + os.close(fd) + os.unlink("/tmp/cdrom") + def driveIsRemovable(device): # assume ide if starts with 'hd', and we don't have to create # device beforehand since it just reads /proc/ide from log import log if device[:2] == "hd": -# log("testing IDE device %s", device) rc = (_isys.isIdeRemovable("/dev/"+device) == 1) else: -# log("testing SCSI device %s", device) makeDevInode(device, "/tmp/disk") rc = (_isys.isScsiRemovable("/tmp/disk") == 1) os.unlink("/tmp/disk") -# log("test result was %d", rc) return rc |