MCPcopy Create free account
hub / github.com/bootc-dev/bootc / find_partition_of_esp_optional

Method find_partition_of_esp_optional

crates/blockdev/src/blockdev.rs:252–285  ·  view source on GitHub ↗

Find the EFI System Partition (ESP) among children. For GPT disks, this matches by the ESP partition type GUID. For MBR (dos) disks, this matches by the MBR partition type IDs (0x06 or 0xEF). If no ESP is found among direct children, this recurses into children that have their own partition table (e.g. firmware RAID arrays where the hierarchy is disk → md array → partitions). Returns `Ok(None)`

(&self)

Source from the content-addressed store, hash-verified

250 /// is present. Returns `Err` only for genuinely unexpected conditions
251 /// (e.g. an unsupported partition table type).
252 pub fn find_partition_of_esp_optional(&self) -> Result<Option<&Device>> {
253 let Some(children) = self.children.as_ref() else {
254 return Ok(None);
255 };
256 let direct = match self.pttype.as_deref() {
257 Some("dos") => children.iter().find(|child| {
258 child
259 .parttype
260 .as_ref()
261 .and_then(|pt| {
262 let pt = pt.strip_prefix("0x").unwrap_or(pt);
263 u8::from_str_radix(pt, 16).ok()
264 })
265 .is_some_and(|pt| ESP_ID_MBR.contains(&pt))
266 }),
267 // When pttype is None (e.g. older lsblk or partition devices), default
268 // to GPT UUID matching which will simply not match MBR hex types.
269 Some("gpt") | None => self.find_partition_of_type(ESP),
270 Some(other) => return Err(anyhow!("Unsupported partition table type: {other}")),
271 };
272 if direct.is_some() {
273 return Ok(direct);
274 }
275 // Recurse into children that carry their own partition table, such as
276 // firmware RAID arrays (disk → md array → partitions).
277 for child in children {
278 if child.pttype.is_some() {
279 if let Some(esp) = child.find_partition_of_esp_optional()? {
280 return Ok(Some(esp));
281 }
282 }
283 }
284 Ok(None)
285 }
286
287 /// Find the EFI System Partition (ESP) among children, or error if absent.
288 ///

Callers 4

mount_esp_partFunction · 0.80
newMethod · 0.80
find_colocated_espsMethod · 0.80
find_partition_of_espMethod · 0.80

Calls 4

as_refMethod · 0.45
findMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected