Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@master
with:
toolchain: 1.69.0
toolchain: 1.70.0
components: rustfmt
- run: cargo fmt --check
- run: cargo check --all-features
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ description = "Decode SMBIOS/DMI information into accessible data structures"
documentation = "https://docs.rs/dmidecode/"
repository = "https://github.com/jcreekmore/dmidecode"
license = "MIT"
rust-version = "1.69"
rust-version = "1.70"
edition = "2021"

[dependencies]
bitflags = "1.2"
bitflags = "2.9.1"
uuid = "1.17.0"

[dev-dependencies]
pretty_assertions = "0.6"
lazy_static = "1.4"
pretty_assertions = "1.4.1"

[features]
default = ["std"]
Expand Down
1 change: 0 additions & 1 deletion src/bitfield.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ pub trait BitField<'a> {
///
/// ```ignore
/// # #[macro_use]
/// # extern crate dmidecode;
/// # use dmidecode::bitfield::{FlagType, Layout};
/// # fn main() {
/// layout!(
Expand Down
18 changes: 3 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@
#[cfg(any(feature = "std", test))]
#[macro_use]
extern crate std;
#[macro_use]
extern crate bitflags;
#[cfg(test)]
extern crate lazy_static;
#[cfg(test)]
extern crate pretty_assertions;

