diff mbox

[2/2] utils.c: offer to limit divisions in pretty_sizes

Message ID 1341855021-14551-1-git-send-email-pierre@spotify.com (mailing list archive)
State New, archived
Headers show

Commit Message

Pierre Carrier July 9, 2012, 5:30 p.m. UTC
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 <pierre@spotify.com>

Comments

David Sterba July 17, 2012, 12:58 p.m. UTC | #1
On Mon, Jul 09, 2012 at 05:30:21PM +0000, Pierre Carrier wrote:
> Dirty hack to allow inspection of sizes in lower units.

A commandline option would suit better IMHO. If this is a one-shot task
to find the sizes expressed with a different multiplier, then I don't
understhand the env variable approach. If it's meant to express all
size-related numbers with a given multiplier, than it could make sense,
but it has to be well documented and possibly a better variable name
picked.

Hugo referenced one of his patches,
http://www.mail-archive.com/linux-btrfs@vger.kernel.org/msg06518.html
that adds -h or -H (1024-based and SI-based), but that does not fix the
problem that you want to se a specific size. So, I'm suggesting a
generic option

--units=PFX

where PFX can be arbitrary from KB, KiB and the rest of the list. Plus a
way to include the human-readable forms, both 1024- and SI-based.


david
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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;