From patchwork Mon Jul 9 17:30:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Carrier X-Patchwork-Id: 1174221 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 4B197DFB7C for ; Mon, 9 Jul 2012 17:30:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751487Ab2GIRa1 (ORCPT ); Mon, 9 Jul 2012 13:30:27 -0400 Received: from mail-lb0-f174.google.com ([209.85.217.174]:47878 "EHLO mail-lb0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750981Ab2GIRa0 (ORCPT ); Mon, 9 Jul 2012 13:30:26 -0400 Received: by mail-lb0-f174.google.com with SMTP id gm6so20477019lbb.19 for ; Mon, 09 Jul 2012 10:30:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=jF9ErOuNkAF6b86faUc/DTLQ5zD//+be7fB3cEBWR+U=; b=lm9sXJmokLfRJvatyzXXrAzShbrt4nC3oj+coQJpRl+FBPBYE4uLZUCaCJTCv5Dc3k euNEPX3th55zuJxKuZSXcyRnpy981vo+mW3tSXdAmO7E5H61s3SQ47Mesh17M79tu0h2 8998pTwNpB3Nxk0Sl5Q6Ip5D5Tqvc/GyhCWUafJHPsAMCa9kN5nKvb7iePKtncks5Aeb 133VxhibJUQVcFD0KDwjVnWmOwykklu87MilUrOufv9D0pKfNuJZv2qme/IPzCVS7aYB tieblv2fJO73uEl+HRwJRyTJorbhzs24NT2b8lD6frKX6uS/1r6BCgUXI7RF9/AYRduV R2iQ== Received: by 10.152.111.200 with SMTP id ik8mr41232877lab.15.1341855025520; Mon, 09 Jul 2012 10:30:25 -0700 (PDT) Received: from bar.spotify.net (155.60.236.194.office.spotify.net. [194.236.60.155]) by mx.google.com with ESMTPS id d3sm16749659lbh.3.2012.07.09.10.30.24 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 09 Jul 2012 10:30:24 -0700 (PDT) From: Pierre Carrier To: linux-btrfs@vger.kernel.org Cc: Pierre Carrier Subject: [PATCH 2/2] utils.c: offer to limit divisions in pretty_sizes Date: Mon, 9 Jul 2012 17:30:21 +0000 Message-Id: <1341855021-14551-1-git-send-email-pierre@spotify.com> X-Mailer: git-send-email 1.7.11.1 In-Reply-To: <1341853347-11788-3-git-send-email-pierre@spotify.com> References: <1341853347-11788-3-git-send-email-pierre@spotify.com> X-Gm-Message-State: ALoCoQmOEH6Dw3xgwTQifjs68tkf2bdVvRl6LmkCO0OihypYnGSnhIwFk49sHq9GeYDOS0yDFHwq Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Dirty hack to allow inspection of sizes in lower units. Useful to know the minimum size a partition shoud be resized to after a 'btrfs filesystem resize'. Label: 'home' uuid: 10453c4c-1c5b-4df5-b4a5-43a7f377430a Total devices 1 FS bytes used 42.80GB devid 1 size 62.16GB used 62.16GB path /dev/sda5 Label: 'home' uuid: 10453c4c-1c5b-4df5-b4a5-43a7f377430a Total devices 1 FS bytes used 44884524.00KB devid 1 size 65182236.00KB used 65182208.00KB path /dev/sda5 Signed-off-by: Pierre Carrier diff --git a/utils.c b/utils.c index 937e763..3f0b7e7 100644 --- a/utils.c +++ b/utils.c @@ -1096,13 +1096,18 @@ static char *size_strs[] = { "", "KB", "MB", "GB", "TB", char *pretty_sizes(u64 size) { int num_divs = 0; + int max_divs = INT_MAX; int pretty_len = 16; u64 last_size = size; u64 fract_size = size; float fraction; char *pretty; + char *max_divs_s; - while(size > 0) { + if (max_divs_s = getenv("MAX_DIVS")) + max_divs = atoi(max_divs_s); + + while(size > 0 && num_divs <= max_divs) { fract_size = last_size; last_size = size; size /= 1024; @@ -1117,7 +1122,6 @@ char *pretty_sizes(u64 size) if (num_divs > ARRAY_SIZE(size_strs)) return NULL; - pretty = malloc(pretty_len); if (!pretty) return NULL;