From patchwork Mon Jul 9 17:02:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Carrier X-Patchwork-Id: 1174111 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 5B0E540B21 for ; Mon, 9 Jul 2012 17:02:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752418Ab2GIRCw (ORCPT ); Mon, 9 Jul 2012 13:02:52 -0400 Received: from mail-bk0-f46.google.com ([209.85.214.46]:41149 "EHLO mail-bk0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751191Ab2GIRCv (ORCPT ); Mon, 9 Jul 2012 13:02:51 -0400 Received: by bkwj10 with SMTP id j10so6229401bkw.19 for ; Mon, 09 Jul 2012 10:02:50 -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=2MDQ1GjdSwotsfy+1oSi5sxD4IgsfwTZalrYDWVi/Hs=; b=TzjPJQfVSjqPIalquinwQuqJLh8I01mxBe+P3bhEOoSG4iWKoQcOC+B56NbOw7GMPs lanrHUYmzREJN2lkvwQ2OYb/prUditC+tpkoYxAC5f9ACuPdNcrIV3hx5KXRrocoPekJ mWGY6Y+a6XhCH5y/knNAUkAp36cBRlApoSPaJf2BETU+/rzhZVLLNnDLsUXdMrHIOy60 +92A+QQoAgUKDljpBhL0skzy2Or6Si9/ah0AzYIjGkRuw8B8m1j0f3ApPD+HVqXwKoCy j4L2z8yZDPreY0VmiTQoI/wAVB7i6MGxu3Nfy6f5vzpM+gbqKHBJmplvIzH8GW6oq0ZF IIqQ== Received: by 10.152.104.77 with SMTP id gc13mr35339660lab.31.1341853370174; Mon, 09 Jul 2012 10:02:50 -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 sy1sm47813914lab.13.2012.07.09.10.02.48 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 09 Jul 2012 10:02:49 -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:02:27 +0000 Message-Id: <1341853347-11788-3-git-send-email-pierre@spotify.com> X-Mailer: git-send-email 1.7.11.1 In-Reply-To: <1341853347-11788-1-git-send-email-pierre@spotify.com> References: <1341853347-11788-1-git-send-email-pierre@spotify.com> X-Gm-Message-State: ALoCoQlY8pgUD1a0q469uQFdG92HdqGfSrq0Yi6jfV2PNELPNNJ9FU0KjZm3SAxVIOSouDf90XnN 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 dde0513..e660799 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;