On 27/09/16 17:57, Roger Pau Monne wrote:
> Introduce a new %pB format specifier to print sizes (in bytes) in a

Code suggests it is pZ.

> human-readable form.
> 
> Signed-off-by: Roger Pau Monné <roger....@citrix.com>
> ---
> Cc: Andrew Cooper <andrew.coop...@citrix.com>
> Cc: George Dunlap <george.dun...@eu.citrix.com>
> Cc: Ian Jackson <ian.jack...@eu.citrix.com>
> Cc: Jan Beulich <jbeul...@suse.com>
> Cc: Konrad Rzeszutek Wilk <konrad.w...@oracle.com>
> Cc: Stefano Stabellini <sstabell...@kernel.org>
> Cc: Tim Deegan <t...@xen.org>
> Cc: Wei Liu <wei.l...@citrix.com>
> ---
>  docs/misc/printk-formats.txt |  5 +++++
>  xen/common/vsprintf.c        | 15 +++++++++++++++
>  2 files changed, 20 insertions(+)
> 
> diff --git a/docs/misc/printk-formats.txt b/docs/misc/printk-formats.txt
> index 525108f..0ee3504 100644
> --- a/docs/misc/printk-formats.txt
> +++ b/docs/misc/printk-formats.txt
> @@ -30,3 +30,8 @@ Domain and vCPU information:
>  
>         %pv     Domain and vCPU ID from a 'struct vcpu *' (printed as
>                 "d<domid>v<vcpuid>")
> +
> +Size in human readable form:
> +
> +       %pZ     Size in human-readable form (input size must be in bytes).
> +                 e.g.  24MB
> diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c
> index f92fb67..2dadaec 100644
> --- a/xen/common/vsprintf.c
> +++ b/xen/common/vsprintf.c
> @@ -386,6 +386,21 @@ static char *pointer(char *str, char *end, const char 
> **fmt_ptr,
>              *str = 'v';
>          return number(str + 1, end, v->vcpu_id, 10, -1, -1, 0);
>      }
> +    case 'Z':
> +    {
> +        static const char units[][3] = {"B", "KB", "MB", "GB", "TB"};
> +        size_t size = (size_t)arg;
> +        int i = 0;
> +
> +        /* Advance parents fmt string, as we have consumed 'B' */
> +        ++*fmt_ptr;
> +
> +        while ( ++i < sizeof(units) && size >= 1024 )

sizeof(units) is 15. That's not what you want to check here.


Juergen

> +            size >>= 10; /* size /= 1024 */
> +
> +        str = number(str, end, size, 10, -1, -1, 0);
> +        return string(str, end, units[i-1], -1, -1, 0);
> +    }
>      }
>  
>      if ( field_width == -1 )
> 


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

Reply via email to