nvo_cmd.c 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. extern struct nvo_block *ugly_nvo_hack;
  12. static int show_exec ( int argc, char **argv ) {
  13. struct config_context dummy_context;
  14. char buf[256];
  15. int rc;
  16. if ( ! ugly_nvo_hack ) {
  17. printf ( "No non-volatile option storage available\n" );
  18. return 1;
  19. }
  20. if ( argc != 2 ) {
  21. printf ( "Syntax: %s <identifier>\n", argv[0] );
  22. return 1;
  23. }
  24. dummy_context.options = ugly_nvo_hack->options;
  25. if ( ( rc = show_setting ( &dummy_context, argv[1], buf,
  26. sizeof ( buf ) ) ) != 0 ) {
  27. printf ( "Could not find \"%s\": %s\n",
  28. argv[1], strerror ( -rc ) );
  29. return 1;
  30. }
  31. printf ( "%s = %s\n", argv[1], buf );
  32. return 0;
  33. }
  34. struct command show_command __command = {
  35. .name = "show",
  36. .exec = show_exec,
  37. };
  38. static int set_exec ( int argc, char **argv ) {
  39. struct config_context dummy_context;
  40. int rc;
  41. if ( ! ugly_nvo_hack ) {
  42. printf ( "No non-volatile option storage available\n" );
  43. return 1;
  44. }
  45. if ( argc != 3 ) {
  46. printf ( "Syntax: %s <identifier> <value>\n",
  47. argv[0] );
  48. return 1;
  49. }
  50. dummy_context.options = ugly_nvo_hack->options;
  51. if ( ( rc = set_setting ( &dummy_context, argv[1], argv[2] ) ) != 0 ) {
  52. printf ( "Could not set \"%s\"=\"%s\": %s\n",
  53. argv[1], argv[2], strerror ( -rc ) );
  54. return 1;
  55. }
  56. if ( nvo_save ( ugly_nvo_hack ) != 0 ) {
  57. printf ( "Could not save options to non-volatile storage\n" );
  58. return 1;
  59. }
  60. return 0;
  61. }
  62. struct command set_command __command = {
  63. .name = "set",
  64. .exec = set_exec,
  65. };
  66. static int clear_exec ( int argc, char **argv ) {
  67. struct config_context dummy_context;
  68. int rc;
  69. if ( ! ugly_nvo_hack ) {
  70. printf ( "No non-volatile option storage available\n" );
  71. return 1;
  72. }
  73. if ( argc != 2 ) {
  74. printf ( "Syntax: %s <identifier>\n",
  75. argv[0] );
  76. return 1;
  77. }
  78. dummy_context.options = ugly_nvo_hack->options;
  79. if ( ( rc = clear_setting ( &dummy_context, argv[1] ) ) != 0 ) {
  80. printf ( "Could not clear \"%s\": %s\n",
  81. argv[1], strerror ( -rc ) );
  82. return 1;
  83. }
  84. return 0;
  85. }
  86. struct command clear_command __command = {
  87. .name = "clear",
  88. .exec = clear_exec,
  89. };