From eaf98290cf111f1427d1c3adeea688b90452802a Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Wed, 14 Dec 2022 17:44:11 +0100 Subject: 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. --- context.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/context.c b/context.c index 8d80d12..c93cd36 100644 --- a/context.c +++ b/context.c @@ -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}, -- cgit v1.2.3-18-g5258