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