MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / print_node

Function print_node

arch/src/riscv64/fdt.rs:423–483  ·  view source on GitHub ↗
(node: fdt_parser::node::FdtNode<'_, '_>, n_spaces: usize)

Source from the content-addressed store, hash-verified

421}
422
423fn print_node(node: fdt_parser::node::FdtNode<'_, '_>, n_spaces: usize) {
424 debug!("{:indent$}{}/", "", node.name, indent = n_spaces);
425 for property in node.properties() {
426 let name = property.name;
427
428 // If the property is 'compatible', its value requires special handling.
429 // The u8 array could contain multiple null-terminated strings.
430 // We copy the original array and simply replace all 'null' characters with spaces.
431 let value = if name == "compatible" {
432 let mut compatible = vec![0u8; 256];
433 let handled_value = property
434 .value
435 .iter()
436 .map(|&c| if c == 0 { b' ' } else { c })
437 .collect::<Vec<_>>();
438 let len = cmp::min(255, handled_value.len());
439 compatible[..len].copy_from_slice(&handled_value[..len]);
440 compatible[..(len + 1)].to_vec()
441 } else {
442 property.value.to_vec()
443 };
444 let value = &value;
445
446 // Now the value can be either:
447 // - A null-terminated C string, or
448 // - Binary data
449 // We follow a very simple logic to present the value:
450 // - At first, try to convert it to CStr and print,
451 // - If failed, print it as u32 array.
452 let value_result = match CStr::from_bytes_with_nul(value) {
453 Ok(value_cstr) => value_cstr.to_str().ok(),
454 Err(_e) => None,
455 };
456
457 if let Some(value_str) = value_result {
458 debug!(
459 "{:indent$}{} : {:#?}",
460 "",
461 name,
462 value_str,
463 indent = (n_spaces + 2)
464 );
465 } else {
466 let mut array = Vec::with_capacity(256);
467 array.resize(value.len() / 4, 0u32);
468 BigEndian::read_u32_into(value, &mut array);
469 debug!(
470 "{:indent$}{} : {:X?}",
471 "",
472 name,
473 array,
474 indent = (n_spaces + 2)
475 );
476 }
477 }
478
479 // Print children nodes if there is any
480 for child in node.children() {

Callers 1

print_fdtFunction · 0.70

Calls 5

iterMethod · 0.80
okMethod · 0.80
mapMethod · 0.45
lenMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected