iPXE
nvo_cmd.c File Reference

Non-volatile option commands. More...

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <getopt.h>
#include <byteswap.h>
#include <ipxe/settings.h>
#include <ipxe/command.h>
#include <ipxe/parseopt.h>
#include <readline/readline.h>

Go to the source code of this file.

Data Structures

struct  show_options
 "show" options More...
struct  set_core_options
 "set", "clear", and "read" options More...
struct  inc_options
 "inc" options More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static int show_exec (int argc, char **argv)
 "show" command
static int set_core_exec (int argc, char **argv, struct command_descriptor *cmd, int(*get_value)(struct named_setting *setting, struct set_core_options *opts, char **args, char **value))
 "set", "clear", and "read" command
static int set_value (struct named_setting *setting __unused, struct set_core_options *opts __unused, char **args, char **value)
 Get setting value for "set" command.
static int set_exec (int argc, char **argv)
 "set" command
static int clear_value (struct named_setting *setting __unused, struct set_core_options *opts __unused, char **args __unused, char **value)
 Get setting value for "clear" command.
static int clear_exec (int argc, char **argv)
 "clear" command
static int read_value (struct named_setting *setting, struct set_core_options *opts, char **args __unused, char **value)
 Get setting value for "read" command.
static int read_exec (int argc, char **argv)
 "read" command
static int inc_exec (int argc, char **argv)
 "inc" command
 COMMAND (show, show_exec)
 Non-volatile option commands.
 COMMAND (set, set_exec)
 COMMAND (clear, clear_exec)
 COMMAND (read, read_exec)
 COMMAND (inc, inc_exec)

Variables

static struct option_descriptor show_opts []
 "show" option list
static struct command_descriptor show_cmd
 "show" command descriptor
