All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@sandeen.net>
To: "Darrick J. Wong" <darrick.wong@oracle.com>, sandeen@redhat.com
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH 02/10] xfs_io: refactor numlen into a library function
Date: Tue, 13 Jun 2017 16:09:36 -0500	[thread overview]
Message-ID: <4956641d-dbe9-9d99-552b-ddeacb0a3e61@sandeen.net> (raw)
In-Reply-To: <149643308671.15899.17508642888971207526.stgit@birch.djwong.org>

On 6/2/17 2:51 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Refactor the competing numlen implementations into a single library function.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>


yay!

Reviewed-by: Eric Sandeen <sandeen@redhat.com>

> ---
>  include/input.h |    1 +
>  io/bmap.c       |   19 ++++---------------
>  io/fiemap.c     |   14 +-------------
>  libxcmd/input.c |   13 +++++++++++++
>  4 files changed, 19 insertions(+), 28 deletions(-)
> 
> 
> diff --git a/include/input.h b/include/input.h
> index 221678e..82cd2f4 100644
> --- a/include/input.h
> +++ b/include/input.h
> @@ -28,6 +28,7 @@ extern char	**breakline(char *input, int *count);
>  extern void	doneline(char *input, char **vec);
>  extern char	*fetchline(void);
>  
> +extern size_t numlen(uint64_t val, size_t base);
>  extern long long cvtnum(size_t blocksize, size_t sectorsize, char *s);
>  extern void	cvtstr(double value, char *str, size_t sz);
>  extern unsigned long cvttime(char *s);
> diff --git a/io/bmap.c b/io/bmap.c
> index 2333244..2e4ff7b 100644
> --- a/io/bmap.c
> +++ b/io/bmap.c
> @@ -18,6 +18,7 @@
>  
>  #include "platform_defs.h"
>  #include "command.h"
> +#include "input.h"
>  #include "init.h"
>  #include "io.h"
>  
> @@ -53,18 +54,6 @@ bmap_help(void)
>  "\n"));
>  }
>  
> -static int
> -numlen(
> -	off64_t	val)
> -{
> -	off64_t	tmp;
> -	int	len;
> -
> -	for (len = 0, tmp = val; tmp > 0; tmp = tmp/10)
> -		len++;
> -	return (len == 0 ? 1 : len);
> -}
> -
>  int
>  bmap_f(
>  	int			argc,
> @@ -323,7 +312,7 @@ bmap_f(
>  			if (map[i + 1].bmv_block == -1) {
>  				foff_w = max(foff_w, strlen(rbuf));
>  				tot_w = max(tot_w,
> -					numlen(map[i+1].bmv_length));
> +					numlen(map[i+1].bmv_length, 10));
>  			} else {
>  				snprintf(bbuf, sizeof(bbuf), "%lld..%lld",
>  					(long long) map[i + 1].bmv_block,
> @@ -344,10 +333,10 @@ bmap_f(
>  					aoff_w = 0;
>  				foff_w = max(foff_w, strlen(rbuf));
>  				tot_w = max(tot_w,
> -					numlen(map[i+1].bmv_length));
> +					numlen(map[i+1].bmv_length, 10));
>  			}
>  		}
> -		agno_w = is_rt ? 0 : max(MINAG_WIDTH, numlen(fsgeo.agcount));
> +		agno_w = is_rt ? 0 : max(MINAG_WIDTH, numlen(fsgeo.agcount, 10));
>  		printf("%4s: %-*s %-*s %*s %-*s %*s%s\n",
>  			_("EXT"),
>  			foff_w, _("FILE-OFFSET"),
> diff --git a/io/fiemap.c b/io/fiemap.c
> index bcbae49..75e8820 100644
> --- a/io/fiemap.c
> +++ b/io/fiemap.c
> @@ -18,6 +18,7 @@
>  
>  #include "platform_defs.h"
>  #include "command.h"
> +#include "input.h"
>  #include <linux/fiemap.h>
>  #include "init.h"
>  #include "io.h"
> @@ -48,19 +49,6 @@ fiemap_help(void)
>  "\n"));
>  }
>  
> -static int
> -numlen(
> -	__u64	val,
> -	int	base)
> -{
> -	__u64	tmp;
> -	int	len;
> -
> -	for (len = 0, tmp = val; tmp > 0; tmp = tmp/base)
> -		len++;
> -	return (len == 0 ? 1 : len);
> -}
> -
>  static void
>  print_verbose(
>  	struct fiemap_extent	*extent,
> diff --git a/libxcmd/input.c b/libxcmd/input.c
> index 8aeb3b0..9437be3 100644
> --- a/libxcmd/input.c
> +++ b/libxcmd/input.c
> @@ -136,6 +136,19 @@ doneline(
>  	free(vec);
>  }
>  
> +size_t
> +numlen(
> +	uint64_t	val,
> +	size_t		base)
> +{
> +	uint64_t	tmp;
> +	size_t		len;
> +
> +	for (len = 0, tmp = val; tmp > 0; tmp = tmp / base)
> +		len++;
> +	return len == 0 ? 1 : len;
> +}
> +
>  #define EXABYTES(x)	((long long)(x) << 60)
>  #define PETABYTES(x)	((long long)(x) << 50)
>  #define TERABYTES(x)	((long long)(x) << 40)
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

  reply	other threads:[~2017-06-13 21:09 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-02 19:51 [PATCH v8 00/10] xfsprogs 4.12: GETFSMAP support Darrick J. Wong
2017-06-02 19:51 ` [PATCH 01/10] xfs: introduce the XFS_IOC_GETFSMAP ioctl Darrick J. Wong
2017-06-02 19:51 ` [PATCH 02/10] xfs_io: refactor numlen into a library function Darrick J. Wong
2017-06-13 21:09   ` Eric Sandeen [this message]
2017-06-02 19:51 ` [PATCH 03/10] xfs_io: support the new getfsmap ioctl Darrick J. Wong
2017-06-13 22:20   ` Eric Sandeen
2017-06-14  0:23     ` Darrick J. Wong
2017-06-02 19:51 ` [PATCH 04/10] xfs_repair: replace rmap_compare with libxfs version Darrick J. Wong
2017-06-13 22:34   ` Eric Sandeen
2017-06-02 19:51 ` [PATCH 05/10] xfs_spaceman: space management tool Darrick J. Wong
2017-06-14 14:15   ` Eric Sandeen
2017-06-14 16:16     ` Darrick J. Wong
2017-06-02 19:51 ` [PATCH 06/10] xfs_spaceman: add FITRIM support Darrick J. Wong
2017-06-14 15:32   ` Eric Sandeen
2017-06-14 16:32     ` Darrick J. Wong
2017-06-02 19:51 ` [PATCH 07/10] xfs_spaceman: add new speculative prealloc control Darrick J. Wong
2017-06-14 15:05   ` Eric Sandeen
2017-06-14 16:39     ` Darrick J. Wong
2017-06-02 19:52 ` [PATCH 08/10] xfs_spaceman: Free space mapping command Darrick J. Wong
2017-06-14 15:43   ` Eric Sandeen
2017-06-14 16:43     ` Darrick J. Wong
2017-06-14 16:04   ` Eric Sandeen
2017-06-14 16:57     ` Darrick J. Wong
2017-06-02 19:52 ` [PATCH 09/10] xfs_spaceman: add a man page Darrick J. Wong
2017-06-14 16:06   ` Eric Sandeen
2017-06-14 20:49     ` Darrick J. Wong
2017-06-02 19:52 ` [PATCH 10/10] xfs_spaceman: add group summary mode Darrick J. Wong
2017-06-14 16:23   ` Eric Sandeen
2017-06-14 17:22     ` Darrick J. Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4956641d-dbe9-9d99-552b-ddeacb0a3e61@sandeen.net \
    --to=sandeen@sandeen.net \
    --cc=darrick.wong@oracle.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.