Skip to main content

linux_info/bios/
mod.rs

1//!
2//! See example `dmidecode_mini` on how to use this.
3//!
4//! ## Support
5//! only SMBIOS 3.0+ is supported.
6//!
7//! To be able to use this the following files need to exist
8//! `/sys/firmware/dmi/tables/{smbios_entry_point, DMI}` and you need permission
9//! to read them.
10
11mod low_level;
12
13use std::io;
14
15pub use uuid::Uuid;
16
17use low_level::{
18	BiosInformation, EntryPoint, StructureKind, Structures, SystemInformation,
19};
20
21#[derive(Debug, PartialEq, Eq)]
22pub struct Bios {
23	entry_point: EntryPoint,
24	structures: Structures,
25}
26
27#[derive(Debug, PartialEq, Eq, Hash)]
28pub struct BiosInfo<'a> {
29	pub vendor: &'a str,
30	pub version: &'a str,
31	pub release_date: &'a str,
32	pub major: u8,
33	pub minor: u8,
34}
35
36#[derive(Debug, PartialEq, Eq, Hash)]
37pub struct SystemInfo<'a> {
38	pub manufacturer: &'a str,
39	pub product_name: &'a str,
40	pub version: &'a str,
41	pub serial_number: &'a str,
42	/// is exactly 16bytes long
43	pub uuid: Uuid,
44	pub sku_number: &'a str,
45	pub family: &'a str,
46}
47
48impl Bios {
49	pub fn read() -> io::Result<Self> {
50		let entry_point = EntryPoint::read()?;
51		Ok(Self {
52			structures: Structures::read(entry_point.table_max)?,
53			entry_point,
54		})
55	}
56
57	pub fn bios_info(&self) -> Option<BiosInfo> {
58		let stru = self
59			.structures
60			.structures()
61			.find(|s| s.header.kind == StructureKind::BiosInformation)?;
62		let info = BiosInformation::from(&stru)?;
63
64		Some(BiosInfo {
65			vendor: stru.get_str(info.vendor)?,
66			version: stru.get_str(info.version)?,
67			release_date: stru.get_str(info.release_date)?,
68			major: info.major,
69			minor: info.minor,
70		})
71	}
72
73	pub fn system_info(&self) -> Option<SystemInfo> {
74		let stru = self
75			.structures
76			.structures()
77			.find(|s| s.header.kind == StructureKind::SystemInformation)?;
78		let info = SystemInformation::from(&stru)?;
79
80		Some(SystemInfo {
81			manufacturer: stru.get_str(info.manufacturer)?,
82			product_name: stru.get_str(info.product_name)?,
83			version: stru.get_str(info.version)?,
84			serial_number: stru.get_str(info.serial_number)?,
85			uuid: info.uuid,
86			sku_number: stru.get_str(info.sku_number)?,
87			family: stru.get_str(info.family)?,
88		})
89	}
90}