// // Copyright (C) <2026> // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see . /* This file contains functions to query system information. */ use std::collections::HashMap; use std::fs; /// /// vis_vram_total - size of vram in bytes #[derive(Debug, Clone, PartialEq, Eq)] pub struct GpuInfo { pub id: u8, pub name: String, pub vis_vram_total: u64, } /// See /proc/meminfo output format and units (kB) pub fn get_meminfo() -> HashMap { let mem_info_str = fs::read_to_string("/proc/meminfo").unwrap(); mem_info_str .lines() .filter_map(|l| { l.split_once(':').and_then(|(k, v)| { u64::from_str_radix(v.trim_end_matches("kB").trim(), 10) .ok() .and_then(|v_num| Some((k.to_string(), v_num))) }) }) .collect() } // cat /sys/class/drm/card1/device/mem_info_vis_vram_total pub fn get_gpus_list() -> Vec { let drm_devs_dirs: Vec<(String, u8)> = fs::read_dir("/sys/class/drm/") .unwrap() .filter_map(|maybe_entry| { maybe_entry.ok().and_then(|entry| { entry.file_type().ok().and_then(|ft| { if ft.is_symlink() || ft.is_dir() { entry.file_name().into_string().ok() } else { None } }) }) }) .filter(|f_name| f_name.len() == 5 && f_name.starts_with("card")) .filter_map(|dir_name| { dir_name.split_once("card").and_then(|name_touple| { u8::from_str_radix(name_touple.1, 10) .ok() .and_then(|gpu_id| Some((dir_name.clone(), gpu_id))) }) }) .collect(); let res: Vec = drm_devs_dirs .iter() .filter_map(|(d, id)| { fs::read_to_string(format!( "/sys/class/drm/{}/device/mem_info_vis_vram_total", d )) .ok() .and_then(|mem_str| { u64::from_str_radix(mem_str.trim(), 10) .ok() .and_then(|mem_size| { Some(GpuInfo { id: *id, name: d.clone(), vis_vram_total: mem_size, }) }) }) }) .collect(); res } use serde::Deserialize; #[derive(Debug, Clone, Deserialize)] pub struct SecureBootStatus { pub installed: bool, pub guid: String, pub setup_mode: bool, pub secure_boot: bool, pub vendors: Vec, pub firmware_quirks: Vec, } pub fn get_secure_boot_status() -> Result { use std::process::Command; //sbctl --json status match Command::new("sbctl").args(["--json", "status"]).output() { Ok(cmd_output) => { if cmd_output.status.success() { match serde_json::from_slice(&cmd_output.stdout) { Ok(res) => Ok(res), Err(ex) => Err(ex.to_string()), } } else { Err(format!( "Error getting disk devices list: {}", String::from_utf8(cmd_output.stderr).unwrap_or("UNKNOWN".into()) )) } } Err(ex) => Err(ex.to_string()), } }