btrfs-progs: Move parse_qgroupid() to utils.c
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Fri, 27 Feb 2015 08:26:35 +0000 (16:26 +0800)
committerDavid Sterba <dsterba@suse.cz>
Mon, 23 Mar 2015 23:16:09 +0000 (00:16 +0100)
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[constified strings in parse_qgroupid]
Signed-off-by: David Sterba <dsterba@suse.cz>
qgroup.c
qgroup.h
utils.c
utils.h

index 388e382..abb4c6d 100644 (file)
--- a/qgroup.c
+++ b/qgroup.c
@@ -1249,34 +1249,6 @@ int btrfs_qgroup_parse_sort_string(char *opt_arg,
        return 0;
 }
 
-u64 parse_qgroupid(char *p)
-{
-       char *s = strchr(p, '/');
-       char *ptr_src_end = p + strlen(p);
-       char *ptr_parse_end = NULL;
-       u64 level;
-       u64 id;
-
-       if (!s) {
-               id = strtoull(p, &ptr_parse_end, 10);
-               if (ptr_parse_end != ptr_src_end)
-                       goto err;
-               return id;
-       }
-       level = strtoull(p, &ptr_parse_end, 10);
-       if (ptr_parse_end != s)
-               goto err;
-
-       id = strtoull(s+1, &ptr_parse_end, 10);
-       if (ptr_parse_end != ptr_src_end)
-               goto  err;
-
-       return (level << 48) | id;
-err:
-       fprintf(stderr, "ERROR:invalid qgroupid\n");
-       exit(-1);
-}
-
 int qgroup_inherit_size(struct btrfs_qgroup_inherit *p)
 {
        return sizeof(*p) + sizeof(p->qgroups[0]) *
index 6e65ef7..22737fa 100644 (file)
--- a/qgroup.h
+++ b/qgroup.h
@@ -93,7 +93,6 @@ void btrfs_qgroup_free_comparer_set(struct btrfs_qgroup_comparer_set *comp_set);
 int btrfs_qgroup_setup_comparer(struct btrfs_qgroup_comparer_set **comp_set,
                                enum btrfs_qgroup_comp_enum comparer,
                                int is_descending);
-u64 parse_qgroupid(char *p);
 int qgroup_inherit_size(struct btrfs_qgroup_inherit *p);
 int qgroup_inherit_add_group(struct btrfs_qgroup_inherit **inherit, char *arg);
 int qgroup_inherit_add_copy(struct btrfs_qgroup_inherit **inherit, char *arg,
diff --git a/utils.c b/utils.c
index 73edb39..ca8efca 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -1795,6 +1795,34 @@ u64 parse_size(char *s)
        return ret;
 }
 
+u64 parse_qgroupid(const char *p)
+{
+       char *s = strchr(p, '/');
+       const char *ptr_src_end = p + strlen(p);
+       char *ptr_parse_end = NULL;
+       u64 level;
+       u64 id;
+
+       if (!s) {
+               id = strtoull(p, &ptr_parse_end, 10);
+               if (ptr_parse_end != ptr_src_end)
+                       goto err;
+               return id;
+       }
+       level = strtoull(p, &ptr_parse_end, 10);
+       if (ptr_parse_end != s)
+               goto err;
+
+       id = strtoull(s + 1, &ptr_parse_end, 10);
+       if (ptr_parse_end != ptr_src_end)
+               goto  err;
+
+       return (level << BTRFS_QGROUP_LEVEL_SHIFT) | id;
+err:
+       fprintf(stderr, "ERROR: invalid qgroupid %s\n", p);
+       exit(-1);
+}
+
 int open_file_or_dir3(const char *fname, DIR **dirstream, int open_flags)
 {
        int ret;
diff --git a/utils.h b/utils.h
index 599b007..6a39ada 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -114,6 +114,7 @@ int pretty_size_snprintf(u64 size, char *str, size_t str_bytes, unsigned unit_mo
 int get_mountpt(char *dev, char *mntpt, size_t size);
 int btrfs_scan_block_devices(int run_ioctl);
 u64 parse_size(char *s);
+u64 parse_qgroupid(const char *p);
 u64 arg_strtou64(const char *str);
 int open_file_or_dir(const char *fname, DIR **dirstream);
 int open_file_or_dir3(const char *fname, DIR **dirstream, int open_flags);