kmod/lib.rs
1//! Bindings to libkmod to manage linux kernel modules.
2//!
3//! # Example
4//! ```
5//! fn main() -> anyhow::Result<()> {
6//! // create a new kmod context
7//! let ctx = kmod::Context::new()?;
8//!
9//! // get a kmod_list of all loaded modules
10//! for module in ctx.modules_loaded()? {
11//! let name = module.name().to_string_lossy();
12//! let refcount = module.refcount();
13//! let size = module.size();
14//!
15//! let holders: Vec<_> = module.holders()
16//! .map(|x| x.name().to_string_lossy().into_owned())
17//! .collect();
18//!
19//! println!("{:<19} {:8} {} {:?}", name, size, refcount, holders);
20//! }
21//! Ok(())
22//! }
23//! ```
24
25pub mod ctx;
26pub mod errors;
27pub mod modules;
28
29pub use ctx::*;
30pub use errno::Errno;
31pub use errors::*;
32pub use modules::*;
33
34#[cfg(test)]
35mod tests {
36 use super::*;
37
38 #[test]
39 fn lsmod() {
40 let ctx = Context::new().unwrap();
41
42 for module in ctx.modules_loaded().unwrap() {
43 let name = module.name().to_string_lossy();
44 let refcount = module.refcount();
45 let size = module.size();
46
47 let holders: Vec<_> = module
48 .holders()
49 .map(|x| x.name().to_string_lossy().into_owned())
50 .collect();
51
52 println!("{:<19} {:8} {} {:?}", name, size, refcount, holders);
53 }
54 }
55
56 #[test]
57 fn bad_name() {
58 let ctx = Context::new().unwrap();
59 let m = ctx
60 .module_new_from_name("/lib/modules/5.1.12-300.fc30.x86_64/kernel/fs/cifs/cifs.ko.xz")
61 .unwrap();
62 println!("name: {:?}", m.name());
63 println!("path: {:?}", m.path());
64 }
65}