Coder Social home page Coder Social logo

dmidecode-rs's Introduction

dmidecode-rs

dmidecode-rs_ci LOC

dmidecode command written in Rust, is a tool to report SMBIOS table content in human readable format.

Help

dmidecode-rs 0.2.2
Jeffrey R. Gerber, Juan Zuluaga
DMI Table Decoder, Rust Edition ⛭

USAGE:
    dmidecode [FLAGS] [OPTIONS]

FLAGS:
    -h, --help
            Prints help information

    -j, --json
            Display output in JSON compact format

        --json-pretty
            Display output in JSON pretty print format

    -l, --list
            List supported DMI string

        --no-sysfs
            Do not attempt to read DMI data from sysfs files.

            This is mainly useful for debugging.
    -q, --quiet
            Less verbose output

    -u, --dump
            Do not decode the entries, dump their contents as hexadecimal instead.

            Note that this is still a text output, no binary data will be thrown upon you. The strings attached to each
            entry are displayed as both hexadecimal and ASCII. This option is mainly useful for debugging.
    -V, --version
            Prints version information


OPTIONS:
    -d, --dev-mem <FILE>
            Read memory from device FILE (default: /dev/mem)

    -t, --type <bios-types>...
            Only display the entries of given type

            Supply one or more keywords, one or more type values,
            or a combination of the two.

               Keyword     Types
               ------------------------------
               bios        0, 13
               system      1, 12, 15, 23, 32
               baseboard   2, 10, 41
               chassis     3
               processor   4
               memory      5, 6, 16, 17
               cache       7
               connector   8
               slot        9
    -H, --handle <handle>
            Only display the entry whose handle matches `handle`. `handle` is a 16-bit integer in either a decimal or a
            hexadecimal (0xN) form
        --from-dump <input>
            Read the DMI data from a binary file

    -s, --string <keyword>
            Only display the value of the DMI string identified by `keyword`.

            `keyword` must be a keyword from the following list: bios-vendor, bios-version, bios-release-date, system-
            manufacturer, system- product-name, system-version, system-serial-number, system-uuid, system-family,
            baseboard-manufacturer, baseboard-product-name, baseboard-version, baseboard-serial-number, baseboard-asset-
            tag, chassis-manufacturer, chassis-type, chassis-version, chassis- serial-number, chassis-
            asset-tag, processor-family, processor- manufacturer, processor-version, processor-frequency.  Each
            keyword corresponds to a given DMI type and a given offset within this entry type.  Not all strings may be
            meaningful or even defined on all systems. Some keywords may return more than one result on some systems
            (e.g.  processor-version on a multi- processor system).  If KEYWORD is not provided or not valid, a list of
            all valid keywords is printed and dmidecode exits with an error.  This option cannot be used more than once.

            Note: on Linux, most of these strings can alternatively be read directly from sysfs, typically from files
            under /sys/devices/virtual/dmi/id.  Most of these files are even readable by regular users.
        --oem-string <oem-string>
            Only display the value of the OEM string number N. The first OEM string has number 1. With special value
            "count", return the number of OEM strings instead
        --dump-bin <output>
            Dump the DMI data to a binary file

dmidecode-rs's People

Contributors

dependabot[bot] avatar jczuluag avatar jrgerber avatar mulark avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dmidecode-rs's Issues

Improve error reporting

The original dmidecode has error reporting that looks like this:

# dmidecode 3.2
Scanning /dev/mem for entry point.
# No SMBIOS nor DMI entry point found, sorry.

Things of note:

  1. The version is output for all commands, not just in the help
  2. The use of the "#" symbol. What is the logic for when "#" is used?
  3. The failure explanation is nice and verbose

Also investigate and understand what information goes to stdout versus stderr.

Add help/usage output

  • Without looking at the src code, it would be beneficial to add an option -h or --help in order to get the options of the command.

Some dmi keyword output look not readable

Using the following script

#!/bin/bash
while read line
do
    echo -n "$line: ">> dmistrings.txt
    ./target/debug/dmidecode -s $line >> dmistrings.txt
    echo "========" >> dmistrings.txt
done < <(./target/debug/dmidecode -l)

Some keywords like system-uuid and chassis-type display internal debug information

...
system-uuid: Uuid(5F1B4CCE-81A8-5B9C-A549-41344AF919BD)
chassis-type: smbioslib::structs::types::system_chassis_information::ChassisTypeData { raw: 9, value: Laptop }
...

Add a -t "type" switch for commane-line

Following dmidecode's command-line and dmiopt.c:

       -t, --type TYPE
              Only display the entries of type TYPE. TYPE can be either a DMI
              type number, or a comma-separated list of type numbers, or a
              keyword from the following list: bios, system, baseboard,
              chassis, processor, memory, cache, connector, slot. Refer to the
              DMI TYPES section below for details.  If this option is used
              more than once, the set of displayed entries will be the union
              of all the given types.  If TYPE is not provided or not valid, a
              list of all valid keywords is printed and dmidecode exits with
              an error.

When one of the following strings is given, the associated types are returned:

