[PATCH 3/5] uservars: Implement USERVAR_TYPE_GLOBAL flag

3 views
Skip to first unread message

Andreas J. Reichel

unread,
Nov 3, 2017, 7:53:50 AM11/3/17
to efibootg...@googlegroups.com, Andreas Reichel
From: Andreas Reichel <andreas.r...@siemens.com>

If the above flag is set in the type field of a user variable,
bgenv_set_uservar_global is called, which iterates all environments
and stores the given variable globally.

If the flag is absent, only the environment specified by the context
handle gets affected.

The flag is set per default if not otherwise specified.

Signed-off-by: Andreas Reichel <andreas.r...@siemens.com>
---
env/env_api_fat.c | 27 +++++++++++++++++++++++++++
include/env_api.h | 2 ++
2 files changed, 29 insertions(+)

diff --git a/env/env_api_fat.c b/env/env_api_fat.c
index 7d5e714..565ab44 100644
--- a/env/env_api_fat.c
+++ b/env/env_api_fat.c
@@ -320,6 +320,29 @@ int bgenv_get(BGENV *env, char *key, uint64_t *type, void *data,
return 0;
}

+int bgenv_set_uservar_global(char *key, uint64_t type, void *data,
+ uint32_t datalen)
+{
+ int ret = 0;
+ for (int i = 0; i < ENV_NUM_CONFIG_PARTS; i++) {
+ BGENV *env = bgenv_open_by_index(i);
+ if (!env) {
+ ret = -EIO;
+ continue;
+ }
+ int r = bgenv_set_uservar(env->data->userdata, key, type, data,
+ datalen);
+ if (r) {
+ ret = r;
+ }
+ if (!bgenv_write(env)) {
+ ret = -EIO;
+ }
+ (void)bgenv_close(env);
+ }
+ return ret;
+}
+
int bgenv_set(BGENV *env, char *key, uint64_t type, void *data,
uint32_t datalen)
{
@@ -337,6 +360,10 @@ int bgenv_set(BGENV *env, char *key, uint64_t type, void *data,
return -EPERM;
}
if (e == EBGENV_UNKNOWN) {
+ if (type & USERVAR_TYPE_GLOBAL) {
+ return bgenv_set_uservar_global(key, type, data,
+ datalen);
+ }
return bgenv_set_uservar(env->data->userdata, key, type, data,
datalen);
}
diff --git a/include/env_api.h b/include/env_api.h
index 8ea2c11..3b1ba1f 100644
--- a/include/env_api.h
+++ b/include/env_api.h
@@ -83,5 +83,7 @@ extern int bgenv_get(BGENV *env, char *key, uint64_t *type, void *data,
uint32_t maxlen);
extern int bgenv_set(BGENV *env, char *key, uint64_t type, void *data,
uint32_t datalen);
+extern int bgenv_set_uservar_global(char *key, uint64_t type,
+ void *data, uint32_t datalen);

#endif // __ENV_API_H__
--
2.14.2

Reply all
Reply to author
Forward
0 new messages