env_flags.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * (C) Copyright 2012
  3. * Joe Hershberger, National Instruments, joe.hershberger@ni.com
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #ifndef __ENV_FLAGS_H__
  24. #define __ENV_FLAGS_H__
  25. enum env_flags_vartype {
  26. env_flags_vartype_string,
  27. env_flags_vartype_decimal,
  28. env_flags_vartype_hex,
  29. env_flags_vartype_bool,
  30. #ifdef CONFIG_CMD_NET
  31. env_flags_vartype_ipaddr,
  32. env_flags_vartype_macaddr,
  33. #endif
  34. env_flags_vartype_end
  35. };
  36. enum env_flags_varaccess {
  37. env_flags_varaccess_any,
  38. env_flags_varaccess_readonly,
  39. env_flags_varaccess_writeonce,
  40. env_flags_varaccess_changedefault,
  41. env_flags_varaccess_end
  42. };
  43. #define ENV_FLAGS_VAR ".flags"
  44. #define ENV_FLAGS_ATTR_MAX_LEN 2
  45. #define ENV_FLAGS_VARTYPE_LOC 0
  46. #define ENV_FLAGS_VARACCESS_LOC 1
  47. #ifndef CONFIG_ENV_FLAGS_LIST_STATIC
  48. #define CONFIG_ENV_FLAGS_LIST_STATIC ""
  49. #endif
  50. #ifdef CONFIG_CMD_NET
  51. #ifdef CONFIG_ENV_OVERWRITE
  52. #define ETHADDR_FLAGS "ethaddr:ma,"
  53. #else
  54. #ifdef CONFIG_OVERWRITE_ETHADDR_ONCE
  55. #define ETHADDR_FLAGS "ethaddr:mc,"
  56. #else
  57. #define ETHADDR_FLAGS "ethaddr:mo,"
  58. #endif
  59. #endif
  60. #else
  61. #define ETHADDR_FLAGS ""
  62. #endif
  63. #ifndef CONFIG_ENV_OVERWRITE
  64. #define SERIAL_FLAGS "serial#:so,"
  65. #else
  66. #define SERIAL_FLAGS ""
  67. #endif
  68. #define ENV_FLAGS_LIST_STATIC \
  69. ETHADDR_FLAGS \
  70. SERIAL_FLAGS \
  71. CONFIG_ENV_FLAGS_LIST_STATIC
  72. #ifdef CONFIG_CMD_ENV_FLAGS
  73. /*
  74. * Print the whole list of available type flags.
  75. */
  76. void env_flags_print_vartypes(void);
  77. /*
  78. * Print the whole list of available access flags.
  79. */
  80. void env_flags_print_varaccess(void);
  81. /*
  82. * Return the name of the type.
  83. */
  84. const char *env_flags_get_vartype_name(enum env_flags_vartype type);
  85. /*
  86. * Return the name of the access.
  87. */
  88. const char *env_flags_get_varaccess_name(enum env_flags_varaccess access);
  89. #endif
  90. /*
  91. * Parse the flags string from a .flags attribute list into the vartype enum.
  92. */
  93. enum env_flags_vartype env_flags_parse_vartype(const char *flags);
  94. /*
  95. * Parse the flags string from a .flags attribute list into the varaccess enum.
  96. */
  97. enum env_flags_varaccess env_flags_parse_varaccess(const char *flags);
  98. /*
  99. * Parse the binary flags from a hash table entry into the varaccess enum.
  100. */
  101. enum env_flags_varaccess env_flags_parse_varaccess_from_binflags(int binflags);
  102. #ifdef USE_HOSTCC
  103. /*
  104. * Look up the type of a variable directly from the .flags var.
  105. */
  106. enum env_flags_vartype env_flags_get_type(const char *name);
  107. /*
  108. * Look up the access of a variable directly from the .flags var.
  109. */
  110. enum env_flags_varaccess env_flags_get_access(const char *name);
  111. /*
  112. * Validate the newval for its type to conform with the requirements defined by
  113. * its flags (directly looked at the .flags var).
  114. */
  115. int env_flags_validate_type(const char *name, const char *newval);
  116. /*
  117. * Validate the newval for its access to conform with the requirements defined
  118. * by its flags (directly looked at the .flags var).
  119. */
  120. int env_flags_validate_access(const char *name, int check_mask);
  121. /*
  122. * Validate that the proposed access to variable "name" is valid according to
  123. * the defined flags for that variable, if any.
  124. */
  125. int env_flags_validate_varaccess(const char *name, int check_mask);
  126. /*
  127. * Validate the parameters passed to "env set" for type compliance
  128. */
  129. int env_flags_validate_env_set_params(int argc, char * const argv[]);
  130. #else /* !USE_HOSTCC */
  131. #include <search.h>
  132. /*
  133. * When adding a variable to the environment, initialize the flags for that
  134. * variable.
  135. */
  136. void env_flags_init(ENTRY *var_entry);
  137. /*
  138. * Validate the newval for to conform with the requirements defined by its flags
  139. */
  140. int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
  141. int flag);
  142. #endif /* USE_HOSTCC */
  143. /*
  144. * These are the binary flags used in the environment entry->flags variable to
  145. * decribe properties of veriables in the table
  146. */
  147. #define ENV_FLAGS_VARTYPE_BIN_MASK 0x00000007
  148. /* The actual variable type values use the enum value (within the mask) */
  149. #define ENV_FLAGS_VARACCESS_PREVENT_DELETE 0x00000008
  150. #define ENV_FLAGS_VARACCESS_PREVENT_CREATE 0x00000010
  151. #define ENV_FLAGS_VARACCESS_PREVENT_OVERWR 0x00000020
  152. #define ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR 0x00000040
  153. #define ENV_FLAGS_VARACCESS_BIN_MASK 0x00000078
  154. #endif /* __ENV_FLAGS_H__ */