Discussion:
[dmidecode] [PATCH v2] dmidecode: New option --oem-string
Jean Delvare
2017-05-01 11:40:20 UTC
Permalink
Add a new option to extract OEM strings, like we already have for
many other strings.

Signed-off-by: Jean Delvare <***@suse.de>
---
Changes since v1:
* Document the new option in --help and man page.
* Return an error message if index is out of range.
* Special value "count" returns the number of OEM strings.

dmidecode.c | 15 +++++++++++++++
dmiopt.c | 40 ++++++++++++++++++++++++++++++++++++++++
man/dmidecode.8 | 7 ++++++-
3 files changed, 61 insertions(+), 1 deletion(-)

--- dmidecode.orig/dmiopt.c 2017-04-04 10:03:43.885412547 +0200
+++ dmidecode/dmiopt.c 2017-05-01 12:23:44.207581011 +0200
@@ -20,6 +20,7 @@
*/

#include <stdio.h>
+#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <getopt.h>
@@ -171,6 +172,10 @@ static const struct string_keyword opt_s
{ "processor-frequency", 4, 0x16 }, /* dmi_processor_frequency() */
};

+/* This is a template, 3rd field is set at runtime. */
+static struct string_keyword opt_oem_string_keyword =
+ { NULL, 11, 0x00 };
+
static void print_opt_string_list(void)
{
unsigned int i;
@@ -206,6 +211,34 @@ static int parse_opt_string(const char *
return -1;
}

+static int parse_opt_oem_string(const char *arg)
+{
+ unsigned long val;
+ char *next;
+
+ if (opt.string)
+ {
+ fprintf(stderr, "Only one string can be specified\n");
+ return -1;
+ }
+
+ /* Return the number of OEM strings */
+ if (strcmp(arg, "count") == 0)
+ goto done;
+
+ val = strtoul(arg, &next, 10);
+ if (next == arg || val == 0x00 || val > 0xff)
+ {
+ fprintf(stderr, "Invalid OEM string number: %s\n", arg);
+ return -1;
+ }
+
+ opt_oem_string_keyword.offset = val;
+done:
+ opt.string = &opt_oem_string_keyword;
+ return 0;
+}
+

/*
* Command line options handling
@@ -225,6 +258,7 @@ int parse_command_line(int argc, char *
{ "dump", no_argument, NULL, 'u' },
{ "dump-bin", required_argument, NULL, 'B' },
{ "from-dump", required_argument, NULL, 'F' },
+ { "oem-string", required_argument, NULL, 'O' },
{ "no-sysfs", no_argument, NULL, 'S' },
{ "version", no_argument, NULL, 'V' },
{ NULL, 0, NULL, 0 }
@@ -255,6 +289,11 @@ int parse_command_line(int argc, char *
return -1;
opt.flags |= FLAG_QUIET;
break;
+ case 'O':
+ if (parse_opt_oem_string(optarg) < 0)
+ return -1;
+ opt.flags |= FLAG_QUIET;
+ break;
case 't':
opt.type = parse_opt_type(opt.type, optarg);
if (opt.type == NULL)
@@ -315,6 +354,7 @@ void print_help(void)
" --dump-bin FILE Dump the DMI data to a binary file\n"
" --from-dump FILE Read the DMI data from a binary file\n"
" --no-sysfs Do not attempt to read DMI data from sysfs files\n"
+ " --oem-string N Only display the value of the given OEM string\n"
" -V, --version Display the version and exit\n";

printf("%s", help);
--- dmidecode.orig/dmidecode.c 2017-04-27 16:55:26.011215158 +0200
+++ dmidecode/dmidecode.c 2017-05-01 12:25:35.269804990 +0200
@@ -4555,6 +4555,21 @@ static void dmi_table_string(const struc
int key;
u8 offset = opt.string->offset;

+ if (opt.string->type == 11) /* OEM strings */
+ {
+ if (h->length < 5 || offset > data[4])
+ {
+ fprintf(stderr, "No OEM string number %u\n", offset);
+ return;
+ }
+
+ if (offset)
+ printf("%s\n", dmi_string(h, offset));
+ else
+ printf("%u\n", data[4]); /* count */
+ return;
+ }
+
if (offset >= h->length)
return;

--- dmidecode.orig/man/dmidecode.8 2015-08-06 12:49:52.339237585 +0200
+++ dmidecode/man/dmidecode.8 2017-05-01 12:07:26.188735324 +0200
@@ -134,13 +134,18 @@ Read the DMI data from a binary file pre
Do not attempt to read DMI data from sysfs files. This is mainly useful for
debugging.
.TP
+.BR " " " " "--oem-string N"
+Only display the value of the \s-1OEM\s0 string number \fBN\fR. The first
+\s-1OEM\s0 string has number 1. With special value "count", return the
+number of OEM strings instead.
+.TP
.BR "-h" ", " "--help"
Display usage information and exit
.TP
.BR "-V" ", " "--version"
Display the version and exit
.P
-Options --string, --type and --dump-bin
+Options --string, --type, --dump-bin and --oem-string
determine the output format and are mutually exclusive.
.P
Please note in case of
--
Jean Delvare
SUSE L3 Support

_______________________________________________
https://lists.nongnu.org/mailman/listinfo/dmidecode-devel
Loading...