From a3b048b306eabd40716607b248f8894ba6b22dab Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Fri, 27 Feb 2015 16:26:35 +0800 Subject: [PATCH] btrfs-progs: Move parse_qgroupid() to utils.c Signed-off-by: Qu Wenruo [constified strings in parse_qgroupid] Signed-off-by: David Sterba --- qgroup.c | 28 ---------------------------- qgroup.h | 1 - utils.c | 28 ++++++++++++++++++++++++++++ utils.h | 1 + 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/qgroup.c b/qgroup.c index 388e382..abb4c6d 100644 --- 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]) * diff --git a/qgroup.h b/qgroup.h index 6e65ef7..22737fa 100644 --- 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 --- 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 --- 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); -- 2.7.4