summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authornima <nima@abc39116-655e-4be6-ad55-d661dc543056>2008-12-20 01:44:55 +0000
committernima <nima@abc39116-655e-4be6-ad55-d661dc543056>2008-12-20 01:44:55 +0000
commit8626bbd2cfcb10109cfa85b8d7ef99898e6f7771 (patch)
treef50b216d694e92505b051a4d2af635bcd3da913b /src
parentf5397d936f5dc85813d1d6d50cf5f7d6ba9716c8 (diff)
downloadpython-dmidecode-8626bbd2cfcb10109cfa85b8d7ef99898e6f7771.tar.gz
python-dmidecode-8626bbd2cfcb10109cfa85b8d7ef99898e6f7771.tar.xz
python-dmidecode-8626bbd2cfcb10109cfa85b8d7ef99898e6f7771.zip
Removed "detected" from appearing in every single function call. TODO: An ivar
should be implemented to return this string, so further cleanup is still required; as it stands, there is no access to this information anymore! Updated test case. Further general cleanup. git-svn-id: svn://svn.autonomy.net.au/python-dmidecode@133 abc39116-655e-4be6-ad55-d661dc543056
Diffstat (limited to 'src')
-rw-r--r--src/dmidecode.c18
-rw-r--r--src/dmidecode.h4
-rw-r--r--src/dmidecodemodule.c46
-rw-r--r--src/dmidecodemodule.h5
-rw-r--r--src/setup.py2
5 files changed, 48 insertions, 27 deletions
diff --git a/src/dmidecode.c b/src/dmidecode.c
index f03ff73..564cd28 100644
--- a/src/dmidecode.c
+++ b/src/dmidecode.c
@@ -4658,30 +4658,30 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem, P
}
-int smbios_decode(u8 *buf, const char *devmem, PyObject* pydata) {
+int smbios_decode(u8 *buf, const char *devmem, PyObject* pydata, PyObject* pydata_ver) {
if(pydata == NULL) return -1; //. TODO: Raise Exception
if(!checksum(buf, buf[0x05]) || !memcmp(buf+0x10, "_DMI_", 5)==0 || !checksum(buf+0x10, 0x0F)) return 0;
u16 ver = (buf[0x06] << 8) + buf[0x07];
/* Some BIOS attempt to encode version 2.3.1 as 2.31, fix it up */
- if(ver == 0x021F) {
- printf("SMBIOS version fixup (2.31 -> 2.3).\n");
- ver = 0x0203;
- }
- dmiSetItem(pydata, "detected", "SMBIOS %i.%i present.", ver>>8, ver&0xFF);
+ if(ver == 0x021F) { fprintf(stderr, "SMBIOS version fixup (2.31 -> 2.3).\n"); ver = 0x0203; }
+ if(pydata_ver) { Py_DECREF(pydata_ver); }
+ pydata_ver = PyString_FromFormat("SMBIOS %i.%i present.", ver>>8, ver&0xFF);
+ Py_INCREF(pydata_ver);
dmi_table(DWORD(buf+0x18), WORD(buf+0x16), WORD(buf+0x1C), ver, devmem, pydata);
return 1;
}
-int legacy_decode(u8 *buf, const char *devmem, PyObject* pydata) {
+int legacy_decode(u8 *buf, const char *devmem, PyObject* pydata, PyObject* pydata_ver) {
if(pydata == NULL) return -1; //. TODO: Raise Exception
if(!checksum(buf, 0x0F)) return 0;
- printf("Legacy DMI %u.%u present.\n", buf[0x0E]>>4, buf[0x0E]&0x0F);
- dmiSetItem(pydata, "detected", "Legacy DMI %i.%i present.", buf[0x0E]>>4, buf[0x0E]&0x0F);
+ if(pydata_ver) { Py_DECREF(pydata_ver); }
+ pydata_ver = PyString_FromFormat("Legacy DMI %i.%i present.", buf[0x0E]>>4, buf[0x0E]&0x0F);
+ Py_INCREF(pydata_ver);
dmi_table(DWORD(buf+0x08), WORD(buf+0x06), WORD(buf+0x0C), ((buf[0x0E]&0xF0)<<4)+(buf[0x0E]&0x0F), devmem, pydata);
return 1;
}
diff --git a/src/dmidecode.h b/src/dmidecode.h
index 46f822f..1673394 100644
--- a/src/dmidecode.h
+++ b/src/dmidecode.h
@@ -30,8 +30,8 @@ PyObject *dmi_dump(struct dmi_header *h);
PyObject* dmi_decode(struct dmi_header *h, u16 ver);
int address_from_efi(size_t *address);
void to_dmi_header(struct dmi_header *h, u8 *data);
-int smbios_decode(u8 *buf, const char *devmem, PyObject* pydata);
-int legacy_decode(u8 *buf, const char *devmem, PyObject* pydata);
+int smbios_decode(u8 *buf, const char *devmem, PyObject* pydata, PyObject* pydata_ver);
+int legacy_decode(u8 *buf, const char *devmem, PyObject* pydata, PyObject* pydata_ver);
const char *dmi_string(const struct dmi_header *dm, u8 s);
const char *dmi_system_uuid(u8 *p);
diff --git a/src/dmidecodemodule.c b/src/dmidecodemodule.c
index e873c6c..06e5cf0 100644
--- a/src/dmidecodemodule.c
+++ b/src/dmidecodemodule.c
@@ -89,6 +89,7 @@ static PyObject* dmidecode_get(PyObject *self, const char* section) {
if(opt.type==NULL) return NULL;
PyObject* pydata = PyDict_New();
+ PyObject* pydata_ver;
/***********************************/
/* Read from dump if so instructed */
@@ -97,9 +98,9 @@ static PyObject* dmidecode_get(PyObject *self, const char* section) {
//. printf("Reading SMBIOS/DMI data from file %s.\n", dumpfile);
if((buf = mem_chunk(0, 0x20, dumpfile))!=NULL) {
if(memcmp(buf, "_SM_", 4)==0) {
- if(smbios_decode(buf, dumpfile, pydata)) found++;
+ if(smbios_decode(buf, dumpfile, pydata, pydata_ver)) found++;
} else if (memcmp(buf, "_DMI_", 5)==0) {
- if(legacy_decode(buf, dumpfile, pydata)) found++;
+ if(legacy_decode(buf, dumpfile, pydata, pydata_ver)) found++;
}
} else ret = 1;
} else { /* Read from /dev/mem */
@@ -110,10 +111,10 @@ static PyObject* dmidecode_get(PyObject *self, const char* section) {
if((buf=mem_chunk(0xF0000, 0x10000, opt.devmem))!=NULL) {
for(fp=0; fp<=0xFFF0; fp+=16) {
if(memcmp(buf+fp, "_SM_", 4)==0 && fp<=0xFFE0) {
- if(smbios_decode(buf+fp, opt.devmem, pydata)) found++;
+ if(smbios_decode(buf+fp, opt.devmem, pydata, pydata_ver)) found++;
fp+=16;
} else if(memcmp(buf+fp, "_DMI_", 5)==0) {
- if(legacy_decode(buf+fp, opt.devmem, pydata)) found++;
+ if(legacy_decode(buf+fp, opt.devmem, pydata, pydata_ver)) found++;
}
}
} else ret = 1;
@@ -121,16 +122,19 @@ static PyObject* dmidecode_get(PyObject *self, const char* section) {
ret = 1;
} else {
if((buf=mem_chunk(fp, 0x20, opt.devmem))==NULL) ret = 1;
- else if(smbios_decode(buf, opt.devmem, pydata)) found++;
+ else if(smbios_decode(buf, opt.devmem, pydata, pydata_ver)) found++;
//. TODO: dmiSetItem(pydata, "efi_address", efiAddress);
}
}
if(ret==0) {
free(buf);
-
- if(!found)
- dmiSetItem(pydata, "detect", "No SMBIOS nor DMI entry point found, sorry G.");
+ if(!found) {
+ if(!pydata_ver) {
+ pydata_ver = PyString_FromString("No SMBIOS nor DMI entry point found, sorry G.");
+ Py_INCREF(pydata_ver);
+ }
+ }
}
free(opt.type);
@@ -184,9 +188,16 @@ static PyObject* dmidecode_set_dev(PyObject *self, PyObject *arg) {
struct stat buf;
char *f = PyString_AsString(arg);
stat(f, &buf);
- if(!S_ISDIR(buf.st_mode)) {
- if(opt.dumpfile)
- Py_DECREF(opt.dumpfile);
+ if(opt.dumpfile) { Py_DECREF(opt.dumpfile); }
+
+ if(S_ISCHR(buf.st_mode)) {
+ if(memcmp(PyString_AsString(arg), "/dev/mem", 8)==0) {
+ opt.dumpfile = NULL;
+ Py_RETURN_TRUE;
+ } else {
+ Py_RETURN_FALSE;
+ }
+ } else if(!S_ISDIR(buf.st_mode)) {
opt.dumpfile = arg;
Py_INCREF(opt.dumpfile);
Py_RETURN_TRUE;
@@ -196,9 +207,18 @@ static PyObject* dmidecode_set_dev(PyObject *self, PyObject *arg) {
//PyErr_Occurred();
}
+/* TODO
+typedef struct {
+ PyObject_HEAD char *version;
+} ivars;
+static PyMemberDef DMIDataMembers[] = {
+ { (char *)"fred", T_STRING, offsetof(ivars, version), 0, "2.10" },
+ { NULL }
+};
+*/
-PyMethodDef DMIDataMethods[] = {
+static PyMethodDef DMIDataMethods[] = {
{ (char *)"dump", dmidecode_dump, METH_NOARGS, (char *)"Dump dmidata to set file" },
{ (char *)"get_dev", dmidecode_get_dev, METH_NOARGS, (char *)"Get an alternative memory device file" },
{ (char *)"set_dev", dmidecode_set_dev, METH_O, (char *)"Set an alternative memory device file" },
@@ -214,10 +234,10 @@ PyMethodDef DMIDataMethods[] = {
{ (char *)"slot", dmidecode_get_slot, METH_VARARGS, (char *)"Slot Data" },
{ (char *)"type", dmidecode_get_type, METH_VARARGS, (char *)"By Type" },
+
{ NULL, NULL, 0, NULL }
};
-
PyMODINIT_FUNC initdmidecode(void) {
init();
(void)Py_InitModule((char *)"dmidecode", DMIDataMethods);
diff --git a/src/dmidecodemodule.h b/src/dmidecodemodule.h
index 89eea87..00532bd 100644
--- a/src/dmidecodemodule.h
+++ b/src/dmidecodemodule.h
@@ -1,4 +1,5 @@
#include <Python.h>
+#include <structmember.h>
#include <stdio.h>
#include <string.h>
@@ -26,8 +27,8 @@ extern PyObject* dmi_decode(struct dmi_header *h, u16 ver);
extern int address_from_efi(size_t *address);
extern void to_dmi_header(struct dmi_header *h, u8 *data);
extern void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem);
-extern int smbios_decode(u8 *buf, const char *devmem, PyObject* pydata);
-extern int legacy_decode(u8 *buf, const char *devmem, PyObject* pydata);
+extern int smbios_decode(u8 *buf, const char *devmem, PyObject* pydata, PyObject* pydata_ver);
+extern int legacy_decode(u8 *buf, const char *devmem, PyObject* pydata, PyObject* pydata_ver);
extern void *mem_chunk(size_t base, size_t len, const char *devmem);
extern u8 *parse_opt_type(u8 *p, const char *arg);
diff --git a/src/setup.py b/src/setup.py
index 0de0e6e..6601964 100644
--- a/src/setup.py
+++ b/src/setup.py
@@ -1,7 +1,7 @@
from distutils.core import setup, Extension
setup(
- name = "python-dmidecode",
+ name = "dmidecode",
version = "2.10",
description = "Python extension module for dmidecode",
author = "Nima Talebi",