From 06e59706fc58fe629832a3f4a89cc5d88161e3c8 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Thu, 6 Oct 2022 16:17:30 +0200 Subject: context: add readonly parameter fdisk_assign_device() contains 'readonly' parameter to indicate how to open the device. Assigned device 'readonly' must be false (0) in order to write in-memory changes to it. --- context.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/context.c b/context.c index a85de66..1524baa 100644 --- a/context.c +++ b/context.c @@ -41,19 +41,19 @@ static PyObject *Context_new(PyTypeObject *type, return (PyObject *)self; } -#define Context_HELP "Context(device=None, details=None)" +#define Context_HELP "Context(device=None, details=True, readonly=False)" static int Context_init(ContextObject *self, PyObject *args, PyObject *kwds) { - char *device = NULL; - int details, rc = 0; char *kwlist[] = { - "device", "details", + "device", "details", "readonly", NULL }; + int details = 1, readonly = 0, rc = 0; + char *device = NULL; if (!PyArg_ParseTupleAndKeywords(args, - kwds, "|sp", kwlist, - &device, &details)) { + kwds, "|spp", kwlist, + &device, &details, &readonly)) { PyErr_SetString(PyExc_TypeError, ARG_ERR); return -1; } @@ -67,8 +67,7 @@ static int Context_init(ContextObject *self, PyObject *args, PyObject *kwds) return -1; } - /* XXX: always readonly */ - if (device && (rc = fdisk_assign_device(self->cxt, device, 1))) + if (device && (rc = fdisk_assign_device(self->cxt, device, readonly))) return -1; if (details && (rc = fdisk_enable_details(self->cxt, details))) return -1; @@ -224,8 +223,10 @@ static PyGetSetDef Context_getseters[] = { static PyObject *Context_repr(ContextObject *self) { - return PyUnicode_FromFormat("", - self, fdisk_is_details(self->cxt) ? "True" : "False"); + return PyUnicode_FromFormat("", + self, + fdisk_is_details(self->cxt) ? "True" : "False", + fdisk_is_readonly(self->cxt) ? "True" : "False"); } PyTypeObject ContextType = { -- cgit v1.2.3-18-g5258