/// Get a list of loaded kernel modules
///
/// This corresponds to the data in `/proc/modules`.
Get a list of loaded kernel modules
This corresponds to the data in `/proc/modules`.
Get a list of loaded kernel modules This corresponds to the data in ` / proc / modules ` .
pub fn modules() -> ProcResult<HashMap<String, KernelModule>> {
    // kernel reference: kernel/module.c m_show()
    let mut map = HashMap::new();
    let file = FileWrapper::open("/proc/modules")?;
    let reader = BufReader::new(file);
    for line in reader.lines() {
        let line: String = line?;
        let mut s = line.split_whitespace();
        let name = expect!(s.next());
        let size = from_str!(u32, expect!(s.next()));
        let refcount = from_str!(i32, expect!(s.next()));
        let used_by: &str = expect!(s.next());
        let state = expect!(s.next());
        map.insert(
            name.to_string(),
            KernelModule {
                name: name.to_string(),
                size,
                refcount,
                used_by: if used_by == "-" {
                    Vec::new()
                } else {
                    used_by
                        .split(',')
                        .filter(|s| !s.is_empty())
                        .map(|s| s.to_string())
                        .collect()
                },
                state: state.to_string(),
            },
        );
    }
    Ok(map)
}
pub fn modules ( ) -> ProcResult < HashMap < String , KernelModule > > { // kernel reference: kernel/module.c m_show() let mut map = HashMap :: new ( ) ; let file = FileWrapper :: open ( " " ) ? ; let reader = BufReader :: new ( file ) ; for line in reader . lines ( ) { let line : String = line ? ; let mut s = line . split_whitespace ( ) ; let name = expect ! ( s next ( ) ) ; let size = from_str ! ( u32 expect ( s next ( ) ) ) ; let refcount = from_str ! ( i32 expect ( s next ( ) ) ) ; let used_by : & str = expect ! ( s next ( ) ) ; let state = expect ! ( s next ( ) ) ; map . insert ( name . to_string ( ) , KernelModule { name : name . to_string ( ) , size , refcount , used_by : if used_by == " " { Vec :: new ( ) } else { used_by . split ( ',' ) . filter ( | s | ! s . is_empty ( ) ) . map ( | s | s . to_string ( ) ) . collect ( ) } , state : state . to_string ( ) , } , ) ; } Ok ( map ) }
Get a list of loaded kernel modules
This corresponds to the data in `/proc/modules`.
Get a list of loaded kernel modules This corresponds to the data in ` / proc / modules ` .