Struct PartitionStatistics

Source
pub struct PartitionStatistics {
    pub total_partitions: usize,
    pub bootable_partitions: usize,
    pub fat_partitions: usize,
    pub linux_partitions: usize,
    pub hidden_partitions: usize,
    pub extended_partitions: usize,
    pub unknown_partitions: usize,
    pub total_used_sectors: u64,
    pub largest_partition_sectors: u32,
    pub smallest_partition_sectors: u32,
}
Expand description

Comprehensive statistics about partitions in an MBR.

This structure provides detailed statistical information about the partitions present in an MBR, including counts by type, size information, and bootability status. It’s useful for disk analysis, partition management tools, and system diagnostics.

§Fields

§Partition Counts

  • Total_partitions - Total number of valid partitions
  • Bootable_partitions - Number of partitions marked as bootable
  • Fat_partitions - Number of FAT file system partitions (FAT16, FAT32, etc.)
  • Linux_partitions - Number of Linux-type partitions
  • Hidden_partitions - Number of hidden partitions
  • Extended_partitions - Number of extended partitions
  • Unknown_partitions - Number of partitions with unknown/unrecognized types

§Size Information

  • Total_used_sectors - Total sectors used by all partitions
  • Largest_partition_sectors - Size of the largest partition in sectors
  • Smallest_partition_sectors - Size of the smallest partition in sectors

§Examples

extern crate alloc;
use file_system::*;

let device = create_device!(Memory_device_type::<512>::new(4 * 1024 * 1024));
// Create an MBR with some partitions
let mut mbr = MBR_type::New_with_signature(0x12345678);
mbr.Add_partition(Partition_type_type::Fat32_lba, 2048, 1024, true).unwrap();
mbr.Add_partition(Partition_type_type::Linux, 4096, 2048, false).unwrap();
mbr.Write_to_device(&device).unwrap();

// Read it back and get statistics
let mbr = MBR_type::Read_from_device(&device).unwrap();
let stats = Partition_statistics_type::From_mbr(&mbr);
println!("Total partitions: {}", stats.Total_partitions);
println!("Bootable partitions: {}", stats.Bootable_partitions);
println!("Total used sectors: {}", stats.Total_used_sectors);

Fields§

§total_partitions: usize

Total number of valid partitions in the MBR.

§bootable_partitions: usize

Number of partitions marked as bootable.

§fat_partitions: usize

Number of FAT file system partitions.

§linux_partitions: usize

Number of Linux-type partitions.

§hidden_partitions: usize

Number of hidden partitions.

§extended_partitions: usize

Number of extended partitions.

§unknown_partitions: usize

Number of partitions with unknown types.

§total_used_sectors: u64

Total sectors used by all partitions.

§largest_partition_sectors: u32

Size of the largest partition in sectors.

§smallest_partition_sectors: u32

Size of the smallest partition in sectors.

Implementations§

Source§

impl PartitionStatistics

Source

pub fn from_mbr(mbr: &Mbr) -> Self

Generate comprehensive statistics from an MBR.

This method analyzes all partitions in the provided MBR and generates detailed statistics about partition types, sizes, and other characteristics.

§Arguments
  • Mbr - The MBR structure to analyze
§Returns

A new Partition_statistics_type containing the computed statistics.

§Examples
extern crate alloc;
use file_system::*;

let device = create_device!(Memory_device_type::<512>::new(4 * 1024 * 1024));
// Create an MBR with some partitions
let mut mbr = MBR_type::New_with_signature(0x12345678);
mbr.Add_partition(Partition_type_type::Fat32_lba, 2048, 1024, true).unwrap();
mbr.Add_partition(Partition_type_type::Linux, 4096, 2048, false).unwrap();
mbr.Write_to_device(&device).unwrap();

// Read it back and analyze
let mbr = MBR_type::Read_from_device(&device).unwrap();
let stats = Partition_statistics_type::From_mbr(&mbr);
if stats.Total_partitions > 0 {
    println!("Average partition size: {} sectors",
             stats.Total_used_sectors / stats.Total_partitions as u64);
}

Trait Implementations§

Source§

impl Clone for PartitionStatistics

Source§

fn clone(&self) -> PartitionStatistics

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PartitionStatistics

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.