Skip to content

Commit a40f10b

Browse files
jah63jdelvare
authored andcommitted
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 <[email protected]> Signed-off-by: Jean Delvare <[email protected]>
1 parent 29e626f commit a40f10b

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

dmidecode.c

+2
Original file line numberDiff line numberDiff line change
@@ -4732,6 +4732,7 @@ static void dmi_table_decode(u8 *buf, u32 len, u16 num, u16 ver, u32 flags)
47324732

47334733
to_dmi_header(&h, data);
47344734
display = ((opt.type == NULL || opt.type[h.type])
4735+
&& (opt.handle == ~0U || opt.handle == h.handle)
47354736
&& !((opt.flags & FLAG_QUIET) && (h.type == 126 || h.type == 127))
47364737
&& !opt.string);
47374738

@@ -5144,6 +5145,7 @@ int main(int argc, char * const argv[])
51445145
/* Set default option values */
51455146
opt.devmem = DEFAULT_MEM_DEV;
51465147
opt.flags = 0;
5148+
opt.handle = ~0U;
51475149

51485150
if (parse_command_line(argc, argv)<0)
51495151
{

dmiopt.c

+23-3
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,19 @@ static int parse_opt_oem_string(const char *arg)
240240
return 0;
241241
}
242242

243+
static u32 parse_opt_handle(const char *arg)
244+
{
245+
u32 val;
246+
char *next;
247+
248+
val = strtoul(arg, &next, 0);
249+
if (next == arg || *next != '\0' || val > 0xffff)
250+
{
251+
fprintf(stderr, "Invalid handle number: %s\n", arg);
252+
return ~0;
253+
}
254+
return val;
255+
}
243256

244257
/*
245258
* Command line options handling
@@ -249,7 +262,7 @@ static int parse_opt_oem_string(const char *arg)
249262
int parse_command_line(int argc, char * const argv[])
250263
{
251264
int option;
252-
const char *optstring = "d:hqs:t:uV";
265+
const char *optstring = "d:hqs:t:uH:V";
253266
struct option longopts[] = {
254267
{ "dev-mem", required_argument, NULL, 'd' },
255268
{ "help", no_argument, NULL, 'h' },
@@ -259,6 +272,7 @@ int parse_command_line(int argc, char * const argv[])
259272
{ "dump", no_argument, NULL, 'u' },
260273
{ "dump-bin", required_argument, NULL, 'B' },
261274
{ "from-dump", required_argument, NULL, 'F' },
275+
{ "handle", required_argument, NULL, 'H' },
262276
{ "oem-string", required_argument, NULL, 'O' },
263277
{ "no-sysfs", no_argument, NULL, 'S' },
264278
{ "version", no_argument, NULL, 'V' },
@@ -300,6 +314,11 @@ int parse_command_line(int argc, char * const argv[])
300314
if (opt.type == NULL)
301315
return -1;
302316
break;
317+
case 'H':
318+
opt.handle = parse_opt_handle(optarg);
319+
if (opt.handle == ~0U)
320+
return -1;
321+
break;
303322
case 'u':
304323
opt.flags |= FLAG_DUMP;
305324
break;
@@ -326,9 +345,9 @@ int parse_command_line(int argc, char * const argv[])
326345

327346
/* Check for mutually exclusive output format options */
328347
if ((opt.string != NULL) + (opt.type != NULL)
329-
+ !!(opt.flags & FLAG_DUMP_BIN) > 1)
348+
+ !!(opt.flags & FLAG_DUMP_BIN) + (opt.handle != ~0U) > 1)
330349
{
331-
fprintf(stderr, "Options --string, --type and --dump-bin are mutually exclusive\n");
350+
fprintf(stderr, "Options --string, --type, --handle and --dump-bin are mutually exclusive\n");
332351
return -1;
333352
}
334353

@@ -351,6 +370,7 @@ void print_help(void)
351370
" -q, --quiet Less verbose output\n"
352371
" -s, --string KEYWORD Only display the value of the given DMI string\n"
353372
" -t, --type TYPE Only display the entries of given type\n"
373+
" -H, --handle HANDLE Only display the entry of given handle\n"
354374
" -u, --dump Do not decode the entries\n"
355375
" --dump-bin FILE Dump the DMI data to a binary file\n"
356376
" --from-dump FILE Read the DMI data from a binary file\n"

dmiopt.h

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct opt
3535
u8 *type;
3636
const struct string_keyword *string;
3737
char *dumpfile;
38+
u32 handle;
3839
};
3940
extern struct opt opt;
4041

man/dmidecode.8

+4
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ is printed and
115115
.B dmidecode
116116
exits with an error.
117117
.TP
118+
.BR "-H" ", " "--handle HANDLE"
119+
Only display the entry whose handle matches \fBHANDLE\fR. \fBHANDLE\fR
120+
is a 16-bit integer.
121+
.TP
118122
.BR "-u" ", " "--dump"
119123
Do not decode the entries, dump their contents as hexadecimal instead.
120124
Note that this is still a text output, no binary data will be thrown upon

0 commit comments

Comments
 (0)