mirror of
https://github.com/ipxe/ipxe
synced 2025-12-23 13:30:57 +03:00
Move nvo_cmd.c to hci/commands.
This commit is contained in:
111
src/hci/commands/nvo_cmd.c
Normal file
111
src/hci/commands/nvo_cmd.c
Normal file
@@ -0,0 +1,111 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <vsprintf.h>
|
||||
#include <getopt.h>
|
||||
#include <gpxe/nvo.h>
|
||||
#include <gpxe/dhcp.h>
|
||||
#include <gpxe/settings.h>
|
||||
#include <gpxe/command.h>
|
||||
|
||||
void nvo_cmd_req() {}
|
||||
|
||||
extern struct nvo_block *ugly_nvo_hack;
|
||||
|
||||
static int show_exec ( int argc, char **argv ) {
|
||||
struct config_context dummy_context;
|
||||
char buf[256];
|
||||
int rc;
|
||||
|
||||
if ( ! ugly_nvo_hack ) {
|
||||
printf ( "No non-volatile option storage available\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( argc != 2 ) {
|
||||
printf ( "Syntax: %s <identifier>\n", argv[0] );
|
||||
return 1;
|
||||
}
|
||||
|
||||
dummy_context.options = ugly_nvo_hack->options;
|
||||
if ( ( rc = show_setting ( &dummy_context, argv[1], buf,
|
||||
sizeof ( buf ) ) ) != 0 ) {
|
||||
printf ( "Could not find \"%s\": %s\n",
|
||||
argv[1], strerror ( -rc ) );
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf ( "%s = %s\n", argv[1], buf );
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct command show_command __command = {
|
||||
.name = "show",
|
||||
.exec = show_exec,
|
||||
};
|
||||
|
||||
static int set_exec ( int argc, char **argv ) {
|
||||
struct config_context dummy_context;
|
||||
int rc;
|
||||
|
||||
if ( ! ugly_nvo_hack ) {
|
||||
printf ( "No non-volatile option storage available\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( argc != 3 ) {
|
||||
printf ( "Syntax: %s <identifier> <value>\n",
|
||||
argv[0] );
|
||||
return 1;
|
||||
}
|
||||
|
||||
dummy_context.options = ugly_nvo_hack->options;
|
||||
if ( ( rc = set_setting ( &dummy_context, argv[1], argv[2] ) ) != 0 ) {
|
||||
printf ( "Could not set \"%s\"=\"%s\": %s\n",
|
||||
argv[1], argv[2], strerror ( -rc ) );
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( nvo_save ( ugly_nvo_hack ) != 0 ) {
|
||||
printf ( "Could not save options to non-volatile storage\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct command set_command __command = {
|
||||
.name = "set",
|
||||
.exec = set_exec,
|
||||
};
|
||||
|
||||
static int clear_exec ( int argc, char **argv ) {
|
||||
struct config_context dummy_context;
|
||||
int rc;
|
||||
|
||||
if ( ! ugly_nvo_hack ) {
|
||||
printf ( "No non-volatile option storage available\n" );
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( argc != 2 ) {
|
||||
printf ( "Syntax: %s <identifier>\n",
|
||||
argv[0] );
|
||||
return 1;
|
||||
}
|
||||
|
||||
dummy_context.options = ugly_nvo_hack->options;
|
||||
if ( ( rc = clear_setting ( &dummy_context, argv[1] ) ) != 0 ) {
|
||||
printf ( "Could not clear \"%s\": %s\n",
|
||||
argv[1], strerror ( -rc ) );
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct command clear_command __command = {
|
||||
.name = "clear",
|
||||
.exec = clear_exec,
|
||||
};
|
||||
Reference in New Issue
Block a user