parted.geom module

@author: Adolfo Gómez, dkmaster at dkmon dot com

class parted.geom.Geometry(geom_or_device: device.Device | cffi.FFI.CData | None = None, start: int = 0, length: int = 0)[source]

Bases: object

This class represents a Geometry

check(sector_offset: int, granularity: int = 1, count: int = 1, buffer_size: int = 1024, tmr: Timer | None = None) int[source]

Checks for physical disk errors.

granularity specificies how sectors should be grouped together. The first bad sector to be returned will always be in the form: * offset + n * granularity

return the first bad sector, or 0 if there were no physical errors

Parameters:
  • sector_offset (int) – The sector offset to start checking

  • granularity (int, optional) – The granularity of how to group sectors. Defaults to 1.

  • buffer_size (int, optional) – The buffer size to use in sectors. Defaults to 1024.

  • insectorstmr (Optional["timer.Timer"], optional) – The timer to use. Defaults to None.

Returns:

The first bad sector, or 0 if there were no physical errors

Raises:

Note

This is a wrapper around the ped_geometry_check function.

close() None[source]

Closes the stream

Raises:

exceptions.NotOpenedError – If the device is not opened

property dev: Device

Device of the geometry

duplicate() Geometry[source]

Returns a copy of this geometry

Returns:

The copy

Return type:

Geometry

Note

This is a wrapper around the ped_geometry_duplicate function.

property end: int

End of the geometry

intersect(other: Geometry) Geometry[source]

Returns the intersection of this geometry with another one

Parameters:

other (Geometry) – The other geometry

Returns:

The intersection geometry

Return type:

Geometry

Note

This is a wrapper around ped_geometry_intersect.

property length: int

Length of the geometry

map(other: Geometry, sector: int) int[source]

This function takes a sector inside the region described by src, and returns that sector’s address inside dst. The two geometries must be on the same device and, must overlap.

Parameters:
  • other – The geometry to map to

  • sector – The sector to map

Returns:

The mapped sector or -1 if error

static new(device: Device, start: int, length: int) Geometry[source]

Create a new PedGeometry object on disk, starting at start with a size of length sectors.

Parameters:
  • device (device.Device) – The device to create the geometry on

  • start (int) – The start sector

  • length (int) – The length in sectors

Returns:

The new geometry object

Return type:

Geometry

property obj: cffi.FFI.CData

Wrapped PedGeometry* object

open() OpenContext[source]

Opens to read/write the geometry

Returns:

The context

Return type:

OpenContext

overlap(other: Geometry) bool[source]

Returns True if this geometry overlaps with another one

Parameters:

other (Geometry) – The other geometry

Returns:

True if the geometries overlap

Return type:

bool

Note

This is a wrapper around the ped_geometry_test_overlap function.

read(sector_offset: int, sector_count: int = 1) bytes[source]

Reads data from the geometry

Parameters:
  • sector_offset (int) – The sector offset to start reading

  • sector_count (int, optional) – The number of sectors to read. Defaults to 1.

Raises:
Returns:

_description_

Return type:

bytes

Note

This is a wrapper around the ped_geometry_read function.

set(start: int = -1, length: int = -1) None[source]

Sets the geometry

Parameters:
  • start (int) – The start sector

  • length (int) – The length in sectors

Raises:
property start: int

Start of the geometry

sync() None[source]

Flushes the cache on geom.

From the parted documentation:

This function flushes all write-behind caches that might be holding writes made by ped_geometry_write() to geom. It is slow, because it guarantees cache coherency among all relevant caches.

Raises:

Note

This is a wrapper around the ped_geometry_sync function.

sync_fast() None[source]

Flushes the cache on geom. (“Fast” version)

From the parted documentation:

This function flushes all write-behind caches that might be holding writes made by ped_geometry_write() to geom. It does NOT ensure cache coherency with other caches that cache data in the region described by geom. If you need cache coherency, use sync() instead.

Raises:

Note

This is a wrapper around the ped_geometry_sync_fast function.

write(data: bytes, sector_offset: int) None[source]

Writes data to the geometry

Parameters:
  • data (bytes) – The data to write

  • sector_offset (int) – The sector offset to start writing (from the beginning of the geometry)

Raises:

exceptions.PartedException – If any error