forked from Mirrors/btrfs-progs
Btrfs-progs: clean up reduplicate parse_qgroupid() and replace atoi with strtoull
1. parse_qgroupid() is implemented twice, clean up the reduplicate code. 2. atoi() can not detect errors, so use strtoull() instead of it. Signed-off-by: Wang Shilong <wangsl-fnst@cn.fujitsu.com> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Gene Czarcinski <gene@czarc.net>master
parent
f933e084ea
commit
9886166880
|
@ -24,26 +24,13 @@
|
||||||
#include "ioctl.h"
|
#include "ioctl.h"
|
||||||
|
|
||||||
#include "commands.h"
|
#include "commands.h"
|
||||||
|
#include "qgroup.h"
|
||||||
|
|
||||||
static const char * const qgroup_cmd_group_usage[] = {
|
static const char * const qgroup_cmd_group_usage[] = {
|
||||||
"btrfs qgroup <command> [options] <path>",
|
"btrfs qgroup <command> [options] <path>",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
static u64 parse_qgroupid(char *p)
|
|
||||||
{
|
|
||||||
char *s = strchr(p, '/');
|
|
||||||
u64 level;
|
|
||||||
u64 id;
|
|
||||||
|
|
||||||
if (!s)
|
|
||||||
return atoll(p);
|
|
||||||
level = atoll(p);
|
|
||||||
id = atoll(s + 1);
|
|
||||||
|
|
||||||
return (level << 48) | id;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int qgroup_assign(int assign, int argc, char **argv)
|
static int qgroup_assign(int assign, int argc, char **argv)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
22
qgroup.c
22
qgroup.c
|
@ -22,15 +22,29 @@
|
||||||
u64 parse_qgroupid(char *p)
|
u64 parse_qgroupid(char *p)
|
||||||
{
|
{
|
||||||
char *s = strchr(p, '/');
|
char *s = strchr(p, '/');
|
||||||
|
char *ptr_src_end = p + strlen(p);
|
||||||
|
char *ptr_parse_end = NULL;
|
||||||
u64 level;
|
u64 level;
|
||||||
u64 id;
|
u64 id;
|
||||||
|
|
||||||
if (!s)
|
if (!s) {
|
||||||
return atoll(p);
|
id = strtoull(p, &ptr_parse_end, 10);
|
||||||
level = atoll(p);
|
if (ptr_parse_end != ptr_src_end)
|
||||||
id = atoll(s + 1);
|
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;
|
return (level << 48) | id;
|
||||||
|
err:
|
||||||
|
fprintf(stderr, "ERROR:invalid qgroupid\n");
|
||||||
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int qgroup_inherit_size(struct btrfs_qgroup_inherit *p)
|
int qgroup_inherit_size(struct btrfs_qgroup_inherit *p)
|
||||||
|
|
2
qgroup.h
2
qgroup.h
|
@ -20,7 +20,9 @@
|
||||||
#define _BTRFS_QGROUP_H
|
#define _BTRFS_QGROUP_H
|
||||||
|
|
||||||
#include "ioctl.h"
|
#include "ioctl.h"
|
||||||
|
#include "kerncompat.h"
|
||||||
|
|
||||||
|
u64 parse_qgroupid(char *p);
|
||||||
int qgroup_inherit_size(struct btrfs_qgroup_inherit *p);
|
int qgroup_inherit_size(struct btrfs_qgroup_inherit *p);
|
||||||
int qgroup_inherit_realloc(struct btrfs_qgroup_inherit **inherit,
|
int qgroup_inherit_realloc(struct btrfs_qgroup_inherit **inherit,
|
||||||
int incgroups, int inccopies);
|
int incgroups, int inccopies);
|
||||||
|
|
Loading…
Reference in New Issue