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.master
parent
0747a84d1c
commit
06e59706fc
21
context.c
21
context.c
|
|
@ -41,19 +41,19 @@ static PyObject *Context_new(PyTypeObject *type,
|
||||||
return (PyObject *)self;
|
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)
|
static int Context_init(ContextObject *self, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
char *device = NULL;
|
|
||||||
int details, rc = 0;
|
|
||||||
char *kwlist[] = {
|
char *kwlist[] = {
|
||||||
"device", "details",
|
"device", "details", "readonly",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
int details = 1, readonly = 0, rc = 0;
|
||||||
|
char *device = NULL;
|
||||||
|
|
||||||
if (!PyArg_ParseTupleAndKeywords(args,
|
if (!PyArg_ParseTupleAndKeywords(args,
|
||||||
kwds, "|sp", kwlist,
|
kwds, "|spp", kwlist,
|
||||||
&device, &details)) {
|
&device, &details, &readonly)) {
|
||||||
PyErr_SetString(PyExc_TypeError, ARG_ERR);
|
PyErr_SetString(PyExc_TypeError, ARG_ERR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -67,8 +67,7 @@ static int Context_init(ContextObject *self, PyObject *args, PyObject *kwds)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX: always readonly */
|
if (device && (rc = fdisk_assign_device(self->cxt, device, readonly)))
|
||||||
if (device && (rc = fdisk_assign_device(self->cxt, device, 1)))
|
|
||||||
return -1;
|
return -1;
|
||||||
if (details && (rc = fdisk_enable_details(self->cxt, details)))
|
if (details && (rc = fdisk_enable_details(self->cxt, details)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -224,8 +223,10 @@ static PyGetSetDef Context_getseters[] = {
|
||||||
|
|
||||||
static PyObject *Context_repr(ContextObject *self)
|
static PyObject *Context_repr(ContextObject *self)
|
||||||
{
|
{
|
||||||
return PyUnicode_FromFormat("<libfdisk.Context object at %p, details=%s>",
|
return PyUnicode_FromFormat("<libfdisk.Context object at %p, details=%s, readonly=%s>",
|
||||||
self, fdisk_is_details(self->cxt) ? "True" : "False");
|
self,
|
||||||
|
fdisk_is_details(self->cxt) ? "True" : "False",
|
||||||
|
fdisk_is_readonly(self->cxt) ? "True" : "False");
|
||||||
}
|
}
|
||||||
|
|
||||||
PyTypeObject ContextType = {
|
PyTypeObject ContextType = {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue