1use libnvme::Root;
8
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10 let root = Root::scan()?;
11 let mut any = false;
12 for host in root.hosts() {
13 for subsys in host.subsystems() {
14 for ctrl in subsys.controllers() {
15 any = true;
16 print_fw(&ctrl)?;
17 }
18 }
19 }
20 if !any {
21 println!("(no NVMe controllers found)");
22 }
23 Ok(())
24}
25
26fn print_fw(ctrl: &libnvme::Controller<'_>) -> Result<(), Box<dyn std::error::Error>> {
27 println!("=== {} ===", ctrl.name()?);
28 let log = ctrl.fw_slot_log()?;
29 println!(" AFI byte : 0x{:02x}", log.afi());
30 println!(" active slot : {}", log.active_slot());
31 match log.next_slot_to_activate() {
32 Some(slot) => println!(" next activate slot : {}", slot),
33 None => println!(" next activate slot : (none — current image stays active)"),
34 }
35 for slot in 1..=7 {
36 match log.slot_firmware(slot) {
37 Ok("") => println!(" slot {slot} : (empty)"),
38 Ok(fw) => println!(" slot {slot} : {fw}"),
39 Err(e) => println!(" slot {slot} : error: {e}"),
40 }
41 }
42 println!();
43 Ok(())
44}