Commit Graph

3 Commits (1a74bf5024ca7fa21ecff5ea755aac393a58377e)

Author SHA1 Message Date
Jose M. Guisado 34fd2cbe48 add 'string' field getter to parttype
'string' getter wraps fdisk_parttype_get_string to fetch the partition
type UUID in case of a GPT label device.

This is useful to confirm or check the partition type UUID of any device
with a GPT label.

>>> import fdisk
>>> cxt = fdisk.Context('./disk.bin', readonly=False)
>>> pa = cxt.partitions[0]
>>> pa.type.string
'C12A7328-F81F-11D2-BA4B-00A0C93EC93B'
>>> pa.type.name
'EFI System'
2023-01-11 17:11:41 +01:00
Jose M. Guisado 975acaf549 coding style: line breaks
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.
2022-12-15 17:37:07 +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