btrfs-progs: move check_arg_type() to util.c
authorGui Hecheng <guihc.fnst@cn.fujitsu.com>
Thu, 25 Dec 2014 01:16:34 +0000 (09:16 +0800)
committerDavid Sterba <dsterba@suse.cz>
Mon, 29 Dec 2014 17:10:58 +0000 (18:10 +0100)
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>
Signed-off-by: David Sterba <dsterba@suse.cz>
cmds-filesystem.c
utils.c
utils.h

index a654e6f..80875ff 100644 (file)
@@ -495,38 +495,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 1dba182..af0a8fe 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -855,6 +855,39 @@ int is_mount_point(const char *path)
 }
 
 /*
+ * 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 uuid;
+       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, uuid))
+               return BTRFS_ARG_UUID;
+
+       return BTRFS_ARG_UNKNOWN;
+}
+
+/*
  * Find the mount point for a mounted device.
  * On success, returns 0 with mountpoint in *mp.
  * On failure, returns -errno (not mounted yields -EINVAL)
diff --git a/utils.h b/utils.h
index 2480a21..3950491 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -118,6 +118,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 */