Struct PartitionEntry

Source
#[repr(C, packed(1))]
pub struct PartitionEntry { pub bootable: u8, pub start_head: u8, pub start_sector: u8, pub start_cylinder: u8, pub partition_type: u8, pub end_head: u8, pub end_sector: u8, pub end_cylinder: u8, pub start_lba: u32, pub size_sectors: u32, }
Expand description

MBR partition table entry structure (16 bytes).

This structure represents a single partition entry in an MBR partition table. Each MBR contains exactly 4 partition entries, defining up to 4 primary partitions. The structure follows the traditional PC BIOS partition table format.

§Memory Layout

The structure is packed and has a fixed 16-byte layout for MBR compatibility:

  • Bytes 0: Boot indicator
  • Bytes 1-3: CHS start address (legacy)
  • Byte 4: Partition type ID
  • Bytes 5-7: CHS end address (legacy)
  • Bytes 8-11: LBA start address (little-endian)
  • Bytes 12-15: Partition size in sectors (little-endian)

§Examples

use file_system::*;

// Create a new bootable FAT32 partition
let partition = Partition_entry_type::New_with_params(
    true,
    Partition_type_type::Fat32_lba,
    2048,
    204800
);

assert!(partition.is_bootable());
assert_eq!(partition.get_start_lba(), 2048);
assert_eq!(partition.get_size_sectors(), 204800);

Fields§

§bootable: u8

Boot indicator (0x80 = bootable, 0x00 = non-bootable)

§start_head: u8

Starting head

§start_sector: u8

Starting sector (bits 5-0) and cylinder high bits (bits 7-6)

§start_cylinder: u8

Starting cylinder (low 8 bits)

§partition_type: u8

Partition type ID

§end_head: u8

Ending head

§end_sector: u8

Ending sector (bits 5-0) and cylinder high bits (bits 7-6)

§end_cylinder: u8

Ending cylinder (low 8 bits)

§start_lba: u32

Starting LBA (Logical Block Address)

§size_sectors: u32

Size in sectors

Implementations§

Source§

impl PartitionEntry

Source

pub fn new() -> Self

Create a new empty (invalid) partition entry.

All fields are initialized to zero, making this an invalid partition entry that will not be recognized by the MBR parser.

§Examples
use file_system::*;

let partition = Partition_entry_type::new();
assert!(!partition.is_valid());
assert!(!partition.is_bootable());
Source

pub fn new_with_params( bootable: bool, partition_type: PartitionKind, start_lba: u32, size_sectors: u32, ) -> Self

Create a new partition entry with specified parameters.

This constructor creates a valid partition entry with the specified type, location, and size. The CHS (Cylinder-Head-Sector) fields are not set as modern systems use LBA addressing.

§Arguments
  • Bootable - Whether this partition should be marked as bootable
  • Partition_type - The type of partition (FAT32, Linux, etc.)
  • Start_lba - Starting logical block address (sector number)
  • Size_sectors - Size of the partition in 512-byte sectors
§Examples
use file_system::*;

// Create a 100MB FAT32 partition starting at sector 2048
let partition = Partition_entry_type::New_with_params(
    true,
    Partition_type_type::Fat32_lba,
    2048,
    204800
);

assert!(partition.is_valid());
assert!(partition.is_bootable());
Source

pub fn is_valid(&self) -> bool

Check if this partition entry is valid (non-zero)

Source

pub fn is_bootable(&self) -> bool

Check if this partition is bootable

Source

pub fn set_bootable(&mut self, bootable: bool)

Set the bootable flag

Source

pub fn get_start_lba(&self) -> u32

Get the starting LBA of this partition

Source

pub fn set_start_lba(&mut self, start_lba: u32)

Set the starting LBA of this partition

Source

pub fn get_size_sectors(&self) -> u32

Get the size in sectors of this partition

Source

pub fn set_size_sectors(&mut self, size_sectors: u32)

Set the size in sectors of this partition

Source

pub fn get_partition_type(&self) -> PartitionKind

Get the partition type as an enum

Source

pub fn set_partition_type(&mut self, partition_type: PartitionKind)

Set the partition type from an enum

Source

pub fn get_partition_type_name(&self) -> &'static str

Get the partition type as a human-readable string

Source

pub fn get_end_lba(&self) -> u32

Get the end LBA of this partition (start + size - 1)

Source

pub fn get_size_bytes(&self) -> u64

Get the size in bytes of this partition

Source

pub fn overlaps_with(&self, other: &Self) -> bool

Check if this partition overlaps with another partition

Source

pub fn contains_lba(&self, lba: u32) -> bool

Check if a given LBA is within this partition

Source

pub fn clear(&mut self)

Clear the partition entry (make it empty)

Trait Implementations§

Source§

impl Clone for PartitionEntry

Source§

fn clone(&self) -> PartitionEntry

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 PartitionEntry

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for PartitionEntry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for PartitionEntry

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Copy for PartitionEntry

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> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.