parse_disk_size_mib

Function parse_disk_size_mib 

Source
pub fn parse_disk_size_mib(s: &str) -> Result<u32>
Expand description

Parse a human-readable size string (e.g. "256mib", "10gib", "1gib") into a count of mebibytes (MiB), rounded down. Returns Err when the suffix is unrecognized, the numeric portion fails to parse, the value is not a positive integer multiple of one MiB, or the result exceeds u32::MAX MiB (the crate::vmm::disk_config::DiskConfig::capacity_mib capacity).

Accepted suffixes (case-insensitive): b, kib, mib, gib. All IEC (powers of two): kib=2^10, mib=2^20, gib=2^30. SI variants (kb/mb/gb) are intentionally NOT accepted; they’re rejected by a dedicated SI-suffix check at the top of the function — before any number-parsing or MiB-alignment runs — so the diagnostic names the IEC-only policy directly instead of leaking through as a misleading “numeric portion not an unsigned integer” message after the suffix strip eats the trailing b. IEC-only is unambiguous and consistent. The bare suffix-less form is also rejected so units are never implicit.

The output unit is MiB to match crate::vmm::disk_config::DiskConfig::capacity_mib (despite the field name, DiskConfig::capacity_bytes left-shifts by 20 — i.e. the field is MiB, not SI MB). A future rename of that field would land in this function in lockstep.