[U-Boot] [RFC PATCH v2 4/7] env: Introduce "transient" and "system" access flags

Bernhard Nortmann bernhard.nortmann at web.de
Fri Nov 25 11:48:16 CET 2016


Hi Simon,

Am 23.11.2016 um 00:08 schrieb Simon Glass:
> Hi Bernhard,
>
> [...]
> Well you could add a separate patch before this one which renames
> everything. I don't think anyone else is working in this area.
>
> Regards,
> Simon

Doing so, I have arrived at the (additional) commit attached below.
With that added to the series, do you think this has matured enough
to promote it from "RFC" to an actual PATCH when submitting v3?

Regards, B. Nortmann
-------------- next part --------------
From f0cae5d87bcf9366786367976a71b908ee9f2410 Mon Sep 17 00:00:00 2001
From: Bernhard Nortmann <bernhard.nortmann at web.de>
Date: Wed, 23 Nov 2016 10:50:16 +0100
Subject: [RFC PATCH v3 3/8] env: Rename env flag constants/enums to improve
 readability

Simon Glass suggested to cut down on the name length of these,
and to use an initializer syntax that makes it clearer which
values are associated with the various enums.

Signed-off-by: Bernhard Nortmann <bernhard.nortmann at web.de>
---

Changes in v3:
- Add new patch to rename env flag constants/enums

Changes in v2: None

 cmd/nvedit.c        |  2 +-
 common/env_flags.c  | 87 +++++++++++++++++++++++++++--------------------------
 include/env_flags.h | 36 +++++++++++-----------
 3 files changed, 63 insertions(+), 62 deletions(-)

diff --git a/cmd/nvedit.c b/cmd/nvedit.c
index 9ca5cb5..84acedb 100644
--- a/cmd/nvedit.c
+++ b/cmd/nvedit.c
@@ -527,7 +527,7 @@ static int print_active_flags(ENTRY *entry)
 		return 0;
 
 	type = (enum env_flags_vartype)
