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, char **args, char **value))
 "set", "clear", and "read" command More...
 
static int set_value (struct named_setting *setting __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, 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, 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...
 
static struct option_descriptor 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_read_cmd
 "clear" and "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:121
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:1280
static union @424 opts
"cert<xxx>" option list
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:447
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:285
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
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:1610

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

130  {
131  struct set_core_options opts;
132  struct named_setting setting;
133  char *value;
134  int rc;
135 
136  /* Parse options */
137  if ( ( rc = parse_options ( argc, argv, cmd, &opts ) ) != 0 )
138  goto err_parse_options;
139 
140  /* Parse setting name */
141  if ( ( rc = parse_autovivified_setting ( argv[optind],
142  &setting ) ) != 0 )
143  goto err_parse_setting;
144 
145  /* Parse setting value */
146  if ( ( rc = get_value ( &setting, &argv[ optind + 1 ], &value ) ) != 0 )
147  goto err_get_value;
148 
149  /* Apply default type if necessary */
150  if ( ! setting.setting.type )
151  setting.setting.type = &setting_type_string;
152 
153  /* Store setting */
154  if ( ( rc = storef_setting ( setting.settings, &setting.setting,
155  value ) ) != 0 ) {
156  printf ( "Could not store \"%s\": %s\n",
157  setting.setting.name, strerror ( rc ) );
158  goto err_store;
159  }
160 
161  err_store:
162  free ( value );
163  err_get_value:
164  err_parse_setting:
165  err_parse_options:
166  return rc;
167 }
"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:121
int optind
Current option index.
Definition: getopt.c:51
static union @424 opts
"cert<xxx>" option list
int parse_autovivified_setting(char *text, struct named_setting *setting)
Parse and autovivify setting name.
Definition: parseopt.c:299
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:447
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:1323
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
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,
char **  args,
char **  value 
)
static

Get setting value for "set" command.

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

Definition at line 177 of file nvo_cmd.c.

178  {
179 
180  *value = concat_args ( args );
181  if ( ! *value )
182  return -ENOMEM;
183 
184  return 0;
185 }
#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 194 of file nvo_cmd.c.

194  {
195  return set_core_exec ( argc, argv, &set_cmd, set_value );
196 }
static struct command_descriptor set_cmd
"set" command descriptor
Definition: nvo_cmd.c:109
static int set_value(struct named_setting *setting __unused, char **args, char **value)
Get setting value for "set" command.
Definition: nvo_cmd.c:177
static int set_core_exec(int argc, char **argv, struct command_descriptor *cmd, int(*get_value)(struct named_setting *setting, char **args, char **value))
"set", "clear", and "read" command
Definition: nvo_cmd.c:127

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

◆ clear_value()

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

Get setting value for "clear" command.

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

Definition at line 206 of file nvo_cmd.c.

207  {
208 
209  *value = NULL;
210  return 0;
211 }
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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

220  {
221  return set_core_exec ( argc, argv, &clear_read_cmd, clear_value );
222 }
static struct command_descriptor clear_read_cmd
"clear" and "read" command descriptor
Definition: nvo_cmd.c:114
static int clear_value(struct named_setting *setting __unused, char **args __unused, char **value)
Get setting value for "clear" command.
Definition: nvo_cmd.c:206
static int set_core_exec(int argc, char **argv, struct command_descriptor *cmd, int(*get_value)(struct named_setting *setting, char **args, char **value))
"set", "clear", and "read" command
Definition: nvo_cmd.c:127

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

◆ read_value()

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

Get setting value for "read" command.

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

Definition at line 232 of file nvo_cmd.c.

233  {
234  char *existing;
235  int rc;
236 
237  /* Read existing value, treating errors as equivalent to an
238  * empty initial setting.
239  */
240  fetchf_setting_copy ( setting->settings, &setting->setting,
241  NULL, &setting->setting, &existing );
242 
243  /* Read new value */
244  if ( ( rc = readline_history ( NULL, existing, NULL, value ) ) != 0 )
245  goto err_readline;
246 
247  err_readline:
248  free ( existing );
249  return rc;
250 }
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:1280
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
A setting.
Definition: settings.h:23
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References fetchf_setting_copy(), free, NULL, 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 259 of file nvo_cmd.c.

