pub struct DiskGeometry {
pub block_size: u32,
pub total_blocks: u64,
pub physical_block_size: Option<u32>,
}Expand description
Disk geometry information.
Contains information about the disk’s logical and physical block sizes, total capacity, and provides utilities for calculating alignment.
Fields§
§block_size: u32Logical block (sector) size in bytes.
total_blocks: u64Total number of blocks on the disk.
physical_block_size: Option<u32>Physical sector size (for alignment), if different from logical.
Modern Advanced Format drives have 4096-byte physical sectors but may present 512-byte logical sectors for compatibility.
Implementations§
Source§impl DiskGeometry
impl DiskGeometry
Sourcepub const STANDARD_BLOCK_SIZE: u32 = 512
pub const STANDARD_BLOCK_SIZE: u32 = 512
Standard logical block size (512 bytes).
Sourcepub const ADVANCED_FORMAT_BLOCK_SIZE: u32 = 4096
pub const ADVANCED_FORMAT_BLOCK_SIZE: u32 = 4096
Advanced Format block size (4096 bytes).
Sourcepub const DEFAULT_ALIGNMENT_BYTES: u64
pub const DEFAULT_ALIGNMENT_BYTES: u64
Default partition alignment (1 MiB in bytes).
1 MiB alignment is the modern standard for optimal performance on both traditional and Advanced Format drives.
Sourcepub const fn standard(total_blocks: u64) -> Self
pub const fn standard(total_blocks: u64) -> Self
Creates geometry for a standard 512-byte sector disk.
§Arguments
total_blocks- Total number of 512-byte sectors on the disk
Sourcepub const fn advanced_format(total_blocks: u64) -> Self
pub const fn advanced_format(total_blocks: u64) -> Self
Creates geometry for a 4K sector disk (Advanced Format).
§Arguments
total_blocks- Total number of 4096-byte sectors on the disk
Sourcepub const fn emulated_512(total_blocks: u64) -> Self
pub const fn emulated_512(total_blocks: u64) -> Self
Creates geometry for a 512e disk (512-byte logical, 4K physical).
These disks present 512-byte logical sectors for compatibility but have 4096-byte physical sectors internally.
§Arguments
total_blocks- Total number of 512-byte logical sectors
Sourcepub const fn new(
block_size: u32,
total_blocks: u64,
physical_block_size: Option<u32>,
) -> Self
pub const fn new( block_size: u32, total_blocks: u64, physical_block_size: Option<u32>, ) -> Self
Creates a new DiskGeometry with custom parameters.
Sourcepub const fn total_bytes(&self) -> u64
pub const fn total_bytes(&self) -> u64
Returns the total disk size in bytes.
Sourcepub const fn alignment_boundary(&self) -> u32
pub const fn alignment_boundary(&self) -> u32
Returns the effective alignment boundary in bytes.
This is the physical block size if set, otherwise the logical block size.
Sourcepub const fn default_alignment(&self) -> u64
pub const fn default_alignment(&self) -> u64
Returns the default partition alignment in sectors.
This is 1 MiB expressed in sectors for the current block size. For 512-byte sectors, this is 2048 sectors. For 4096-byte sectors, this is 256 sectors.
Sourcepub const fn align_down(&self, lba: u64, alignment_sectors: u64) -> u64
pub const fn align_down(&self, lba: u64, alignment_sectors: u64) -> u64
Sourcepub const fn is_aligned(&self, lba: u64, alignment_sectors: u64) -> bool
pub const fn is_aligned(&self, lba: u64, alignment_sectors: u64) -> bool
Checks if an LBA is properly aligned.
§Arguments
lba- The LBA to checkalignment_sectors- The alignment boundary in sectors
Sourcepub const fn gpt_first_usable_lba(
&self,
num_entries: u32,
entry_size: u32,
) -> u64
pub const fn gpt_first_usable_lba( &self, num_entries: u32, entry_size: u32, ) -> u64
Calculates the first usable LBA for GPT partitions.
This accounts for:
- MBR (1 sector)
- GPT header (1 sector)
- Partition entry array
§Arguments
num_entries- Number of partition entries (typically 128)entry_size- Size of each entry in bytes (typically 128)
Sourcepub const fn gpt_first_usable_lba_aligned(
&self,
num_entries: u32,
entry_size: u32,
) -> u64
pub const fn gpt_first_usable_lba_aligned( &self, num_entries: u32, entry_size: u32, ) -> u64
Calculates the first usable LBA aligned to the default alignment.
§Arguments
num_entries- Number of partition entries (typically 128)entry_size- Size of each entry in bytes (typically 128)
Sourcepub const fn gpt_last_usable_lba(
&self,
num_entries: u32,
entry_size: u32,
) -> u64
pub const fn gpt_last_usable_lba( &self, num_entries: u32, entry_size: u32, ) -> u64
Calculates the last usable LBA for GPT partitions.
This accounts for:
- Backup partition entry array
- Backup GPT header (1 sector at the last LBA)
§Arguments
num_entries- Number of partition entries (typically 128)entry_size- Size of each entry in bytes (typically 128)
Trait Implementations§
Source§impl Clone for DiskGeometry
impl Clone for DiskGeometry
Source§fn clone(&self) -> DiskGeometry
fn clone(&self) -> DiskGeometry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more