linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>
To: Gui Hecheng <guihc.fnst@cn.fujitsu.com>,
	"linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Subject: Re: [PATCH 1/2] btrfs-progs: move check_arg_type() to util.c
Date: Thu, 25 Dec 2014 15:43:52 +0900	[thread overview]
Message-ID: <549BB228.5040007@jp.fujitsu.com> (raw)
In-Reply-To: <1419470195-2889-1-git-send-email-guihc.fnst@cn.fujitsu.com>

On 2014/12/25 10:16, Gui Hecheng wrote:
> The check_arg_type() function does quite generic thing,
> move it to utils.c.
> 
> Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>

Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com>

> ---
>   cmds-filesystem.c | 32 --------------------------------
>   utils.c           | 32 ++++++++++++++++++++++++++++++++
>   utils.h           |  1 +
>   3 files changed, 33 insertions(+), 32 deletions(-)
> 
> diff --git a/cmds-filesystem.c b/cmds-filesystem.c
> index 253f105..4d7a797 100644
> --- a/cmds-filesystem.c
> +++ b/cmds-filesystem.c
> @@ -537,38 +537,6 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info,
>   	return 0;
>   }
>   
> -/* This function checks if the given input parameter is
> - * an uuid or a path
> - * return -1: some error in the given input
> - * return 0: unknow input
> - * return 1: given input is uuid
> - * return 2: given input is path
> - */
> -static int check_arg_type(char *input)
> -{
> -	uuid_t	out;
> -	char path[PATH_MAX];
> -
> -	if (!input)
> -		return -EINVAL;
> -
> -	if (realpath(input, path)) {
> -		if (is_block_device(path) == 1)
> -			return BTRFS_ARG_BLKDEV;
> -
> -		if (is_mount_point(path) == 1)
> -			return BTRFS_ARG_MNTPOINT;
> -
> -		return BTRFS_ARG_UNKNOWN;
> -	}
> -
> -	if (strlen(input) == (BTRFS_UUID_UNPARSED_SIZE - 1) &&
> -		!uuid_parse(input, out))
> -		return BTRFS_ARG_UUID;
> -
> -	return BTRFS_ARG_UNKNOWN;
> -}
> -
>   static int btrfs_scan_kernel(void *search)
>   {
>   	int ret = 0, fd;
> diff --git a/utils.c b/utils.c
> index 2a92416..80f85e9 100644
> --- a/utils.c
> +++ b/utils.c
> @@ -852,6 +852,38 @@ int is_mount_point(const char *path)
>   	return ret;
>   }
>   
> +/* This function checks if the given input parameter is
> + * an uuid or a path
> + * return -1: some error in the given input
> + * return 0: unknow input
> + * return 1: given input is uuid
> + * return 2: given input is path
> + */
> +int check_arg_type(const char *input)
> +{
> +	uuid_t	out;
> +	char path[PATH_MAX];
> +
> +	if (!input)
> +		return -EINVAL;
> +
> +	if (realpath(input, path)) {
> +		if (is_block_device(path) == 1)
> +			return BTRFS_ARG_BLKDEV;
> +
> +		if (is_mount_point(path) == 1)
> +			return BTRFS_ARG_MNTPOINT;
> +
> +		return BTRFS_ARG_UNKNOWN;
> +	}
> +
> +	if (strlen(input) == (BTRFS_UUID_UNPARSED_SIZE - 1) &&
> +		!uuid_parse(input, out))
> +		return BTRFS_ARG_UUID;
> +
> +	return BTRFS_ARG_UNKNOWN;
> +}
> +
>   /*
>    * Find the mount point for a mounted device.
>    * On success, returns 0 with mountpoint in *mp.
> diff --git a/utils.h b/utils.h
> index 289e86b..8d67720 100644
> --- a/utils.h
> +++ b/utils.h
> @@ -115,6 +115,7 @@ int set_label(const char *btrfs_dev, const char *label);
>   char *__strncpy__null(char *dest, const char *src, size_t n);
>   int is_block_device(const char *file);
>   int is_mount_point(const char *file);
> +int check_arg_type(const char *input);
>   int open_path_or_dev_mnt(const char *path, DIR **dirstream);
>   u64 btrfs_device_size(int fd, struct stat *st);
>   /* Helper to always get proper size of the destination string */
> 


      parent reply	other threads:[~2014-12-25  6:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-25  1:16 [PATCH 1/2] btrfs-progs: move check_arg_type() to util.c Gui Hecheng
2014-12-25  1:16 ` [PATCH 2/2] btrfs-progs: refine btrfs-debug-tree error prompt when a mount point given Gui Hecheng
2014-12-25  6:49   ` Satoru Takeuchi
2014-12-25  7:23     ` Gui Hecheng
2014-12-29 16:29   ` David Sterba
2014-12-25  6:43 ` Satoru Takeuchi [this message]

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=549BB228.5040007@jp.fujitsu.com \
    --to=takeuchi_satoru@jp.fujitsu.com \
    --cc=guihc.fnst@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).