Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bd871c1

Browse files
committed
dmidecode: New option --oem-string
Add a new option to extract OEM strings, like we already have for many other strings. Signed-off-by: Jean Delvare <jdelvare@suse.de>
1 parent 77ac1e2 commit bd871c1

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

‎dmidecode.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4555,6 +4555,21 @@ static void dmi_table_string(const struct dmi_header *h, const u8 *data, u16 ver
45554555
int key;
45564556
u8 offset = opt.string->offset;
45574557

4558+
if (opt.string->type == 11) /* OEM strings */
4559+
{
4560+
if (h->length < 5 || offset > data[4])
4561+
{
4562+
fprintf(stderr, "No OEM string number %u\n", offset);
4563+
return;
4564+
}
4565+
4566+
if (offset)
4567+
printf("%s\n", dmi_string(h, offset));
4568+
else
4569+
printf("%u\n", data[4]); /* count */
4570+
return;
4571+
}
4572+
45584573
if (offset >= h->length)
45594574
return;
45604575

‎dmiopt.c‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
#include <stdio.h>
23+
#include <string.h>
2324
#include <strings.h>
2425
#include <stdlib.h>
2526
#include <getopt.h>
@@ -171,6 +172,10 @@ static const struct string_keyword opt_string_keyword[] = {
171172
{ "processor-frequency", 4, 0x16 }, /* dmi_processor_frequency() */
172173
};
173174

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

214+
static int parse_opt_oem_string(const char *arg)
215+
{
216+
unsigned long val;
217+
char *next;
218+
219+
if (opt.string)
220+
{
221+
fprintf(stderr, "Only one string can be specified\n");
222+
return -1;
223+
}
224+
225+
/* Return the number of OEM strings */
226+
if (strcmp(arg, "count") == 0)
227+
goto done;
228+
229+
val = strtoul(arg, &next, 10);
230+
if (next == arg || val == 0x00 || val > 0xff)
231+
{
232+
fprintf(stderr, "Invalid OEM string number: %s\n", arg);
233+
return -1;
234+
}
235+
236+
opt_oem_string_keyword.offset = val;
237+
done:
238+
opt.string = &opt_oem_string_keyword;
239+
return 0;
240+
}
241+
209242

210243
/*
211244
* Command line options handling
@@ -225,6 +258,7 @@ int parse_command_line(int argc, char * const argv[])
225258
{ "dump", no_argument, NULL, 'u' },
226259
{ "dump-bin", required_argument, NULL, 'B' },
227260
{ "from-dump", required_argument, NULL, 'F' },
261+
{ "oem-string", required_argument, NULL, 'O' },
228262
{ "no-sysfs", no_argument, NULL, 'S' },
229263
{ "version", no_argument, NULL, 'V' },
230264
{ NULL, 0, NULL, 0 }
@@ -255,6 +289,11 @@ int parse_command_line(int argc, char * const argv[])
255289
return -1;
256290
opt.flags |= FLAG_QUIET;
257291
break;
292+
case 'O':
293+
if (parse_opt_oem_string(optarg) < 0)
294+
return -1;
295+
opt.flags |= FLAG_QUIET;
296+
break;
258297
case 't':
259298
opt.type = parse_opt_type(opt.type, optarg);
260299
if (opt.type == NULL)
@@ -315,6 +354,7 @@ void print_help(void)
315354
" --dump-bin FILE Dump the DMI data to a binary file\n"
316355
" --from-dump FILE Read the DMI data from a binary file\n"
317356
" --no-sysfs Do not attempt to read DMI data from sysfs files\n"
357+
" --oem-string N Only display the value of the given OEM string\n"
318358
" -V, --version Display the version and exit\n";
319359

320360
printf("%s", help);

‎man/dmidecode.8‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,18 @@ Read the DMI data from a binary file previously generated using
134134
Do not attempt to read DMI data from sysfs files. This is mainly useful for
135135
debugging.
136136
.TP
137+
.BR " " " " "--oem-string N"
138+
Only display the value of the \s-1OEM\s0 string number \fBN\fR. The first
139+
\s-1OEM\s0 string has number 1. With special value "count", return the
140+
number of OEM strings instead.
141+
.TP
137142
.BR "-h" ", " "--help"
138143
Display usage information and exit
139144
.TP
140145
.BR "-V" ", " "--version"
141146
Display the version and exit
142147
.P
143-
Options --string, --type and --dump-bin
148+
Options --string, --type, --dump-bin and --oem-string
144149
determine the output format and are mutually exclusive.
145150
.P
146151
Please note in case of

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /