@@ -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)
249262int 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"
0 commit comments