summaryrefslogtreecommitdiffstats
path: root/fdisk.c
diff options
context:
space:
mode:
authorJose M. Guisado Gomez <guigom@riseup.net>2022-04-06 11:31:30 +0200
committerJose M. Guisado Gomez <guigom@riseup.net>2022-04-06 12:56:11 +0200
commitca92f15e2a5836f0734c82d786dcead732ddad22 (patch)
treedef46ce5bf1f39293bd5fe90d32d644512b1dd5a /fdisk.c
Initial commit
Add sources, setup.py and .gitignore Build/Install: python setup.py build python setup.py install
Diffstat (limited to 'fdisk.c')
-rw-r--r--fdisk.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/fdisk.c b/fdisk.c
new file mode 100644
index 0000000..5be7b66
--- /dev/null
+++ b/fdisk.c
@@ -0,0 +1,59 @@
+#include <dirent.h>
+
+#include "fdisk.h"
+
+PyObject *PyObjectResultStr(const char *s)
+{
+ PyObject *result;
+ if (!s)
+ /* TODO: maybe lie about it and return "":
+ * which would allow for
+ * fs = libmount.Fs()
+ * fs.comment += "comment"
+ return Py_BuildValue("s", ""); */
+ Py_RETURN_NONE;
+ result = Py_BuildValue("s", s);
+ if (!result)
+ PyErr_SetString(PyExc_RuntimeError, CONSTRUCT_ERR);
+ return result;
+}
+
+static PyMethodDef FdiskMethods[] = {
+ {NULL, NULL, 0, NULL} /* Sentinel */
+};
+
+
+static struct PyModuleDef fdiskmodule = {
+ PyModuleDef_HEAD_INIT,
+ "fdisk", /* name of module */
+ NULL, /* module documentation, may be NULL */
+ -1, /* size of per-interpreter state of the module,
+ or -1 if the module keeps state in global variables. */
+ FdiskMethods
+};
+
+PyMODINIT_FUNC
+PyInit_fdisk(void)
+{
+ PyObject *m = PyModule_Create(&fdiskmodule);
+
+ PyModule_AddIntConstant(m, "FDISK_SIZEUNIT_BYTES", FDISK_SIZEUNIT_BYTES);
+ PyModule_AddIntConstant(m, "FDISK_SIZEUNIT_HUMAN", FDISK_SIZEUNIT_HUMAN);
+
+ PyModule_AddIntConstant(m, "FDISK_FIELD_DEVICE", FDISK_FIELD_DEVICE);
+ PyModule_AddIntConstant(m, "FDISK_FIELD_SIZE", FDISK_FIELD_SIZE);
+ PyModule_AddIntConstant(m, "FDISK_FIELD_TYPE", FDISK_FIELD_TYPE);
+ PyModule_AddIntConstant(m, "FDISK_FIELD_TYPEID", FDISK_FIELD_TYPEID);
+ PyModule_AddIntConstant(m, "FDISK_FIELD_FSTYPE", FDISK_FIELD_FSTYPE);
+
+ PyModule_AddIntConstant(m, "FDISK_DISKLABEL_DOS", FDISK_DISKLABEL_DOS);
+ PyModule_AddIntConstant(m, "FDISK_DISKLABEL_GPT", FDISK_DISKLABEL_GPT);
+ PyModule_AddIntConstant(m, "FDISK_ITER_FORWARD", FDISK_ITER_FORWARD);
+ PyModule_AddIntConstant(m, "FDISK_ITER_BACKWARD", FDISK_ITER_BACKWARD);
+
+ Context_AddModuleObject(m);
+ Label_AddModuleObject(m);
+
+
+ return m;
+}