use core::array::TryFromSliceError;
use core::convert::TryInto;
Expand Down Expand Up @@ -158,19 +152,14 @@ impl EntryPoint {
/// # Example
///
/// ```
/// # extern crate dmidecode;
/// # use std::error::Error;
/// use dmidecode::EntryPoint;
/// # fn try_main() -> Result<(), Box<dyn Error>> {
/// #
/// const DMIDECODE_BIN: &'static [u8] = include_bytes!("../tests/data/dmidecode.bin");
///
/// let entry_point = EntryPoint::search(DMIDECODE_BIN)?;
/// let entry_point = EntryPoint::search(DMIDECODE_BIN).unwrap();
/// for s in entry_point.structures(&DMIDECODE_BIN[entry_point.smbios_address() as usize..]) {
/// let table = s?;
/// let table = s.unwrap();
/// // process raw...
/// }
/// Ok(())
/// # }
/// ```
pub fn structures<'buffer>(&self, buffer: &'buffer [u8]) -> Structures<'buffer> {
Structures {
Expand All @@ -186,7 +175,6 @@ impl EntryPoint {
/// # Example
///
/// ```
/// # extern crate dmidecode;
/// use dmidecode::EntryPoint;
///
/// const ENTRY_BIN: &'static [u8] = include_bytes!("../tests/data/entry.bin");
Expand Down
37 changes: 19 additions & 18 deletions src/structures/000_bios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl<'buffer> Bios<'buffer> {
pub(crate) fn try_from(structure: RawStructure<'buffer>) -> Result<Bios<'buffer>, MalformedStructureError> {
#[repr(C)]
#[repr(packed)]
struct BiosPacked_3_1 {
struct BiosPacked3_1 {
vendor: u8,
bios_version: u8,
bios_starting_address_segment: u16,
Expand All @@ -99,7 +99,7 @@ impl<'buffer> Bios<'buffer> {

#[repr(C)]
#[repr(packed)]
struct BiosPacked_2_4 {
struct BiosPacked2_4 {
vendor: u8,
bios_version: u8,
bios_starting_address_segment: u16,
Expand All @@ -116,7 +116,7 @@ impl<'buffer> Bios<'buffer> {

#[repr(C)]
#[repr(packed)]
struct BiosPacked_2_0 {
struct BiosPacked2_0 {
vendor: u8,
bios_version: u8,
bios_starting_address_segment: u16,
Expand All @@ -127,7 +127,7 @@ impl<'buffer> Bios<'buffer> {

match structure.version {
v if v >= (3, 1).into() => {
let_as_struct!(packed, BiosPacked_3_1, structure.data);
let_as_struct!(packed, BiosPacked3_1, structure.data);
Ok(Bios {
handle: structure.handle,
vendor: structure.find_string(packed.vendor)?,
Expand Down Expand Up @@ -156,7 +156,7 @@ impl<'buffer> Bios<'buffer> {
})
}
v if v >= (2, 4).into() => {
let_as_struct!(packed, BiosPacked_2_4, structure.data);
let_as_struct!(packed, BiosPacked2_4, structure.data);
Ok(Bios {
handle: structure.handle,
vendor: structure.find_string(packed.vendor)?,
Expand Down Expand Up @@ -185,7 +185,7 @@ impl<'buffer> Bios<'buffer> {
})
}
_ => {
let_as_struct!(packed, BiosPacked_2_0, structure.data);
let_as_struct!(packed, BiosPacked2_0, structure.data);
Ok(Bios {
handle: structure.handle,
vendor: structure.find_string(packed.vendor)?,
Expand Down Expand Up @@ -355,18 +355,19 @@ impl fmt::Display for FirmwareRevision {

#[cfg(test)]
mod tests {
use std::prelude::v1::*;
use std::{prelude::v1::*, sync::OnceLock};

use lazy_static::lazy_static;
use pretty_assertions::assert_eq;

use super::*;
use crate::bitfield::Position;

const PRIMES: &[usize] = &[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61];
const DMIDECODE_BIN: &[u8] = include_bytes!("../../tests/data/dmi.0.bin");
lazy_static! {
static ref ENTRY_POINT: crate::EntryPoint = crate::EntryPoint::search(DMIDECODE_BIN).unwrap();

fn entrypoint() -> &'static crate::EntryPoint {
static ENTRYPOINT: OnceLock<crate::EntryPoint> = OnceLock::new();
ENTRYPOINT.get_or_init(|| crate::EntryPoint::search(DMIDECODE_BIN).unwrap())
}

#[test]
Expand Down Expand Up @@ -542,8 +543,8 @@ mod tests {
minor: 0xFF,
}),
};
let bios_result = ENTRY_POINT
.structures(&DMIDECODE_BIN[(ENTRY_POINT.smbios_address() as usize)..])
let bios_result = entrypoint()
.structures(&DMIDECODE_BIN[(entrypoint().smbios_address() as usize)..])
.find_map(|s| {
if let Ok(crate::Structure::Bios(bios)) = s {
Some(bios)
Expand Down Expand Up @@ -580,8 +581,8 @@ mod tests {
"Targeted content distribution is supported",
"UEFI is supported",
];
let bios_result = ENTRY_POINT
.structures(&DMIDECODE_BIN[(ENTRY_POINT.smbios_address() as usize)..])
let bios_result = entrypoint()
.structures(&DMIDECODE_BIN[(entrypoint().smbios_address() as usize)..])
.find_map(|s| {
if let Ok(crate::Structure::Bios(bios)) = s {
Some(bios)
Expand All @@ -607,8 +608,8 @@ mod tests {
fn dmi_bin_revisions() {
let bios_revision = "2.8";
let firmware_revision = "N/A";
let bios_result = ENTRY_POINT
.structures(&DMIDECODE_BIN[(ENTRY_POINT.smbios_address() as usize)..])
let bios_result = entrypoint()
.structures(&DMIDECODE_BIN[(entrypoint().smbios_address() as usize)..])
.find_map(|s| {
if let Ok(crate::Structure::Bios(bios)) = s {
Some(bios)
Expand All @@ -632,8 +633,8 @@ mod tests {
#[test]
fn dmi_bin_bios_size() {
let size = 32u64 << 20;
let bios_result = ENTRY_POINT
.structures(&DMIDECODE_BIN[(ENTRY_POINT.smbios_address() as usize)..])
let bios_result = entrypoint()
.structures(&DMIDECODE_BIN[(entrypoint().smbios_address() as usize)..])
.find_map(|s| {
if let Ok(crate::Structure::Bios(bios)) = s {
Some(bios)
Expand Down
16 changes: 8 additions & 8 deletions src/structures/001_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<'buffer> System<'buffer> {

#[repr(C)]
#[repr(packed)]
struct SystemPacked_2_0 {
struct SystemPacked2_0 {
manufacturer: u8,
product: u8,
version: u8,
Expand All @@ -93,22 +93,22 @@ impl<'buffer> System<'buffer> {

#[repr(C)]
#[repr(packed)]
struct SystemPacked_2_1 {
v2_0: SystemPacked_2_0,
struct SystemPacked2_1 {
v2_0: SystemPacked2_0,
uuid: wrapper::UuidRepr,
wakeup: u8,
}

#[repr(C)]
#[repr(packed)]
struct SystemPacked_2_4 {
v2_1: SystemPacked_2_1,
struct SystemPacked2_4 {
v2_1: SystemPacked2_1,
sku: u8,
family: u8,
}

if structure.version < (2, 1).into() {
let_as_struct!(packed, SystemPacked_2_0, structure.data);
let_as_struct!(packed, SystemPacked2_0, structure.data);

Ok(System {
handle: structure.handle,
Expand All @@ -122,7 +122,7 @@ impl<'buffer> System<'buffer> {
family: None,
})
} else if structure.version < (2, 4).into() {
let_as_struct!(packed, SystemPacked_2_1, structure.data);
let_as_struct!(packed, SystemPacked2_1, structure.data);

Ok(System {
handle: structure.handle,
Expand All @@ -136,7 +136,7 @@ impl<'buffer> System<'buffer> {
family: None,
})
} else {
let_as_struct!(packed, SystemPacked_2_4, structure.data);
let_as_struct!(packed, SystemPacked2_4, structure.data);

Ok(System {
handle: structure.handle,
Expand Down
3 changes: 3 additions & 0 deletions src/structures/002_baseboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//! motherboard, planar, server blade, or other standard system module).
use core::fmt;

use bitflags::bitflags;

use crate::{MalformedStructureError, RawStructure};

/// The baseboard type defined in the SMBIOS specification.
Expand Down Expand Up @@ -71,6 +73,7 @@ impl fmt::Display for BoardType {

bitflags! {
/// The baseboard characteristic flags defined in the SMBIOS specification.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct BaseBoardFlags: u8 {
const HOSTING = 0b0000_0001;
const REQUIRES_DAUGHTER = 0b0000_0010;
Expand Down
16 changes: 8 additions & 8 deletions src/structures/003_enclosure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl<'buffer> Enclosure<'buffer> {
pub(crate) fn try_from(structure: RawStructure<'buffer>) -> Result<Enclosure<'buffer>, MalformedStructureError> {
#[repr(C)]
#[repr(packed)]
struct EnclosurePacked_2_0 {
struct EnclosurePacked2_0 {
manufacturer: u8,
enclosure_type: u8,
version: u8,
Expand All @@ -176,7 +176,7 @@ impl<'buffer> Enclosure<'buffer> {
// compile time assertion that our minimum enclosure structure
// fits the minimum required by the BIOS spec
const _: () = {
assert!(core::mem::size_of::<EnclosurePacked_2_0>() + core::mem::size_of::<HeaderPacked>() == 0x09);
assert!(core::mem::size_of::<EnclosurePacked2_0>() + core::mem::size_of::<HeaderPacked>() == 0x09);
};

struct RawEnclosureType(u8);
Expand All @@ -192,17 +192,17 @@ impl<'buffer> Enclosure<'buffer> {
}
}

if structure.data.len() < core::mem::size_of::<EnclosurePacked_2_0>() {
if structure.data.len() < core::mem::size_of::<EnclosurePacked2_0>() {
return Err(crate::MalformedStructureError::InvalidFormattedSectionLength(
structure.info,
structure.handle,
"minimum of ",
core::mem::size_of::<EnclosurePacked_2_0>() as u8,
core::mem::size_of::<EnclosurePacked2_0>() as u8,
));
}

let (minimum, mut extra) = structure.data.split_at(core::mem::size_of::<EnclosurePacked_2_0>());
let_as_struct!(packed, EnclosurePacked_2_0, minimum);
let (minimum, mut extra) = structure.data.split_at(core::mem::size_of::<EnclosurePacked2_0>());
let_as_struct!(packed, EnclosurePacked2_0, minimum);
let enclosure_type = RawEnclosureType::new(packed.enclosure_type);
let mut enclosure = Enclosure {
handle: structure.handle,
Expand Down Expand Up @@ -463,12 +463,12 @@ impl From<&[u8]> for ContainedElement {
fn from(data: &[u8]) -> ContainedElement {
#[repr(C)]
#[repr(packed)]
struct ContainedElement_2_3 {
struct ContainedElement2_3 {
type_: u8,
minimum: u8,
maximum: u8,
}
let_as_struct!(packed, ContainedElement_2_3, data);
let_as_struct!(packed, ContainedElement2_3, data);
ContainedElement {
type_: packed.type_.into(),
minimum: packed.minimum,
Expand Down
Loading