Skip to main content

id_ctrl/
id_ctrl.rs

1//! Print the Identify Controller data for each NVMe controller.
2
3use libnvme::Root;
4
5fn main() -> Result<(), Box<dyn std::error::Error>> {
6    let root = Root::scan()?;
7    let mut any = false;
8    for host in root.hosts() {
9        for subsys in host.subsystems() {
10            for ctrl in subsys.controllers() {
11                any = true;
12                print_controller(&ctrl)?;
13            }
14        }
15    }
16    if !any {
17        println!("(no NVMe controllers found)");
18    }
19    Ok(())
20}
21
22fn print_controller(ctrl: &libnvme::Controller<'_>) -> Result<(), Box<dyn std::error::Error>> {
23    println!("=== {} ===", ctrl.name()?);
24    let id = ctrl.identify()?;
25    println!("  vendor id          : 0x{:04x}", id.vendor_id());
26    println!("  subsystem vendor   : 0x{:04x}", id.subsystem_vendor_id());
27    println!("  model              : {}", id.model_number()?);
28    println!("  serial             : {}", id.serial_number()?);
29    println!("  firmware           : {}", id.firmware_revision()?);
30    println!("  nvme spec          : {}", id.nvme_version());
31    println!("  controller id      : {}", id.controller_id());
32    println!("  controller type    : {}", id.controller_type());
33    println!("  num namespaces     : {}", id.num_namespaces());
34    println!(
35        "  total nvm capacity : {} bytes",
36        id.total_nvm_capacity_bytes()
37    );
38    println!(
39        "  warn temp threshold: {} K",
40        id.warning_temp_threshold_kelvin()
41    );
42    println!(
43        "  crit temp threshold: {} K",
44        id.critical_temp_threshold_kelvin()
45    );
46    println!();
47    Ok(())
48}