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 62 of file nvo_cmd.c.

62 {
63 struct show_options opts;
65 struct settings *origin;
66 struct setting fetched;
67 char name_buf[32];
68 char *value;
69 int len;
70 int rc;
71
72 /* Parse options */
73 if ( ( rc = parse_options ( argc, argv, &show_cmd, &opts ) ) != 0 )
74 goto err_parse_options;
75
76 /* Parse setting name */
77 if ( ( rc = parse_existing_setting ( argv[optind], &setting ) ) != 0 )
78 goto err_parse_setting;
79
80 /* Fetch formatted setting value */
81 if ( ( len = fetchf_setting_copy ( setting.settings, &setting.setting,
82 &origin, &fetched, &value ) ) < 0 ) {
83 rc = len;
84 printf ( "Could not find \"%s\": %s\n",
85 setting.setting.name, strerror ( rc ) );
86 goto err_fetchf;
87 }
88
89 /* Print setting value */
90 setting_name ( origin, &fetched, name_buf, sizeof ( name_buf ) );
91 printf ( "%s = %s\n", name_buf, value );
92
93 /* Success */
94 rc = 0;
95
96 free ( value );
97 err_fetchf:
98 err_parse_setting:
99 err_parse_options:
100 return rc;
101}
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:52
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:1607
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:1277
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:465

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 148 of file nvo_cmd.c.

152 {
153 struct set_core_options opts;
154 struct named_setting setting;
155 char *value;
156 int rc;
157
158 /* Parse options */
159 if ( ( rc = parse_options ( argc, argv, cmd, &opts ) ) != 0 )
160 goto err_parse_options;
161
162 /* Parse setting name */
163 if ( ( rc = parse_autovivified_setting ( argv[optind],
164 &setting ) ) != 0 )
165 goto err_parse_setting;
166
167 /* Parse setting value */
168 if ( ( rc = get_value ( &setting, &opts, &argv[ optind + 1 ],
169 &value ) ) != 0 )
170 goto err_get_value;
171
172 /* Apply default type if necessary */
173 if ( ! setting.setting.type )
174 setting.setting.type = &setting_type_string;
175
176 /* Store setting */
177 if ( ( rc = storef_setting ( setting.settings, &setting.setting,
178 value ) ) != 0 ) {
179 printf ( "Could not store \"%s\": %s\n",
180 setting.setting.name, strerror ( rc ) );
181 goto err_store;
182 }
183
184 err_store:
185 free ( value );
186 err_get_value:
187 err_parse_setting:
188 err_parse_options:
189 return rc;
190}
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:1320
"set", "clear", and "read" options
Definition nvo_cmd.c:104
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 201 of file nvo_cmd.c.

203 {
204
205 *value = concat_args ( args );
206 if ( ! *value )
207 return -ENOMEM;
208
209 return 0;
210}
char * concat_args(char **args)
Concatenate arguments.
Definition exec.c:359
#define ENOMEM
Not enough space.
Definition errno.h:535

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 219 of file nvo_cmd.c.

219 {
220 return set_core_exec ( argc, argv, &set_cmd, set_value );
221}
static struct command_descriptor set_cmd
"set" command descriptor
Definition nvo_cmd.c:125
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:148
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:201

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 232 of file nvo_cmd.c.

234 {
235
236 *value = NULL;
237 return 0;
238}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322

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 247 of file nvo_cmd.c.

247 {
248 return set_core_exec ( argc, argv, &clear_cmd, clear_value );
249}
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:232
static struct command_descriptor clear_cmd
"clear" command descriptor
Definition nvo_cmd.c:130

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 260 of file nvo_cmd.c.

262 {
263 char *existing;
264 int rc;
265
266 /* Read existing value, treating errors as equivalent to an
267 * empty initial setting.
268 */
269 fetchf_setting_copy ( setting->settings, &setting->setting,
270 NULL, &setting->setting, &existing );
271
272 /* Read new value */
273 if ( ( rc = readline_history ( NULL, existing, NULL, opts->timeout,
274 value ) ) != 0 )
275 goto err_readline;
276
277 err_readline:
278 free ( existing );
279 return rc;
280}
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 289 of file nvo_cmd.c.

289 {
290 return set_core_exec ( argc, argv, &read_cmd, read_value );
291}
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:260
static struct command_descriptor read_cmd
"read" command descriptor
Definition nvo_cmd.c:135

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 311 of file nvo_cmd.c.

311 {
312 struct inc_options opts;
313 struct named_setting setting;
314 unsigned int increment = 1;
315 unsigned long value;
316 int rc;
317
318 /* Parse options */
319 if ( ( rc = parse_options ( argc, argv, &inc_cmd, &opts ) ) != 0 )
320 goto err_parse_options;
321
322 /* Parse setting name */
323 if ( ( rc = parse_existing_setting ( argv[optind], &setting ) ) != 0 )
324 goto err_parse_setting;
325
326 /* Parse increment (if present) */
327 if ( ( ( optind + 1 ) < argc ) &&
328 ( ( rc = parse_integer ( argv[ optind + 1 ], &increment ) ) != 0))
329 goto err_parse_increment;
330
331 /* Read existing value, treating errors as equivalent to a
332 * zero-valued :int32 initial setting.
333 */
334 if ( ( rc = fetchn_setting ( setting.settings, &setting.setting,
335 NULL, &setting.setting, &value ) ) != 0 ) {
336 value = 0;
337 if ( ! setting.setting.type )
338 setting.setting.type = &setting_type_int32;
339 }
340
341 /* Increment value */
342 value += increment;
343
344 /* Store updated setting value */
345 if ( ( rc = storen_setting ( setting.settings, &setting.setting,
346 value ) ) != 0 ) {
347 printf ( "Could not store \"%s\": %s\n",
348 setting.setting.name, strerror ( rc ) );
349 goto err_store;
350 }
351
352 err_store:
353 err_parse_increment:
354 err_parse_setting:
355 err_parse_options:
356 return rc;
357}
static struct command_descriptor inc_cmd
"inc" command descriptor
Definition nvo_cmd.c:300
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:1373
int storen_setting(struct settings *settings, const struct setting *setting, unsigned long value)
Store numeric value of setting.
Definition settings.c:1415
"inc" options
Definition nvo_cmd.c:294

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

"show" option list

Definition at line 49 of file nvo_cmd.c.

49{};

◆ 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:49
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition parseopt.h:109

"show" command descriptor

Definition at line 52 of file nvo_cmd.c.

Referenced by show_exec().

◆ set

fd_set * set

◆ clear

struct option_descriptor clear[0]

Definition at line 114 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
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition parseopt.h:68

"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 125 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 130 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 135 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 297 of file nvo_cmd.c.

297{};

◆ 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:297

"inc" command descriptor

Definition at line 300 of file nvo_cmd.c.

Referenced by inc_exec().