259  {
260  return set_core_exec ( argc, argv, &clear_read_cmd, read_value );
261 }
static struct command_descriptor clear_read_cmd
"clear" and "read" command descriptor
Definition: nvo_cmd.c:114
static int read_value(struct named_setting *setting, char **args __unused, char **value)
Get setting value for "read" command.
Definition: nvo_cmd.c:232
static int set_core_exec(int argc, char **argv, struct command_descriptor *cmd, int(*get_value)(struct named_setting *setting, char **args, char **value))
"set", "clear", and "read" command
Definition: nvo_cmd.c:127

References clear_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 281 of file nvo_cmd.c.

281  {
282  struct inc_options opts;
283  struct named_setting setting;
284  unsigned int increment = 1;
285  unsigned long value;
286  int rc;
287 
288  /* Parse options */
289  if ( ( rc = parse_options ( argc, argv, &inc_cmd, &opts ) ) != 0 )
290  goto err_parse_options;
291 
292  /* Parse setting name */
293  if ( ( rc = parse_existing_setting ( argv[optind], &setting ) ) != 0 )
294  goto err_parse_setting;
295 
296  /* Parse increment (if present) */
297  if ( ( ( optind + 1 ) < argc ) &&
298  ( ( rc = parse_integer ( argv[ optind + 1 ], &increment ) ) != 0))
299  goto err_parse_increment;
300 
301  /* Read existing value, treating errors as equivalent to a
302  * zero-valued :int32 initial setting.
303  */
304  if ( ( rc = fetchn_setting ( setting.settings, &setting.setting,
305  NULL, &setting.setting, &value ) ) != 0 ) {
306  value = 0;
307  if ( ! setting.setting.type )
308  setting.setting.type = &setting_type_int32;
309  }
310 
311  /* Increment value */
312  value += increment;
313 
314  /* Store updated setting value */
315  if ( ( rc = storen_setting ( setting.settings, &setting.setting,
316  value ) ) != 0 ) {
317  printf ( "Could not store \"%s\": %s\n",
318  setting.setting.name, strerror ( rc ) );
319  goto err_store;
320  }
321 
322  err_store:
323  err_parse_increment:
324  err_parse_setting:
325  err_parse_options:
326  return rc;
327 }
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:88
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:121
int optind
Current option index.
Definition: getopt.c:51
static union @424 opts
"cert<xxx>" option list
int storen_setting(struct settings *settings, const struct setting *setting, unsigned long value)
Store numeric value of setting.
Definition: settings.c:1418
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:447
const char * name
Name.
Definition: settings.h:28
"inc" options
Definition: nvo_cmd.c:264
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:285
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:1376
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
A setting.
Definition: settings.h:23
static struct command_descriptor inc_cmd
"inc" command descriptor
Definition: nvo_cmd.c:270
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

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:107

"show" command descriptor

Definition at line 51 of file nvo_cmd.c.

Referenced by show_exec().

◆ set_core_opts

struct option_descriptor set_core_opts[] = {}
static

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

Definition at line 106 of file nvo_cmd.c.

◆ set_cmd

struct command_descriptor set_cmd
static
Initial value:
=
"<setting> <value>" )
"set", "clear", and "read" options
Definition: nvo_cmd.c:103
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition: parseopt.h:96
static struct option_descriptor set_core_opts[]
"set", "clear", and "read" option list
Definition: nvo_cmd.c:106
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:107

"set" command descriptor

Definition at line 109 of file nvo_cmd.c.

Referenced by set_exec().

◆ clear_read_cmd

struct command_descriptor clear_read_cmd
static
Initial value:
=
"<setting>" )
"set", "clear", and "read" options
Definition: nvo_cmd.c:103
static struct option_descriptor set_core_opts[]
"set", "clear", and "read" option list
Definition: nvo_cmd.c:106
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:107

"clear" and "read" command descriptor

Definition at line 114 of file nvo_cmd.c.

Referenced by clear_exec(), and read_exec().

◆ inc_opts

struct option_descriptor inc_opts[] = {}
static

"inc" option list

Definition at line 267 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:267
"inc" options
Definition: nvo_cmd.c:264
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:107

"inc" command descriptor

Definition at line 270 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:281
static int clear_exec(int argc, char **argv)
"clear" command
Definition: nvo_cmd.c:220
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:194
static int read_exec(int argc, char **argv)
"read" command
Definition: nvo_cmd.c:259

Non-volatile option commands.

Definition at line 330 of file nvo_cmd.c.