Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added functions

  • Loading branch information...
commit e446854d0a0d1df686169c4513f9d53c535cf964 1 parent 7db4c40
Anant Kamath authored
Showing with 135 additions and 3 deletions.
  1. +135 −3 pyATASmart.c
138 pyATASmart.c
View
@@ -44,8 +44,8 @@ int ret;
}
//sk_disk_free(d); Reimplimentation:
- if (d->fd >= 0)
- close(d->fd);
+ if (d->fd >= 0);
+ // close(d->fd);
// PyMem_Free(d->name);
//PyMem_Free(d->blob);
//PyMem_Free(d);
@@ -86,6 +86,65 @@ int ret;
return Py_BuildValue("K", (unsigned long long) ms);
}
+
+//Get number of power cycles
+ static PyObject *pyATASmart_getPowerCycle(PyObject *self, PyObject *args)
+{
+
+int ret;
+ uint64_t count;
+ SkDisk *d;
+
+ if (!PyArg_ParseTuple(args, "O", &d))
+ {
+ return NULL;
+ }
+
+
+ if ((ret = sk_disk_smart_read_data(d)) < 0) {
+ PyErr_SetString(PyExc_OSError, "Failed to read SMART data");
+ return NULL;
+
+ }
+
+ if ((ret = sk_disk_smart_get_power_cycle(d, &count)) < 0) {
+
+ PyErr_SetString(PyExc_OSError, "Failed to get number of power cycles");
+ return NULL;
+ }
+ return Py_BuildValue("K", (unsigned long long) count);
+}
+
+
+//Get the number of bad sectors (i.e. pending and reallocated)
+ static PyObject *pyATASmart_getBad(PyObject *self, PyObject *args)
+{
+
+int ret;
+ uint64_t sectors;
+ SkDisk *d;
+
+ if (!PyArg_ParseTuple(args, "O", &d))
+ {
+ return NULL;
+ }
+
+
+ if ((ret = sk_disk_smart_read_data(d)) < 0) {
+ PyErr_SetString(PyExc_OSError, "Failed to read SMART data");
+ return NULL;
+
+ }
+
+ if ((ret = sk_disk_smart_get_bad(d, &sectors)) < 0) {
+
+ PyErr_SetString(PyExc_OSError, "Failed to get number of bad sectors");
+ return NULL;
+ }
+ return Py_BuildValue("K", (unsigned long long) sectors);
+}
+
+
static PyObject *pyATASmart_getTemperature(PyObject *self, PyObject *args)
{
@@ -119,11 +178,84 @@ uint64_t mkelvin;
+static PyObject *pyATASmart_smartIsAvailable(PyObject *self, PyObject *args)
+{
+
+int ret;
+
+SkDisk *d;
+SkBool available;
+
+
+
+
+ if (!PyArg_ParseTuple(args, "O", &d))
+ {
+ return NULL;
+ }
+
+
+
+
+ if ((ret = sk_disk_smart_is_available(d, &available)) < 0) {
+
+ PyErr_SetString(PyExc_OSError, "Unable to check if SMART is available.");
+ return NULL;
+ }
+
+ return Py_BuildValue("i", (int) available);
+}
+
+
+static PyObject *pyATASmart_smartStatus(PyObject *self, PyObject *args)
+{
+
+int ret;
+
+ SkDisk *d;
+SkBool statusGood;
+
+
+
+
+ if (!PyArg_ParseTuple(args, "O", &d))
+ {
+ return NULL;
+ }
+
+
+ if ((ret = sk_disk_smart_read_data(d)) < 0) {
+ PyErr_SetString(PyExc_OSError, "Failed to read SMART data");
+ return NULL;
+
+ }
+
+ if ((ret = sk_disk_smart_status(d, &statusGood)) < 0) {
+
+ PyErr_SetString(PyExc_OSError, "Failed to get SMART status");
+ return NULL;
+ }
+ return Py_BuildValue("i", (int) statusGood);
+}
+
+
+
+
+
+
+
+
+
+
+
static PyMethodDef pyATASmart_methods[] = {
{ "diskOpen", (PyCFunction)pyATASmart_diskOpen, METH_VARARGS, "Open a disk" },
{ "getPowerOn", (PyCFunction)pyATASmart_getPowerOn, METH_VARARGS, "Get the disk power-on time"},
{ "getTemperature", (PyCFunction)pyATASmart_getTemperature, METH_VARARGS, "Get the disk temperature" },
- { "diskFree", (PyCFunction)pyATASmart_diskFree, METH_VARARGS, NULL },
+ { "getBad", (PyCFunction)pyATASmart_getBad, METH_VARARGS, "Get number of bad sectors" },
+ { "getPowerCycle", (PyCFunction)pyATASmart_getPowerCycle, METH_VARARGS, "Get number of power cycles" },
+ { "smartStatus", (PyCFunction)pyATASmart_smartStatus, METH_VARARGS, "Get smart status" },
+ { "smartIsAvailable", (PyCFunction)pyATASmart_smartIsAvailable, METH_VARARGS, "Check if SMART is available" },
{ NULL, NULL, 0, NULL }
};
Please sign in to comment.
Something went wrong with that request. Please try again.