union { 
   struct option_descriptor   set [0] 
   struct option_descriptor   clear [0] 
   struct option_descriptor   read [1] 
set_core_opts
 "set", "clear", and "read" option list
static struct command_descriptor set_cmd
 "set" command descriptor
static struct command_descriptor clear_cmd
 "clear" command descriptor
static struct command_descriptor read_cmd
 "read" command descriptor
static struct option_descriptor inc_opts [] = {}
 "inc" option list
static struct command_descriptor inc_cmd
 "inc" command descriptor

Detailed Description

Non-volatile option commands.

Definition in file nvo_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ show_exec()

int show_exec ( int argc,
char ** argv )
static

"show" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 68 of file nvo_cmd.c.

68 {
69 struct show_options opts;
71 struct settings *origin;
72 struct setting fetched;
73 char name_buf[32];
74 char *value;
75 int len;
76 int rc;
77
78 /* Parse options */
79 if ( ( rc = parse_options ( argc, argv, &show_cmd, &opts ) ) != 0 )
80 goto err_parse_options;
81
82 /* Parse setting name */
83 if ( ( rc = parse_existing_setting ( argv[optind], &setting ) ) != 0 )
84 goto err_parse_setting;
85
86 /* Fetch formatted setting value */
87 if ( ( len = fetchf_setting_copy ( setting.settings, &setting.setting,
88 &origin, &fetched, &value ) ) < 0 ) {
89 rc = len;
90 printf ( "Could not find \"%s\": %s\n",
91 setting.setting.name, strerror ( rc ) );
92 goto err_fetchf;
93 }
94
95 /* Print setting value */
96 setting_name ( origin, &fetched, name_buf, sizeof ( name_buf ) );
97 if ( ! opts.quiet )
98 printf ( "%s = ", name_buf );
99 printf ( "%s\n", value );
100
101 /* Success */
102 rc = 0;
103
104 free ( value );
105 err_fetchf:
106 err_parse_setting:
107 err_parse_options:
108 return rc;
109}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
pseudo_bit_t value[0x00020]
Definition arbel.h:2
static union @024010030001061367220137227263210031030210157031 opts
"cert<xxx>" option list
ring len
Length.
Definition dwmac.h:226
int optind
Current option index.
Definition getopt.c:52
uint64_t origin
Origin.
Definition hyperv.h:9
static struct command_descriptor show_cmd
"show" command descriptor
Definition nvo_cmd.c:58
int parse_existing_setting(char *text, struct named_setting *setting)
Parse existing setting name.
Definition parseopt.c:323
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition parseopt.c:485
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
int setting_name(struct settings *settings, const struct setting *setting, char *buf, size_t len)
Return full setting name.
Definition settings.c:1617
int fetchf_setting_copy(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, char **value)
Fetch copy of formatted value of setting.
Definition settings.c:1287
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
A parsed named setting.
Definition parseopt.h:123
A setting.
Definition settings.h:24
const char * name
Name.
Definition settings.h:29
A settings block.
Definition settings.h:133
"show" options
Definition nvo_cmd.c:46
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:485

References fetchf_setting_copy(), free, len, setting::name, optind, opts, origin, parse_existing_setting(), parse_options(), printf(), rc, setting_name(), show_cmd, strerror(), and value.

Referenced by COMMAND().

◆ set_core_exec()

int set_core_exec ( int argc,
char ** argv,
struct command_descriptor * cmd,
int(* get_value )(struct named_setting *setting, struct set_core_options *opts, char **args, char **value) )
static

"set", "clear", and "read" command

Parameters
argcArgument count
argvArgument list
cmdCommand descriptor
get_valueMethod to obtain setting value
Return values
rcReturn status code

Definition at line 156 of file nvo_cmd.c.

160 {
161 struct set_core_options opts;
162 struct named_setting setting;
163 char *value;
164 int rc;
165
166 /* Parse options */
167 if ( ( rc = parse_options ( argc, argv, cmd, &opts ) ) != 0 )
168 goto err_parse_options;
169
170 /* Parse setting name */
171 if ( ( rc = parse_autovivified_setting ( argv[optind],
172 &setting ) ) != 0 )
173 goto err_parse_setting;
174
175 /* Parse setting value */
176 if ( ( rc = get_value ( &setting, &opts, &argv[ optind + 1 ],
177 &value ) ) != 0 )
178 goto err_get_value;
179
180 /* Apply default type if necessary */
181 if ( ! setting.setting.type )
182 setting.setting.type = &setting_type_string;
183
184 /* Store setting */
185 if ( ( rc = storef_setting ( setting.settings, &setting.setting,
186 value ) ) != 0 ) {
187 printf ( "Could not store \"%s\": %s\n",
188 setting.setting.name, strerror ( rc ) );
189 goto err_store;
190 }
191
192 err_store:
193 free ( value );
194 err_get_value:
195 err_parse_setting:
196 err_parse_options:
197 return rc;
198}
struct golan_eqe_cmd cmd
Definition CIB_PRM.h:1
int parse_autovivified_setting(char *text, struct named_setting *setting)
Parse and autovivify setting name.
Definition parseopt.c:337
int storef_setting(struct settings *settings, const struct setting *setting, const char *value)
Store formatted value of setting.
Definition settings.c:1330
"set", "clear", and "read" options
Definition nvo_cmd.c:112
const struct setting_type * type
Setting type.
Definition settings.h:37

References cmd, free, setting::name, optind, opts, parse_autovivified_setting(), parse_options(), printf(), rc, storef_setting(), strerror(), setting::type, and value.

Referenced by clear_exec(), read_exec(), and set_exec().

◆ set_value()

int set_value ( struct named_setting *setting __unused,
struct set_core_options *opts __unused,
char ** args,
char ** value )
static

Get setting value for "set" command.

Parameters
settingNamed setting
optsOptions list
argsRemaining arguments
Return values
valueSetting value
rcReturn status code

Definition at line 209 of file nvo_cmd.c.

211 {
212
213 *value = concat_args ( args );
214 if ( ! *value )
215 return -ENOMEM;
216
217 return 0;
218}
char * concat_args(char **args)
Concatenate arguments.
Definition exec.c:359
#define ENOMEM
Not enough space.
Definition errno.h:578

References __unused, concat_args(), ENOMEM, opts, and value.

Referenced by set_exec().

◆ set_exec()

int set_exec ( int argc,
char ** argv )
static

"set" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 227 of file nvo_cmd.c.

227 {
228 return set_core_exec ( argc, argv, &set_cmd, set_value );
229}
static struct command_descriptor set_cmd
"set" command descriptor
Definition nvo_cmd.c:133
static int set_core_exec(int argc, char **argv, struct command_descriptor *cmd, int(*get_value)(struct named_setting *setting, struct set_core_options *opts, char **args, char **value))
"set", "clear", and "read" command
Definition nvo_cmd.c:156
static int set_value(struct named_setting *setting __unused, struct set_core_options *opts __unused, char **args, char **value)
Get setting value for "set" command.
Definition nvo_cmd.c:209

References set_cmd, set_core_exec(), and set_value().

Referenced by COMMAND().

◆ clear_value()

int clear_value ( struct named_setting *setting __unused,
struct set_core_options *opts __unused,
char **args __unused,
char ** value )
static

Get setting value for "clear" command.

Parameters
settingNamed setting
argsRemaining arguments
optsOptions list
Return values
valueSetting value
rcReturn status code

Definition at line 240 of file nvo_cmd.c.

242 {
243
244 *value = NULL;
245 return 0;
246}
#define NULL
NULL pointer (VOID *).
Definition Base.h:321

References __unused, NULL, opts, and value.

Referenced by clear_exec().

◆ clear_exec()

int clear_exec ( int argc,
char ** argv )
static

"clear" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 255 of file nvo_cmd.c.

255 {
256 return set_core_exec ( argc, argv, &clear_cmd, clear_value );
257}
static int clear_value(struct named_setting *setting __unused, struct set_core_options *opts __unused, char **args __unused, char **value)
Get setting value for "clear" command.
Definition nvo_cmd.c:240
static struct command_descriptor clear_cmd
"clear" command descriptor
Definition nvo_cmd.c:138

References clear_cmd, clear_value(), and set_core_exec().

Referenced by COMMAND().

◆ read_value()

int read_value ( struct named_setting * setting,
struct set_core_options * opts,
char **args __unused,
char ** value )
static

Get setting value for "read" command.

Parameters
settingNamed setting
argsRemaining arguments
optsOptions list
Return values
valueSetting value
rcReturn status code

Definition at line 268 of file nvo_cmd.c.

270 {
271 char *existing;
272 int rc;
273
274 /* Read existing value, treating errors as equivalent to an
275 * empty initial setting.
276 */
277 fetchf_setting_copy ( setting->settings, &setting->setting,
278 NULL, &setting->setting, &existing );
279
280 /* Read new value */
281 if ( ( rc = readline_history ( NULL, existing, NULL, opts->timeout,
282 value ) ) != 0 )
283 goto err_readline;
284
285 err_readline:
286 free ( existing );
287 return rc;
288}
A readline history buffer.
Definition readline.h:32

References __unused, fetchf_setting_copy(), free, NULL, opts, rc, and value.

Referenced by read_exec().

◆ read_exec()

int read_exec ( int argc,
char ** argv )
static

"read" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 297 of file nvo_cmd.c.

297 {
298 return set_core_exec ( argc, argv, &read_cmd, read_value );
299}
static int read_value(struct named_setting *setting, struct set_core_options *opts, char **args __unused, char **value)
Get setting value for "read" command.
Definition nvo_cmd.c:268
static struct command_descriptor read_cmd
"read" command descriptor
Definition nvo_cmd.c:143

References read_cmd, read_value(), and set_core_exec().

Referenced by COMMAND().

◆ inc_exec()

int inc_exec ( int argc,
char ** argv )
static

"inc" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 319 of file nvo_cmd.c.

319 {
320 struct inc_options opts;
321 struct named_setting setting;
322 unsigned int increment = 1;
323 unsigned long value;
324 int rc;
325
326 /* Parse options */
327 if ( ( rc = parse_options ( argc, argv, &inc_cmd, &opts ) ) != 0 )
328 goto err_parse_options;
329
330 /* Parse setting name */
331 if ( ( rc = parse_existing_setting ( argv[optind], &setting ) ) != 0 )
332 goto err_parse_setting;
333
334 /* Parse increment (if present) */
335 if ( ( ( optind + 1 ) < argc ) &&
336 ( ( rc = parse_integer ( argv[ optind + 1 ], &increment ) ) != 0))
337 goto err_parse_increment;
338
339 /* Read existing value, treating errors as equivalent to a
340 * zero-valued :int32 initial setting.
341 */
342 if ( ( rc = fetchn_setting ( setting.settings, &setting.setting,
343 NULL, &setting.setting, &value ) ) != 0 ) {
344 value = 0;
345 if ( ! setting.setting.type )
346 setting.setting.type = &setting_type_int32;
347 }
348
349 /* Increment value */
350 value += increment;
351
352 /* Store updated setting value */
353 if ( ( rc = storen_setting ( setting.settings, &setting.setting,
354 value ) ) != 0 ) {
355 printf ( "Could not store \"%s\": %s\n",
356 setting.setting.name, strerror ( rc ) );
357 goto err_store;
358 }
359
360 err_store:
361 err_parse_increment:
362 err_parse_setting:
363 err_parse_options:
364 return rc;
365}
static struct command_descriptor inc_cmd
"inc" command descriptor
Definition nvo_cmd.c:308
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition parseopt.c:92
int fetchn_setting(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, unsigned long *value)
Fetch numeric value of setting.
Definition settings.c:1383
int storen_setting(struct settings *settings, const struct setting *setting, unsigned long value)
Store numeric value of setting.
Definition settings.c:1425
"inc" options
Definition nvo_cmd.c:302

References fetchn_setting(), inc_cmd, setting::name, NULL, optind, opts, parse_existing_setting(), parse_integer(), parse_options(), printf(), rc, storen_setting(), strerror(), setting::type, and value.

Referenced by COMMAND().

◆ COMMAND() [1/5]

COMMAND ( show ,
show_exec  )

Non-volatile option commands.

References show_exec().

◆ COMMAND() [2/5]

COMMAND ( set ,
set_exec  )

References set, and set_exec().

◆ COMMAND() [3/5]

COMMAND ( clear ,
clear_exec  )

References clear, and clear_exec().

◆ COMMAND() [4/5]

COMMAND ( read ,
read_exec  )

References read, and read_exec().

◆ COMMAND() [5/5]

COMMAND ( inc ,
inc_exec  )

References inc_exec().

Variable Documentation

◆ show_opts

struct option_descriptor show_opts[]
static
Initial value:
= {
OPTION_DESC ( "quiet", 'q', no_argument,
struct show_options, quiet, parse_flag ),
}
@ no_argument
Option does not take an argument.
Definition getopt.h:17
int parse_flag(char *text __unused, int *flag)
Parse flag.
Definition parseopt.c:227
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition parseopt.h:68

"show" option list

Definition at line 52 of file nvo_cmd.c.

52 {
53 OPTION_DESC ( "quiet", 'q', no_argument,
54 struct show_options, quiet, parse_flag ),
55};

◆ show_cmd

struct command_descriptor show_cmd
static
Initial value:
=
COMMAND_DESC ( struct show_options, show_opts, 1, 1, "<setting>" )
static struct option_descriptor show_opts[]
"show" option list
Definition nvo_cmd.c:52
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition parseopt.h:109

"show" command descriptor

Definition at line 58 of file nvo_cmd.c.

Referenced by show_exec().

◆ set

fd_set * set

◆ clear

struct option_descriptor clear[0]

Definition at line 122 of file nvo_cmd.c.

Referenced by b44_wait_bit(), COMMAND(), and net80211_set_state().

◆ read

◆ [union]

union { ... } set_core_opts
Initial value:
= {
.read = {
OPTION_DESC ( "timeout", 't', required_argument,
},
}
void timeout(int)
@ required_argument
Option requires an argument.
Definition getopt.h:19
int parse_timeout(char *text, unsigned long *value)
Parse timeout value (in ms).
Definition parseopt.c:115

"set", "clear", and "read" option list

◆ set_cmd

struct command_descriptor set_cmd
static
Initial value:
=
1, MAX_ARGUMENTS, "<setting> <value>" )
static union @042366366224015251152162264074251001343161101060 set_core_opts
"set", "clear", and "read" option list
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition parseopt.h:98

"set" command descriptor

Definition at line 133 of file nvo_cmd.c.

Referenced by set_exec().

◆ clear_cmd

struct command_descriptor clear_cmd
static
Initial value:
=
1, 1, "<setting>" )

"clear" command descriptor

Definition at line 138 of file nvo_cmd.c.

Referenced by clear_exec().

◆ read_cmd

struct command_descriptor read_cmd
static
Initial value:
=
1, 1, "<setting>" )

"read" command descriptor

Definition at line 143 of file nvo_cmd.c.

Referenced by eeprom_read(), falcon_spi_rw(), mdio_read(), read_eeprom(), read_eeprom(), read_eeprom(), read_exec(), and sis900_read_eeprom().

◆ inc_opts

struct option_descriptor inc_opts[] = {}
static

"inc" option list

Definition at line 305 of file nvo_cmd.c.

305{};

◆ inc_cmd

struct command_descriptor inc_cmd
static
Initial value:
=
"<setting> [<increment>]" )
static struct option_descriptor inc_opts[]
"inc" option list
Definition nvo_cmd.c:305

"inc" command descriptor

Definition at line 308 of file nvo_cmd.c.

Referenced by inc_exec().