2024-01-09 01:07:00 +00:00
|
|
|
use xenstore::client::{XsdClient, XsdInterface};
|
2024-01-30 09:58:10 +00:00
|
|
|
use xenstore::error::Result;
|
2024-01-09 01:07:00 +00:00
|
|
|
use xenstore::sys::XSD_ERROR_EINVAL;
|
2024-01-08 20:43:16 +00:00
|
|
|
|
2024-01-30 09:58:10 +00:00
|
|
|
fn list_recursive(client: &mut XsdClient, level: usize, path: &str) -> Result<()> {
|
2024-01-08 20:43:16 +00:00
|
|
|
let children = match client.list(path) {
|
|
|
|
Ok(children) => children,
|
2024-01-08 22:13:51 +00:00
|
|
|
Err(error) => {
|
2024-01-08 22:16:33 +00:00
|
|
|
return if error.to_string() == XSD_ERROR_EINVAL.error {
|
2024-01-08 22:13:51 +00:00
|
|
|
Ok(())
|
|
|
|
} else {
|
|
|
|
Err(error)
|
|
|
|
}
|
2024-01-08 20:43:16 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for child in children {
|
2024-01-08 22:13:51 +00:00
|
|
|
let full = format!("{}/{}", if path == "/" { "" } else { path }, child);
|
2024-01-08 20:43:16 +00:00
|
|
|
let value = client.read(full.as_str())?;
|
2024-01-08 22:13:51 +00:00
|
|
|
println!(
|
|
|
|
"{}{} = {:?}",
|
|
|
|
" ".repeat(level),
|
|
|
|
child,
|
|
|
|
String::from_utf8(value)?
|
|
|
|
);
|
2024-01-08 20:43:16 +00:00
|
|
|
list_recursive(client, level + 1, full.as_str())?;
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2024-01-30 09:58:10 +00:00
|
|
|
fn main() -> Result<()> {
|
2024-01-09 07:23:26 +00:00
|
|
|
let mut client = XsdClient::open()?;
|
2024-01-08 20:43:16 +00:00
|
|
|
list_recursive(&mut client, 0, "/")?;
|
|
|
|
Ok(())
|
|
|
|
}
|