[][src]Struct gptman::GPTPartitionEntry

pub struct GPTPartitionEntry {
    pub partition_type_guid: [u8; 16],
    pub unique_partition_guid: [u8; 16],
    pub starting_lba: u64,
    pub ending_lba: u64,
    pub attribute_bits: u64,
    pub partition_name: PartitionName,
}

A GPT partition's entry in the partition array.

Examples

Basic usage:

let ss = 512;
let data = vec![0; 100 * ss as usize];
let mut cur = std::io::Cursor::new(data);
let mut gpt = gptman::GPT::new_from(&mut cur, ss as u64, [0xff; 16])
    .expect("could not create partition table");

// NOTE: partition entries starts at 1
gpt[1] = gptman::GPTPartitionEntry {
    partition_type_guid: [0xff; 16],
    unique_partition_guid: [0xff; 16],
    starting_lba: gpt.header.first_usable_lba,
    ending_lba: gpt.header.last_usable_lba,
    attribute_bits: 0,
    partition_name: "A Robot Named Fight!".into(),
};

assert_eq!(gpt[1].partition_name.as_str(), "A Robot Named Fight!");

Fields

partition_type_guid: [u8; 16]

16 bytes representing the UUID of the partition's type.

unique_partition_guid: [u8; 16]

16 bytes representing the UUID of the partition.

starting_lba: u64

The position (in sectors) of the first sector (used) of the partition.

ending_lba: u64

The position (in sectors) of the last sector (used) of the partition.

attribute_bits: u64

The attribute bits.

See Wikipedia's page for more information.

partition_name: PartitionName

The partition name.

Examples

Basic usage:

let name: gptman::PartitionName = "A Robot Named Fight!".into();

assert_eq!(name.as_str(), "A Robot Named Fight!");

Implementations

impl GPTPartitionEntry[src]

pub fn empty() -> GPTPartitionEntry[src]

Creates an empty partition entry

Examples

Basic usage:

let ss = 512;
let data = vec![0; 100 * ss as usize];
let mut cur = std::io::Cursor::new(data);
let mut gpt = gptman::GPT::new_from(&mut cur, ss as u64, [0xff; 16])
    .expect("could not create partition table");

gpt[1] = gptman::GPTPartitionEntry::empty();

// NOTE: an empty partition entry is considered as not allocated
assert!(gpt[1].is_unused());

pub fn read_from<R: ?Sized>(reader: &mut R) -> Result<GPTPartitionEntry> where
    R: Read
[src]

Read a partition entry from the reader at the current position.

pub fn is_unused(&self) -> bool[src]

Returns true if the partition entry is not used (type GUID == [0; 16])

pub fn is_used(&self) -> bool[src]

Returns true if the partition entry is used (type GUID != [0; 16])

pub fn size(&self) -> Result<u64>[src]

Returns the number of sectors in the partition. A partition entry must always be 1 sector long at minimum.

Errors

This function will return an error if the ending_lba is lesser than the starting_lba.

Examples

Basic usage:

let ss = 512;
let data = vec![0; 100 * ss as usize];
let mut cur = std::io::Cursor::new(data);
let mut gpt = gptman::GPT::new_from(&mut cur, ss as u64, [0xff; 16])
    .expect("could not create partition table");

gpt[1] = gptman::GPTPartitionEntry {
    partition_type_guid: [0xff; 16],
    unique_partition_guid: [0xff; 16],
    starting_lba: gpt.header.first_usable_lba,
    ending_lba: gpt.header.last_usable_lba,
    attribute_bits: 0,
    partition_name: "A Robot Named Fight!".into(),
};

assert_eq!(
    gpt[1].size().ok(),
    Some(gpt.header.last_usable_lba + 1 - gpt.header.first_usable_lba)
);

Trait Implementations

impl Clone for GPTPartitionEntry[src]

impl Debug for GPTPartitionEntry[src]

impl<'de> Deserialize<'de> for GPTPartitionEntry[src]

impl Eq for GPTPartitionEntry[src]

impl PartialEq<GPTPartitionEntry> for GPTPartitionEntry[src]

impl Serialize for GPTPartitionEntry[src]

impl StructuralEq for GPTPartitionEntry[src]

impl StructuralPartialEq for GPTPartitionEntry[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,