Commit Graph

7 Commits (7271bc99db8dcb349464eabd50da3f41942f6822)

Author SHA1 Message Date
Jose M. Guisado 7271bc99db partition: add *_follow_default optional params
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
2022-12-15 17:36:57 +01:00
Jose M. Guisado 8707d43111 context: add add_partition method
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.
2022-12-15 12:27:35 +01:00
Jose M. Guisado 46ad17eaa7 partition: add partno setter
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>
2022-12-15 12:27:22 +01:00
Jose M. Guisado bd2703c54e partition: return None if partno is unset
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.
2022-12-15 12:16:52 +01:00
Jose M. Guisado Gomez ba67cc7a7b Use c99 struct initialization
Declutters PyTypeObject struct initialization when declaring new types.
2022-04-28 15:47:55 +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