summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJose M. Guisado <jguisado@soleta.eu>2022-10-06 16:17:30 +0200
committerJose M. Guisado <jguisado@soleta.eu>2022-12-15 10:51:04 +0100
commit06e59706fc58fe629832a3f4a89cc5d88161e3c8 (patch)
treea3a3c48e606f52207c8710a7318fe84780a08e4a
parent0747a84d1cd7e49549b551ae7d02a3c619bd4ab2 (diff)
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.
-rw-r--r--context.c21
1 files 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("<libfdisk.Context object at %p, details=%s>",
- self, fdisk_is_details(self->cxt) ? "True" : "False");
+ return PyUnicode_FromFormat("<libfdisk.Context object at %p, details=%s, readonly=%s>",
+ self,
+ fdisk_is_details(self->cxt) ? "True" : "False",
+ fdisk_is_readonly(self->cxt) ? "True" : "False");
}
PyTypeObject ContextType = {