|
Anton Arapov |
c2a608 |
From a40f10bcae68caf6fd00379c06f92f34ba5c8d07 Mon Sep 17 00:00:00 2001
|
|
Anton Arapov |
c2a608 |
From: Jerry Hoemann <jerry.hoemann@hpe.com>
|
|
Anton Arapov |
c2a608 |
Date: Tue, 3 Jul 2018 09:55:57 +0200
|
|
Anton Arapov |
c2a608 |
Subject: [PATCH 17/21] dmidecode: Add option to filter output based upon
|
|
Anton Arapov |
c2a608 |
handle
|
|
Anton Arapov |
c2a608 |
|
|
Anton Arapov |
c2a608 |
Add option "--handle HANDLE" to dmiopt to allow user to filter
|
|
Anton Arapov |
c2a608 |
output to only those entry that matches HANDLE.
|
|
Anton Arapov |
c2a608 |
|
|
Anton Arapov |
c2a608 |
Signed-off-by: Jerry Hoemann <jerry.hoemann@hpe.com>
|
|
Anton Arapov |
c2a608 |
Signed-off-by: Jean Delvare <jdelvare@suse.de>
|
|
Anton Arapov |
c2a608 |
---
|
|
Anton Arapov |
c2a608 |
dmidecode.c | 2 ++
|
|
Anton Arapov |
c2a608 |
dmiopt.c | 26 +++++++++++++++++++++++---
|
|
Anton Arapov |
c2a608 |
dmiopt.h | 1 +
|
|
Anton Arapov |
c2a608 |
man/dmidecode.8 | 4 ++++
|
|
Anton Arapov |
c2a608 |
4 files changed, 30 insertions(+), 3 deletions(-)
|
|
Anton Arapov |
c2a608 |
|
|
Anton Arapov |
c2a608 |
diff --git a/dmidecode.c b/dmidecode.c
|
|
Anton Arapov |
c2a608 |
index f8c3b30..fa6ecf1 100644
|
|
Anton Arapov |
c2a608 |
--- a/dmidecode.c
|
|
Anton Arapov |
c2a608 |
+++ b/dmidecode.c
|
|
Anton Arapov |
c2a608 |
@@ -4732,6 +4732,7 @@ static void dmi_table_decode(u8 *buf, u32 len, u16 num, u16 ver, u32 flags)
|
|
Anton Arapov |
c2a608 |
|
|
Anton Arapov |
c2a608 |
to_dmi_header(&h, data);
|
|
Anton Arapov |
c2a608 |
display = ((opt.type == NULL || opt.type[h.type])
|
|
Anton Arapov |
c2a608 |
+ && (opt.handle == ~0U || opt.handle == h.handle)
|
|
Anton Arapov |
c2a608 |
&& !((opt.flags & FLAG_QUIET) && (h.type == 126 || h.type == 127))
|
|
Anton Arapov |
c2a608 |
&& !opt.string);
|
|
Anton Arapov |
c2a608 |
|
|
Anton Arapov |
c2a608 |
@@ -5144,6 +5145,7 @@ int main(int argc, char * const argv[])
|
|
Anton Arapov |
c2a608 |
/* Set default option values */
|
|
Anton Arapov |
c2a608 |
opt.devmem = DEFAULT_MEM_DEV;
|
|
Anton Arapov |
c2a608 |
opt.flags = 0;
|
|
Anton Arapov |
c2a608 |
+ opt.handle = ~0U;
|
|
Anton Arapov |
c2a608 |
|
|
Anton Arapov |
c2a608 |
if (parse_command_line(argc, argv)<0)
|
|
Anton Arapov |
c2a608 |
{
|
|
Anton Arapov |
c2a608 |
diff --git a/dmiopt.c b/dmiopt.c
|
|
Anton Arapov |
c2a608 |
index a36cf16..1531ddf 100644
|
|
Anton Arapov |
c2a608 |
--- a/dmiopt.c
|
|
Anton Arapov |
c2a608 |
+++ b/dmiopt.c
|
|
Anton Arapov |
c2a608 |
@@ -240,6 +240,19 @@ static int parse_opt_oem_string(const char *arg)
|
|
Anton Arapov |
c2a608 |
return 0;
|
|
Anton Arapov |
c2a608 |
}
|
|
Anton Arapov |
c2a608 |
|
|
Anton Arapov |
c2a608 |
+static u32 parse_opt_handle(const char *arg)
|
|
Anton Arapov |
c2a608 |
+{
|
|
Anton Arapov |
c2a608 |
+ u32 val;
|
|
Anton Arapov |
c2a608 |
+ char *next;
|
|
Anton Arapov |
c2a608 |
+
|
|
Anton Arapov |
c2a608 |
+ val = strtoul(arg, &next, 0);
|
|
Anton Arapov |
c2a608 |
+ if (next == arg || *next != '\0' || val > 0xffff)
|
|
Anton Arapov |
c2a608 |
+ {
|
|
Anton Arapov |
c2a608 |
+ fprintf(stderr, "Invalid handle number: %s\n", arg);
|
|
Anton Arapov |
c2a608 |
+ return ~0;
|
|
Anton Arapov |
c2a608 |
+ }
|
|
Anton Arapov |
c2a608 |
+ return val;
|
|
Anton Arapov |
c2a608 |
+}
|
|
Anton Arapov |
c2a608 |
|
|
Anton Arapov |
c2a608 |
/*
|
|
Anton Arapov |
c2a608 |
* Command line options handling
|
|
Anton Arapov |
c2a608 |
@@ -249,7 +262,7 @@ static int parse_opt_oem_string(const char *arg)
|
|
Anton Arapov |
c2a608 |
int parse_command_line(int argc, char * const argv[])
|
|
Anton Arapov |
c2a608 |
{
|
|
Anton Arapov |
c2a608 |
int option;
|
|
Anton Arapov |
c2a608 |
- const char *optstring = "d:hqs:t:uV";
|
|
Anton Arapov |
c2a608 |
+ const char *optstring = "d:hqs:t:uH:V";
|
|
Anton Arapov |
c2a608 |
struct option longopts[] = {
|
|
Anton Arapov |
c2a608 |
{ "dev-mem", required_argument, NULL, 'd' },
|
|
Anton Arapov |
c2a608 |
{ "help", no_argument, NULL, 'h' },
|
|
Anton Arapov |
c2a608 |
@@ -259,6 +272,7 @@ int parse_command_line(int argc, char * const argv[])
|
|
Anton Arapov |
c2a608 |
{ "dump", no_argument, NULL, 'u' },
|
|
Anton Arapov |
c2a608 |
{ "dump-bin", required_argument, NULL, 'B' },
|
|
Anton Arapov |
c2a608 |
{ "from-dump", required_argument, NULL, 'F' },
|
|
Anton Arapov |
c2a608 |
+ { "handle", required_argument, NULL, 'H' },
|
|
Anton Arapov |
c2a608 |
{ "oem-string", required_argument, NULL, 'O' },
|
|
Anton Arapov |
c2a608 |
{ "no-sysfs", no_argument, NULL, 'S' },
|
|
Anton Arapov |
c2a608 |
{ "version", no_argument, NULL, 'V' },
|
|
Anton Arapov |
c2a608 |
@@ -300,6 +314,11 @@ int parse_command_line(int argc, char * const argv[])
|
|
Anton Arapov |
c2a608 |
if (opt.type == NULL)
|
|
Anton Arapov |
c2a608 |
return -1;
|
|
Anton Arapov |
c2a608 |
break;
|
|
Anton Arapov |
c2a608 |
+ case 'H':
|
|
Anton Arapov |
c2a608 |
+ opt.handle = parse_opt_handle(optarg);
|
|
Anton Arapov |
c2a608 |
+ if (opt.handle == ~0U)
|
|
Anton Arapov |
c2a608 |
+ return -1;
|
|
Anton Arapov |
c2a608 |
+ break;
|
|
Anton Arapov |
c2a608 |
case 'u':
|
|
Anton Arapov |
c2a608 |
opt.flags |= FLAG_DUMP;
|
|
Anton Arapov |
c2a608 |
break;
|
|
Anton Arapov |
c2a608 |
@@ -326,9 +345,9 @@ int parse_command_line(int argc, char * const argv[])
|
|
Anton Arapov |
c2a608 |
|
|
Anton Arapov |
c2a608 |
/* Check for mutually exclusive output format options */
|
|
Anton Arapov |
c2a608 |
if ((opt.string != NULL) + (opt.type != NULL)
|
|
Anton Arapov |
c2a608 |
- + !!(opt.flags & FLAG_DUMP_BIN) > 1)
|
|
Anton Arapov |
c2a608 |
+ + !!(opt.flags & FLAG_DUMP_BIN) + (opt.handle != ~0U) > 1)
|
|
Anton Arapov |
c2a608 |
{
|
|
Anton Arapov |
c2a608 |
- fprintf(stderr, "Options --string, --type and --dump-bin are mutually exclusive\n");
|
|
Anton Arapov |
c2a608 |
+ fprintf(stderr, "Options --string, --type, --handle and --dump-bin are mutually exclusive\n");
|
|
Anton Arapov |
c2a608 |
return -1;
|
|
Anton Arapov |
c2a608 |
}
|
|
Anton Arapov |
c2a608 |
|
|
Anton Arapov |
c2a608 |
@@ -351,6 +370,7 @@ void print_help(void)
|
|
Anton Arapov |
c2a608 |
" -q, --quiet Less verbose output\n"
|
|
Anton Arapov |
c2a608 |
" -s, --string KEYWORD Only display the value of the given DMI string\n"
|
|
Anton Arapov |
c2a608 |
" -t, --type TYPE Only display the entries of given type\n"
|
|
Anton Arapov |
c2a608 |
+ " -H, --handle HANDLE Only display the entry of given handle\n"
|
|
Anton Arapov |
c2a608 |
" -u, --dump Do not decode the entries\n"
|
|
Anton Arapov |
c2a608 |
" --dump-bin FILE Dump the DMI data to a binary file\n"
|
|
Anton Arapov |
c2a608 |
" --from-dump FILE Read the DMI data from a binary file\n"
|
|
Anton Arapov |
c2a608 |
diff --git a/dmiopt.h b/dmiopt.h
|
|
Anton Arapov |
c2a608 |
index c676308..2374637 100644
|
|
Anton Arapov |
c2a608 |
--- a/dmiopt.h
|
|
Anton Arapov |
c2a608 |
+++ b/dmiopt.h
|
|
Anton Arapov |
c2a608 |
@@ -35,6 +35,7 @@ struct opt
|
|
Anton Arapov |
c2a608 |
u8 *type;
|
|
Anton Arapov |
c2a608 |
const struct string_keyword *string;
|
|
Anton Arapov |
c2a608 |
char *dumpfile;
|
|
Anton Arapov |
c2a608 |
+ u32 handle;
|
|
Anton Arapov |
c2a608 |
};
|
|
Anton Arapov |
c2a608 |
extern struct opt opt;
|
|
Anton Arapov |
c2a608 |
|
|
Anton Arapov |
c2a608 |
diff --git a/man/dmidecode.8 b/man/dmidecode.8
|
|
Anton Arapov |
c2a608 |
index e3b6b2a..df861e1 100644
|
|
Anton Arapov |
c2a608 |
--- a/man/dmidecode.8
|
|
Anton Arapov |
c2a608 |
+++ b/man/dmidecode.8
|
|
Anton Arapov |
c2a608 |
@@ -115,6 +115,10 @@ is printed and
|
|
Anton Arapov |
c2a608 |
.B dmidecode
|
|
Anton Arapov |
c2a608 |
exits with an error.
|
|
Anton Arapov |
c2a608 |
.TP
|
|
Anton Arapov |
c2a608 |
+.BR "-H" ", " "--handle HANDLE"
|
|
Anton Arapov |
c2a608 |
+Only display the entry whose handle matches \fBHANDLE\fR. \fBHANDLE\fR
|
|
Anton Arapov |
c2a608 |
+is a 16-bit integer.
|
|
Anton Arapov |
c2a608 |
+.TP
|
|
Anton Arapov |
c2a608 |
.BR "-u" ", " "--dump"
|
|
Anton Arapov |
c2a608 |
Do not decode the entries, dump their contents as hexadecimal instead.
|
|
Anton Arapov |
c2a608 |
Note that this is still a text output, no binary data will be thrown upon
|
|
Anton Arapov |
c2a608 |
--
|
|
Anton Arapov |
c2a608 |
2.17.1
|
|
Anton Arapov |
c2a608 |
|