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