freebsd_geom/
lib.rs

1#![allow(dead_code)]
2
3#[macro_use]
4extern crate scan_fmt;
5extern crate sysctl;
6
7use sysctl::Sysctl;
8
9#[cfg(target_os = "freebsd")]
10fn get_confxml() -> Result<String, Error> {
11    const CTLNAME: &str = "kern.geom.confxml";
12
13    let ctl = sysctl::Ctl::new(CTLNAME)?;
14    return Ok(ctl.value_string()?);
15}
16
17/// Returns a structure representing the GEOM graph on the running system.
18///
19/// # Examples
20///
21/// ```
22/// use freebsd_geom as geom;
23///
24/// fn myfoo() -> Result<(), geom::Error> {
25///     let graph = geom::get_graph()?;
26///     Ok(())
27/// }
28/// ```
29#[cfg(target_os = "freebsd")]
30pub fn get_graph() -> Result<Graph, Error> {
31    let raw_mesh = raw::get_mesh()?;
32    return graph::decode_graph(&raw_mesh);
33}
34
35#[cfg(all(test, target_os = "freebsd"))]
36mod tests_freebsd {
37    use crate::*;
38
39    #[test]
40    #[ignore = "not reproducible"]
41    fn getsysctlstr() {
42        let s = get_confxml().unwrap();
43        assert_ne!(s, "", "sysctl output is non-empty");
44    }
45}
46
47// reexport
48pub mod error;
49mod graph;
50pub mod structs;
51
52pub use error::Error;
53pub use graph::{
54    Edge, EdgeId, EdgeMetadata, Geom, GeomClass, Graph, Mode, NodeId, PartMetadata, PartScheme,
55    PartState,
56};
57pub use structs as raw;