fconfig-listmode.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. diff -x.svn -u fconfig/crunchfc.c ../../../snapgear_avila/user/fconfig/crunchfc.c
  2. --- fconfig/crunchfc.c 2006-03-15 01:18:17.000000000 +1100
  3. +++ ../../../snapgear_avila/user/fconfig/crunchfc.c 2007-09-06 13:48:38.000000000 +1000
  4. @@ -320,6 +320,48 @@
  5. }
  6. /*
  7. + * List known keys.
  8. + */
  9. +int8_t list_keys(struct config_data *data)
  10. +{
  11. + struct fconfig_key key;
  12. + uint32_t len = data->reallen;
  13. + uint8_t *keyptr = NULL;
  14. + uint8_t *ptr = data->buf+8;
  15. + uint8_t *ptrend = data->buf+len-9;
  16. + printer_t printer;
  17. +
  18. + while (ptr < ptrend-4) {
  19. + keyptr = ptr;
  20. + ptr = get_key(ptr, &key);
  21. + if (ptr == NULL) {
  22. + MESSAGE(VERB_LOW, "Error in structure\n");
  23. + return -1;
  24. + }
  25. + if (ptr > ptrend) {
  26. + MESSAGE(VERB_LOW, "Parser went out of struct!\n");
  27. + return -1;
  28. + }
  29. +
  30. + if ((key.type == 0) && (key.namelen==0)) {
  31. + MESSAGE(VERB_NORMAL, "EOF reached - key not found\n");
  32. + return -1;
  33. + }
  34. +
  35. + print_key(&key, VERB_HIGH, data->swab);
  36. +
  37. + printf("%s: ", key.keyname);
  38. + printer = TYPE_PRINTER(key.type);
  39. + if (printer == NULL) {
  40. + MESSAGE(VERB_LOW, "Printer missing for type %d\n", key.type);
  41. + return -1;
  42. + }
  43. + printer(key.dataval);
  44. + printf("\n");
  45. + }
  46. +}
  47. +
  48. +/*
  49. * Find a key with given nickname, check its type and set value
  50. * Assumes that verify_fconfig() has been called on 'data' before.
  51. */
  52. diff -x.svn -u fconfig/crunchfc.h ../../../snapgear_avila/user/fconfig/crunchfc.h
  53. --- fconfig/crunchfc.h 2006-03-15 01:18:17.000000000 +1100
  54. +++ ../../../snapgear_avila/user/fconfig/crunchfc.h 2007-09-06 13:48:38.000000000 +1000
  55. @@ -31,6 +31,7 @@
  56. int8_t verify_fconfig(struct config_data *data);
  57. int8_t get_key_value(struct config_data *data, uint8_t *nickname);
  58. int8_t set_key_value(struct config_data *data, uint8_t *nickname, void *value);
  59. +int8_t list_keys(struct config_data *data);
  60. void recalculate_crc(struct config_data *data);
  61. #endif //CRUNCHFC_H
  62. diff -x.svn -u fconfig/fconfig.c ../../../snapgear_avila/user/fconfig/fconfig.c
  63. --- fconfig/fconfig.c 2006-03-15 01:18:18.000000000 +1100
  64. +++ ../../../snapgear_avila/user/fconfig/fconfig.c 2007-09-06 13:48:38.000000000 +1000
  65. @@ -35,8 +35,9 @@
  66. #include <string.h>
  67. #include <unistd.h>
  68. #include <fcntl.h>
  69. +#include <getopt.h>
  70. #include "debug.h"
  71. #include "ftypes.h"
  72. #include "crunchfc.h"
  73. @@ -72,7 +73,7 @@
  74. }
  75. fputs("Read or write Redboot configuration\n", stdout);
  76. - fputs("usage: fconfig [-r|-w] -d dev -n nickname -x value\n", stdout);
  77. + fputs("usage: fconfig [-r|-w|-l] -d dev -n nickname -x value\n", stdout);
  78. fputs("'dev' may be a char device, block device or a file\n", stdout);
  79. fputs("Supported types: \n", stdout);
  80. for (i = 0; i < NUM_TYPES; i++) {
  81. @@ -181,7 +182,33 @@
  82. close_fconfig_handle(data);
  83. return 0;
  84. -exit_fail:
  85. +exit_fail:
  86. + close_fconfig_handle(data);
  87. + return 1;
  88. +}
  89. +
  90. +/*
  91. + * List mode of operation: list parameter values from the configuration.
  92. + */
  93. +static int list_mode(struct config_data *data, uint8_t *device)
  94. +{
  95. + if (get_fconfig_handle(data, device, O_RDONLY) == NULL) {
  96. + MESSAGE(VERB_LOW, "Could not get a config data handle!\n");
  97. + return 1;
  98. + }
  99. + if (verify_fconfig(data)) {
  100. + MESSAGE(VERB_LOW, "Config verification failed!\n");
  101. + goto exit_fail;
  102. + }
  103. +
  104. + if (list_keys(data)) {
  105. + goto exit_fail;
  106. + }
  107. +
  108. + close_fconfig_handle(data);
  109. + return 0;
  110. +
  111. +exit_fail:
  112. close_fconfig_handle(data);
  113. return 1;
  114. }
  115. @@ -189,6 +216,7 @@
  116. #define MODE_NONE 0
  117. #define MODE_WRITE 1
  118. #define MODE_READ 2
  119. +#define MODE_LIST 3
  120. /*
  121. * main(). ...nuff said.
  122. @@ -202,14 +230,17 @@
  123. uint8_t *value = NULL;
  124. uint8_t *device = NULL;
  125. - while ((c = getopt(argc, argv, "hrwvsd:n:x:")) != -1) {
  126. + while ((c = getopt(argc, argv, "hrwlvsd:n:x:")) != -1) {
  127. switch (c) {
  128. case 'r':
  129. mode = MODE_READ;
  130. break;
  131. - case 'w':
  132. + case 'w':
  133. mode = MODE_WRITE;
  134. break;
  135. + case 'l':
  136. + mode = MODE_LIST;
  137. + break;
  138. case 'n':
  139. nickname = optarg;
  140. break;
  141. @@ -240,7 +271,7 @@
  142. MESSAGE(VERB_NORMAL, "Normal verbosity messages are printed.\n");
  143. MESSAGE(VERB_HIGH, "High verbosity messages are printed.\n");
  144. - if (nickname == NULL) {
  145. + if (nickname == NULL && mode != MODE_LIST) {
  146. usage();
  147. exit(1);
  148. }
  149. @@ -251,13 +282,16 @@
  150. }
  151. switch (mode) {
  152. - case MODE_WRITE :
  153. + case MODE_WRITE :
  154. ret = write_mode(&data, device, nickname, value);
  155. break;
  156. - case MODE_READ :
  157. + case MODE_READ :
  158. ret = read_mode(&data, device, nickname);
  159. break;
  160. - default :
  161. + case MODE_LIST :
  162. + ret = list_mode(&data, device);
  163. + break;
  164. + default :
  165. MESSAGE(VERB_LOW, "Unknown mode of operation\n");
  166. usage();
  167. ret = 1;