diff options
author | Jose M. Guisado <jguisado@soleta.eu> | 2022-12-14 17:44:11 +0100 |
---|---|---|
committer | Jose M. Guisado <jguisado@soleta.eu> | 2022-12-15 17:37:07 +0100 |
commit | eaf98290cf111f1427d1c3adeea688b90452802a (patch) | |
tree | 6735c88563f3a6eed516c30fa9454d6d5c863c7c /context.c | |
parent | bc6f5cbdffe19c62fd69791ea5e19a1900442adc (diff) |
context: add_partition returns partno
libfdisk context add_partition function initializes a passed argument
with the new partition's partno.
If add_partition is successful, return its partno.
Diffstat (limited to 'context.c')
-rw-r--r-- | context.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -161,10 +161,11 @@ static PyObject *Context_write_disklabel(ContextObject *self, PyObject *args, Py Py_RETURN_NONE; } #define Context_add_partition_HELP "add_partition(fdisk.Partition)\n\n" \ - "Adds partition to context" + "Adds partition to context. Returns partno of the new partition." static PyObject *Context_add_partition(ContextObject *self, PyObject *args, PyObject *kwds) { PartitionObject *partobj; + size_t partno; int rc; if (!PyArg_ParseTuple(args, "O!", &PartitionType, &partobj)) { @@ -177,13 +178,13 @@ static PyObject *Context_add_partition(ContextObject *self, PyObject *args, PyOb return NULL; } - rc = fdisk_add_partition(self->cxt, partobj->pa, NULL); + rc = fdisk_add_partition(self->cxt, partobj->pa, &partno); if (rc < 0) { PyErr_Format(PyExc_RuntimeError, "Error adding partition to context: %s", strerror(-rc)); return NULL; } - Py_RETURN_NONE; + return Py_BuildValue("n", partno); } static PyMethodDef Context_methods[] = { {"assign_device", (PyCFunction)Context_assign_device, METH_VARARGS, Context_assign_device_HELP}, |