2024-02-23 04:37:53 +00:00
|
|
|
use futures::executor::block_on;
|
2024-01-08 17:07:00 -08:00
|
|
|
use xenstore::client::{XsdClient, XsdInterface};
|
2024-01-30 01:58:10 -08:00
|
|
|
use xenstore::error::Result;
|
2024-01-08 17:07:00 -08:00
|
|
|
use xenstore::sys::XSD_ERROR_EINVAL;
|
2024-01-08 12:43:16 -08:00
|
|
|
|
2024-01-30 01:58:10 -08:00
|
|
|
fn list_recursive(client: &mut XsdClient, level: usize, path: &str) -> Result<()> {
|
2024-02-23 04:37:53 +00:00
|
|
|
let children = match block_on(client.list(path)) {
|
2024-01-08 12:43:16 -08:00
|
|
|
Ok(children) => children,
|
2024-01-08 14:13:51 -08:00
|
|
|
Err(error) => {
|
2024-01-08 14:16:33 -08:00
|
|
|
return if error.to_string() == XSD_ERROR_EINVAL.error {
|
2024-01-08 14:13:51 -08:00
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
Err(error)
|
|
|
|
}
|
2024-01-08 12:43:16 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for child in children {
|
2024-01-08 14:13:51 -08:00
|
|
|
let full = format!("{}/{}", if path == "/" { "" } else { path }, child);
|
2024-02-23 04:37:53 +00:00
|
|
|
let value = block_on(client.read_string(full.as_str()))?.expect("expected value");
|
|
|
|
println!("{}{} = {:?}", " ".repeat(level), child, value,);
|
2024-01-08 12:43:16 -08:00
|
|
|
list_recursive(client, level + 1, full.as_str())?;
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2024-02-23 04:37:53 +00:00
|
|
|
#[tokio::main]
|
|
|
|
async fn main() -> Result<()> {
|
|
|
|
let mut client = XsdClient::open().await?;
|
2024-01-08 12:43:16 -08:00
|
|
|
list_recursive(&mut client, 0, "/")?;
|
|
|
|
Ok(())
|
|
|
|
}
|