static const u8 opt_type_bios[] = { 0, 13, 255 };
static const u8 opt_type_system[] = { 1, 12, 15, 23, 32, 255 };
static const u8 opt_type_baseboard[] = { 2, 10, 41, 255 };
static const u8 opt_type_chassis[] = { 3, 255 };
static const u8 opt_type_processor[] = { 4, 255 };
static const u8 opt_type_memory[] = { 5, 6, 16, 17, 255 };
static const u8 opt_type_cache[] = { 7, 255 };
static const u8 opt_type_connector[] = { 8, 255 };
static const u8 opt_type_slot[] = { 9, 255 };

static const struct type_keyword opt_type_keyword[] = {
	{ "bios", opt_type_bios },
	{ "system", opt_type_system },
	{ "baseboard", opt_type_baseboard },
	{ "chassis", opt_type_chassis },
	{ "processor", opt_type_processor },
	{ "memory", opt_type_memory },
	{ "cache", opt_type_cache },
	{ "connector", opt_type_connector },
	{ "slot", opt_type_slot },
};

If a decimal value is given (or array of values), it indicates the type and only those types are retrieved.

Examples from dmidecode man page:

       Keywords are matched case-insensitively. The following command lines
       are equivalent:

       o
        dmidecode --type 0 --type 13
       o
        dmidecode --type 0,13
       o
        dmidecode --type bios
       o
        dmidecode --type BIOS

Add tests for new CL options

I added new options and had not added tests paired with them after the new dependencies for CLI testing were added to the project.

Currently working on two new options for the CLI so this work can be either done as part of that or afterwards. So this work is to add whatever missing CLI tests exist.

Add -H, --handle switch

Usage: dmidecode [OPTIONS]
Options are:
 -d, --dev-mem FILE     Read memory from device FILE (default: /dev/mem)
 -h, --help             Display this help text and exit
 -q, --quiet            Less verbose output
 -s, --string KEYWORD   Only display the value of the given DMI string
 -t, --type TYPE        Only display the entries of given type
 -H, --handle HANDLE    Only display the entry of given handle
 -u, --dump             Do not decode the entries
     --dump-bin FILE    Dump the DMI data to a binary file
     --from-dump FILE   Read the DMI data from a binary file
     --no-sysfs         Do not attempt to read DMI data from sysfs files
     --oem-string N     Only display the value of the given OEM string
 -V, --version          Display the version and exit

Diverge JSON output from simple serialization of smbios structures?

This is more a documentation of an idea I had.

Essentially, the smbios spec often includes sentinel values to tell you to look at another field. Particularly with memory capacity fields, an example being the recent CacheMemorySize fields. These also can be redundant if the values held fit in the first of the fields (although some of these may be spec violations, the values are present here anyway).

        "maximum_cache_size": {
          "Kilobytes": 32768
        },
        "installed_size": {
          "Kilobytes": 32768
        },
        "maximum_cache_size_2": {
          "Kilobytes": 32768
        },
        "installed_cache_size_2": {
          "Kilobytes": 32768
        }

This application could instead perform such parsing/deduplication tasks prior to outputting.

PathBuf and OsStr use - not String

There are some functions which take file paths as Strings. These should probably be using PathBuf and OsStr. Different OS's treat paths differently with \ or / for example and possibly some characters are invalid between them.

Review the existing API's that DMIDECODE uses for file paths from smbios-lib and make them both use proper types to describe paths.

https://doc.rust-lang.org/std/path/struct.PathBuf.html
https://doc.rust-lang.org/std/ffi/struct.OsString.html

Add processor additional information

The original dmidecode does not yet support the latest type Processor Additional Information. The smbios-lib library does support it and therefore it can be added.

Create parity with dmidecode standard output

The format of the standard output of dmidecode should match exactly. Presently the output is that of the smbios-lib debug output and this is not acceptable for either users or tools.

Add switch: -u, --dump (Do not decode the entries)

Usage: dmidecode [OPTIONS]
Options are:
 -d, --dev-mem FILE     Read memory from device FILE (default: /dev/mem)
 -h, --help             Display this help text and exit
 -q, --quiet            Less verbose output
 -s, --string KEYWORD   Only display the value of the given DMI string
 -t, --type TYPE        Only display the entries of given type
 -H, --handle HANDLE    Only display the entry of given handle
 -u, --dump             Do not decode the entries
     --dump-bin FILE    Dump the DMI data to a binary file
     --from-dump FILE   Read the DMI data from a binary file
     --no-sysfs         Do not attempt to read DMI data from sysfs files
     --oem-string N     Only display the value of the given OEM string
 -V, --version          Display the version and exit

--string muti-return feature

dmidecode has this feature which is not currently implemented:

Some keywords may return more than one result on some systems (e.g.  processor-version on a multi-processor system).

Make JSON output possible

First, check out serde (serializer/deserializer): https://serde.rs/

Investigate "Serde's derive attribute"

Alternatively, a solution might be to consume the fmt::Debug output and massage it into JSON.

Panic when piping output to head

sudo ./target/debug/dmidecode | head
# dmidecode-rs 0.2.0
Getting SMBIOS data from sysfs.
SMBIOS 3.2.0 present.
Table at 0x000E8D60.

Handle 0x0000, DMI type 0, 26 bytes
BIOS Information
        Vendor: American Megatrends Inc.
        Version: F6b
        Release Date: 09/17/2019
thread 'main' panicked at 'failed printing to stdout: Broken pipe (os error 32)', library/std/src/io/stdio.rs:935:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Create crate for dmidecode-rs

Be able to perform an install from crates.io using cargo install dmidecode-rs would simplify the usage of the command line tool.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.