Signed-off-by: David Sterba <[email protected]>
---
 cmds-balance.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/cmds-balance.c b/cmds-balance.c
index 1fd8d2018b7a..457d693eec42 100644
--- a/cmds-balance.c
+++ b/cmds-balance.c
@@ -161,6 +161,37 @@ 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;
+}
+
+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;
-- 
2.6.1

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to