From patchwork Mon Oct 29 17:53:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Goffredo Baroncelli X-Patchwork-Id: 1665091 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id BEA4D3FCF7 for ; Mon, 29 Oct 2012 17:53:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932145Ab2J2RxS (ORCPT ); Mon, 29 Oct 2012 13:53:18 -0400 Received: from mail-ee0-f46.google.com ([74.125.83.46]:37468 "EHLO mail-ee0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760057Ab2J2Rwo (ORCPT ); Mon, 29 Oct 2012 13:52:44 -0400 Received: by mail-ee0-f46.google.com with SMTP id b15so2229927eek.19 for ; Mon, 29 Oct 2012 10:52:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=hg6BxPD7N1d0/j/sJoee7M5xSuOt1gaBS/S2Ys/qpnA=; b=kRZzpFEzNPQPUOwpMU0tb+6Zbts46lvBu7qXQTPEzl6IRlJKQYrgCLRd6N7yRmplAV /lWatYPlNBOSuNw2m6KFsoTG1kClFaOR1H83mJ/RMA/LBccHptw7DB506hfPPc9oac/T c5m9egaVMGXeBtHJTQM4z/dV14g483mrUimCf8/wtJm4oXtoP4LOxgBunCXktbU/mXzI kl8SZWzNgCSVGSUNp+I8F6mWlXHFHawmyRKnsH//v+oAZhrdDHs3FbBQCrFS/SD3q0le Quhn8SDMRpFz8JN6pJkEASLTYpoMlMfMyUv4FheqamMIsC+3zoAz3VCSMnnSq5PfuuAR YPdA== Received: by 10.14.179.6 with SMTP id g6mr63363662eem.46.1351533163393; Mon, 29 Oct 2012 10:52:43 -0700 (PDT) Received: from venice..bhome (host103-133-static.242-95-b.business.telecomitalia.it. [95.242.133.103]) by mx.google.com with ESMTPS id k2sm24096182eep.15.2012.10.29.10.52.42 (version=SSLv3 cipher=OTHER); Mon, 29 Oct 2012 10:52:42 -0700 (PDT) From: Goffredo Baroncelli To: linux-btrfs@vger.kernel.org Cc: Stefan Behrens , Wang Sheng-Hui Subject: [PATCH 1/4] Move parse_size() to utils.[hc] Date: Mon, 29 Oct 2012 18:53:17 +0100 Message-Id: <1351533200-5703-2-git-send-email-kreijack@inwind.it> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1351533200-5703-1-git-send-email-kreijack@inwind.it> References: <1351533200-5703-1-git-send-email-kreijack@inwind.it> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Move the function from cmds-filesystem.c and mkfs.c to utils.c Signed-off-by: Goffredo Baroncelli --- cmds-filesystem.c | 26 -------------------------- mkfs.c | 31 ------------------------------- utils.c | 26 ++++++++++++++++++++++++++ utils.h | 2 ++ 4 files changed, 28 insertions(+), 57 deletions(-) diff --git a/cmds-filesystem.c b/cmds-filesystem.c index 9c43d35..507239a 100644 --- a/cmds-filesystem.c +++ b/cmds-filesystem.c @@ -311,32 +311,6 @@ static int cmd_sync(int argc, char **argv) return 0; } -static u64 parse_size(char *s) -{ - int len = strlen(s); - char c; - u64 mult = 1; - - if (!isdigit(s[len - 1])) { - c = tolower(s[len - 1]); - switch (c) { - case 'g': - mult *= 1024; - case 'm': - mult *= 1024; - case 'k': - mult *= 1024; - case 'b': - break; - default: - fprintf(stderr, "Unknown size descriptor %c\n", c); - exit(1); - } - s[len - 1] = '\0'; - } - return atoll(s) * mult; -} - static int parse_compress_type(char *s) { if (strcmp(optarg, "zlib") == 0) diff --git a/mkfs.c b/mkfs.c index 47f0c9c..ca850d9 100644 --- a/mkfs.c +++ b/mkfs.c @@ -54,37 +54,6 @@ struct directory_name_entry { struct list_head list; }; -static u64 parse_size(char *s) -{ - int len = strlen(s); - char c; - u64 mult = 1; - u64 ret; - - s = strdup(s); - - if (len && !isdigit(s[len - 1])) { - c = tolower(s[len - 1]); - switch (c) { - case 'g': - mult *= 1024; - case 'm': - mult *= 1024; - case 'k': - mult *= 1024; - case 'b': - break; - default: - fprintf(stderr, "Unknown size descriptor %c\n", c); - exit(1); - } - s[len - 1] = '\0'; - } - ret = atol(s) * mult; - free(s); - return ret; -} - static int make_root_dir(struct btrfs_root *root, int mixed) { struct btrfs_trans_handle *trans; diff --git a/utils.c b/utils.c index 205e667..705be7b 100644 --- a/utils.c +++ b/utils.c @@ -1220,3 +1220,29 @@ scan_again: return 0; } +u64 parse_size(char *s) +{ + int len = strlen(s); + char c; + u64 mult = 1; + + if (!isdigit(s[len - 1])) { + c = tolower(s[len - 1]); + switch (c) { + case 'g': + mult *= 1024; + case 'm': + mult *= 1024; + case 'k': + mult *= 1024; + case 'b': + break; + default: + fprintf(stderr, "Unknown size descriptor %c\n", c); + exit(1); + } + s[len - 1] = '\0'; + } + return atoll(s) * mult; +} + diff --git a/utils.h b/utils.h index 3a0368b..714fd7a 100644 --- a/utils.h +++ b/utils.h @@ -46,4 +46,6 @@ int check_label(char *input); int get_mountpt(char *dev, char *mntpt, size_t size); int btrfs_scan_block_devices(int run_ioctl); + +u64 parse_size(char *s); #endif