| Commit message (Collapse) | Author | Age | Files | Lines |
|
|
|
|
|
|
| |
libfdisk context add_partition function initializes a passed argument
with the new partition's partno.
If add_partition is successful, return its partno.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Partition type getset enables modifying and getting the type
of a give libfdisk partition.
The type of a partition is defined using PartType, which
can only be instanced via label specific functions
get_parttype_from_string or get_parttype_from_code.
For example, to set the type of a new partitions to 'EFI System':
>>> import fdisk
>>> pa = fdisk.Partition()
>>> pa.type
>>> cxt = fdisk.Context('./disk.bin', readonly=False)
>>> cxt.create_disklabel('gpt')
>>> efitype = cxt.label.get_parttype_from_string("c12a7328-f81f-11d2-ba4b-00a0c93ec93b")
>>> pa.type = efitype
Following the previous example, getting its current partition type:
>>> pa.type
<libfdisk.PartType object at 0x7f2f0a9a12d0, name=EFI System>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Add optional parameters inside init function of partition. Optional
parameters refer to:
- partno_follow_default
- start_follow_default
- end_follow_default
These options can be used in order to enable or disable default partno,
start and end value when adding partitions.
With those optional parameters enabled by default a user is able
to add a partition into the context label without specifying any
attribute.
>>> import fdisk
>>> cxt = fdisk.Context('./disk.bin', readonly=False)
>>> cxt.create_disklabel('gpt')
>>> pa = fdisk.Partition()
>>> cxt.add_partition(pa)
This enables:
- "Filling" the rest of the disk with last partition
- No need to track start/end sector for any following partition
- No need to track next partno number for any following partition
See:
https://cdn.kernel.org/pub/linux/utils/util-linux/v2.34/libfdisk-docs/libfdisk-Partition.html#fdisk-partition-partno-follow-default
https://cdn.kernel.org/pub/linux/utils/util-linux/v2.34/libfdisk-docs/libfdisk-Partition.html#fdisk-partition-start-follow-default
https://cdn.kernel.org/pub/linux/utils/util-linux/v2.34/libfdisk-docs/libfdisk-Partition.html#fdisk-partition-end-follow-default
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Allows changing in-memory partno field of a Partition instance:
>>> import fdisk
>>> pa = fdisk.Partition()
>>> pa.partno = 3
>>> pa
<libfdisk.Partition object at 0x7f4603a38f30, partno=3>
If partno is unset repr shows 'None':
>>> import fdisk
>>> pa = fdisk.Partition()
>>> pa
<libfdisk.Partition object at 0x7f86c4338f30, partno=None>
|
|
|
|
|
|
|
| |
Undefined values in libfdisk should map to None type in Python.
Py_BuildValue("%d", -1); is also incorrectly formatted and raises an
error when executed.
|
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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
|
|
|
|
| |
Declutters PyTypeObject struct initialization when declaring new types.
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
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'
|
|
|
|
| |
LGPL2.1 or later.
|
|
|
|
| |
Add MANIFEST.in to include .h files in source distributions.
|
|
Add sources, setup.py and .gitignore
Build/Install:
python setup.py build
python setup.py install
|