From patchwork Tue Oct 13 15:42:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Sterba X-Patchwork-Id: 7386341 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D7A8D9F1B9 for ; Tue, 13 Oct 2015 15:44:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 146F020827 for ; Tue, 13 Oct 2015 15:44:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2289120824 for ; Tue, 13 Oct 2015 15:44:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932514AbbJMPoB (ORCPT ); Tue, 13 Oct 2015 11:44:01 -0400 Received: from mx2.suse.de ([195.135.220.15]:38529 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932575AbbJMPnh (ORCPT ); Tue, 13 Oct 2015 11:43:37 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id CD3E5ABCC for ; Tue, 13 Oct 2015 15:43:34 +0000 (UTC) Received: by ds.suse.cz (Postfix, from userid 10065) id 2AA40DAB57; Tue, 13 Oct 2015 17:42:26 +0200 (CEST) From: David Sterba To: linux-btrfs@vger.kernel.org Cc: David Sterba Subject: [PATCH 3/7] btrfs-progs: add helpers for parsing 32bit ranges Date: Tue, 13 Oct 2015 17:42:26 +0200 Message-Id: <9232a2e4aac6c4b79124d06d047ebd7380b15104.1444750808.git.dsterba@suse.com> X-Mailer: git-send-email 2.6.1 In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: David Sterba --- cmds-balance.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/cmds-balance.c b/cmds-balance.c index 62bee3cc78b6..72714b23b45c 100644 --- a/cmds-balance.c +++ b/cmds-balance.c @@ -159,6 +159,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;