pub struct PartitionEntry {
pub bootable: bool,
pub start_head: u8,
pub start_sector: u8,
pub start_cylinder: u8,
pub kind: PartitionKind,
pub end_head: u8,
pub end_sector: u8,
pub end_cylinder: u8,
pub start_block: u32,
pub block_count: 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::mbr::{PartitionEntry, PartitionKind};
// Create a new bootable FAT32 partition
let partition = PartitionEntry::new_with_params(
true,
PartitionKind::Fat32Lba,
2048,
204800
);
assert!(partition.bootable);
assert_eq!(partition.start_block, 2048);
assert_eq!(partition.block_count, 204800);Fields§
§bootable: boolBoot indicator
start_head: u8Starting head
start_sector: u8Starting sector (bits 5-0) and cylinder high bits (bits 7-6)
start_cylinder: u8Starting cylinder (low 8 bits)
kind: PartitionKindPartition type ID
end_head: u8Ending head
end_sector: u8Ending sector (bits 5-0) and cylinder high bits (bits 7-6)
end_cylinder: u8Ending cylinder (low 8 bits)
start_block: u32Starting LBA (Logical Block Address)
block_count: u32Size in sectors
Implementations§
Source§impl PartitionEntry
impl PartitionEntry
pub const SIZE: usize = 16
pub const BOOTABLE_FLAG: u8 = 0x80
pub fn parse(data: &[u8]) -> Option<Self>
Sourcepub fn new_empty() -> Self
pub fn new_empty() -> 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::mbr::PartitionEntry;
let partition = PartitionEntry::new_empty();
assert!(!partition.is_valid());
assert!(!partition.bootable);Sourcepub fn new_with_params(
bootable: bool,
kind: PartitionKind,
start_lba: u32,
size_sectors: u32,
) -> Self
pub fn new_with_params( bootable: bool, kind: 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::mbr::{PartitionEntry, PartitionKind};
// Create a 100MB FAT32 partition starting at sector 2048
let partition = PartitionEntry::new_with_params(
true,
PartitionKind::Fat32Lba,
2048,
204800
);
assert!(partition.is_valid());
assert!(partition.bootable);pub fn to_bytes(&self) -> [u8; 16]
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