env_flags.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #define ENV_FLAGS_LIST_STATIC \
  51. CONFIG_ENV_FLAGS_LIST_STATIC
  52. #ifdef CONFIG_CMD_ENV_FLAGS
  53. /*
  54. * Print the whole list of available type flags.
  55. */
  56. void env_flags_print_vartypes(void);
  57. /*
  58. * Print the whole list of available access flags.
  59. */
  60. void env_flags_print_varaccess(void);
  61. /*
  62. * Return the name of the type.
  63. */
  64. const char *env_flags_get_vartype_name(enum env_flags_vartype type);
  65. /*
  66. * Return the name of the access.
  67. */
  68. const char *env_flags_get_varaccess_name(enum env_flags_varaccess access);
  69. #endif
  70. /*
  71. * Parse the flags string from a .flags attribute list into the vartype enum.
  72. */
  73. enum env_flags_vartype env_flags_parse_vartype(const char *flags);
  74. /*
  75. * Parse the flags string from a .flags attribute list into the varaccess enum.
  76. */
  77. enum env_flags_varaccess env_flags_parse_varaccess(const char *flags);
  78. /*
  79. * Parse the binary flags from a hash table entry into the varaccess enum.
  80. */
  81. enum env_flags_varaccess env_flags_parse_varaccess_from_binflags(int binflags);
  82. #ifdef USE_HOSTCC
  83. /*
  84. * Look up the type of a variable directly from the .flags var.
  85. */
  86. enum env_flags_vartype env_flags_get_type(const char *name);
  87. /*
  88. * Look up the access of a variable directly from the .flags var.
  89. */
  90. enum env_flags_varaccess env_flags_get_access(const char *name);
  91. /*
  92. * Validate the newval for its type to conform with the requirements defined by
  93. * its flags (directly looked at the .flags var).
  94. */
  95. int env_flags_validate_type(const char *name, const char *newval);
  96. /*
  97. * Validate the newval for its access to conform with the requirements defined
  98. * by its flags (directly looked at the .flags var).
  99. */
  100. int env_flags_validate_access(const char *name, int check_mask);
  101. /*
  102. * Validate that the proposed access to variable "name" is valid according to
  103. * the defined flags for that variable, if any.
  104. */
  105. int env_flags_validate_varaccess(const char *name, int check_mask);
  106. /*
  107. * Validate the parameters passed to "env set" for type compliance
  108. */
  109. int env_flags_validate_env_set_params(int argc, char * const argv[]);
  110. #else /* !USE_HOSTCC */
  111. #include <search.h>
  112. /*
  113. * When adding a variable to the environment, initialize the flags for that
  114. * variable.
  115. */
  116. void env_flags_init(ENTRY *var_entry);
  117. /*
  118. * Validate the newval for to conform with the requirements defined by its flags
  119. */
  120. int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
  121. int flag);
  122. #endif /* USE_HOSTCC */
  123. /*
  124. * These are the binary flags used in the environment entry->flags variable to
  125. * decribe properties of veriables in the table
  126. */
  127. #define ENV_FLAGS_VARTYPE_BIN_MASK 0x00000007
  128. /* The actual variable type values use the enum value (within the mask) */
  129. #define ENV_FLAGS_VARACCESS_PREVENT_DELETE 0x00000008
  130. #define ENV_FLAGS_VARACCESS_PREVENT_CREATE 0x00000010
  131. #define ENV_FLAGS_VARACCESS_PREVENT_OVERWR 0x00000020
  132. #define ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR 0x00000040
  133. #define ENV_FLAGS_VARACCESS_BIN_MASK 0x00000078
  134. #endif /* __ENV_FLAGS_H__ */