iPXE
Data Structures | Functions | Variables
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)
 
static int show_exec (int argc, char **argv)
 "show" command More...
 
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 More...
 
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. More...
 
static int set_exec (int argc, char **argv)
 "set" command More...
 
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. More...
 
static int clear_exec (int argc, char **argv)
 "clear" command More...
 
static int read_value (struct named_setting *setting, struct set_core_options *opts, char **args __unused, char **value)
 Get setting value for "read" command. More...
 
static int read_exec (int argc, char **argv)
 "read" command More...
 
static int inc_exec (int argc, char **argv)
 "inc" command More...
 

Variables

static struct option_descriptor show_opts [] = {}
 "show" option list More...
 
static struct command_descriptor show_cmd
 "show" command descriptor More...
 
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 More...
 
static struct command_descriptor set_cmd
 "set" command descriptor More...
 
static struct command_descriptor clear_cmd
 "clear" command descriptor More...
 
static struct command_descriptor read_cmd
 "read" command descriptor More...
 
static struct option_descriptor inc_opts [] = {}
 "inc" option list More...
 
static struct command_descriptor inc_cmd
 "inc" command descriptor More...
 
struct command nvo_commands [] __command
 Non-volatile option commands. More...
 

Detailed Description

Non-volatile option commands.

Definition in file nvo_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ show_exec()

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

"show" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 61 of file nvo_cmd.c.

