summaryrefslogtreecommitdiffstats
path: root/context.c
Commit message (Collapse)AuthorAgeFilesLines
* context: fix assign_deviceJose M. Guisado2023-01-101-6/+6
| | | | | | | | | | | | | | | | | | | | Fixes a bug where calling assign_device with readonly keyword parameter raises exception stating it takes no keyword arguments. Context_assign_device has positional and keyword arguments. Adds flags METH_KEYWORDS in method declaration (see Context_methods). Replaces format string in PyArg_ParseTupleAndKeywords from "s|p" to "s|$p". Adds $ after |, meaning all later optional arguments are also keyword only. (See https://docs.python.org/3/c-api/arg.html#other-objects) Empty names in the kwlist array correspond to positional arguments. Replaces fname variable name with device for better readability. Fixes 88c7374db2309e708e9f9713a3d55acb1472f339 ("context: check self->cxt and rc in assign_device")
* context: check self->cxt and rc in assign_deviceJose M. Guisado2022-12-201-2/+10
| | | | | | | Assert self->cxt before calling libfdisk fdisk_assign_device. Also check for its return code and raise exception if libfdisk report any error assigning the device.
* context: add readonly optional param to assign_deviceJose M. Guisado2022-12-201-7/+7
| | | | | assign_device with readonly set to false by default to keep consistency with Context object constructor.
* context: add label to repr functionJose M. Guisado2022-12-201-1/+7
| | | | | | | | | | | | | | | | Adds label information to context repr function. %R is used to get the repr result of a PyObject, in this case this object is the LabelObject representing the context's label information. Helps showing more of the context information when printing out a context object instance. >>> import fdisk >>> cxt = fdisk.Context('disk.bin') >>> cxt <libfdisk.Context object at 0x7fec52f39330, label=<libfdisk.Label object at 0x7fec52f39310, name=gpt>, details=True, readonly=False>
* context: delete unused label fieldJose M. Guisado2022-12-201-2/+0
| | | | | | | | | | | | It's not necessary to store the label in the context type, instead use the corresponding library function to get the current in-memory label container. The device label information is stored in-memory by libfdisk library when creating a context or assigning a device. Avoids possible incosistencies between libfdisk in-memory label and python-libfdisk context type label information.
* context: don't raise exception when no partitions foundJose M. Guisado2022-12-201-10/+2
| | | | | | | | | Allows creation of a context object or device assign if no label is present in the device. This case is not frecuent but not critical, do not raise an exception. For example, a brand new disk with no label or a raw virtual disk image with no label.
* fdisk: declare kwlist array staticJose M. Guisado2022-12-151-1/+1
|
* fdisk: add set_PyErr_from_rcJose M. Guisado2022-12-151-5/+15
| | | | | | | | | python-libfdisk raises Python exceptions when the libfdisk reports an error when executing some function. libfdisk returns negative errno values when reporting some error. Adds utility function to set PyErr string based on the strerror of a given errno code. Useful when raising Python exceptions.
* coding style: line breaksJose M. Guisado2022-12-151-3/+13
| | | | | | | | | Only two line breaks separate copyright notice from source. For the rest of the source file any function declaration or similar block is separated with a line break from any other block. Except when a python function definition is previously followed by a docstring #define block.
* context: add_partition returns partnoJose M. Guisado2022-12-151-3/+4
| | | | | | | libfdisk context add_partition function initializes a passed argument with the new partition's partno. If add_partition is successful, return its partno.
* context: add add_partition methodJose M. Guisado2022-12-151-0/+26
| | | | | | | | This method wraps fdisk_add_partition. Allows modifying in-memory partition table of a given context. Remember that changes need to be written to disk using the relevant fdisk_write_disklabel function wrapper.
* context: add disklabel creation and writingJose M. Guisado2022-12-151-0/+36
| | | | | | | | | Adds wrappers for following label related functions from libfdisk: - fdisk_create_disklabel - fdisk_write_disklabel These functions are declared as methods of a Context python object.
* context: rename set_size_unit variablesJose M. Guisado2022-12-151-3/+3
| | | | | | Renames 'cval' to 'szunit' for better readability. This variable is used to store the size_unit constant that is going to be set using fdisk_set_size_unit.
* context: add readonly parameterJose M. Guisado2022-12-151-10/+11
| | | | | | | | 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: add size_unit getsetJose M. Guisado Gomez2022-06-071-0/+30
| | | | | | | | | | | | | | | | | | | | | | | | Size unit can be get or set using 'size_unit' context member. >>> for pa in cxt.partitions: ... cxt.partition_to_string(pa, fdisk.FDISK_FIELD_SIZE) ... '114.6G' >>> cxt.size_unit 0 >>> cxt.size_unit == fdisk.FDISK_SIZEUNIT_HUMAN True >>> cxt.size_unit = fdisk.FDISK_SIZEUNIT_BYTES >>> for pa in cxt.partitions: ... cxt.partition_to_string(pa, fdisk.FDISK_FIELD_SIZE) ... '123010531328' Use fdisk_get_size_unit to get size unit value. https://cdn.kernel.org/pub/linux/utils/util-linux/v2.34/libfdisk-docs/libfdisk-Context.html#fdisk-get-size-unit Use fdisk_set_size_unit to set size unit value. https://cdn.kernel.org/pub/linux/utils/util-linux/v2.34/libfdisk-docs/libfdisk-Context.html#fdisk-set-size-unit
* Use c99 struct initializationJose M. Guisado Gomez2022-04-281-37/+11
| | | | Declutters PyTypeObject struct initialization when declaring new types.
* context: rename parts to partitionsJose M. Guisado Gomez2022-04-281-2/+2
|
* Add COPYING and license headersJose M. Guisado Gomez2022-04-071-0/+12
| | | | LGPL2.1 or later.
* Initial commitJose M. Guisado Gomez2022-04-061-0/+237
Add sources, setup.py and .gitignore Build/Install: python setup.py build python setup.py install