-		(entry->flags & ENV_FLAGS_VARTYPE_BIN_MASK);
+		(entry->flags & ENV_FLAGS_TYPE_MASK);
 	access = env_flags_parse_varaccess_from_binflags(entry->flags);
 	printf("\t%-20s %-20s %-20s\n", entry->key,
 		env_flags_get_vartype_name(type),
diff --git a/common/env_flags.c b/common/env_flags.c
index 1087f4e..18cb5cf 100644
--- a/common/env_flags.c
+++ b/common/env_flags.c
@@ -22,39 +22,40 @@
 #endif
 
 #ifdef CONFIG_CMD_NET
-#define ENV_FLAGS_NET_VARTYPE_REPS "im"
+#define ENV_FLAGS_NET_VARTYPES "im"
 #else
-#define ENV_FLAGS_NET_VARTYPE_REPS ""
+#define ENV_FLAGS_NET_VARTYPES ""
 #endif
 
-static const char env_flags_vartype_rep[] = "sdxb" ENV_FLAGS_NET_VARTYPE_REPS;
+static const char env_flags_vartype_rep[] = "sdxb" ENV_FLAGS_NET_VARTYPES;
 static const char env_flags_varaccess_rep[] = "aroc";
 static const int env_flags_varaccess_mask[] = {
-	0,
-	ENV_FLAGS_VARACCESS_PREVENT_DELETE |
-		ENV_FLAGS_VARACCESS_PREVENT_CREATE |
-		ENV_FLAGS_VARACCESS_PREVENT_OVERWR,
-	ENV_FLAGS_VARACCESS_PREVENT_DELETE |
-		ENV_FLAGS_VARACCESS_PREVENT_OVERWR,
-	ENV_FLAGS_VARACCESS_PREVENT_DELETE |
-		ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR};
+	[env_flags_access_any] =
+		0, /* no restrictions */
+	[env_flags_access_readonly] =
+		ENV_FLAGS_NO_DELETE | ENV_FLAGS_NO_CREATE | ENV_FLAGS_NO_OVERWR,
+	[env_flags_access_writeonce] =
+		ENV_FLAGS_NO_DELETE | ENV_FLAGS_NO_OVERWR,
+	[env_flags_access_changedefault] =
+		ENV_FLAGS_NO_DELETE | ENV_FLAGS_NO_NONDEF_OVERWR
+	};
 
 #ifdef CONFIG_CMD_ENV_FLAGS
 static const char * const env_flags_vartype_names[] = {
-	"string",
-	"decimal",
-	"hexadecimal",
-	"boolean",
+	[env_flags_type_string] = "string",
+	[env_flags_type_decimal] = "decimal",
+	[env_flags_type_hex] = "hexadecimal",
+	[env_flags_type_bool] = "boolean",
 #ifdef CONFIG_CMD_NET
-	"IP address",
-	"MAC address",
+	[env_flags_type_ipaddr] = "IP address",
+	[env_flags_type_macaddr] = "MAC address",
 #endif
 };
 static const char * const env_flags_varaccess_names[] = {
-	"any",
-	"read-only",
-	"write-once",
-	"change-default",
+	[env_flags_access_any] = "any",
+	[env_flags_access_readonly] = "read-only",
+	[env_flags_access_writeonce] = "write-once",
+	[env_flags_access_changedefault] = "change-default",
 };
 
 /*
@@ -64,7 +65,7 @@ void env_flags_print_vartypes(void)
 {
 	enum env_flags_vartype curtype = (enum env_flags_vartype)0;
 
-	while (curtype != env_flags_vartype_end) {
+	while (curtype != env_flags_type_end) {
 		printf("\t%c   -\t%s\n", env_flags_vartype_rep[curtype],
 			env_flags_vartype_names[curtype]);
 		curtype++;
@@ -78,7 +79,7 @@ void env_flags_print_varaccess(void)
 {
 	enum env_flags_varaccess curaccess = (enum env_flags_varaccess)0;
 
-	while (curaccess != env_flags_varaccess_end) {
+	while (curaccess != env_flags_access_end) {
 		printf("\t%c   -\t%s\n", env_flags_varaccess_rep[curaccess],
 			env_flags_varaccess_names[curaccess]);
 		curaccess++;
@@ -110,7 +111,7 @@ enum env_flags_vartype env_flags_parse_vartype(const char *flags)
 	char *type;
 
 	if (strlen(flags) <= ENV_FLAGS_VARTYPE_LOC)
-		return env_flags_vartype_string;
+		return env_flags_type_string;
 
 	type = strchr(env_flags_vartype_rep,
 		flags[ENV_FLAGS_VARTYPE_LOC]);
@@ -121,7 +122,7 @@ enum env_flags_vartype env_flags_parse_vartype(const char *flags)
 
 	printf("## Warning: Unknown environment variable type '%c'\n",
 		flags[ENV_FLAGS_VARTYPE_LOC]);
-	return env_flags_vartype_string;
+	return env_flags_type_string;
 }
 
 /*
@@ -132,7 +133,7 @@ enum env_flags_varaccess env_flags_parse_varaccess(const char *flags)
 	char *access;
 
 	if (strlen(flags) <= ENV_FLAGS_VARACCESS_LOC)
-		return env_flags_varaccess_any;
+		return env_flags_access_any;
 
 	access = strchr(env_flags_varaccess_rep,
 		flags[ENV_FLAGS_VARACCESS_LOC]);
@@ -143,7 +144,7 @@ enum env_flags_varaccess env_flags_parse_varaccess(const char *flags)
 
 	printf("## Warning: Unknown environment variable access method '%c'\n",
 		flags[ENV_FLAGS_VARACCESS_LOC]);
-	return env_flags_varaccess_any;
+	return env_flags_access_any;
 }
 
 /*
@@ -155,13 +156,13 @@ enum env_flags_varaccess env_flags_parse_varaccess_from_binflags(int binflags)
 
 	for (i = 0; i < ARRAY_SIZE(env_flags_varaccess_mask); i++)
 		if (env_flags_varaccess_mask[i] ==
-		    (binflags & ENV_FLAGS_VARACCESS_BIN_MASK))
+		    (binflags & ENV_FLAGS_ACCESS_MASK))
 			return (enum env_flags_varaccess)i;
 
 	printf("Warning: Non-standard access flags. (0x%x)\n",
-		binflags & ENV_FLAGS_VARACCESS_BIN_MASK);
+		binflags & ENV_FLAGS_ACCESS_MASK);
 
-	return env_flags_varaccess_any;
+	return env_flags_access_any;
 }
 
 static inline int is_hex_prefix(const char *value)
@@ -227,21 +228,21 @@ static int _env_flags_validate_type(const char *value,
 #endif
 
 	switch (type) {
-	case env_flags_vartype_string:
+	case env_flags_type_string:
 		break;
-	case env_flags_vartype_decimal:
+	case env_flags_type_decimal:
 		skip_num(0, value, &end, -1);
 		if (*end != '\0')
 			return -1;
 		break;
-	case env_flags_vartype_hex:
+	case env_flags_type_hex:
 		skip_num(1, value, &end, -1);
 		if (*end != '\0')
 			return -1;
 		if (value + 2 == end && is_hex_prefix(value))
 			return -1;
 		break;
-	case env_flags_vartype_bool:
+	case env_flags_type_bool:
 		if (value[0] != '1' && value[0] != 'y' && value[0] != 't' &&
 		    value[0] != 'Y' && value[0] != 'T' &&
 		    value[0] != '0' && value[0] != 'n' && value[0] != 'f' &&
@@ -251,7 +252,7 @@ static int _env_flags_validate_type(const char *value,
 			return -1;
 		break;
 #ifdef CONFIG_CMD_NET
-	case env_flags_vartype_ipaddr:
+	case env_flags_type_ipaddr:
 		cur = value;
 		for (i = 0; i < 4; i++) {
 			skip_num(0, cur, &end, 3);
@@ -264,12 +265,12 @@ static int _env_flags_validate_type(const char *value,
 			cur = end + 1;
 		}
 		break;
-	case env_flags_vartype_macaddr:
+	case env_flags_type_macaddr:
 		if (eth_validate_ethaddr_str(value))
 			return -1;
 		break;
 #endif
-	case env_flags_vartype_end:
+	case env_flags_type_end:
 		return -1;
 	}
 
@@ -404,7 +405,7 @@ static int env_parse_flags_to_bin(const char *flags)
 {
 	int binflags;
 
-	binflags = env_flags_parse_vartype(flags) & ENV_FLAGS_VARTYPE_BIN_MASK;
+	binflags = env_flags_parse_vartype(flags) & ENV_FLAGS_TYPE_MASK;
 	binflags |= env_flags_varaccess_mask[env_flags_parse_varaccess(flags)];
 
 	return binflags;
@@ -512,7 +513,7 @@ int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
 	/* validate the value to match the variable type */
 	if (op != env_op_delete) {
 		enum env_flags_vartype type = (enum env_flags_vartype)
-			(ENV_FLAGS_VARTYPE_BIN_MASK & item->flags);
+			(ENV_FLAGS_TYPE_MASK & item->flags);
 
 		if (_env_flags_validate_type(newval, type) < 0) {
 			printf("## Error: flags type check failure for "
@@ -531,17 +532,17 @@ int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
 #endif
 	switch (op) {
 	case env_op_delete:
-		if (item->flags & ENV_FLAGS_VARACCESS_PREVENT_DELETE) {
+		if (item->flags & ENV_FLAGS_NO_DELETE) {
 			printf("## Error: Can't delete \"%s\"\n", name);
 			return 1;
 		}
 		break;
 	case env_op_overwrite:
-		if (item->flags & ENV_FLAGS_VARACCESS_PREVENT_OVERWR) {
+		if (item->flags & ENV_FLAGS_NO_OVERWR) {
 			printf("## Error: Can't overwrite \"%s\"\n", name);
 			return 1;
 		} else if (item->flags &
-		    ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR) {
+		    ENV_FLAGS_NO_NONDEF_OVERWR) {
 			const char *defval = getenv_default(name);
 
 			if (defval == NULL)
@@ -555,7 +556,7 @@ int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
 		}
 		break;
 	case env_op_create:
-		if (item->flags & ENV_FLAGS_VARACCESS_PREVENT_CREATE) {
+		if (item->flags & ENV_FLAGS_NO_CREATE) {
 			printf("## Error: Can't create \"%s\"\n", name);
 			return 1;
 		}
diff --git a/include/env_flags.h b/include/env_flags.h
index 0dcec06..5ee96a1 100644
--- a/include/env_flags.h
+++ b/include/env_flags.h
@@ -9,23 +9,23 @@
 #define __ENV_FLAGS_H__
 
 enum env_flags_vartype {
-	env_flags_vartype_string,
-	env_flags_vartype_decimal,
-	env_flags_vartype_hex,
-	env_flags_vartype_bool,
+	env_flags_type_string,
+	env_flags_type_decimal,
+	env_flags_type_hex,
+	env_flags_type_bool,
 #ifdef CONFIG_CMD_NET
-	env_flags_vartype_ipaddr,
-	env_flags_vartype_macaddr,
+	env_flags_type_ipaddr,
+	env_flags_type_macaddr,
 #endif
-	env_flags_vartype_end
+	env_flags_type_end
 };
 
 enum env_flags_varaccess {
-	env_flags_varaccess_any,
-	env_flags_varaccess_readonly,
-	env_flags_varaccess_writeonce,
-	env_flags_varaccess_changedefault,
-	env_flags_varaccess_end
+	env_flags_access_any,
+	env_flags_access_readonly,
+	env_flags_access_writeonce,
+	env_flags_access_changedefault,
+	env_flags_access_end
 };
 
 #define ENV_FLAGS_VAR ".flags"
@@ -167,12 +167,12 @@ int env_flags_validate(const ENTRY *item, const char *newval, enum env_op op,
  * These are the binary flags used in the environment entry->flags variable to
  * decribe properties of veriables in the table
  */
-#define ENV_FLAGS_VARTYPE_BIN_MASK			0x00000007
+#define ENV_FLAGS_TYPE_MASK		0x00000007
 /* The actual variable type values use the enum value (within the mask) */
-#define ENV_FLAGS_VARACCESS_PREVENT_DELETE		0x00000008
-#define ENV_FLAGS_VARACCESS_PREVENT_CREATE		0x00000010
-#define ENV_FLAGS_VARACCESS_PREVENT_OVERWR		0x00000020
-#define ENV_FLAGS_VARACCESS_PREVENT_NONDEF_OVERWR	0x00000040
-#define ENV_FLAGS_VARACCESS_BIN_MASK			0x00000078
+#define ENV_FLAGS_NO_DELETE		0x00000008
+#define ENV_FLAGS_NO_CREATE		0x00000010
+#define ENV_FLAGS_NO_OVERWR		0x00000020
+#define ENV_FLAGS_NO_NONDEF_OVERWR	0x00000040
+#define ENV_FLAGS_ACCESS_MASK		0x00000078
 
 #endif /* __ENV_FLAGS_H__ */
-- 
2.7.3



More information about the U-Boot mailing list