Commit Graph

6 Commits (1a74bf5024ca7fa21ecff5ea755aac393a58377e)

Author SHA1 Message Date
Jose M. Guisado e23d9cd027 context: delete unused label field
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.
2022-12-20 16:18:31 +01:00
Jose M. Guisado 5ec9ec73c8 fdisk: add set_PyErr_from_rc
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.
2022-12-15 17:46:42 +01:00
Jose M. Guisado 5eba6d4d65 parttype: add parttype class and functions
Parttype is a container for partition types in libfdisk.

In python-libfdisk, the only way to create parttype instances
is using the corresponding label-specific function:

	get_parttype_from_{code,string}

This function wraps libfdisk's label_get_parttype_from_code (lookup DOS
label parttype by hex code) and label_get_parttype_from_string (lookup
GPT parttype by type uuid)

For example, to get the parttype instance of 'EFI System'
partition type of a GPT label, with type uuid
'c12a7328-f81f-11d2-ba4b-00a0c93ec93b':

>>> import fdisk
>>> cxt = fdisk.Context('./disk.bin', readonly=False)
>>> cxt.create_disklabel('gpt')
>>> efitype = cxt.label.get_parttype_from_string("c12a7328-f81f-11d2-ba4b-00a0c93ec93b")
>>> efitype
<libfdisk.PartType object at 0x7f503e4a5270, name=EFI System>

See:

https://cdn.kernel.org/pub/linux/utils/util-linux/v2.34/libfdisk-docs/libfdisk-Partition-types.html
https://cdn.kernel.org/pub/linux/utils/util-linux/v2.34/libfdisk-docs/libfdisk-Label.html#fdisk-label-get-parttype-from-code
https://cdn.kernel.org/pub/linux/utils/util-linux/v2.34/libfdisk-docs/libfdisk-Label.html#fdisk-label-get-parttype-from-string
2022-12-15 17:37:07 +01:00
Jose M. Guisado Gomez b905c1996f fdisk.c: add partition module object
Call Partition_AddModuleObject when initializing the python module.

Fixes bug when using the Partition class but the class has not
been added to the module via Py_TypeReady.

A common error was the type not being ready (missing attributes):

>>> for pa in cxt.parts:
...     print(pa.partno)
...
Traceback (most recent call last):
   File "<stdin>", line 2, in <module>
AttributeError: 'libfdisk.Partition' object has no attribute 'partno'
2022-04-26 17:08:49 +02:00
Jose M. Guisado Gomez ef613790e9 Add COPYING and license headers
LGPL2.1 or later.
2022-04-07 17:03:34 +02:00
Jose M. Guisado Gomez ca92f15e2a Initial commit
Add sources, setup.py and .gitignore

Build/Install:

	python setup.py build
	python setup.py install
2022-04-06 12:56:11 +02:00