summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2015-10-13 16:34:33 +0200
committerDavid Sterba <dsterba@suse.com>2015-11-02 09:35:04 +0100
commitd0d2b43e71ec2f947e688aa5d979f8f0c0841f6d (patch)
treef58ccc106771b2a81a9ad469a95d3fde1d5de4b4
parentbe85a75fece2fc226b3ef4d81bd1918c2002cc96 (diff)
btrfs-progs: add helpers for parsing 32bit ranges
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--cmds-balance.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/cmds-balance.c b/cmds-balance.c
index 053cd9b5..1fd40e4e 100644
--- a/cmds-balance.c
+++ b/cmds-balance.c
@@ -161,6 +161,38 @@ static int parse_range_strict(const char *range, u64 *start, u64 *end)
return 1;
}
+/*
+ * Convert 64bit range to 32bit with boundary checkso
+ */
+static int range_to_u32(u64 start, u64 end, u32 *start32, u32 *end32)
+{
+ if (start > (u32)-1)
+ return 1;
+
+ if (end != (u64)-1 && end > (u32)-1)
+ return 1;
+
+ *start32 = (u32)start;
+ *end32 = (u32)end;
+
+ return 0;
+}
+
+__attribute__ ((unused))
+static int parse_range_u32(const char *range, u32 *start, u32 *end)
+{
+ u64 tmp_start;
+ u64 tmp_end;
+
+ if (parse_range(range, &tmp_start, &tmp_end))
+ return 1;
+
+ if (range_to_u32(tmp_start, tmp_end, start, end))
+ return 1;
+
+ return 0;
+}
+
static int parse_filters(char *filters, struct btrfs_balance_args *args)
{
char *this_char;