Patchwork lib: fwts_uefi: add a helper fuction to convert attribute into readable form

login
register
mail settings
Submitter Ivan Hu
Date March 5, 2013, 3:11 a.m.
Message ID <1362453079-23891-1-git-send-email-ivan.hu@canonical.com>
Download mbox | patch
Permalink /patch/224924/
State Accepted
Headers show

Comments

Ivan Hu - March 5, 2013, 3:11 a.m.
Add a helper fuction in fwts_uefi to covert attributes into a human readable
form for reducing the duplicating code in uefidump.c and securebootcert.c

Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
---
 src/lib/include/fwts_uefi.h              |    1 +
 src/lib/src/fwts_uefi.c                  |   40 ++++++++++++++++++++++++++++++
 src/uefi/securebootcert/securebootcert.c |   38 +---------------------------
 src/uefi/uefidump/uefidump.c             |   30 +---------------------
 4 files changed, 43 insertions(+), 66 deletions(-)
Colin King - March 5, 2013, 9:43 a.m.
On 05/03/13 03:11, Ivan Hu wrote:
> Add a helper fuction in fwts_uefi to covert attributes into a human readable
> form for reducing the duplicating code in uefidump.c and securebootcert.c
>
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>   src/lib/include/fwts_uefi.h              |    1 +
>   src/lib/src/fwts_uefi.c                  |   40 ++++++++++++++++++++++++++++++
>   src/uefi/securebootcert/securebootcert.c |   38 +---------------------------
>   src/uefi/uefidump/uefidump.c             |   30 +---------------------
>   4 files changed, 43 insertions(+), 66 deletions(-)
>
> diff --git a/src/lib/include/fwts_uefi.h b/src/lib/include/fwts_uefi.h
> index ba663b8..98eddb0 100644
> --- a/src/lib/include/fwts_uefi.h
> +++ b/src/lib/include/fwts_uefi.h
> @@ -354,5 +354,6 @@ void fwts_uefi_free_variable_names(fwts_list *list);
>   int fwts_uefi_get_variable_names(fwts_list *list);
>
>   void fwts_uefi_print_status_info(fwts_framework *fw, const uint64_t status);
> +char *fwts_uefi_attribute_info(uint32_t attr);
>
>   #endif
> diff --git a/src/lib/src/fwts_uefi.c b/src/lib/src/fwts_uefi.c
> index 53fa810..0b721fb 100644
> --- a/src/lib/src/fwts_uefi.c
> +++ b/src/lib/src/fwts_uefi.c
> @@ -471,3 +471,43 @@ void fwts_uefi_print_status_info(fwts_framework *fw, const uint64_t status)
>   	fwts_log_info(fw, "Cannot find the return status information, value = 0x%" PRIx64 ".", status);
>
>   }
> +
> +/*
> + *  fwts_uefi_attribute_info()
> + *	convert attribute into a human readable form
> + */
> +char *fwts_uefi_attribute_info(uint32_t attr)
> +{
> +	static char str[100];
> +
> +	*str = 0;
> +
> +	if (attr & FWTS_UEFI_VAR_NON_VOLATILE)
> +		strcat(str, "NonVolatile");
> +
> +	if (attr & FWTS_UEFI_VAR_BOOTSERVICE_ACCESS) {
> +		if (*str)
> +			strcat(str, ",");
> +		strcat(str, "BootServ");
> +	}
> +
> +	if (attr & FWTS_UEFI_VAR_RUNTIME_ACCESS) {
> +		if (*str)
> +			strcat(str, ",");
> +		strcat(str, "RunTime");
> +	}
> +
> +	if (attr & FWTS_UEFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) {
> +		if (*str)
> +			strcat(str, ",");
> +		strcat(str, "AuthenicatedWrite");
> +	}
> +
> +	if (attr & FWTS_UEFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) {
> +		if (*str)
> +			strcat(str, ",");
> +		strcat(str, "TimeBaseAuthenicatedWrite");
> +	}
> +
> +	return str;
> +}
> diff --git a/src/uefi/securebootcert/securebootcert.c b/src/uefi/securebootcert/securebootcert.c
> index 6a88932..22a6373 100644
> --- a/src/uefi/securebootcert/securebootcert.c
> +++ b/src/uefi/securebootcert/securebootcert.c
> @@ -303,42 +303,6 @@ static securebootcert_info securebootcert_info_table[] = {
>   	{ NULL, NULL }
>   };
>
> -static char *securebootcert_attribute(uint32_t attr)
> -{
> -	static char str[100];
> -
> -	*str = 0;
> -
> -	if (attr & FWTS_UEFI_VAR_NON_VOLATILE)
> -		strcat(str, "NonVolatile");
> -
> -	if (attr & FWTS_UEFI_VAR_BOOTSERVICE_ACCESS) {
> -		if (*str)
> -			strcat(str, ",");
> -		strcat(str, "BootServ");
> -	}
> -
> -	if (attr & FWTS_UEFI_VAR_RUNTIME_ACCESS) {
> -		if (*str)
> -			strcat(str, ",");
> -		strcat(str, "RunTime");
> -	}
> -
> -	if (attr & FWTS_UEFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) {
> -		if (*str)
> -			strcat(str, ",");
> -		strcat(str, "AuthenicatedWrite");
> -	}
> -
> -	if (attr & FWTS_UEFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) {
> -		if (*str)
> -			strcat(str, ",");
> -		strcat(str, "TimeBaseAuthenicatedWrite");
> -	}
> -
> -	return str;
> -}
> -
>   static void securebootcert_var(fwts_framework *fw, fwts_uefi_var *var)
>   {
>   	char varname[512];
> @@ -353,7 +317,7 @@ static void securebootcert_var(fwts_framework *fw, fwts_uefi_var *var)
>   			fwts_guid_buf_to_str(var->guid, guid_str, sizeof(guid_str));
>   			fwts_log_info_verbatum(fw, "  GUID: %s", guid_str);
>   			fwts_log_info_verbatum(fw, "  Attr: 0x%x (%s).", var->attributes,
> -							securebootcert_attribute(var->attributes));
> +							fwts_uefi_attribute_info(var->attributes));
>   			info->func(fw, var, varname);
>   			fwts_log_nl(fw);
>   			return;
> diff --git a/src/uefi/uefidump/uefidump.c b/src/uefi/uefidump/uefidump.c
> index 622abe3..b115a62 100644
> --- a/src/uefi/uefidump/uefidump.c
> +++ b/src/uefi/uefidump/uefidump.c
> @@ -681,34 +681,6 @@ static uefidump_info uefidump_info_table[] = {
>   	{ NULL, NULL }
>   };
>
> -/*
> - *  uefidump_attribute()
> - *	convert attribute into a human readable form
> - */
> -static char *uefidump_attribute(uint32_t attr)
> -{
> -	static char str[50];
> -
> -	*str = 0;
> -
> -	if (attr & FWTS_UEFI_VAR_NON_VOLATILE)
> -		strcat(str, "NonVolatile");
> -
> -	if (attr & FWTS_UEFI_VAR_BOOTSERVICE_ACCESS) {
> -		if (*str)
> -			strcat(str, ",");
> -		strcat(str, "BootServ");
> -	}
> -
> -	if (attr & FWTS_UEFI_VAR_RUNTIME_ACCESS) {
> -		if (*str)
> -			strcat(str, ",");
> -		strcat(str, "RunTime");
> -	}
> -
> -	return str;
> -}
> -
>   static void uefidump_var(fwts_framework *fw, fwts_uefi_var *var)
>   {
>   	char varname[512];
> @@ -720,7 +692,7 @@ static void uefidump_var(fwts_framework *fw, fwts_uefi_var *var)
>   	fwts_log_info_verbatum(fw, "Name: %s.", varname);
>   	fwts_guid_buf_to_str(var->guid, guid_str, sizeof(guid_str));
>   	fwts_log_info_verbatum(fw, "  GUID: %s", guid_str);
> -	fwts_log_info_verbatum(fw, "  Attr: 0x%x (%s).", var->attributes, uefidump_attribute(var->attributes));
> +	fwts_log_info_verbatum(fw, "  Attr: 0x%x (%s).", var->attributes, fwts_uefi_attribute_info(var->attributes));
>
>   	/* If we've got an appropriate per variable dump mechanism, use this */
>   	for (info = uefidump_info_table; info->description != NULL; info++) {
>
Thanks Ivan

Acked-by: Colin Ian King <colin.king@canonical.com>
Keng-Yu Lin - March 8, 2013, 7:49 a.m.
On Tue, Mar 5, 2013 at 11:11 AM, Ivan Hu <ivan.hu@canonical.com> wrote:
> Add a helper fuction in fwts_uefi to covert attributes into a human readable
> form for reducing the duplicating code in uefidump.c and securebootcert.c
>
> Signed-off-by: Ivan Hu <ivan.hu@canonical.com>
> ---
>  src/lib/include/fwts_uefi.h              |    1 +
>  src/lib/src/fwts_uefi.c                  |   40 ++++++++++++++++++++++++++++++
>  src/uefi/securebootcert/securebootcert.c |   38 +---------------------------
>  src/uefi/uefidump/uefidump.c             |   30 +---------------------
>  4 files changed, 43 insertions(+), 66 deletions(-)
>
> diff --git a/src/lib/include/fwts_uefi.h b/src/lib/include/fwts_uefi.h
> index ba663b8..98eddb0 100644
> --- a/src/lib/include/fwts_uefi.h
> +++ b/src/lib/include/fwts_uefi.h
> @@ -354,5 +354,6 @@ void fwts_uefi_free_variable_names(fwts_list *list);
>  int fwts_uefi_get_variable_names(fwts_list *list);
>
>  void fwts_uefi_print_status_info(fwts_framework *fw, const uint64_t status);
> +char *fwts_uefi_attribute_info(uint32_t attr);
>
>  #endif
> diff --git a/src/lib/src/fwts_uefi.c b/src/lib/src/fwts_uefi.c
> index 53fa810..0b721fb 100644
> --- a/src/lib/src/fwts_uefi.c
> +++ b/src/lib/src/fwts_uefi.c
> @@ -471,3 +471,43 @@ void fwts_uefi_print_status_info(fwts_framework *fw, const uint64_t status)
>         fwts_log_info(fw, "Cannot find the return status information, value = 0x%" PRIx64 ".", status);
>
>  }
> +
> +/*
> + *  fwts_uefi_attribute_info()
> + *     convert attribute into a human readable form
> + */
> +char *fwts_uefi_attribute_info(uint32_t attr)
> +{
> +       static char str[100];
> +
> +       *str = 0;
> +
> +       if (attr & FWTS_UEFI_VAR_NON_VOLATILE)
> +               strcat(str, "NonVolatile");
> +
> +       if (attr & FWTS_UEFI_VAR_BOOTSERVICE_ACCESS) {
> +               if (*str)
> +                       strcat(str, ",");
> +               strcat(str, "BootServ");
> +       }
> +
> +       if (attr & FWTS_UEFI_VAR_RUNTIME_ACCESS) {
> +               if (*str)
> +                       strcat(str, ",");
> +               strcat(str, "RunTime");
> +       }
> +
> +       if (attr & FWTS_UEFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) {
> +               if (*str)
> +                       strcat(str, ",");
> +               strcat(str, "AuthenicatedWrite");
> +       }
> +
> +       if (attr & FWTS_UEFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) {
> +               if (*str)
> +                       strcat(str, ",");
> +               strcat(str, "TimeBaseAuthenicatedWrite");
> +       }
> +
> +       return str;
> +}
> diff --git a/src/uefi/securebootcert/securebootcert.c b/src/uefi/securebootcert/securebootcert.c
> index 6a88932..22a6373 100644
> --- a/src/uefi/securebootcert/securebootcert.c
> +++ b/src/uefi/securebootcert/securebootcert.c
> @@ -303,42 +303,6 @@ static securebootcert_info securebootcert_info_table[] = {
>         { NULL, NULL }
>  };
>
> -static char *securebootcert_attribute(uint32_t attr)
> -{
> -       static char str[100];
> -
> -       *str = 0;
> -
> -       if (attr & FWTS_UEFI_VAR_NON_VOLATILE)
> -               strcat(str, "NonVolatile");
> -
> -       if (attr & FWTS_UEFI_VAR_BOOTSERVICE_ACCESS) {
> -               if (*str)
> -                       strcat(str, ",");
> -               strcat(str, "BootServ");
> -       }
> -
> -       if (attr & FWTS_UEFI_VAR_RUNTIME_ACCESS) {
> -               if (*str)
> -                       strcat(str, ",");
> -               strcat(str, "RunTime");
> -       }
> -
> -       if (attr & FWTS_UEFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) {
> -               if (*str)
> -                       strcat(str, ",");
> -               strcat(str, "AuthenicatedWrite");
> -       }
> -
> -       if (attr & FWTS_UEFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) {
> -               if (*str)
> -                       strcat(str, ",");
> -               strcat(str, "TimeBaseAuthenicatedWrite");
> -       }
> -
> -       return str;
> -}
> -
>  static void securebootcert_var(fwts_framework *fw, fwts_uefi_var *var)
>  {
>         char varname[512];
> @@ -353,7 +317,7 @@ static void securebootcert_var(fwts_framework *fw, fwts_uefi_var *var)
>                         fwts_guid_buf_to_str(var->guid, guid_str, sizeof(guid_str));
>                         fwts_log_info_verbatum(fw, "  GUID: %s", guid_str);
>                         fwts_log_info_verbatum(fw, "  Attr: 0x%x (%s).", var->attributes,
> -                                                       securebootcert_attribute(var->attributes));
> +                                                       fwts_uefi_attribute_info(var->attributes));
>                         info->func(fw, var, varname);
>                         fwts_log_nl(fw);
>                         return;
> diff --git a/src/uefi/uefidump/uefidump.c b/src/uefi/uefidump/uefidump.c
> index 622abe3..b115a62 100644
> --- a/src/uefi/uefidump/uefidump.c
> +++ b/src/uefi/uefidump/uefidump.c
> @@ -681,34 +681,6 @@ static uefidump_info uefidump_info_table[] = {
>         { NULL, NULL }
>  };
>
> -/*
> - *  uefidump_attribute()
> - *     convert attribute into a human readable form
> - */
> -static char *uefidump_attribute(uint32_t attr)
> -{
> -       static char str[50];
> -
> -       *str = 0;
> -
> -       if (attr & FWTS_UEFI_VAR_NON_VOLATILE)
> -               strcat(str, "NonVolatile");
> -
> -       if (attr & FWTS_UEFI_VAR_BOOTSERVICE_ACCESS) {
> -               if (*str)
> -                       strcat(str, ",");
> -               strcat(str, "BootServ");
> -       }
> -
> -       if (attr & FWTS_UEFI_VAR_RUNTIME_ACCESS) {
> -               if (*str)
> -                       strcat(str, ",");
> -               strcat(str, "RunTime");
> -       }
> -
> -       return str;
> -}
> -
>  static void uefidump_var(fwts_framework *fw, fwts_uefi_var *var)
>  {
>         char varname[512];
> @@ -720,7 +692,7 @@ static void uefidump_var(fwts_framework *fw, fwts_uefi_var *var)
>         fwts_log_info_verbatum(fw, "Name: %s.", varname);
>         fwts_guid_buf_to_str(var->guid, guid_str, sizeof(guid_str));
>         fwts_log_info_verbatum(fw, "  GUID: %s", guid_str);
> -       fwts_log_info_verbatum(fw, "  Attr: 0x%x (%s).", var->attributes, uefidump_attribute(var->attributes));
> +       fwts_log_info_verbatum(fw, "  Attr: 0x%x (%s).", var->attributes, fwts_uefi_attribute_info(var->attributes));
>
>         /* If we've got an appropriate per variable dump mechanism, use this */
>         for (info = uefidump_info_table; info->description != NULL; info++) {
> --
> 1.7.10.4
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>

Patch

diff --git a/src/lib/include/fwts_uefi.h b/src/lib/include/fwts_uefi.h
index ba663b8..98eddb0 100644
--- a/src/lib/include/fwts_uefi.h
+++ b/src/lib/include/fwts_uefi.h
@@ -354,5 +354,6 @@  void fwts_uefi_free_variable_names(fwts_list *list);
 int fwts_uefi_get_variable_names(fwts_list *list);
 
 void fwts_uefi_print_status_info(fwts_framework *fw, const uint64_t status);
+char *fwts_uefi_attribute_info(uint32_t attr);
 
 #endif
diff --git a/src/lib/src/fwts_uefi.c b/src/lib/src/fwts_uefi.c
index 53fa810..0b721fb 100644
--- a/src/lib/src/fwts_uefi.c
+++ b/src/lib/src/fwts_uefi.c
@@ -471,3 +471,43 @@  void fwts_uefi_print_status_info(fwts_framework *fw, const uint64_t status)
 	fwts_log_info(fw, "Cannot find the return status information, value = 0x%" PRIx64 ".", status);
 
 }
+
+/*
+ *  fwts_uefi_attribute_info()
+ *	convert attribute into a human readable form
+ */
+char *fwts_uefi_attribute_info(uint32_t attr)
+{
+	static char str[100];
+
+	*str = 0;
+
+	if (attr & FWTS_UEFI_VAR_NON_VOLATILE)
+		strcat(str, "NonVolatile");
+
+	if (attr & FWTS_UEFI_VAR_BOOTSERVICE_ACCESS) {
+		if (*str)
+			strcat(str, ",");
+		strcat(str, "BootServ");
+	}
+
+	if (attr & FWTS_UEFI_VAR_RUNTIME_ACCESS) {
+		if (*str)
+			strcat(str, ",");
+		strcat(str, "RunTime");
+	}
+
+	if (attr & FWTS_UEFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) {
+		if (*str)
+			strcat(str, ",");
+		strcat(str, "AuthenicatedWrite");
+	}
+
+	if (attr & FWTS_UEFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) {
+		if (*str)
+			strcat(str, ",");
+		strcat(str, "TimeBaseAuthenicatedWrite");
+	}
+
+	return str;
+}
diff --git a/src/uefi/securebootcert/securebootcert.c b/src/uefi/securebootcert/securebootcert.c
index 6a88932..22a6373 100644
--- a/src/uefi/securebootcert/securebootcert.c
+++ b/src/uefi/securebootcert/securebootcert.c
@@ -303,42 +303,6 @@  static securebootcert_info securebootcert_info_table[] = {
 	{ NULL, NULL }
 };
 
-static char *securebootcert_attribute(uint32_t attr)
-{
-	static char str[100];
-
-	*str = 0;
-
-	if (attr & FWTS_UEFI_VAR_NON_VOLATILE)
-		strcat(str, "NonVolatile");
-
-	if (attr & FWTS_UEFI_VAR_BOOTSERVICE_ACCESS) {
-		if (*str)
-			strcat(str, ",");
-		strcat(str, "BootServ");
-	}
-
-	if (attr & FWTS_UEFI_VAR_RUNTIME_ACCESS) {
-		if (*str)
-			strcat(str, ",");
-		strcat(str, "RunTime");
-	}
-
-	if (attr & FWTS_UEFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS) {
-		if (*str)
-			strcat(str, ",");
-		strcat(str, "AuthenicatedWrite");
-	}
-
-	if (attr & FWTS_UEFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS) {
-		if (*str)
-			strcat(str, ",");
-		strcat(str, "TimeBaseAuthenicatedWrite");
-	}
-
-	return str;
-}
-
 static void securebootcert_var(fwts_framework *fw, fwts_uefi_var *var)
 {
 	char varname[512];
@@ -353,7 +317,7 @@  static void securebootcert_var(fwts_framework *fw, fwts_uefi_var *var)
 			fwts_guid_buf_to_str(var->guid, guid_str, sizeof(guid_str));
 			fwts_log_info_verbatum(fw, "  GUID: %s", guid_str);
 			fwts_log_info_verbatum(fw, "  Attr: 0x%x (%s).", var->attributes,
-							securebootcert_attribute(var->attributes));
+							fwts_uefi_attribute_info(var->attributes));
 			info->func(fw, var, varname);
 			fwts_log_nl(fw);
 			return;
diff --git a/src/uefi/uefidump/uefidump.c b/src/uefi/uefidump/uefidump.c
index 622abe3..b115a62 100644
--- a/src/uefi/uefidump/uefidump.c
+++ b/src/uefi/uefidump/uefidump.c
@@ -681,34 +681,6 @@  static uefidump_info uefidump_info_table[] = {
 	{ NULL, NULL }
 };
 
-/*
- *  uefidump_attribute()
- *	convert attribute into a human readable form
- */
-static char *uefidump_attribute(uint32_t attr)
-{
-	static char str[50];
-
-	*str = 0;
-
-	if (attr & FWTS_UEFI_VAR_NON_VOLATILE)
-		strcat(str, "NonVolatile");
-
-	if (attr & FWTS_UEFI_VAR_BOOTSERVICE_ACCESS) {
-		if (*str)
-			strcat(str, ",");
-		strcat(str, "BootServ");
-	}
-
-	if (attr & FWTS_UEFI_VAR_RUNTIME_ACCESS) {
-		if (*str)
-			strcat(str, ",");
-		strcat(str, "RunTime");
-	}
-
-	return str;
-}
-
 static void uefidump_var(fwts_framework *fw, fwts_uefi_var *var)
 {
 	char varname[512];
@@ -720,7 +692,7 @@  static void uefidump_var(fwts_framework *fw, fwts_uefi_var *var)
 	fwts_log_info_verbatum(fw, "Name: %s.", varname);
 	fwts_guid_buf_to_str(var->guid, guid_str, sizeof(guid_str));
 	fwts_log_info_verbatum(fw, "  GUID: %s", guid_str);
-	fwts_log_info_verbatum(fw, "  Attr: 0x%x (%s).", var->attributes, uefidump_attribute(var->attributes));
+	fwts_log_info_verbatum(fw, "  Attr: 0x%x (%s).", var->attributes, fwts_uefi_attribute_info(var->attributes));
 
 	/* If we've got an appropriate per variable dump mechanism, use this */
 	for (info = uefidump_info_table; info->description != NULL; info++) {