Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Motherboard support #1069

Open
Notarin opened this issue Sep 18, 2023 · 8 comments
Open

Motherboard support #1069

Notarin opened this issue Sep 18, 2023 · 8 comments

Comments

@Notarin
Copy link

Notarin commented Sep 18, 2023

Being able to lookup the motherboard from the library would be great.
Here is my implementation in this features absence.

#[cfg(target_os = "linux")]
fn get_motherboard() -> String {
    use std::fs;
    fs::read_to_string("/sys/class/dmi/id/board_name")
        .unwrap_or(String::from("Unknown"))
        .trim()
        .to_string()
}

#[cfg(target_os = "windows")]
fn get_motherboard() -> String {
    use winreg::{enums::HKEY_LOCAL_MACHINE, RegKey};

    let local_machine_key: RegKey = RegKey::predef(HKEY_LOCAL_MACHINE);
    let path: &str = r"SYSTEM\HardwareConfig\Current";

    match local_machine_key.open_subkey(path) {
        Ok(sub_key) => {
            match sub_key.get_value("BaseBoardProduct") {
                Ok(name) => name,
                Err(_) => String::from("Unknown"),
            }
        }
        Err(_) => String::from("Unknown"),
    }
}

P.S. dev, your crate is awesome, thanks for the awesome library.

@GuillaumeGomez
Copy link
Owner

Hum. Not sure if many people would be interested by this feature. If at least one other dev is interested, I'm ok with adding it. You'll need to get the code for FreeBSD and macOS too but you already have a good start. ;)

P.S. dev, your crate is awesome, thanks for the awesome library.

You're welcome!

@Notarin
Copy link
Author

Notarin commented Sep 18, 2023

Thank you for the feedback, I think that the biggest crowd that would wish for this would come from the community that develops fetch utilities.
I'd be interested in hearing if other developers want this, if I am the only of this request then I would be fine closing this issue.
When I finish my current project I will see if I cant touch all bases for pulling this information across the board.
If it goes well I may open a pull request.

@GuillaumeGomez
Copy link
Owner

Great to hear that! Don't hesitate to ask around and tell people to just leave a comment on the issue if they are interested in the feature. No need to close the issue even if no one comes around, who knows if someone will in a future after all.

@CarterLi
Copy link

On FreeBSD, it is (in C) kenv(KENV_GET, "smbios.planar.product", buffer, bufLen)

I doubt if it's possible on macOS

@jdswensen
Copy link

I would be interested in this feature.

I know a bit about the macOS related stuff. It depends on what you would want to return for the "board". There are a number of ways to go about getting the info, none of them as simple as the other OSes. The information is there though.

The "Model Identifier" is typically indicative of the type of computer and the release order. That or "Model Number" is going to be the closest you can get to a motherboard on a Mac. I would argue that the Model Identifier is more useful because there have been times when Apple reuses the same Model Number for multiple computers year over year.

~ system_profiler SPHardwareDataType
Hardware:

    Hardware Overview:

      Model Name: MacBook Pro
      Model Identifier: Mac14,6
      Model Number: MNWA3LL/A
~ sysctl hw.model
hw.model: Mac14,6

I think there's also a way to read a plist to get the info (not sure if that still works on Apple Silicon). Anyway you look at it, the Apple solution will be a bit of a pain.

@npmaile
Copy link

npmaile commented Nov 25, 2023

myself and @Notarin got this bad boy working just a few minutes ago live on the natestream

#[cfg(target_os = "macos")]
pub(crate) async fn get_motherboard() -> String {
    let output_raw: Result<Output, std::io::Error> = Command::new("system_profiler")
        .arg("SPHardwareDataType")
        .output();

    let output: String = match output_raw {
        Err(_) => {
            return "Unknown".to_string();
        }
        Ok(x) => String::from_utf8(x.stdout)
            .expect("non-utf8 response found from call to system_proflier"),
    };

    output
        .split("\n")
        .into_iter()
        .filter(|x| x.contains("Model Number:"))
        .map(|y| y.replace("Model Number:", ""))
        .map(|z| z.trim().clone().to_string())
        .collect()
}

@GuillaumeGomez
Copy link
Owner

.map(|z| z.trim().clone().to_string())

could be:

.map(|z| z.trim().to_string())

But otherwise, PR is very welcome. :)

@CarterLi
Copy link

CarterLi commented Nov 27, 2023

It's ioreg -c IOPlatformExpertDevice | grep \"model-number\". You can get it via IOKit

The "Model Identifier" is typically indicative of the type of computer and the release order. That or "Model Number" is going to be the closest you can get to a motherboard on a Mac

Why? Do you mean that every mac uses unique mother board type?


EDIT:

Model Number turns out to be IOPlatformExpertDevice::model-number + IOPlatformExpertDevice::region-info. For mine (MacBookPro18,1), it's MK193 + CH/A.

I don't think Apple designs unique mother board types for different regions / countries.


EDIT2:

The Model Number is actually the Apple part number described in Apple Support website. Model Number and Model Identifier are both tied to the whole machine but not just for motherboard.

I generally expect motherboard info prints something about the product name (e.g. GIGABYTE XXX, MSI XXX), and / or the chipset name (e.g. Intel Z690, AMD B650). As Apple never sells motherboard independently, it's understandable that they don't have a unique motherboard product name or chipset name, and it's reasonable to leave the motherboard information empty or unsupported

Hackintosh is an exception though.


EDIT3:

According to https://www.theiphonewiki.com/wiki/Models#MacBook_Pro, different models of MBP have different storage sizes. Storage sizes must have no business with motherboards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants