[libubootenv,v2,3/8] uboot_env: add a callback to validate a value before it is set
Commit Message
Add an optional callback to check a value before it is set. This allows
a storage format whose variables accept only some values to report an
invalid one as soon as it is set, instead of when the environment is
stored.
The U-Boot environment does not use it.
No functional change.
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---
Changes in v2:
- New patch
src/uboot_env.c | 9 +++++++++
src/uboot_private.h | 3 +++
2 files changed, 12 insertions(+)
--
2.43.0
@@ -1011,6 +1011,15 @@ int libuboot_set_env(struct uboot_ctx *ctx, const char *varname, const char *val
if (!entryvarlist)
return -EPERM;
}
+
+ if (value && storages[ctx->format]->validate) {
+ int ret;
+
+ ret = storages[ctx->format]->validate(ctx, varname, value);
+ if (ret)
+ return ret;
+ }
+
return __libuboot_set_env(ctx, varname, value, entryvarlist);
}
@@ -212,6 +212,9 @@ struct env_storage {
int (*load)(struct uboot_ctx *ctx, const struct env_helpers *h);
/** write the variable list to the storage */
int (*store)(struct uboot_ctx *ctx, const struct env_helpers *h);
+ /** check a value before it is set, can be NULL */
+ int (*validate)(struct uboot_ctx *ctx, const char *varname,
+ const char *value);
};
#if defined(__FreeBSD__)