On 17.10.23 09:01, 'Felix Moessbauer' via EFI Boot Guard wrote:
> This patch deprecated the ebg_beverbose function and ports the logic
> over to the ebg_set_opt_bool infrastructure. By that, the interface can
> be simplified.
> 
> Signed-off-by: Felix Moessbauer <[email protected]>
> ---
>  env/env_api.c                 | 12 ++++++++++--
>  env/env_api_fat.c             |  2 --
>  include/ebgenv.h              |  6 ++++--
>  include/env_api.h             |  7 +++----
>  tools/bg_printenv.c           |  3 +++
>  tools/bg_setenv.c             |  3 +++
>  tools/tests/test_ebgenv_api.c | 19 +++++++++++++++++++
>  7 files changed, 42 insertions(+), 10 deletions(-)
> 
> diff --git a/env/env_api.c b/env/env_api.c
> index 49cee3b..3843a41 100644
> --- a/env/env_api.c
> +++ b/env/env_api.c
> @@ -66,6 +66,10 @@ int ebg_set_opt_bool(ebg_opt_t opt, bool value)
>       case EBG_OPT_PROBE_ALL_DEVICES:
>               ebgenv_opts.search_all_devices = value;
>               break;
> +     case EBG_OPT_VERBOSE:
> +             ebgenv_opts.verbose = value;
> +             bgenv_be_verbose(value);
> +             break;
>       default:
>               return EINVAL;
>       }
> @@ -78,15 +82,19 @@ int ebg_get_opt_bool(ebg_opt_t opt, bool *value)
>       case EBG_OPT_PROBE_ALL_DEVICES:
>               *value = ebgenv_opts.search_all_devices;
>               break;
> +     case EBG_OPT_VERBOSE:
> +             *value = ebgenv_opts.verbose;
> +             break;
>       default:
>               return EINVAL;
>       }
>       return 0;
>  }
>  
> -void ebg_beverbose(ebgenv_t __attribute__((unused)) *e, bool v)
> +void __attribute__((deprecated))

Nit: We do not need the attribute here. It's sufficient in the declaration.

Jan

