nvo_cmd.c 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include <stdint.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <errno.h>
  5. #include <vsprintf.h>
  6. #include <getopt.h>
  7. #include <gpxe/nvo.h>
  8. #include <gpxe/dhcp.h>
  9. #include <gpxe/settings.h>
  10. #include <gpxe/command.h>
  11. void nvo_cmd_req() {}
  12. extern struct nvo_block *ugly_nvo_hack;
  13. static int show_exec ( int argc, char **argv ) {
  14. struct config_context dummy_context;
  15. char buf[256];
  16. int rc;
  17. if ( ! ugly_nvo_hack ) {
  18. printf ( "No non-volatile option storage available\n" );
  19. return 1;
  20. }
  21. if ( argc != 2 ) {
  22. printf ( "Syntax: %s <identifier>\n", argv[0] );
  23. return 1;
  24. }
  25. dummy_context.options = ugly_nvo_hack->options;
  26. if ( ( rc = show_setting ( &dummy_context, argv[1], buf,
  27. sizeof ( buf ) ) ) != 0 ) {
  28. printf ( "Could not find \"%s\": %s\n",
  29. argv[1], strerror ( -rc ) );
  30. return 1;
  31. }
  32. printf ( "%s = %s\n", argv[1], buf );
  33. return 0;
  34. }
  35. struct command show_command __command = {
  36. .name = "show",
  37. .exec = show_exec,
  38. };
  39. static int set_exec ( int argc, char **argv ) {
  40. struct config_context dummy_context;
  41. int rc;
  42. if ( ! ugly_nvo_hack ) {
  43. printf ( "No non-volatile option storage available\n" );
  44. return 1;
  45. }
  46. if ( argc != 3 ) {
  47. printf ( "Syntax: %s <identifier> <value>\n",
  48. argv[0] );
  49. return 1;
  50. }
  51. dummy_context.options = ugly_nvo_hack->options;
  52. if ( ( rc = set_setting ( &dummy_context, argv[1], argv[2] ) ) != 0 ) {
  53. printf ( "Could not set \"%s\"=\"%s\": %s\n",
  54. argv[1], argv[2], strerror ( -rc ) );
  55. return 1;
  56. }
  57. if ( nvo_save ( ugly_nvo_hack ) != 0 ) {
  58. printf ( "Could not save options to non-volatile storage\n" );
  59. return 1;
  60. }
  61. return 0;
  62. }
  63. struct command set_command __command = {
  64. .name = "set",
  65. .exec = set_exec,
  66. };