kmoddep/
lib.rs

1pub mod kerman;
2pub mod moddeps;
3pub mod modinfo;
4
5use kerman::{KernelInfo, MOD_D};
6use std::{fs::read_dir, io::Error};
7
8/// Get the list of existing kernels in the system.
9pub fn get_kernel_infos(rootfs: Option<&str>) -> Result<Vec<KernelInfo>, Error> {
10    let mut rfs_path = "";
11    if let Some(mut rootfs) = rootfs {
12        rootfs = rootfs.trim().trim_end_matches("/");
13        if !rootfs.is_empty() && !rootfs.eq("/") {
14            rfs_path = rootfs;
15        }
16    }
17
18    let mut kernels: Vec<KernelInfo> = vec![];
19
20    for fres in read_dir(format!("{}{}", rfs_path.trim_end_matches("/"), MOD_D)).unwrap() {
21        let fd = fres.unwrap();
22        if fd.file_type().unwrap().is_dir() {
23            let kinfo: KernelInfo =
24                KernelInfo::new(rfs_path, fd.path().file_name().unwrap().to_str().unwrap())?;
25            if kinfo.is_valid() {
26                kernels.push(kinfo);
27            }
28        }
29    }
30
31    Ok(kernels)
32}