You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

nvo_cmd.c 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include <stdint.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <errno.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_named_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. static int set_exec ( int argc, char **argv ) {
  35. struct config_context dummy_context;
  36. int rc;
  37. if ( ! ugly_nvo_hack ) {
  38. printf ( "No non-volatile option storage available\n" );
  39. return 1;
  40. }
  41. if ( argc != 3 ) {
  42. printf ( "Syntax: %s <identifier> <value>\n",
  43. argv[0] );
  44. return 1;
  45. }
  46. dummy_context.options = ugly_nvo_hack->options;
  47. if ( ( rc = set_named_setting ( &dummy_context, argv[1],
  48. argv[2] ) ) != 0 ) {
  49. printf ( "Could not set \"%s\"=\"%s\": %s\n",
  50. argv[1], argv[2], strerror ( -rc ) );
  51. return 1;
  52. }
  53. if ( nvo_save ( ugly_nvo_hack ) != 0 ) {
  54. printf ( "Could not save options to non-volatile storage\n" );
  55. return 1;
  56. }
  57. return 0;
  58. }
  59. static int clear_exec ( int argc, char **argv ) {
  60. struct config_context dummy_context;
  61. int rc;
  62. if ( ! ugly_nvo_hack ) {
  63. printf ( "No non-volatile option storage available\n" );
  64. return 1;
  65. }
  66. if ( argc != 2 ) {
  67. printf ( "Syntax: %s <identifier>\n",
  68. argv[0] );
  69. return 1;
  70. }
  71. dummy_context.options = ugly_nvo_hack->options;
  72. if ( ( rc = clear_named_setting ( &dummy_context, argv[1] ) ) != 0 ) {
  73. printf ( "Could not clear \"%s\": %s\n",
  74. argv[1], strerror ( -rc ) );
  75. return 1;
  76. }
  77. return 0;
  78. }
  79. struct command nvo_commands[] __command = {
  80. {
  81. .name = "show",
  82. .exec = show_exec,
  83. },
  84. {
  85. .name = "set",
  86. .exec = set_exec,
  87. },
  88. {
  89. .name = "clear",
  90. .exec = clear_exec,
  91. },
  92. };