1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#![allow(dead_code)]

#[macro_use]
extern crate scan_fmt;
extern crate sysctl;

use sysctl::Sysctl;

#[cfg(target_os = "freebsd")]
fn get_confxml() -> Result<String, Error> {
    const CTLNAME: &str = "kern.geom.confxml";

    let ctl = sysctl::Ctl::new(CTLNAME)?;
    return Ok(ctl.value_string()?);
}

/// Returns a structure representing the GEOM graph on the running system.
///
/// # Examples
///
/// ```
/// use freebsd_geom as geom;
///
/// fn myfoo() -> Result<(), geom::Error> {
///     let graph = geom::get_graph()?;
///     Ok(())
/// }
/// ```
#[cfg(target_os = "freebsd")]
pub fn get_graph() -> Result<Graph, Error> {
    let raw_mesh = raw::get_mesh()?;
    return graph::decode_graph(&raw_mesh);
}

#[cfg(all(test, target_os = "freebsd"))]
mod tests_freebsd {
    use crate::*;

    #[test]
    #[ignore = "not reproducible"]
    fn getsysctlstr() {
        let s = get_confxml().unwrap();
        assert_ne!(s, "", "sysctl output is non-empty");
    }
}

// reexport
pub mod error;
mod graph;
pub mod structs;

pub use error::Error;
pub use graph::{
    Edge, EdgeId, EdgeMetadata, Geom, GeomClass, Graph, Mode, NodeId, PartMetadata, PartScheme,
    PartState,
};
pub use structs as raw;