mirror of
https://github.com/kdave/btrfs-progs
synced 2025-02-03 03:11:46 +00:00
btrfs-progs: move parse_qgroupid to parse utils
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
cb5a542871
commit
47b04b747d
@ -276,3 +276,34 @@ int parse_bg_profile(const char *profile, u64 *flags)
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse qgroupid of format LEVEL/ID, level and id are numerical, nothing must
|
||||
* follow after the last character of ID.
|
||||
*/
|
||||
int parse_qgroupid(const char *str, u64 *qgroupid)
|
||||
{
|
||||
char *end = NULL;
|
||||
u64 level;
|
||||
u64 id;
|
||||
|
||||
level = strtoull(str, &end, 10);
|
||||
if (str == end)
|
||||
return -EINVAL;
|
||||
if (end[0] != '/')
|
||||
return -EINVAL;
|
||||
str = end + 1;
|
||||
end = NULL;
|
||||
id = strtoull(str, &end, 10);
|
||||
if (str == end)
|
||||
return -EINVAL;
|
||||
if (end[0])
|
||||
return -EINVAL;
|
||||
if (id >= (1ULL << BTRFS_QGROUP_LEVEL_SHIFT))
|
||||
return -ERANGE;
|
||||
if (level >= (1ULL << (64 - BTRFS_QGROUP_LEVEL_SHIFT)))
|
||||
return -ERANGE;
|
||||
|
||||
*qgroupid = (level << BTRFS_QGROUP_LEVEL_SHIFT) | id;
|
||||
return 0;
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ int parse_range(const char *range, u64 *start, u64 *end);
|
||||
int parse_range_strict(const char *range, u64 *start, u64 *end);
|
||||
int parse_bg_profile(const char *profile, u64 *flags);
|
||||
int parse_compress_type(const char *type);
|
||||
int parse_qgroupid(const char *str, u64 *qgroupid);
|
||||
int fls64(u64 x);
|
||||
|
||||
#endif
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include "common/utils.h"
|
||||
#include "common/path-utils.h"
|
||||
#include "common/device-scan.h"
|
||||
#include "common/parse-utils.h"
|
||||
#include "kernel-shared/volumes.h"
|
||||
#include "ioctl.h"
|
||||
#include "cmds/commands.h"
|
||||
@ -227,37 +228,6 @@ int set_label(const char *btrfs_dev, const char *label)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse qgroupid of format LEVEL/ID, level and id are numerical, nothing must
|
||||
* follow after the last character of ID.
|
||||
*/
|
||||
int parse_qgroupid(const char *str, u64 *qgroupid)
|
||||
{
|
||||
char *end = NULL;
|
||||
u64 level;
|
||||
u64 id;
|
||||
|
||||
level = strtoull(str, &end, 10);
|
||||
if (str == end)
|
||||
return -EINVAL;
|
||||
if (end[0] != '/')
|
||||
return -EINVAL;
|
||||
str = end + 1;
|
||||
end = NULL;
|
||||
id = strtoull(str, &end, 10);
|
||||
if (str == end)
|
||||
return -EINVAL;
|
||||
if (end[0])
|
||||
return -EINVAL;
|
||||
if (id >= (1ULL << BTRFS_QGROUP_LEVEL_SHIFT))
|
||||
return -ERANGE;
|
||||
if (level >= (1ULL << (64 - BTRFS_QGROUP_LEVEL_SHIFT)))
|
||||
return -ERANGE;
|
||||
|
||||
*qgroupid = (level << BTRFS_QGROUP_LEVEL_SHIFT) | id;
|
||||
return 0;
|
||||
}
|
||||
|
||||
u64 parse_qgroupid_or_path(const char *p)
|
||||
{
|
||||
enum btrfs_util_error err;
|
||||
|
Loading…
Reference in New Issue
Block a user