61  {
62  struct show_options opts;
63  struct named_setting setting;
64  struct settings *origin;
65  struct setting fetched;
66  char name_buf[32];
67  char *value;
68  int len;
69  int rc;
70 
71  /* Parse options */
72  if ( ( rc = parse_options ( argc, argv, &show_cmd, &opts ) ) != 0 )
73  goto err_parse_options;
74 
75  /* Parse setting name */
76  if ( ( rc = parse_existing_setting ( argv[optind], &setting ) ) != 0 )
77  goto err_parse_setting;
78 
79  /* Fetch formatted setting value */
80  if ( ( len = fetchf_setting_copy ( setting.settings, &setting.setting,
81  &origin, &fetched, &value ) ) < 0 ) {
82  rc = len;
83  printf ( "Could not find \"%s\": %s\n",
84  setting.setting.name, strerror ( rc ) );
85  goto err_fetchf;
86  }
87 
88  /* Print setting value */
89  setting_name ( origin, &fetched, name_buf, sizeof ( name_buf ) );
90  printf ( "%s = %s\n", name_buf, value );
91 
92  /* Success */
93  rc = 0;
94 
95  free ( value );
96  err_fetchf:
97  err_parse_setting:
98  err_parse_options:
99  return rc;
100 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint64_t origin
Origin.
Definition: hyperv.h:20
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
A parsed named setting.
Definition: parseopt.h:122
int optind
Current option index.
Definition: getopt.c:51
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:1276
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:484
const char * name
Name.
Definition: settings.h:28
int parse_existing_setting(char *text, struct named_setting *setting)
Parse existing setting name.
Definition: parseopt.c:322
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
static struct command_descriptor show_cmd
"show" command descriptor
Definition: nvo_cmd.c:51
"show" options
Definition: nvo_cmd.c:45
A settings block.
Definition: settings.h:132
static union @437 opts
"cert<xxx>" option list
A setting.
Definition: settings.h:23
uint32_t len
Length.
Definition: ena.h:14
int setting_name(struct settings *settings, const struct setting *setting, char *buf, size_t len)
Return full setting name.
Definition: settings.c:1606

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.

◆ set_core_exec()

static int set_core_exec ( int  argc,
char **  argv,
struct command_descriptor cmd,
int(*)(struct named_setting *setting, struct set_core_options *opts, char **args, char **value get_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 147 of file nvo_cmd.c.

151  {
152  struct set_core_options opts;
153  struct named_setting setting;
154  char *value;
155  int rc;
156 
157  /* Parse options */
158  if ( ( rc = parse_options ( argc, argv, cmd, &opts ) ) != 0 )
159  goto err_parse_options;
160 
161  /* Parse setting name */
162  if ( ( rc = parse_autovivified_setting ( argv[optind],
163  &setting ) ) != 0 )
164  goto err_parse_setting;
165 
166  /* Parse setting value */
167  if ( ( rc = get_value ( &setting, &opts, &argv[ optind + 1 ],
168  &value ) ) != 0 )
169  goto err_get_value;
170 
171  /* Apply default type if necessary */
172  if ( ! setting.setting.type )
173  setting.setting.type = &setting_type_string;
174 
175  /* Store setting */
176  if ( ( rc = storef_setting ( setting.settings, &setting.setting,
177  value ) ) != 0 ) {
178  printf ( "Could not store \"%s\": %s\n",
179  setting.setting.name, strerror ( rc ) );
180  goto err_store;
181  }
182 
183  err_store:
184  free ( value );
185  err_get_value:
186  err_parse_setting:
187  err_parse_options:
188  return rc;
189 }
"set", "clear", and "read" options
Definition: nvo_cmd.c:103
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
A parsed named setting.
Definition: parseopt.h:122
int optind
Current option index.
Definition: getopt.c:51
int parse_autovivified_setting(char *text, struct named_setting *setting)
Parse and autovivify setting name.
Definition: parseopt.c:336
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:484
const char * name
Name.
Definition: settings.h:28
const struct setting_type * type
Setting type.
Definition: settings.h:36
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
int storef_setting(struct settings *settings, const struct setting *setting, const char *value)
Store formatted value of setting.
Definition: settings.c:1319
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
static union @437 opts
"cert<xxx>" option list
A setting.
Definition: settings.h:23
struct golan_eqe_cmd cmd
Definition: CIB_PRM.h:29

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()

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

202  {
203 
204  *value = concat_args ( args );
205  if ( ! *value )
206  return -ENOMEM;
207 
208  return 0;
209 }
#define ENOMEM
Not enough space.
Definition: errno.h:534
char * concat_args(char **args)
Concatenate arguments.
Definition: exec.c:358
pseudo_bit_t value[0x00020]
Definition: arbel.h:13

References concat_args(), ENOMEM, and value.

Referenced by set_exec().

◆ set_exec()

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

"set" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 218 of file nvo_cmd.c.

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

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

◆ clear_value()

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

233  {
234 
235  *value = NULL;
236  return 0;
237 }
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References NULL, and value.

Referenced by clear_exec().

◆ clear_exec()

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

"clear" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 246 of file nvo_cmd.c.

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

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

◆ read_value()

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

261  {
262  char *existing;
263  int rc;
264 
265  /* Read existing value, treating errors as equivalent to an
266  * empty initial setting.
267  */
268  fetchf_setting_copy ( setting->settings, &setting->setting,
269  NULL, &setting->setting, &existing );
270 
271  /* Read new value */
272  if ( ( rc = readline_history ( NULL, existing, NULL, opts->timeout,
273  value ) ) != 0 )
274  goto err_readline;
275 
276  err_readline:
277  free ( existing );
278  return rc;
279 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
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:1276
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
A readline history buffer.
Definition: readline.h:31
static union @437 opts
"cert<xxx>" option list
A setting.
Definition: settings.h:23
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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

Referenced by read_exec().

◆ read_exec()

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

"read" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 288 of file nvo_cmd.c.

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

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

◆ inc_exec()

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

"inc" command

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 310 of file nvo_cmd.c.

310  {
311  struct inc_options opts;
312  struct named_setting setting;
313  unsigned int increment = 1;
314  unsigned long value;
315  int rc;
316 
317  /* Parse options */
318  if ( ( rc = parse_options ( argc, argv, &inc_cmd, &opts ) ) != 0 )
319  goto err_parse_options;
320 
321  /* Parse setting name */
322  if ( ( rc = parse_existing_setting ( argv[optind], &setting ) ) != 0 )
323  goto err_parse_setting;
324 
325  /* Parse increment (if present) */
326  if ( ( ( optind + 1 ) < argc ) &&
327  ( ( rc = parse_integer ( argv[ optind + 1 ], &increment ) ) != 0))
328  goto err_parse_increment;
329 
330  /* Read existing value, treating errors as equivalent to a
331  * zero-valued :int32 initial setting.
332  */
333  if ( ( rc = fetchn_setting ( setting.settings, &setting.setting,
334  NULL, &setting.setting, &value ) ) != 0 ) {
335  value = 0;
336  if ( ! setting.setting.type )
337  setting.setting.type = &setting_type_int32;
338  }
339 
340  /* Increment value */
341  value += increment;
342 
343  /* Store updated setting value */
344  if ( ( rc = storen_setting ( setting.settings, &setting.setting,
345  value ) ) != 0 ) {
346  printf ( "Could not store \"%s\": %s\n",
347  setting.setting.name, strerror ( rc ) );
348  goto err_store;
349  }
350 
351  err_store:
352  err_parse_increment:
353  err_parse_setting:
354  err_parse_options:
355  return rc;
356 }
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:91
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
A parsed named setting.
Definition: parseopt.h:122
int optind
Current option index.
Definition: getopt.c:51
int storen_setting(struct settings *settings, const struct setting *setting, unsigned long value)
Store numeric value of setting.
Definition: settings.c:1414
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:484
const char * name
Name.
Definition: settings.h:28
"inc" options
Definition: nvo_cmd.c:293
const struct setting_type * type
Setting type.
Definition: settings.h:36
int parse_existing_setting(char *text, struct named_setting *setting)
Parse existing setting name.
Definition: parseopt.c:322
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
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:1372
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static union @437 opts
"cert<xxx>" option list
A setting.
Definition: settings.h:23
static struct command_descriptor inc_cmd
"inc" command descriptor
Definition: nvo_cmd.c:299
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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.

Variable Documentation

◆ show_opts

struct option_descriptor show_opts[] = {}
static

"show" option list

Definition at line 48 of file nvo_cmd.c.

◆ 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:48
"show" options
Definition: nvo_cmd.c:45
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:108

"show" command descriptor

Definition at line 51 of file nvo_cmd.c.

Referenced by show_exec().

◆ set

static fd_set * set
Initial value:
{
*set &= ~( 1 << fd )
struct option_descriptor set[0]
Definition: nvo_cmd.c:111

Definition at line 111 of file nvo_cmd.c.

Referenced by ath5k_hw_rfb_op(), ath9k_hw_set_operating_mode(), ath9k_hw_setrxabort(), ath9k_reg_rmw(), igbvf_vfta_set_vf(), net80211_set_state(), and tg3_phy_auxctl_write().

◆ clear

struct option_descriptor clear[0]

Definition at line 113 of file nvo_cmd.c.

Referenced by b44_wait_bit(), and net80211_set_state().

◆ read

struct option_descriptor read[1]

◆ set_core_opts

union { ... } set_core_opts
Initial value:
= {
.read = {
OPTION_DESC ( "timeout", 't', required_argument,
},
}
"set", "clear", and "read" options
Definition: nvo_cmd.c:103
int parse_timeout(char *text, unsigned long *value)
Parse timeout value (in ms)
Definition: parseopt.c:114
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:67
Option requires an argument.
Definition: getopt.h:18
void timeout(int)

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

◆ set_cmd

struct command_descriptor set_cmd
static
Initial value:
=
1, MAX_ARGUMENTS, "<setting> <value>" )
"set", "clear", and "read" options
Definition: nvo_cmd.c:103
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition: parseopt.h:97
static union @439 set_core_opts
"set", "clear", and "read" option list
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:108

"set" command descriptor

Definition at line 124 of file nvo_cmd.c.

Referenced by set_exec().

◆ clear_cmd

struct command_descriptor clear_cmd
static
Initial value:
=
1, 1, "<setting>" )
"set", "clear", and "read" options
Definition: nvo_cmd.c:103
static union @439 set_core_opts
"set", "clear", and "read" option list
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:108

"clear" command descriptor

Definition at line 129 of file nvo_cmd.c.

Referenced by clear_exec().

◆ read_cmd

struct command_descriptor read_cmd
static
Initial value:
=
1, 1, "<setting>" )
"set", "clear", and "read" options
Definition: nvo_cmd.c:103
static union @439 set_core_opts
"set", "clear", and "read" option list
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:108

"read" command descriptor

Definition at line 134 of file nvo_cmd.c.

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

◆ inc_opts

struct option_descriptor inc_opts[] = {}
static

"inc" option list

Definition at line 296 of file nvo_cmd.c.

◆ 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:296
"inc" options
Definition: nvo_cmd.c:293
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:108

"inc" command descriptor

Definition at line 299 of file nvo_cmd.c.

Referenced by inc_exec().

◆ __command

struct command nvo_commands [] __command
Initial value:
= {
{
.name = "show",
.exec = show_exec,
},
{
.name = "set",
.exec = set_exec,
},
{
.name = "clear",
.exec = clear_exec,
},
{
.name = "read",
.exec = read_exec,
},
{
.name = "inc",
.exec = inc_exec,
},
}
static int inc_exec(int argc, char **argv)
"inc" command
Definition: nvo_cmd.c:310
static int clear_exec(int argc, char **argv)
"clear" command
Definition: nvo_cmd.c:246
static int show_exec(int argc, char **argv)
"show" command
Definition: nvo_cmd.c:61
static int set_exec(int argc, char **argv)
"set" command
Definition: nvo_cmd.c:218
static int read_exec(int argc, char **argv)
"read" command
Definition: nvo_cmd.c:288

Non-volatile option commands.

Definition at line 359 of file nvo_cmd.c.