Struct Geometry

Source
pub struct Geometry<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> Geometry<'a>

Source

pub fn from_raw(geometry: *mut PedGeometry) -> Geometry<'a>

Source

pub fn exact(&self) -> Option<Constraint<'_>>

Return a constraint that only the given region will satisfy.

Source

pub fn check( &self, offset: i64, granularity: i64, count: i64, timer: &Timer<'_>, ) -> Result<(), u64>

Checks for physical disk errors.

Checks a region for physical defects on geom. The region checked starts at offset sectors inside the region represented by geom, and is count sectors long. granularity specifies how sectors should be grouped together.

The first bad sector to be returned will always be in the form:

    offset + n * granularity

Returns the first bad sector if a bad sector was found.

Source

pub fn dev(&self) -> Device<'_>

Source

pub fn dev_mut(&mut self) -> Device<'_>

Source

pub fn duplicate<'b>(&self) -> Result<Geometry<'b>>

Duplicate a Geometry object.

Source

pub fn end(&self) -> i64

Source

pub fn init( &mut self, device: &Device<'_>, start: i64, length: i64, ) -> Result<()>

Initializes a pre-allocated Geometry.

Source

pub fn intersect(&self, other: &Geometry<'_>) -> Option<Geometry<'a>>

Return a Geometry object that refers to the intersection between itself and another Geometry.

Source

pub fn length(&self) -> i64

Source

pub fn map(&self, src: &Geometry<'_>, sector: i64) -> Option<u64>

Takes a sector inside the region described by src and returns that sector’s address inside of our own Geometry marked as self. This means that the following code examples are equivalent:

geometry.read(buf, geometry.map(src, sector), 1);
geometry.read(buf, sector, 1);

Clearly, this will only work if self and src overlap.

Source

pub fn new(device: &Device<'_>, start: i64, length: i64) -> Result<Geometry<'a>>

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

Source

pub fn read(&self, buffer: &mut Vec<u8>, offset: i64, count: i64) -> Result<()>

Reads data from the region within our Geometry. offset is the location from within the region, not from the start of the disk. count sectors are read into buffer. An exception is thrown when attempting to read sectors outside of the partition.

§Note:

The supplied vector will be reallocated to the correct size automatically.

§Throws:

Throws PED_EXCEPTION_ERROR when attempting to read sectors outside of partition.

Source

pub fn set(&mut self, start: i64, length: i64) -> Result<()>

Assign a new start and length, where end will also be set implicitly from those values.

Source

pub fn set_end(&mut self, end: i64) -> Result<()>

Assign a new end to self without changing self->start field.

self->length will be updated accordingly.

Source

pub fn set_start(&mut self, start: i64) -> Result<()>

Assign a new start to self witout changing self->end.

self->length will be updated accordingly.

Source

pub fn start(&self) -> i64

Source

pub fn sync(&mut self) -> Result<()>

Flushes the cache on self.

This function flushses all write-behind caches that might be holding writes made by Geometry::write() to self. It is slow because it guarantees cache coherency among all relevant caches.

Source

pub fn sync_fast(&mut self) -> Result<()>

Flushes the cache on self.

This function flushses all write-behind caches that might be holding writes made by Geometry::write() to self. It does not ensure cache coherency with other caches that cache data in the region described by self.

If you need cache coherency, use Geometry::sync() instead.

Source

pub fn test_equal(&self, other: &Geometry<'_>) -> bool

Tests if the other Geometry refers to the same physical region as self.

Source

pub fn test_inside(&self, other: &Geometry<'_>) -> bool

Tests if the other Geometry is inside self.

Source

pub fn test_sector_inside(&self, sector: i64) -> bool

Tests if sector is inside the geometry.

Source

pub fn write_to_sectors( &mut self, buffer: &[u8], offset: i64, count: i64, ) -> Result<()>

Writes data into the region represented by self. The offset is the location from within the region, not from the start of the disk. count sectors are to be written.

Source

pub fn open_fs(&self) -> Option<FileSystem<'_>>

Opens the file system stored in the given Geometry.

§Examples
let mut fs = FileSystem::open(&mut geometry);
let mut fs = geometry.open_fs();
§Throws
  • PED_EXCEPTION_ERROR if the file system could not be detected.
  • PED_EXCEPTION_ERROR if the file system is bigger than its volume.
  • PED_EXCEPTION_NO_FEATURE if opening of a file system stored on geom is not implemented.
Source

pub fn probe_fs(&self) -> Result<FileSystemType<'_>>

Attempt to detect a file system in the given Geometry.

This function tries to be clever at dealing with ambiguous situations, such as when one file system was not completely erased before a new file system was created on on top of it.

Source

pub fn probe_specific_fs<'b>( &'b self, fs_type: &'b FileSystemType<'_>, ) -> Option<Geometry<'b>>

Attempt to find a file system and return the region it occupies.

Trait Implementations§

Source§

impl<'a> Drop for Geometry<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Geometry<'a>

§

impl<'a> RefUnwindSafe for Geometry<'a>

§

impl<'a> !Send for Geometry<'a>

§

impl<'a> !Sync for Geometry<'a>

§

impl<'a> Unpin for Geometry<'a>

§

impl<'a> UnwindSafe for Geometry<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.