#[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
impl PartitionEntry
Sourcepub fn new() -> Self
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());
Sourcepub fn new_with_params(
bootable: bool,
partition_type: PartitionKind,
start_lba: u32,
size_sectors: u32,
) -> Self
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 bootablePartition_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());
Sourcepub fn is_bootable(&self) -> bool
pub fn is_bootable(&self) -> bool
Check if this partition is bootable
Sourcepub fn set_bootable(&mut self, bootable: bool)
pub fn set_bootable(&mut self, bootable: bool)
Set the bootable flag
Sourcepub fn get_start_lba(&self) -> u32
pub fn get_start_lba(&self) -> u32
Get the starting LBA of this partition
Sourcepub fn set_start_lba(&mut self, start_lba: u32)
pub fn set_start_lba(&mut self, start_lba: u32)
Set the starting LBA of this partition
Sourcepub fn get_size_sectors(&self) -> u32
pub fn get_size_sectors(&self) -> u32
Get the size in sectors of this partition
Sourcepub fn set_size_sectors(&mut self, size_sectors: u32)
pub fn set_size_sectors(&mut self, size_sectors: u32)
Set the size in sectors of this partition
Sourcepub fn get_partition_type(&self) -> PartitionKind
pub fn get_partition_type(&self) -> PartitionKind
Get the partition type as an enum
Sourcepub fn set_partition_type(&mut self, partition_type: PartitionKind)
pub fn set_partition_type(&mut self, partition_type: PartitionKind)
Set the partition type from an enum
Sourcepub fn get_partition_type_name(&self) -> &'static str
pub fn get_partition_type_name(&self) -> &'static str
Get the partition type as a human-readable string
Sourcepub fn get_end_lba(&self) -> u32
pub fn get_end_lba(&self) -> u32
Get the end LBA of this partition (start + size - 1)
Sourcepub fn get_size_bytes(&self) -> u64
pub fn get_size_bytes(&self) -> u64
Get the size in bytes of this partition
Sourcepub fn overlaps_with(&self, other: &Self) -> bool
pub fn overlaps_with(&self, other: &Self) -> bool
Check if this partition overlaps with another partition
Sourcepub fn contains_lba(&self, lba: u32) -> bool
pub fn contains_lba(&self, lba: u32) -> bool
Check if a given LBA is within this partition
Trait Implementations§
Source§impl Clone for PartitionEntry
impl Clone for PartitionEntry
Source§fn clone(&self) -> PartitionEntry
fn clone(&self) -> PartitionEntry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more