mirror of
https://github.com/kdave/btrfs-progs
synced 2025-01-12 08:49:33 +00:00
btrfs-progs: extend parse_range API to accept a relaxed range
In some cases we want to accept a range of type [a..a]. Add a new function to do the 'a < b' check for the caller and use it. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
2b7f0192e8
commit
be85a75fec
@ -128,9 +128,10 @@ static int parse_range(const char *range, u64 *start, u64 *end)
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (*start >= *end) {
|
||||
fprintf(stderr, "Range %llu..%llu doesn't make "
|
||||
"sense\n", (unsigned long long)*start,
|
||||
if (*start > *end) {
|
||||
fprintf(stderr,
|
||||
"ERROR: range %llu..%llu doesn't make sense\n",
|
||||
(unsigned long long)*start,
|
||||
(unsigned long long)*end);
|
||||
return 1;
|
||||
}
|
||||
@ -141,6 +142,25 @@ static int parse_range(const char *range, u64 *start, u64 *end)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parse range and check if start < end
|
||||
*/
|
||||
static int parse_range_strict(const char *range, u64 *start, u64 *end)
|
||||
{
|
||||
if (parse_range(range, start, end) == 0) {
|
||||
if (*start >= *end) {
|
||||
fprintf(stderr,
|
||||
"ERROR: range %llu..%llu not allowed\n",
|
||||
(unsigned long long)*start,
|
||||
(unsigned long long)*end);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int parse_filters(char *filters, struct btrfs_balance_args *args)
|
||||
{
|
||||
char *this_char;
|
||||
@ -198,7 +218,7 @@ static int parse_filters(char *filters, struct btrfs_balance_args *args)
|
||||
"an argument\n");
|
||||
return 1;
|
||||
}
|
||||
if (parse_range(value, &args->pstart, &args->pend)) {
|
||||
if (parse_range_strict(value, &args->pstart, &args->pend)) {
|
||||
fprintf(stderr, "Invalid drange argument\n");
|
||||
return 1;
|
||||
}
|
||||
@ -209,7 +229,7 @@ static int parse_filters(char *filters, struct btrfs_balance_args *args)
|
||||
"an argument\n");
|
||||
return 1;
|
||||
}
|
||||
if (parse_range(value, &args->vstart, &args->vend)) {
|
||||
if (parse_range_strict(value, &args->vstart, &args->vend)) {
|
||||
fprintf(stderr, "Invalid vrange argument\n");
|
||||
return 1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user