> +ebg_beverbose(ebgenv_t __attribute__((unused)) * e, bool v)
>  {
> -     bgenv_be_verbose(v);
> +     ebg_set_opt_bool(EBG_OPT_VERBOSE, v);
>  }
>  
>  int ebg_env_create_new(ebgenv_t *e)
> diff --git a/env/env_api_fat.c b/env/env_api_fat.c
> index 2bfdc4f..3433165 100644
> --- a/env/env_api_fat.c
> +++ b/env/env_api_fat.c
> @@ -20,7 +20,6 @@
>  #include "test-interface.h"
>  #include "ebgpart.h"
>  
> -bool bgenv_verbosity = false;
>  extern ebgenv_opts_t ebgenv_opts;
>  
>  EBGENVKEY bgenv_str2enum(char *key)
> @@ -48,7 +47,6 @@ EBGENVKEY bgenv_str2enum(char *key)
>  
>  void bgenv_be_verbose(bool v)
>  {
> -     bgenv_verbosity = v;
>       ebgpart_beverbose(v);
>  }
>  
> diff --git a/include/ebgenv.h b/include/ebgenv.h
> index c1eacc2..64bcce2 100644
> --- a/include/ebgenv.h
> +++ b/include/ebgenv.h
> @@ -38,6 +38,7 @@
>  
>  typedef struct {
>       bool search_all_devices;
> +     bool verbose;
>  } ebgenv_opts_t;
>  
>  typedef struct {
> @@ -46,7 +47,7 @@ typedef struct {
>       ebgenv_opts_t opts;
>  } ebgenv_t;
>  
> -typedef enum { EBG_OPT_PROBE_ALL_DEVICES } ebg_opt_t;
> +typedef enum { EBG_OPT_PROBE_ALL_DEVICES, EBG_OPT_VERBOSE } ebg_opt_t;
>  
>  /**
>   * @brief Set a global EBG option. Call before creating the ebg env.
> @@ -67,8 +68,9 @@ int ebg_get_opt_bool(ebg_opt_t opt, bool *value);
>  /** @brief Tell the library to output information for the user.
>   *  @param e A pointer to an ebgenv_t context.
>   *  @param v A boolean to set verbosity.
> + *  @note deprecated. Use \c ebg_set_opt_bool(EBG_OPT_VERBOSE,true) instead
>   */
> -void ebg_beverbose(ebgenv_t *e, bool v);
> +void __attribute__((deprecated)) ebg_beverbose(ebgenv_t *e, bool v);
>  
>  /** @brief Initialize environment library and open environment. The first
>   *         time this function is called, it will create a new environment 
> with
> diff --git a/include/env_api.h b/include/env_api.h
> index 7999727..93d29c8 100644
> --- a/include/env_api.h
> +++ b/include/env_api.h
> @@ -42,11 +42,10 @@
>  
>  #define DEFAULT_TIMEOUT_SEC 30
>  
> -extern bool bgenv_verbosity;
> +extern ebgenv_opts_t ebgenv_opts;
>  
> -#define VERBOSE(o, ...)                                                      
>  \
> -     if (bgenv_verbosity)                                                    
> \
> -     fprintf(o, __VA_ARGS__)
> +#define VERBOSE(o, ...)                                                      
>   \
> +     if (ebgenv_opts.verbose) fprintf(o, __VA_ARGS__)
>  
>  typedef enum {
>       EBGENV_KERNELFILE,
> diff --git a/tools/bg_printenv.c b/tools/bg_printenv.c
> index 4e11b78..5e5a55f 100644
> --- a/tools/bg_printenv.c
> +++ b/tools/bg_printenv.c
> @@ -347,6 +347,9 @@ error_t bg_printenv(int argc, char **argv)
>       if (arguments.common.search_all_devices) {
>               ebg_set_opt_bool(EBG_OPT_PROBE_ALL_DEVICES, true);
>       }
> +     if (arguments.common.verbosity) {
> +             ebg_set_opt_bool(EBG_OPT_VERBOSE, true);
> +     }
>       if (!bgenv_init()) {
>               fprintf(stderr, "Error initializing FAT environment.\n");
>               return 1;
> diff --git a/tools/bg_setenv.c b/tools/bg_setenv.c
> index a322582..0757e80 100644
> --- a/tools/bg_setenv.c
> +++ b/tools/bg_setenv.c
> @@ -422,6 +422,9 @@ error_t bg_setenv(int argc, char **argv)
>       if (arguments.common.search_all_devices) {
>               ebg_set_opt_bool(EBG_OPT_PROBE_ALL_DEVICES, true);
>       }
> +     if (arguments.common.verbosity) {
> +             ebg_set_opt_bool(EBG_OPT_VERBOSE, true);
> +     }
>       if (!bgenv_init()) {
>               fprintf(stderr, "Error initializing FAT environment.\n");
>               return 1;
> diff --git a/tools/tests/test_ebgenv_api.c b/tools/tests/test_ebgenv_api.c
> index cd08e9a..e4f9c46 100644
> --- a/tools/tests/test_ebgenv_api.c
> +++ b/tools/tests/test_ebgenv_api.c
> @@ -83,6 +83,24 @@ int __wrap_bgenv_set(BGENV *env, char *key, uint64_t type, 
> void *buffer,
>  CONFIG_PART config_parts[ENV_NUM_CONFIG_PARTS];
>  BG_ENVDATA envdata[ENV_NUM_CONFIG_PARTS];
>  
> +START_TEST(ebgenv_api_ebg_env_options)
> +{
> +     int status;
> +     status = ebg_set_opt_bool(EBG_OPT_VERBOSE, true);
> +     ck_assert_int_eq(status, 0);
> +     bool verbose;
> +     status = ebg_get_opt_bool(EBG_OPT_VERBOSE, &verbose);
> +     ck_assert_int_eq(status, 0);
> +     ck_assert_int_eq(verbose, 1);
> +
> +     // try invalid option
> +     status = ebg_set_opt_bool(0xffff, false);
> +     ck_assert_int_ne(status, 0);
> +     status = ebg_get_opt_bool(0xffff, &verbose);
> +     ck_assert_int_ne(status, 0);
> +}
> +END_TEST
> +
>  START_TEST(ebgenv_api_ebg_env_create_new)
>  {
>       ebgenv_t e;
> @@ -665,6 +683,7 @@ Suite *ebg_test_suite(void)
>  
>       tc_core = tcase_create("Core");
>  
> +     tcase_add_test(tc_core, ebgenv_api_ebg_env_options);
>       tcase_add_test(tc_core, ebgenv_api_ebg_env_create_new);
>       tcase_add_test(tc_core, ebgenv_api_ebg_env_open_current);
>       tcase_add_test(tc_core, ebgenv_api_ebg_env_get);

-- 
Siemens AG, Technology
Linux Expert Center

-- 
You received this message because you are subscribed to the Google Groups "EFI 
Boot Guard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/efibootguard-dev/03bccb6c-a079-4d99-8f86-99c759910204%40siemens.com.

Reply via email to