env_flags.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * (C) Copyright 2012
  3. * Joe Hershberger, National Instruments, joe.hershberger@ni.com
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #ifndef __ENV_FLAGS_H__
  8. #define __ENV_FLAGS_H__
  9. enum env_flags_vartype {
  10. env_flags_vartype_string,
  11. env_flags_vartype_decimal,
  12. env_flags_vartype_hex,
  13. env_flags_vartype_bool,
  14. #ifdef CONFIG_CMD_NET
  15. env_flags_vartype_ipaddr,
  16. env_flags_vartype_macaddr,
  17. #endif
  18. env_flags_vartype_end
  19. };
  20. enum env_flags_varaccess {
  21. env_flags_varaccess_any,
  22. env_flags_varaccess_readonly,
  23. env_flags_varaccess_writeonce,
  24. env_flags_varaccess_changedefault,
  25. env_flags_varaccess_end
  26. };
  27. #define ENV_FLAGS_VAR ".flags"
  28. #define ENV_FLAGS_ATTR_MAX_LEN 2
  29. #define ENV_FLAGS_VARTYPE_LOC 0
  30. #define ENV_FLAGS_VARACCESS_LOC 1
  31. #ifndef CONFIG_ENV_FLAGS_LIST_STATIC
  32. #define CONFIG_ENV_FLAGS_LIST_STATIC ""
  33. #endif
  34. #ifdef CONFIG_CMD_NET
  35. #ifdef CONFIG_ENV_OVERWRITE
  36. #define ETHADDR_FLAGS "ethaddr:ma,"
  37. #else
  38. #ifdef CONFIG_OVERWRITE_ETHADDR_ONCE
  39. #define ETHADDR_FLAGS "ethaddr:mc,"
  40. #else
  41. #define ETHADDR_FLAGS "ethaddr:mo,"
  42. #endif
  43. #endif
  44. #else
  45. #define ETHADDR_FLAGS ""
  46. #endif
  47. #ifndef CONFIG_ENV_OVERWRITE
  48. #define SERIAL_FLAGS "serial#:so,"
  49. #else
  50. #define SERIAL_FLAGS ""
  51. #endif
  52. #define ENV_FLAGS_LIST_STATIC \
  53. ETHADDR_FLAGS \
  54. SERIAL_FLAGS \
  55. CONFIG_ENV_FLAGS_LIST_STATIC
  56. #ifdef CONFIG_CMD_ENV_FLAGS
  57. /*
  58. * Print the whole list of available type flags.
  59. */
  60. void env_flags_print_vartypes(void);
  61. /*
  62. * Print the whole list of available access flags.
  63. */
  64. void env_flags_print_varaccess(void);
  65. /*
  66. * Return the name of the type.
  67. */
  68. const char *env_flags_get_vartype_name(enum env_flags_vartype type);
  69. /*
  70. * Return the name of the access.
  71. */
  72. const char *env_flags_get_varaccess_name(enum env_flags_varaccess access);
  73. #endif
  74. /*
  75. * Parse the flags string from a .flags attribute list into the vartype enum.
  76. */
  77. enum env_flags_vartype env_flags_parse_vartype(const char *flags);
  78. /*
  79. * Parse the flags string from a .flags attribute list into the varaccess enum.
  80. */
  81. enum env_flags_varaccess env_flags_parse_varaccess(const char *flags);
  82. /*
  83. * Parse the binary flags from a hash table entry into the varaccess enum.
  84. */
  85. enum env_flags_varaccess env_flags_parse_varaccess_from_binflags(int binflags);
  86. #ifdef USE_HOSTCC
  87. /*
  88. * Look up the type of a variable directly from the .flags var.
  89. */
  90. enum env_flags_vartype env_flags_get_type(const char *name);
  91. /*
  92. * Look up the access of a variable directly from the .flags var.
  93. */
  94. enum env_flags_varaccess env_flags_get_access(const char *name);
  95. /*
  96. * Validate the newval for its type to conform with the requirements defined by
  97. * its flags (directly looked at the .flags var).
  98. */
  99. int env_flags_validate_type(const char *name, const char *newval);
  100. /*
  101. * Validate the newval for its access to conform with the requirements defined
  102. * by its flags (directly looked at the .flags var).
  103. */
  104. int env_flags_validate_access(const char *name, int check_mask);
  105. /*
  106. * Validate that the proposed access to variable "name" is valid according to
  107. * the defined flags for that variable, if any.
  108. */
  109. int env_flags_validate_varaccess(const char *name, int check_mask);
  110. /*
  111. * Validate the parameters passed to "env set" for type compliance
  112. */
  113. int env_flags_validate_env_set_params(int argc, char * const argv[]);
  114. #else /* !USE_HOSTCC */
  115. #include <search.h>
  116. /*
  117. * When adding a variable to the environment, initialize the flags for that
  118. * variable.
  119. */
  120. void env_flags_init(ENTRY *var_entry);
  121. /*
  122. * Validate the newval for to conform with the requirements defined by its flags
  123. */
  124. int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
  125. int flag);
  126. #endif /* USE_HOSTCC */
  127. /*
  128. * These are the binary flags used in the environment entry->flags variable to
  129. * decribe properties of veriables in the table
  130. */
  131. #define ENV_FLAGS_VARTYPE_BIN_MASK 0x00000007
  132. /* The actual variable type values use the enum value (within the mask) */
  133. #define ENV_FLAGS_VARACCESS_PREVENT_DELETE 0x00000008
  134. #define ENV_FLAGS_VARACCESS_PREVENT_CREATE 0x00000010
  135. #define ENV_FLAGS_VARACCESS_PREVENT_OVERWR 0x00000020
  136. #define ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR 0x00000040
  137. #define ENV_FLAGS_VARACCESS_BIN_MASK 0x00000078
  138. #endif /* __ENV_FLAGS_H__ */